]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5728: Batch job to update computed current location now uses abstract class...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 5 Jan 2013 01:34:42 +0000 (17:34 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 5 Jan 2013 01:34:42 +0000 (17:34 -0800)
services/JaxRsServiceProvider/build.xml
services/batch/service/pom.xml
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java

index 6c712920da2529a3020902c38f8e429773a0ed22..4dfd46c9af2b7eb49a98fec0c7044ffd7e8efdc4 100644 (file)
@@ -57,7 +57,7 @@
             <arg value="-f" />
             <arg value="${basedir}/pom.xml" />
             <arg value="-N" />
-            <arg value="${mvn.opts}" />
+            <!-- arg value="${mvn.opts}" / -->
         </exec>
     </target>
     <target name="package-windows" if="osfamily-windows">
index f7a6db9361ddacb7455db0e167222727a9d25561..0942dac4ba3359a28b66100a84495c77e3ab8a00 100644 (file)
             <artifactId>org.collectionspace.services.batch.client</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.collectionspace.services</groupId>
+            <artifactId>org.collectionspace.services.collectionobject.client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.collectionspace.services</groupId>
             <artifactId>org.collectionspace.services.loanout.client</artifactId>
index 64db074a942cb5c3fb24e1de4c70bbc1deb1249a..49a2d16652caa24f5a31c2c36da4b396ed330c13 100644 (file)
@@ -1,8 +1,20 @@
 package org.collectionspace.services.batch.nuxeo;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriInfo;
 import org.collectionspace.services.batch.AbstractBatchInvocable;
+import org.collectionspace.services.client.CollectionObjectClient;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.ResourceBase;
 import org.collectionspace.services.common.api.Tools;
+import org.dom4j.DocumentException;
+import org.jboss.resteasy.specimpl.UriInfoImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -13,7 +25,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
 
     // Initialization tasks
     public UpdateObjectLocationBatchJob() {
-        setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE));
+        setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_SINGLE, INVOCATION_MODE_LIST));
     }
 
     /**
@@ -23,28 +35,81 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
     public void run() {
 
         setCompletionStatus(STATUS_MIN_PROGRESS);
+
         try {
             // FIXME: Placeholder during early development
             if (logger.isInfoEnabled()) {
                 logger.info("Invoking " + CLASSNAME + " ...");
                 logger.info("Invocation context is: " + getInvocationContext().getMode());
             }
+
             if (!requestedInvocationModeIsSupported()) {
                 setInvocationModeNotSupportedResult();
             }
-            String csid;
+
+            List<String> csids = new ArrayList<String>();
             if (requestIsForInvocationModeSingle()) {
-                csid = getInvocationContext().getSingleCSID();
-                if (Tools.isBlank(csid)) {
-                    throw new Exception("Could not find required CSID value in the context for this batch job.");
+                String singleCsid = getInvocationContext().getSingleCSID();
+                if (Tools.notBlank(singleCsid)) {
+                    csids.add(singleCsid);
+                }
+            } else if (requestIsForInvocationModeList()) {
+                List<String> listCsids = (getInvocationContext().getListCSIDs().getCsid());
+                if (listCsids == null || listCsids.isEmpty()) {
+                    throw new Exception(CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT_MESSAGE);
+                }
+                csids.addAll(listCsids);
+            } else if (requestIsForInvocationModeGroup()) {
+                String groupCsid = getInvocationContext().getGroupCSID();
+                // FIXME: Get individual CSIDs from the group
+                // and add them to the list
+            }
+
+            if (csids.isEmpty()) {
+                throw new Exception(CSID_VALUES_NOT_PROVIDED_IN_INVOCATION_CONTEXT_MESSAGE);
+            }
+
+            ResourceBase collectionObjectResource = getResourceMap().get(CollectionObjectClient.SERVICE_NAME);
+            PoxPayloadOut collectionObjectPayload;
+            // For each CollectionObject record:
+            for (String csid : csids) {
+                // Get the movement records related to this record
+                // Get the latest movement record from among those
+                // Extract its current location value
+                // Update the computed current location value in the CollectionObject record
+                collectionObjectPayload = findByCsid(collectionObjectResource, csid);
+                if (logger.isInfoEnabled()) {
+                    logger.info("Payload: " + "\n" + collectionObjectPayload);
                 }
-                logger.info("CSID value is: " + csid);
             }
-            String docType = getInvocationContext().getDocType();
         } catch (Exception e) {
             String errMsg = "Error encountered in " + CLASSNAME + ": " + e.getLocalizedMessage();
             setErrorResult(errMsg);
         }
+
         setCompletionStatus(STATUS_COMPLETE);
     }
+
+    // Ray'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 {
+        ResourceBase resource = getResourceMap().get(serviceName);
+        return findByCsid(resource, csid);
+    }
+
+    protected PoxPayloadOut findByCsid(ResourceBase resource, String csid) throws URISyntaxException, DocumentException {
+        byte[] response = resource.get(null, createUriInfo(), csid);
+        PoxPayloadOut payload = new PoxPayloadOut(response);
+        return payload;
+    }
+
+    protected UriInfo createUriInfo() throws URISyntaxException {
+        return createUriInfo("");
+    }
+
+    protected UriInfo createUriInfo(String queryString) throws URISyntaxException {
+        URI absolutePath = new URI("");
+        URI baseUri = new URI("");
+        return new UriInfoImpl(absolutePath, baseUri, "", queryString, Collections.<PathSegment>emptyList());
+    }
 }