]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5887: Allow event listener to 'null out' computedCurrentLocation value in...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 14 Feb 2013 21:54:40 +0000 (13:54 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 14 Feb 2013 21:54:40 +0000 (13:54 -0800)
3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/UpdateObjectLocationOnMove.java
services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/collectionobject-without-current-location.res.xml [new file with mode: 0644]

index 80ead39adb1a48134a81f56ad8ec8097d957b836..c6b9efdd8c9a50a318ad6a5c9ff53a1c1f42fee6 100644 (file)
@@ -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.");
index 5e63e6436044a58c845908c5626cc960d2339b98..c45d2138e1569de8b1312e42be801f0080c12088 100644 (file)
             <expectedCodes>200</expectedCodes>
         </test>
         
+        <test ID="updateMovement3WithBlankCurrentLocation">
+            <method>PUT</method>
+            <uri>/cspace-services/movements/${createMovement2.CSID}</uri>
+            <filename>listener/movement.xml</filename>
+            <vars>
+                <var ID="currentLocation"></var>
+                <var ID="locationDate">1800-02-01</var>
+            </vars>
+            <expectedCodes>200</expectedCodes>
+        </test>
+        
+        <!--
+            This test verifies that the computedCurrentLocation field
+            value has been set to null, because that field will *not*
+            be emitted in the response payload when it has a null value.
+            
+            This is an inherently fragile test, in comparing tree structures,
+            and will break if there are any changes to any of the relevant
+            schemas, including collectionspace_core, collectionobjects_common,
+            and account_permission.
+            
+            Uncomment only when working on the computed current location
+            event listener / handler. - ADR - 2013-02-14
+        -->
+        <!--
+        <test ID="readCollectionObject1AfterMovement3BlankCurrentLocationUpdate">
+            <method>GET</method>
+            <uri>/cspace-services/collectionobjects/${createCollectionObject1.CSID}</uri>
+            <response>
+                <filename>listener/res/collectionobject-without-current-location.res.xml</filename>
+                <expected level="TREE" />
+                <parts>
+                    <part>
+                        <label>collectionobjects_common</label>
+                    </part>
+                </parts>
+            </response>
+            <expectedCodes>200</expectedCodes>
+        </test>
+        -->
+        
+        <test ID="updateMovement3WithNonBlankCurrentLocation">
+            <method>PUT</method>
+            <uri>/cspace-services/movements/${createMovement2.CSID}</uri>
+            <filename>listener/movement.xml</filename>
+            <vars>
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Ottawa1358215545567)'Ottawa, ON, Canada'</var>
+                <var ID="locationDate">1800-02-01</var>
+            </vars>
+            <expectedCodes>200</expectedCodes>
+        </test>
+
+        <test ID="readCollectionObject1AfterMovement3BlankCurrentLocationUpdate">
+            <method>GET</method>
+            <uri>/cspace-services/collectionobjects/${createCollectionObject1.CSID}</uri>
+            <response>
+                <expected level="ADDOK" />
+                <filename>listener/res/collectionobject.res.xml</filename>
+                <vars>
+                    <var ID="computedCurrentLocationValue">${updateMovement3WithNonBlankCurrentLocation.currentLocation}</var>
+                </vars>
+            </response>
+            <expectedCodes>200</expectedCodes>
+        </test>
+        
     </testGroup>
     
