]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5728: Added a skeletal (no-op) batch job and an initial XmlReplay-based test...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 4 Jan 2013 04:03:00 +0000 (20:03 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 4 Jan 2013 04:03:00 +0000 (20:03 -0800)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-invoke-updateobjloc.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/updateobjloc.xml [new file with mode: 0644]
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java [new file with mode: 0644]

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 (file)
index 0000000..a4a1d6a
--- /dev/null
@@ -0,0 +1,10 @@
+<?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>single</mode>\r
+    <docType>CollectionObject</docType>\r
+    <singleCSID>${collectionObjectCSID}</singleCSID>\r
+</ns2:invocationContext>\r
+\r
+\r
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 (file)
index 0000000..dccb500
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xmlReplay>\r
+    <auths>\r
+        <!-- IMPORTANT: THESE ARE STICKY :: THEY STICK AROUND UNTIL RESET, IN EXEC ORDER OF THIS FILE. -->\r
+        <auth ID="admin@core.collectionspace.org">YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I=</auth>\r
+    </auths>\r
+        \r
+    <!-- This tests the UpdateObjectLocationBatchJob -->\r
+        \r
+    <testGroup ID="testSingleRecordBatchUpdate" autoDeletePOSTS="true">\r
+            \r
+        <test ID="createBatchRecord">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/batch</uri>\r
+            <filename>batch/updateobjloc.xml</filename>\r
+        </test>\r
+                \r
+        <test ID="createCollectionObject">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/collectionobjects</uri>\r
+            <filename>batch/collObj1.xml</filename>\r
+        </test>\r
+        \r
+        <!-- This post of a batch job invocation request doesn't create a new record, -->\r
+        <!-- so we need to exclude it from the post-run auto-deletion of records. -->\r
+        <test ID="invokeBatch" auth="test" autoDeletePOSTS="false">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/batch/${createBatchRecord.CSID}</uri>\r
+            <filename>batch/batch-invoke-updateobjloc.xml</filename>\r
+            <vars>\r
+                <var ID="collectionObjectCSID">${createCollectionObject.CSID}</var>\r
+            </vars>\r
+        </test>\r
+\r
+        <test ID="readUpdatedCollectionObjectRecord">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/collectionobjects/${createCollectionObject.CSID}</uri>\r
+            <filename>batch/updateobjloc.xml</filename>\r
+        </test> \r
+        \r
+    </testGroup>\r
+    \r
+</xmlReplay>\r
+\r
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 (file)
index 0000000..c83b22d
--- /dev/null
@@ -0,0 +1,15 @@
+<?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>false</supportsDocList>\r
+        <createsNewFocus>false</createsNewFocus>\r
+        <className>org.collectionspace.services.batch.nuxeo.UpdateObjectLocationBatchJob</className>\r
+    </ns2:batch_common>\r
+</document>\r
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 (file)
index 0000000..b6c6e36
--- /dev/null
@@ -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<String> 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<String>(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<String> 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;
+    }
+}