]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5728: Tests now successfully create related records. First pass at obtaining...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 8 Jan 2013 20:58:47 +0000 (12:58 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 8 Jan 2013 20:58:47 +0000 (12:58 -0800)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch-update-object-loc.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/movement.xml [moved from services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/movement1-with-relation.xml with 90% similarity]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/relation.xml [new file with mode: 0644]
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateObjectLocationBatchJob.java

index 9e45a6277d723cdb2c5904a6d736161cf61be8ac..63b308b5a21732112a39eca98da798621207457e 100644 (file)
             <method>POST</method>\r
             <uri>/cspace-services/batch</uri>\r
             <filename>batch/updateobjloc.xml</filename>\r
+            <expectedCodes>201</expectedCodes>\r
         </test>\r
                 \r
         <test ID="createCollectionObject">\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="createMovement1WithRelationToCollectionObject">\r
+        <test ID="createMovement1">\r
             <method>POST</method>\r
             <uri>/cspace-services/movements</uri>\r
-            <filename>batch/movement1-with-relation.xml</filename>\r
+            <filename>batch/movement.xml</filename>\r
             <vars>\r
                 <var ID="currentLocation">location-1</var>\r
                 <var ID="locationDate">1900-01-01</var>\r
-                <var ID="relatedCollectionObjectCSID">${createCollectionObject.CSID}</var>\r
             </vars>\r
+            <expectedCodes>201</expectedCodes>\r
         </test>\r
         \r
-        <test ID="createMovement2WithRelationToCollectionObject">\r
+        <test ID="createMovement2">\r
             <method>POST</method>\r
             <uri>/cspace-services/movements</uri>\r
-            <filename>batch/movement1-with-relation.xml</filename>\r
+            <filename>batch/movement.xml</filename>\r
             <vars>\r
                 <var ID="currentLocation">location-2</var>\r
                 <var ID="locationDate">2000-01-01</var>\r
-                <var ID="relatedCollectionObjectCSID">${createCollectionObject.CSID}</var>\r
             </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="createMovement3">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/movements</uri>\r
+            <filename>batch/movement.xml</filename>\r
+            <vars>\r
+                <var ID="currentLocation">location-3</var>\r
+                <var ID="locationDate">1800-01-01</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
+        </test>\r
+        \r
+        <test ID="relateMovement1ToCollectionObject">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/relations</uri>\r
+            <filename>batch/relation.xml</filename>\r
+            <vars>\r
+                <var ID="subjectCsid">${createCollectionObject.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="relateMovement2ToCollectionObject">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/relations</uri>\r
+            <filename>batch/relation.xml</filename>\r
+            <vars>\r
+                <var ID="subjectCsid">${createCollectionObject.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="relateMovement3ToCollectionObject">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/relations</uri>\r
+            <filename>batch/relation.xml</filename>\r
+            <vars>\r
+                <var ID="subjectCsid">${createCollectionObject.CSID}</var>\r
+                <var ID="subjectDocumentType">CollectionObject</var>\r
+                <var ID="objectCsid">${createMovement3.CSID}</var>\r
+                <var ID="objectDocumentType">Movement</var>\r
+            </vars>\r
+            <expectedCodes>201</expectedCodes>\r
         </test>\r
         \r
         <!-- This post of a batch job invocation request doesn't create a new record, -->\r
similarity index 90%
rename from services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/movement1-with-relation.xml
rename to services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/movement.xml
index 416bce612df81cd9c844aabc7f2c08f86d18209b..e6751c24e8c3e42d9a9d13cb79ece1af2253d36a 100644 (file)
@@ -7,8 +7,7 @@
         <locationDate>${locationDate}</locationDate>
     </ns2:movements_common>
 
-    <ns3:relations-common-list xmlns:ns3="http://collectionspace.org/services/relation"
-                               xmlns:ns2="http://collectionspace.org/services/jaxb">
+    <ns3:relations-common-list xmlns:ns3="http://collectionspace.org/services/relation">
         <!-- 
              ${itemCSID} is a convention understood by the Relations service,
              which is replaced by the CSID of the item being created.  (This
@@ -25,7 +24,7 @@
                 <documentType>Movement</documentType>
             </subject>
             <!-- ... has an 'affects' relationship to ... -->
-            <predicate>affects</predicate>
+            <relationshipType>affects</relationshipType>
             <!-- ... its related item -->
             <object>
                 <csid>${relatedCollectionObjectCSID}</csid>
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/relation.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/relation.xml
new file mode 100644 (file)
index 0000000..3523647
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document name="relations">
+  <ns2:relations_common 
+          xmlns:ns2="http://collectionspace.org/services/relation" 
+          xmlns:ns3="http://collectionspace.org/services/jaxb">
+    <subjectCsid>${subjectCsid}</subjectCsid>
+    <subjectDocumentType>${subjectDocumentType}</subjectDocumentType>
+    <objectCsid>${objectCsid}</objectCsid>
+    <objectDocumentType>${objectDocumentType}</objectDocumentType>
+    <relationshipType>affects</relationshipType>
+  </ns2:relations_common>
+</document>
+
+
index def2a3d0bc15538d3d125bed4f6ef5ea276324a0..b1fb0ad5ce1707fbfd4cb7c306645d1ab943b6fa 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Map;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriInfo;
 import org.collectionspace.services.batch.AbstractBatchInvocable;
+import org.collectionspace.services.client.AbstractCommonListUtils;
 import org.collectionspace.services.client.CollectionObjectClient;
 import org.collectionspace.services.client.MovementClient;
 import org.collectionspace.services.client.PayloadOutputPart;
@@ -38,23 +39,16 @@ import org.slf4j.LoggerFactory;
 
 public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
 
-    // FIXME; Get from existing constants and replace these local declarations
-    final static String COLLECTIONOBJECTS_COMMON_SCHEMA_NAME = "collectionobjects_common";
-    final static String OBJECT_NUMBER_FIELD_NAME = "objectNumber";
-    private final static String RELATIONS_COMMON_SCHEMA = "relations_common"; // FIXME: Get from external constant
-    private final static String RELATION_DOCTYPE = "Relation"; // FIXME: Get from external constant
-    private final static String SUBJECT_CSID_PROPERTY = "subjectCsid"; // FIXME: Get from external constant
-    private final static String OBJECT_CSID_PROPERTY = "objectCsid"; // FIXME: Get from external constant
-    private final static String SUBJECT_DOCTYPE_PROPERTY = "subjectDocumentType"; // FIXME: Get from external constant
-    private final static String OBJECT_DOCTYPE_PROPERTY = "objectDocumentType"; // FIXME: Get from external constant
-    protected final static String COLLECTIONOBJECTS_COMMON_SCHEMA = "collectionobjects_common"; // FIXME: Get from external constant
-    private final static String COLLECTIONOBJECT_DOCTYPE = "CollectionObject"; // FIXME: Get from external constant
-    protected final static String COMPUTED_CURRENT_LOCATION_PROPERTY = "computedCurrentLocation"; // FIXME: Create and then get from external constant
-    protected final static String MOVEMENTS_COMMON_SCHEMA = "movements_common"; // FIXME: Get from external constant
-    private final static String MOVEMENT_DOCTYPE = MovementConstants.NUXEO_DOCTYPE;
+    // FIXME: Where appropriate, get from existing constants rather than local declarations
+    private final static String COLLECTIONOBJECTS_COMMON_SCHEMA_NAME = "collectionobjects_common";
+    private final static String COLLECTIONOBJECTS_COMMON_SCHEMA = "collectionobjects_common";
+    private final static String MOVEMENTS_COMMON_SCHEMA = MovementConstants.NUXEO_SCHEMA_NAME;
+    private final static String COMPUTED_CURRENT_LOCATION_ELEMENT_NAME = "computedCurrentLocation";
+    private final static String LOCATION_DATE_ELEMENT_NAME = "locationDate";
+    private final static String OBJECT_NUMBER_ELEMENT_NAME = "objectNumber";
     private InvocationResults results = new InvocationResults();
-    final String CLASSNAME = this.getClass().getSimpleName();
-    final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationBatchJob.class);
+    private final String CLASSNAME = this.getClass().getSimpleName();
+    private final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationBatchJob.class);
 
     // Initialization tasks
     public UpdateObjectLocationBatchJob() {
@@ -220,20 +214,11 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
                 if (relatedMovements.getTotalItems() == 0) {
                     // continue;
                 }
-                
-                /*
-                 * Query resulting from the above:
-                 * Executing CMIS query: SELECT DOC.nuxeo:pathSegment, DOC.dc:title,
-                 * REL.dc:title, REL.relations_common:objectCsid, REL.relations_common:subjectCsid
-                 * FROM Movement DOC JOIN Relation REL ON REL.relations_common:subjectCsid = DOC.nuxeo:pathSegment
-                 * WHERE REL.relations_common:objectCsid = 'c0bdd018-01c1-412a-bc21' AND
-                 * DOC.nuxeo:isVersion = false ORDER BY DOC.collectionspace_core:updatedAt
-                 */
 
                 // FIXME: Get the reciprocal relation records, via rtSbj=, as well,
                 // and remove duplicates
 
-                // FIXME Temporary for testing
+                // FIXME Temporary for testing, until we integrate the two list results
                 queryString = "rtSbj=" + csid;
                 uri = new URI(null, null, null, queryString, null);
                 uriInfo = createUriInfo(uri.getRawQuery());
@@ -246,44 +231,37 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
                 if (relatedMovements.getTotalItems() == 0) {
                     continue;
                 }
-                
-                /*
-                 * Query resulting from the above:
-                 * Executing CMIS query: SELECT DOC.nuxeo:pathSegment, DOC.dc:title,
-                 * REL.dc:title, REL.relations_common:objectCsid, REL.relations_common:subjectCsid
-                 * FROM Movement DOC JOIN Relation REL ON REL.relations_common:objectCsid = DOC.nuxeo:pathSegment
-                 * WHERE REL.relations_common:subjectCsid = '7db3c206-3a3c-4f5c-8155' AND
-                 * DOC.nuxeo:isVersion = false ORDER BY DOC.collectionspace_core:updatedAt DESC
-                 */
-
-
-                /*
-                 // FIXME: Similar to RelationsUtils.buildWhereClause()
-                 // We might consider adding a 'bidirectional where clause' like the following there.
-
-                 String query = String.format(
-                 "SELECT * FROM %1$s WHERE " // collectionspace_core:tenantId =  "
-                 + "("
-                 + "  (%2$s:subjectCsid = '%3$s' "
-                 + "  AND %2$s:objectDocumentType = '%4$s') "
-                 + " OR "
-                 + "  (%2$s:objectCsid = '%3$s' "
-                 + "  AND %2$s:subjectDocumentType = '%4$s') "
-                 + ")"
-                 + ACTIVE_DOCUMENT_WHERE_CLAUSE_FRAGMENT,
-                 RELATION_DOCTYPE, RELATIONS_COMMON_SCHEMA, csid, MOVEMENT_DOCTYPE);
-
-                 relationResource.getList(uriInfo);
-                 query = NuxeoUtils.buildNXQLQuery(csids, null);
-                 DocumentModelList relationDocModels = coreSession.query(query);
-                 */
-
-                // Get the latest movement record from among those
-
-                // Extract its current location value
-
-                // FIXME: Temporary during testing/development
-                computedCurrentLocation = COMPUTED_CURRENT_LOCATION;
+
+                // Get the latest movement record from among those, and extract
+                // its current location value
+                computedCurrentLocation = "";
+                String currentLocation;
+                String locationDate;
+                String mostRecentLocationDate = "";
+                for (AbstractCommonList.ListItem movementRecord : relatedMovements.getListItem()) {
+                    locationDate = AbstractCommonListUtils.ListItemGetElementValue(movementRecord, LOCATION_DATE_ELEMENT_NAME);
+                    if (Tools.notBlank(locationDate)) {
+                        if (logger.isInfoEnabled()) {
+                            logger.info("Location date value = " + locationDate);
+                        }
+                    }
+                    currentLocation = AbstractCommonListUtils.ListItemGetElementValue(movementRecord, COMPUTED_CURRENT_LOCATION_ELEMENT_NAME);
+                    if (Tools.notBlank(currentLocation)) {
+                        if (logger.isInfoEnabled()) {
+                            logger.info("Current location value = " + currentLocation);
+                        }
+                    }
+                    if (Tools.notBlank(locationDate) && Tools.notBlank(currentLocation)) {
+                        // Assumes for  that all values for this element/field will be
+                        // ISO 8601 date values that can be ordered via string comparison.
+                        // We might consider whether to first convert to date values instead.
+                        if (locationDate.compareTo(mostRecentLocationDate) > 1) {
+                            mostRecentLocationDate = locationDate;
+                            computedCurrentLocation = currentLocation;
+                        }
+                    }
+
+                }
 
                 // Update the computed current location value in the CollectionObject record
                 collectionObjectPayload = findByCsid(collectionObjectResource, csid);
@@ -297,7 +275,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
                      objectNumber = getFieldValue(collectionObjectPayload,
                      COLLECTIONOBJECTS_COMMON_SCHEMA_NAME,
                      "ns2", "http://collectionspace.org/services/collectionobject",
-                     OBJECT_NUMBER_FIELD_NAME);
+                     OBJECT_NUMBER_ELEMENT_NAME);
                      if (logger.isInfoEnabled()) {
                      logger.info("Object number: " + objectNumber);
                      }
@@ -332,8 +310,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable {
             return getResults();
         }
 
-        getResults()
-                .setNumAffected(numAffected);
+        getResults().setNumAffected(numAffected);
         return getResults();
     }
 }