From d4c39452e654dff091e49d3264b2bc941485729f Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 10 Jan 2013 20:03:00 -0800 Subject: [PATCH] CSPACE-5728: UpdateObjectLocationBatchJob now supports a 'no context' invocation mode, which updates the computed current location value in all active CollectionObject records. --- ...> batch-create-updateobjloc-nocontext.xml} | 2 + .../batch/batch-create-updateobjloc.xml | 17 +++ .../batch-invoke-updateobjloc-nocontext.xml | 13 ++ .../batch/batch-update-object-loc.xml | 139 +++++++++++++++++- .../test-data/xmlreplay/xml-replay-master.xml | 5 + .../nuxeo/UpdateObjectLocationBatchJob.java | 95 +++++++----- 6 files changed, 232 insertions(+), 39 deletions(-) rename services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/{updateobjloc.xml => batch-create-updateobjloc-nocontext.xml} (85%) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-nocontext.xml diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc-nocontext.xml 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 1129a2a77..91198eb93 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc-nocontext.xml @@ -9,6 +9,8 @@ true true + false + true false org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob 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 index 000000000..afe6d20e3 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-create-updateobjloc.xml @@ -0,0 +1,17 @@ + + + + TestUpdateObjectLocationBatchJob + + CollectionObject + + true + true + false + false + false + org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob + + 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 index 000000000..74d7b17d7 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc-nocontext.xml @@ -0,0 +1,13 @@ + + + nocontext + CollectionObject + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml index 0f4e5d0eb..e96a8b613 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml @@ -14,7 +14,7 @@ POST /cspace-services/batch - batch/updateobjloc.xml + batch/batch-create-updateobjloc.xml 201 @@ -286,7 +286,7 @@ POST /cspace-services/batch - batch/updateobjloc.xml + batch/batch-create-updateobjloc.xml 201 @@ -421,5 +421,140 @@ + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml index 258e96384..46895cdeb 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml @@ -44,8 +44,13 @@ + + + + diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java index 7e01e9296..8604fb7f0 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java @@ -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 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 = - "" - + "" - + " " - + " " + objectNumber + "" - + " " + computedCurrentLocation + "" - + " " - + ""; - 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 = + "" + + "" + + " " + + " " + objectNumber + "" + + " " + computedCurrentLocation + "" + + " " + + ""; + 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 getMemberCsidsFromGroup(String groupCsid) throws URISyntaxException { List memberCsids = Collections.emptyList(); return memberCsids; } private List getNoContextCsids() throws URISyntaxException { - List noContextCsids = Collections.emptyList(); + List noContextCsids = new ArrayList(); 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; - } } -- 2.47.3