]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5728: UpdateObjectLocationBatchJob now supports a 'no context' invocation...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 11 Jan 2013 04:03:00 +0000 (20:03 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 11 Jan 2013 04:03:00 +0000 (20:03 -0800)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc-nocontext.xml [moved from services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml with 85% similarity]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-nocontext.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java

similarity index 85%
rename from services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml
rename to services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc-nocontext.xml
index 1129a2a777d7db3b8a17ad66b6e10780e3356668..91198eb9321fbdd41d6ea6054abfccc66b79e82a 100644 (file)
@@ -9,6 +9,8 @@
         </forDocTypes>\r
         <supportsSingleDoc>true</supportsSingleDoc>\r
         <supportsDocList>true</supportsDocList>\r
+        <supportsGroup>false</supportsGroup>\r
+        <supportsNoContext>true</supportsNoContext>\r
         <createsNewFocus>false</createsNewFocus>\r
         <className>org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob</className>\r
     </ns2:batch_common>\r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc.xml
new file mode 100644 (file)
index 0000000..afe6d20
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+<document name="batch">\r
+    <ns2:batch_common\r
+        xmlns:ns2="http://collectionspace.org/services/batch"\r
+        xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+        <name>TestUpdateObjectLocationBatchJob</name>\r
+        <forDocTypes>\r
+            <forDocType>CollectionObject</forDocType>\r
+        </forDocTypes>\r
+        <supportsSingleDoc>true</supportsSingleDoc>\r
+        <supportsDocList>true</supportsDocList>\r
+        <supportsGroup>false</supportsGroup>\r
+        <supportsNoContext>false</supportsNoContext>\r
+        <createsNewFocus>false</createsNewFocus>\r
+        <className>org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob</className>\r
+    </ns2:batch_common>\r
+</document>\r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-nocontext.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-nocontext.xml
new file mode 100644 (file)
index 0000000..74d7b17
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+<ns2:invocationContext\r
+    xmlns:ns2="http://collectionspace.org/services/common/invocable"\r
+    xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+    <mode>nocontext</mode>\r
+    <docType>CollectionObject</docType>\r
+    <singleCSID></singleCSID>\r
+    <groupCSID></groupCSID>\r
+    <listCSIDs></listCSIDs>\r
+    <params></params>\r
+</ns2:invocationContext>\r
+\r
+\r
index 0f4e5d0ebf2b012dffa580ada0d0b429715bcf0d..e96a8b613a00bdfa05295cb254506c4d1ecada0d 100644 (file)
@@ -14,7 +14,7 @@
         <test ID="createBatchRecord">\r
             <method>POST</method>\r
             <uri>/cspace-services/batch</uri>\r
-            <filename>batch/updateobjloc.xml</filename>\r
+            <filename>batch/batch-create-updateobjloc.xml</filename>\r
             <expectedCodes>201</expectedCodes>\r
         </test>\r
                 \r
         <test ID="createBatchRecord">\r
             <method>POST</method>\r
             <uri>/cspace-services/batch</uri>\r
-            <filename>batch/updateobjloc.xml</filename>\r
+            <filename>batch/batch-create-updateobjloc.xml</filename>\r
             <expectedCodes>201</expectedCodes>\r
         </test>\r
                 \r
 \r
     </testGroup>\r
     \r
+    <!--\r
+        WARNING: DANGER, WILL ROBINSON! This test group will process every active\r
+        CollectionObject record available to the batch job.\r
+        \r
+        This may:\r
+        * Update existing data, not just test-created data.\r
+        * Take a very long time.\r
+    \r
+        Uncomment this test group, and add a line to a control file invoking it\r
+        only at your peril.  Use ONLY during development. - ADR 2013-01-10\r
+    -->\r
+    \r
+    <!--\r
+    <testGroup ID="invocationModeModeNoContext" autoDeletePOSTS="true">\r
+        \r
+        <test ID="createBatchRecord">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/batch</uri>\r
+            <filename>batch/batch-create-updateobjloc-nocontext.xml</filename>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="createCollectionObject1">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/collectionobjects</uri>\r
+            <filename>batch/collObj1.xml</filename>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="createCollectionObject2">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/collectionobjects</uri>\r
+            <filename>batch/collObj1.xml</filename>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="createMovement1">\r
+            <method>POST</method>\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="locationDate">2050-01-01</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="createMovement2">\r
+            <method>POST</method>\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="locationDate">1950-01-01</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="relateCollectionObject1ToMovement1">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/relations</uri>\r
+            <filename>batch/relation.xml</filename>\r
+            <vars>\r
+                <var ID="subjectCsid">${createCollectionObject1.CSID}</var>\r
+                <var ID="subjectDocumentType">CollectionObject</var>\r
+                <var ID="objectCsid">${createMovement1.CSID}</var>\r
+                <var ID="objectDocumentType">Movement</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="relateCollectionObject1ToMovement2">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/relations</uri>\r
+            <filename>batch/relation.xml</filename>\r
+            <vars>\r
+                <var ID="subjectCsid">${createCollectionObject1.CSID}</var>\r
+                <var ID="subjectDocumentType">CollectionObject</var>\r
+                <var ID="objectCsid">${createMovement2.CSID}</var>\r
+                <var ID="objectDocumentType">Movement</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="relateMovement2ToCollectionObject2">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/relations</uri>\r
+            <filename>batch/relation.xml</filename>\r
+            <vars>\r
+                <var ID="subjectCsid">${createMovement2.CSID}</var>\r
+                <var ID="subjectDocumentType">Movement</var>\r
+                <var ID="objectCsid">${createCollectionObject2.CSID}</var>\r
+                <var ID="objectDocumentType">CollectionObject</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="invokeBatchWithNoContext" auth="test" autoDeletePOSTS="false">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/batch/${createBatchRecord.CSID}</uri>\r
+            <filename>batch/batch-invoke-updateobjloc-nocontext.xml</filename>\r
+            <expectedCodes>200</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="readUpdatedCollectionObject1Record">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/collectionobjects/${createCollectionObject1.CSID}</uri>\r
+            <filename>batch/updateobjloc.xml</filename>\r
+            <response>\r
+                <expected level="ADDOK" />\r
+                <filename>batch/res/collectionobject.res.xml</filename>\r
+                <vars>\r
+                    <var ID="computedCurrentLocationValue">${createMovement1.currentLocation}</var>\r
+                </vars>\r
+            </response>\r
+            <expectedCodes>200</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="readUpdatedCollectionObject2Record">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/collectionobjects/${createCollectionObject2.CSID}</uri>\r
+            <filename>batch/updateobjloc.xml</filename>\r
+            <response>\r
+                <expected level="ADDOK" />\r
+                <filename>batch/res/collectionobject.res.xml</filename>\r
+                <vars>\r
+                    <var ID="computedCurrentLocationValue">${createMovement2.currentLocation}</var>\r
+                </vars>\r
+            </response>\r
+            <expectedCodes>200</expectedCodes>\r
+        </test>\r
+        \r
+    </testGroup>\r
+    -->\r
+    \r
 </xmlReplay>\r
 \r
index 258e96384f7fdd35b58f3d1ddb7e65e0c222b73f..46895cdeb8d9f0657ef6fff7a59dd8a9d256a444 100644 (file)
     <run controlFile="versioning/versioning.xml" testGroup="VersionedRecordFiltering" />\r
     \r
     <run controlFile="batch/batch.xml" />\r
+    \r
+    <!-- Uncomment the following when needed to test the UpdateObjectLocationBatchJob -->\r
+    <!-- which updates the computed current location value in CollectionObject records. -->\r
+    <!--\r
     <run controlFile="batch/batch-update-object-loc.xml" testGroup="invocationModeSingle" />\r
     <run controlFile="batch/batch-update-object-loc.xml" testGroup="invocationModeList" />\r
+    -->\r
     \r
     <!-- Broken tests -->\r
     \r
index 7e01e9296746eb2eac86e8e46c9100f8b1450d87..8604fb7f02e59e3137df2c7baae9ae975c42e9f1 100644 (file)
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
 public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
 
     // FIXME: Where appropriate, get from existing constants rather than local declarations
+    private final static String COMPUTED_CURRENT_LOCATION_ELEMENT_NAME = "computedCurrentLocation";
     private final static String CSID_ELEMENT_NAME = "csid";
     private final static String CURRENT_LOCATION_ELEMENT_NAME = "currentLocation";
     private final static String LIFECYCLE_STATE_ELEMENT_NAME = "currentLifeCycleState";
@@ -60,7 +61,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
 
     // Initialization tasks
     public UpdateObjectLocationBatchJob() {
-        setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE, INVOCATION_MODE_LIST));
+        setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE, INVOCATION_MODE_LIST, INVOCATION_MODE_NO_CONTEXT));
     }
 
     /**
@@ -91,7 +92,8 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
                 }
                 csids.addAll(listCsids);
             } else if (requestIsForInvocationModeGroup()) {
-                // Currently not supported
+                // This invocation mode is currently not yet supported.
+                // FIXME: Add code to getMemberCsidsFromGroup() to support this mode.
                 String groupCsid = getInvocationContext().getGroupCSID();
                 List<String> groupMemberCsids = getMemberCsidsFromGroup(groupCsid);
                 if (groupMemberCsids.isEmpty()) {
@@ -221,8 +223,9 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             if (locationDate.compareTo(mostRecentLocationDate) > 0) {
                 mostRecentLocationDate = locationDate;
                 // FIXME: Add optional validation here that the currentLocation value
-                // parses successfully as an item refName. (We might make that validation
-                // dependent on the value of a parameter passed in during batch job invocation.)
+                // parses successfully as an item refName.
+                // Consider making this optional validation, in turn dependent on the
+                // value of a parameter passed in during batch job invocation.
                 computedCurrentLocation = currentLocation;
             }
 
@@ -235,46 +238,65 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             throws DocumentException, URISyntaxException {
         PoxPayloadOut collectionObjectPayload;
         String objectNumber;
+        String previousComputedCurrentLocation;
 
         collectionObjectPayload = findByCsid(collectionObjectResource, collectionObjectCsid);
-        if (Tools.notBlank(collectionObjectPayload.toXML())) {
+        if (Tools.isBlank(collectionObjectPayload.toXML())) {
+            return numUpdated;
+        } else {
             if (logger.isTraceEnabled()) {
                 logger.trace("Payload: " + "\n" + collectionObjectPayload);
             }
-            objectNumber = getFieldElementValue(collectionObjectPayload,
-                    COLLECTIONOBJECTS_COMMON_SCHEMA_NAME, COLLECTIONOBJECTS_COMMON_NAMESPACE,
-                    OBJECT_NUMBER_ELEMENT_NAME);
-            if (logger.isTraceEnabled()) {
-                logger.trace("Object number: " + objectNumber);
-            }
-            if (Tools.notBlank(objectNumber)) {
-                String collectionObjectUpdatePayload =
-                        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-                        + "<document name=\"collectionobject\">"
-                        + "  <ns2:collectionobjects_common "
-                        + "      xmlns:ns2=\"http://collectionspace.org/services/collectionobject\">"
-                        + "    <objectNumber>" + objectNumber + "</objectNumber>"
-                        + "    <computedCurrentLocation>" + computedCurrentLocation + "</computedCurrentLocation>"
-                        + "  </ns2:collectionobjects_common>"
-                        + "</document>";
-                if (logger.isTraceEnabled()) {
-                    logger.trace("Update payload: " + "\n" + collectionObjectUpdatePayload);
-                }
-                byte[] response = collectionObjectResource.update(resourcemap, null, collectionObjectCsid,
-                        collectionObjectUpdatePayload);
-                numUpdated++;
-                if (logger.isTraceEnabled()) {
-                    logger.trace("Computed current location value for CollectionObject " + collectionObjectCsid
-                            + " was set to " + computedCurrentLocation);
-                }
-            }
+        }
+        // Perform the update only if the computed current location value will change
+        previousComputedCurrentLocation = getFieldElementValue(collectionObjectPayload,
+                COLLECTIONOBJECTS_COMMON_SCHEMA_NAME, COLLECTIONOBJECTS_COMMON_NAMESPACE,
+                COMPUTED_CURRENT_LOCATION_ELEMENT_NAME);
+        if (Tools.notBlank(previousComputedCurrentLocation)
+                && computedCurrentLocation.equals(previousComputedCurrentLocation)) {
+            return numUpdated;
+        }
+        // In the default CollectionObject validation handler, the object number
+        // is a required field and its (non-blank) value must be present in update
+        // payloads to successfully perform an update.
+        //
+        // FIXME: Consider making this check for an object number dependent on the
+        // value of a parameter passed in during batch job invocation.
+        objectNumber = getFieldElementValue(collectionObjectPayload,
+                COLLECTIONOBJECTS_COMMON_SCHEMA_NAME, COLLECTIONOBJECTS_COMMON_NAMESPACE,
+                OBJECT_NUMBER_ELEMENT_NAME);
+        if (logger.isTraceEnabled()) {
+            logger.trace("Object number: " + objectNumber);
+        }
+        if (Tools.isBlank(objectNumber)) {
+            return numUpdated;
+        }
+
+        String collectionObjectUpdatePayload =
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+                + "<document name=\"collectionobject\">"
+                + "  <ns2:collectionobjects_common "
+                + "      xmlns:ns2=\"http://collectionspace.org/services/collectionobject\">"
+                + "    <objectNumber>" + objectNumber + "</objectNumber>"
+                + "    <computedCurrentLocation>" + computedCurrentLocation + "</computedCurrentLocation>"
+                + "  </ns2:collectionobjects_common>"
+                + "</document>";
+        if (logger.isTraceEnabled()) {
+            logger.trace("Update payload: " + "\n" + collectionObjectUpdatePayload);
+        }
+        byte[] response = collectionObjectResource.update(resourcemap, null, collectionObjectCsid,
+                collectionObjectUpdatePayload);
+        numUpdated++;
+        if (logger.isTraceEnabled()) {
+            logger.trace("Computed current location value for CollectionObject " + collectionObjectCsid
+                    + " was set to " + computedCurrentLocation);
 
         }
         return numUpdated;
     }
 
     // #################################################################
-    // Ray's convenience methods from his AbstractBatchJob class for the
+    // Ray Lee's convenience methods from his AbstractBatchJob class for the
     // UC Berkeley Botanical Garden v2.4 implementation.
     // #################################################################
     protected PoxPayloadOut findByCsid(String serviceName, String csid) throws URISyntaxException, DocumentException {
@@ -395,27 +417,26 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
         return relatedRecords;
     }
 
-    // Not currently supported
+    // Stub method, as this invocation mode is not currently supported
     private List<String> getMemberCsidsFromGroup(String groupCsid) throws URISyntaxException {
         List<String> memberCsids = Collections.emptyList();
         return memberCsids;
     }
 
     private List<String> getNoContextCsids() throws URISyntaxException {
-        List<String> noContextCsids = Collections.emptyList();
+        List<String> noContextCsids = new ArrayList<String>();
         ResourceMap resourcemap = getResourceMap();
         ResourceBase collectionObjectResource = resourcemap.get(CollectionObjectClient.SERVICE_NAME);
         UriInfo uriInfo = createUriInfo();
         uriInfo.getQueryParameters().add(WorkflowClient.WORKFLOW_QUERY_NONDELETED, "false");
         AbstractCommonList collectionObjects = collectionObjectResource.getList(uriInfo);
         for (AbstractCommonList.ListItem collectionObjectRecord : collectionObjects.getListItem()) {
-            noContextCsids.add(AbstractCommonListUtils.ListItemGetElementValue(collectionObjectRecord, CSID_ELEMENT_NAME));
+            noContextCsids.add(AbstractCommonListUtils.ListItemGetCSID(collectionObjectRecord));
         }
         if (logger.isInfoEnabled()) {
             logger.info("Identified " + noContextCsids.size()
                     + " total active CollectionObjects to process in the 'no context' invocation mode.");
         }
         return noContextCsids;
-
     }
 }