From 97e28800e6b695d8ad257ae335d3ac839f94858b Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 3 Jan 2013 20:03:00 -0800 Subject: [PATCH] CSPACE-5728: Added a skeletal (no-op) batch job and an initial XmlReplay-based test to invoke it, as a starting point for work on this issue. --- .../batch/batch-invoke-updateobjloc.xml | 10 ++ .../batch/batch-update-object-loc.xml | 44 +++++++ .../xmlreplay/batch/updateobjloc.xml | 15 +++ .../nuxeo/UpdateObjectLocationBatchJob.java | 114 ++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml create mode 100644 services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc.xml new file mode 100644 index 000000000..a4a1d6af5 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc.xml @@ -0,0 +1,10 @@ + + + single + CollectionObject + ${collectionObjectCSID} + + + 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 new file mode 100644 index 000000000..dccb500b2 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml @@ -0,0 +1,44 @@ + + + + + YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I= + + + + + + + + POST + /cspace-services/batch + batch/updateobjloc.xml + + + + POST + /cspace-services/collectionobjects + batch/collObj1.xml + + + + + + POST + /cspace-services/batch/${createBatchRecord.CSID} + batch/batch-invoke-updateobjloc.xml + + ${createCollectionObject.CSID} + + + + + GET + /cspace-services/collectionobjects/${createCollectionObject.CSID} + batch/updateobjloc.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/updateobjloc.xml new file mode 100644 index 000000000..c83b22db1 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml @@ -0,0 +1,15 @@ + + + + TestUpdateObjectLocationBatchJob + + CollectionObject + + true + false + false + org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob + + 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 new file mode 100644 index 000000000..b6c6e3607 --- /dev/null +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java @@ -0,0 +1,114 @@ +package org.collectionspace.services.batch.nuxeo; + +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.Response; +import org.collectionspace.services.batch.BatchInvocable; +import org.collectionspace.services.common.ResourceMap; +import org.collectionspace.services.common.invocable.InvocationContext; +import org.collectionspace.services.common.invocable.InvocationResults; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UpdateObjectLocationBatchJob implements BatchInvocable { + + final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationBatchJob.class); + private static ArrayList invocationModes = null; + private InvocationContext context; + private int completionStatus; + private ResourceMap resourceMap; + private InvocationResults results; + private InvocationError errorInfo; + protected final int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + protected final int BAD_REQUEST_STATUS = Response.Status.BAD_REQUEST.getStatusCode(); + protected final int INT_ERROR_STATUS = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); + + public UpdateObjectLocationBatchJob() { + UpdateObjectLocationBatchJob.setupClassStatics(); + context = null; + completionStatus = STATUS_UNSTARTED; + resourceMap = null; + results = new InvocationResults(); + errorInfo = null; + } + + private static void setupClassStatics() { + if (invocationModes == null) { + invocationModes = new ArrayList(1); + invocationModes.add(INVOCATION_MODE_SINGLE); + // invocationModes.add(INVOCATION_MODE_LIST); + } + } + + /** + * @return a set of modes that this plugin can support on invocation. Must + * be non-empty. + */ + public List getSupportedInvocationModes() { + return UpdateObjectLocationBatchJob.invocationModes; + } + + /** + * Sets the invocation context for the batch job. Called before run(). + * + * @param context an instance of InvocationContext. + */ + public void setInvocationContext(InvocationContext context) { + this.context = context; + } + + /** + * Sets the invocation context for the batch job. Called before run(). + * + * @param context an instance of InvocationContext. + */ + public void setResourceMap(ResourceMap resourceMap) { + this.resourceMap = resourceMap; + } + + /** + * The main work logic of the batch job. Will be called after setContext. + */ + public void run() { + completionStatus = STATUS_MIN_PROGRESS; + + try { + // FIXME: Placeholder during early development + if (logger.isInfoEnabled()) { + logger.info("Invoking " + this.getClass().getSimpleName() + " ..."); + } + } catch (Exception e) { + completionStatus = STATUS_ERROR; + errorInfo = new InvocationError(INT_ERROR_STATUS, + "UpdateObjectLocationBatchJob problem: " + e.getLocalizedMessage()); + results.setUserNote(errorInfo.getMessage()); + } + } + + /** + * @return one of the STATUS_* constants, or a value from 1-99 to indicate + * progress. Implementations need not support partial completion (progress) + * values, and can transition from STATUS_MIN_PROGRESS to STATUS_COMPLETE. + */ + public int getCompletionStatus() { + return completionStatus; + } + + /** + * @return information about the batch job actions and results + */ + public InvocationResults getResults() { + if (completionStatus != STATUS_COMPLETE) { + return null; + } + return results; + } + + /** + * @return a user-presentable note when an error occurs in batch processing. + * Will only be called if getCompletionStatus() returns STATUS_ERROR. + */ + public InvocationError getErrorInfo() { + return errorInfo; + } +} -- 2.47.3