]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6134: In the batch job that updates computed current locations in Cataloging...
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 20 Feb 2014 03:35:32 +0000 (19:35 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 20 Feb 2014 03:35:32 +0000 (19:35 -0800)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java

index d68b1ac5c3cda6ca1f2959d17b90832e8de13f5b..439cc9e4b68fe13acd93a239e37da2d65af69a94 100644 (file)
@@ -32,7 +32,7 @@
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-1</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Seattle1358215545509)'Seattle, WA, USA'</var>\r
                 <var ID="locationDate">1900-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
@@ -47,7 +47,7 @@
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-2</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Portland1358215545512)'Portland, OR, USA'</var>\r
                 <var ID="locationDate">2000-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
@@ -58,7 +58,7 @@
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-3</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Victoria1358215545515)'Victoria, BC, Canada'</var>\r
                 <var ID="locationDate">1800-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-4</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Vancouver1358215545518)'Vancouver, BC, Canada'</var>\r
                 <var ID="locationDate">2100-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-1-with-tiebreaker</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Olympia1358215545521)'Olympia, WA, USA'</var>\r
                 <var ID="locationDate">1900-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-2-with-tiebreaker</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Ottawa1358215545567)'Ottawa, ON, Canada'</var>\r
                 <var ID="locationDate">${createMovement1WithTiebreaker.locationDate}</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-3-with-tiebreaker</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Spokane1358215545524)'Spokane, WA, USA'</var>\r
                 <var ID="locationDate">${createMovement1WithTiebreaker.locationDate}</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements/${createMovement1WithTiebreaker.CSID}</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-1-modified-with-tiebreaker</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Guadalajara13582155455562)'Guadalajara, Mexico'</var>\r
                 <var ID="locationDate">${createMovement1WithTiebreaker.locationDate}</var>\r
             </vars>\r
             <expectedCodes>200</expectedCodes>\r
             <uri>/cspace-services/movements/${createMovement2WithTiebreaker.CSID}</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-2-modified-with-tiebreaker</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Ecatepec13582155455560)'Ecatepec, Mexico'</var>\r
                 <var ID="locationDate">${createMovement1WithTiebreaker.locationDate}</var>\r
             </vars>\r
             <expectedCodes>200</expectedCodes>\r
             <uri>/cspace-services/movements/${createMovement3WithTiebreaker.CSID}</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-3-modified-with-tiebreaker</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Calgary1358215545564)'Calgary, AB, Canada'</var>\r
                 <var ID="locationDate">${createMovement1WithTiebreaker.locationDate}</var>\r
             </vars>\r
             <expectedCodes>200</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-1</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Winnipeg13582155455568)'Winnipeg, MB, Canada'</var>\r
                 <var ID="locationDate">1900-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-2</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Saskatoon13582155455570)'Saskatoon, SK, Canada'</var>\r
                 <var ID="locationDate">2000-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-3</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Montreal13582155455570)'Montreal, QC, Canada'</var>\r
                 <var ID="locationDate">1800-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-1</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Eugene13582155455572)'Eugene, OR, USA'</var>\r
                 <var ID="locationDate">1900-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-2</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Salem13582155455574)'Salem, OR, USA'</var>\r
                 <var ID="locationDate">2000-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-3</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Gresham13582155455574)'Gresham, OR, USA'</var>\r
                 <var ID="locationDate">1800-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-nocontext-1</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Hillsboro13582155455576)'Hillsboro, OR, USA'</var>\r
                 <var ID="locationDate">2050-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
             <uri>/cspace-services/movements</uri>\r
             <filename>batch/movement.xml</filename>\r
             <vars>\r
-                <var ID="currentLocation">location-nocontext-2</var>\r
+                <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Beaverton13582155455578)'Beaverton, OR, USA'</var>\r
                 <var ID="locationDate">1950-01-01</var>\r
             </vars>\r
             <expectedCodes>201</expectedCodes>\r
index 590f0cac8f434e23e0fb03f83c300a23565a833b..d9d722ca6eedb9a44fd580e67f0ad77bd2ff4663 100644 (file)
@@ -20,6 +20,7 @@ import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.workflow.WorkflowClient;
 import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.ResourceMap;
+import org.collectionspace.services.common.api.RefNameUtils;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.invocable.InvocationResults;
 import org.collectionspace.services.jaxb.AbstractCommonList;
@@ -229,16 +230,24 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             if (Tools.isBlank(currentLocation)) {
                 continue;
             }
-            // FIXME: Add optional validation here that this Movement record's
-            // currentLocation value parses successfully as an item refName,
-            // before identifying that record as the most recent Movement.
-            // Consider making this optional validation, in turn dependent on the
+            // Validate that this Movement record's currentLocation value parses
+            // successfully as an item refName, before identifying that record
+            // as the most recent Movement.
+            //
+            // TODO: Consider making this optional validation, in turn dependent on the
             // value of a parameter passed in during batch job invocation.
+            if (RefNameUtils.parseAuthorityTermInfo(currentLocation) == null) {
+                logger.warn(String.format("Could not parse current location refName '%s' in Movement record",
+                    currentLocation));
+                 continue;
+            }
+           
             if (logger.isTraceEnabled()) {
                 logger.trace("Location date value = " + locationDate);
                 logger.trace("Update date value = " + updateDate);
                 logger.trace("Current location value = " + currentLocation);
             }
+            
             // If this record's location date value is more recent than that of other
             // Movement records processed so far, set the current Movement record
             // as the most recent Movement.
@@ -320,12 +329,16 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             return numUpdated;
         }
 
-        // Update the location.
-        // (Updated location values can legitimately be blank, to 'null out' existing locations.)  
+        // At this point in the code, the most recent related Movement record
+        // should not have a null current location, as such records are
+        // excluded from consideration altogether in getMostRecentMovement().
+        // This is a redundant fallback check, in case that code somehow fails
+        // or is modified or deleted.
         if (computedCurrentLocation == null) {
-            computedCurrentLocation = "";
+            return numUpdated;
         }
 
+        // Update the location.
         String collectionObjectUpdatePayload =
                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                 + "<document name=\"collectionobject\">"