From fe9642dd17539fa26f024c9cf5525fda5f01bef7 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 14 Feb 2013 13:54:40 -0800 Subject: [PATCH] CSPACE-5887: Allow event listener to 'null out' computedCurrentLocation value in Cataloging / CollectionObject if that value is blank / null in most recent related Movement record. --- .../listener/UpdateObjectLocationOnMove.java | 39 ++--- .../listener/listener-update-object-loc.xml | 68 +++++++++ ...ionobject-without-current-location.res.xml | 139 ++++++++++++++++++ 3 files changed, 228 insertions(+), 18 deletions(-) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/collectionobject-without-current-location.res.xml diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java index 80ead39ad..c6b9efdd8 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java @@ -1,5 +1,6 @@ package org.collectionspace.services.listener; +import java.io.Serializable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.collectionspace.services.common.api.RefNameUtils; @@ -28,23 +29,18 @@ public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValu DocumentModel movementDocModel) throws ClientException { - // Get the current location value from the Movement. + // Get the current location value from the Movement (the "new" value) String currentLocationRefName = (String) movementDocModel.getProperty(MOVEMENTS_COMMON_SCHEMA, CURRENT_LOCATION_PROPERTY); // Check that the value returned, which is expected to be a // reference (refName) to an authority term (such as a storage - // location or organization term) is, at a minimum: + // location or organization term): // - // * Non-null and non-blank. - // (Note: we need to verify this assumption; can a CollectionObject's - // computed current location value ever meaningfully be 'un-set' - // by returning it to a null value?) - // - // * Capable of being successfully parsed by an authority item parser; - // that is, returning a non-null parse result. - if ((Tools.isBlank(currentLocationRefName) - || (RefNameUtils.parseAuthorityTermInfo(currentLocationRefName) == null))) { + // * If it is not blank ... + // * Is then capable of being successfully parsed by an authority item parser. + if ((Tools.notBlank(currentLocationRefName) + && (RefNameUtils.parseAuthorityTermInfo(currentLocationRefName) == null))) { logger.warn("Could not parse current location refName '" + currentLocationRefName + "'"); return collectionObjectDocModel; } else { @@ -53,9 +49,9 @@ public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValu logger.trace("currentLocation refName=" + currentLocationRefName); } } - // If the value returned from the function passes validation, - // compare it to the value in the computed current location - // field of the CollectionObject. + + // Get the computed current location value of the CollectionObject + // (the "existing" value) String existingComputedCurrentLocationRefName = (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_COMMON_SCHEMA, COMPUTED_CURRENT_LOCATION_PROPERTY); @@ -63,16 +59,23 @@ public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValu logger.trace("Existing computedCurrentLocation refName=" + existingComputedCurrentLocationRefName); } - // If the CollectionObject lacks a computed current location value, - // or if the new value differs from its existing value ... - if (Tools.isBlank(existingComputedCurrentLocationRefName) + // If the new value is blank, the existing value should always be + // overwritten ('nulled out') with a blank value. + if (Tools.isBlank(currentLocationRefName)) { + collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_COMMON_SCHEMA, + COMPUTED_CURRENT_LOCATION_PROPERTY, (Serializable) null); + // Otherwise, if the existing value is blank, or if the new value + // is different than the existing value ... + } else if (Tools.isBlank(existingComputedCurrentLocationRefName) || (!currentLocationRefName.equals(existingComputedCurrentLocationRefName))) { if (logger.isTraceEnabled()) { logger.trace("computedCurrentLocation refName requires updating."); } - // ... update that value. + // ... update the existing value in the CollectionObject with the + // new value from the Movement. collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_COMMON_SCHEMA, COMPUTED_CURRENT_LOCATION_PROPERTY, currentLocationRefName); + } else { if (logger.isTraceEnabled()) { logger.trace("computedCurrentLocation refName does NOT require updating."); diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml index 5e63e6436..c45d2138e 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml @@ -333,8 +333,76 @@ 200 + + PUT + /cspace-services/movements/${createMovement2.CSID} + listener/movement.xml + + + 1800-02-01 + + 200 + + + + + + + PUT + /cspace-services/movements/${createMovement2.CSID} + listener/movement.xml + + urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Ottawa1358215545567)'Ottawa, ON, Canada' + 1800-02-01 + + 200 + + + + GET + /cspace-services/collectionobjects/${createCollectionObject1.CSID} + + + listener/res/collectionobject.res.xml + + ${updateMovement3WithNonBlankCurrentLocation.currentLocation} + + + 200 + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/collectionobject-without-current-location.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/collectionobject-without-current-location.res.xml new file mode 100644 index 000000000..6ff9d0ea2 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/collectionobject-without-current-location.res.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + objectNumber + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.47.3