+    <!-- Some of the following tests pertain to CSPACE-5793, not yet -->
+    <!-- resolved as of this writing. - ADR 2013-02-14 -->
+    
     <testGroup ID="TestsStillUnderDevelopment">
         
         <test ID="deleteRelationBetweenCollectionObject1AndMovement4">
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 (file)
index 0000000..6ff9d0e
--- /dev/null
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="collectionobjects">
+    
+    <ns2:collectionspace_core
+        xmlns:ns2="http://collectionspace.org/collectionspace_core/">
+        <tenantId></tenantId>
+        <updatedAt></updatedAt>
+        <workflowState></workflowState>
+        <createdBy></createdBy>
+        <createdAt></createdAt>
+        <refName></refName>
+        <uri></uri>
+        <updatedBy></updatedBy>
+    </ns2:collectionspace_core>
+
+    <ns2:collectionobjects_common
+        xmlns:ns2="http://collectionspace.org/services/collectionobject">
+        <objectProductionDateGroupList/>
+        <fieldCollectionMethods/>
+        <titleGroupList/>
+        <assocEventPeoples/>
+        <nonTextualInscriptionGroupList/>
+        <assocActivityGroupList/>
+        <responsibleDepartments/>
+        <assocOrganizationGroupList/>
+        <measuredPartGroupList/>
+        <contentPositions/>
+        <styles/>
+        <assocObjectGroupList/>
+        <assocPeopleGroupList/>
+        <objectProductionOrganizationGroupList/>
+        <ownershipDateGroupList/>
+        <owners/>
+        <objectProductionReasons/>
+        <contentLanguages/>
+        <otherNumberList/>
+        <assocCulturalContextGroupList/>
+        <objectProductionPersonGroupList/>
+        <objectNameList/>
+        <objectStatusList/>
+        <assocDateGroupList/>
+        <viewersReferences/>
+        <assocEventPersons/>
+        <assocPlaceGroupList/>
+        <comments/>
+        <textualInscriptionGroupList/>
+        <briefDescriptions/>
+        <contentOrganizations/>
+        <objectProductionPlaceGroupList/>
+        <contentActivities/>
+        <contentPersons/>
+        <contentScripts/>
+        <objectNumber>objectNumber</objectNumber>
+        <colors/>
+        <ownersReferences/>
+        <contentConcepts/>
+        <fieldColEventNames/>
+        <techniqueGroupList/>
+        <assocEventPlaces/>
+        <fieldCollectionDateGroup>
+            <dateEarliestSingleQualifier/>
+            <scalarValuesComputed/>
+            <dateLatestDay/>
+            <dateLatestYear/>
+            <dateAssociation/>
+            <dateEarliestSingleEra/>
+            <dateDisplayDate/>
+            <dateEarliestSingleCertainty/>
+            <dateLatestEra/>
+            <dateEarliestSingleQualifierValue/>
+            <dateLatestCertainty/>
+            <dateEarliestSingleYear/>
+            <dateLatestQualifier/>
+            <dateLatestQualifierValue/>
+            <dateEarliestSingleQualifierUnit/>
+            <datePeriod/>
+            <dateEarliestScalarValue/>
+            <dateLatestMonth/>
+            <dateNote/>
+            <dateLatestScalarValue/>
+            <dateLatestQualifierUnit/>
+            <dateEarliestSingleDay/>
+            <dateEarliestSingleMonth/>
+        </fieldCollectionDateGroup>
+        <contentPlaces/>
+        <contentPeoples/>
+        <objectComponentGroupList/>
+        <technicalAttributeGroupList/>
+        <referenceGroupList/>
+        <fieldCollectionSources/>
+        <forms/>
+        <assocConceptGroupList/>
+        <contentDateGroup>
+            <dateEarliestSingleQualifier/>
+            <scalarValuesComputed/>
+            <dateLatestDay/>
+            <dateLatestYear/>
+            <dateAssociation/>
+            <dateEarliestSingleEra/>
+            <dateDisplayDate/>
+            <dateEarliestSingleCertainty/>
+            <dateLatestEra/>
+            <dateEarliestSingleQualifierValue/>
+            <dateLatestCertainty/>
+            <dateEarliestSingleYear/>
+            <dateLatestQualifier/>
+            <dateLatestQualifierValue/>
+            <dateEarliestSingleQualifierUnit/>
+            <datePeriod/>
+            <dateEarliestScalarValue/>
+            <dateLatestMonth/>
+            <dateNote/>
+            <dateLatestScalarValue/>
+            <dateLatestQualifierUnit/>
+            <dateEarliestSingleDay/>
+            <dateEarliestSingleMonth/>
+        </contentDateGroup>
+        <usageGroupList/>
+        <fieldCollectors/>
+        <assocPersonGroupList/>
+        <assocEventOrganizations/>
+        <contentEventNameGroupList/>
+        <contentOtherGroupList/>
+        <materialGroupList/>
+        <contentObjectGroupList/>
+        <objectProductionPeopleGroupList/>
+    </ns2:collectionobjects_common>
+    
+    <ns2:account_permission
+        xmlns:ns2="http://collectionspace.org/services/authorization">
+        <account>
+            <accountId></accountId>
+            <screenName></screenName>
+            <userId></userId>
+            <tenantId></tenantId>
+        </account>
+    </ns2:account_permission>
+
+</document>
\ No newline at end of file