From 4f5162fceda5f4fd7da86af1a6b8389edc7f8c83 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 20 May 2013 18:38:16 -0700 Subject: [PATCH] CSPACE-6019: In the event listener / handler that keeps denormalized computedCurrentLocation values current in CollectionObject / Cataloging records, use the creation timestamp as a tiebreaker if two related Movement records otherwise have identical locationDate timestamps, with the most recently created Movement record assumed to represent a later physical movement. --- .../AbstractUpdateObjectLocationValues.java | 23 +++++ .../listener/listener-update-object-loc.xml | 89 +++++++++++++------ .../xmlreplay/listener/res/movement.res.xml | 12 +++ 3 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/movement.res.xml diff --git a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java index 6ca3d6672..d66777a73 100644 --- a/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java +++ b/3rdparty/nuxeo/nuxeo-platform-listener/updateobjectlocationonmove/src/main/java/org/collectionspace/services/listener/AbstractUpdateObjectLocationValues.java @@ -40,6 +40,8 @@ public abstract class AbstractUpdateObjectLocationValues implements EventListene private final static String MOVEMENT_DOCTYPE = MovementConstants.NUXEO_DOCTYPE; private final static String LOCATION_DATE_PROPERTY = "locationDate"; // FIXME: Get from external constant protected final static String CURRENT_LOCATION_PROPERTY = "currentLocation"; // FIXME: Get from external constant + protected final static String COLLECTIONSPACE_CORE_SCHEMA = "collectionspace_core"; // FIXME: Get from external constant + protected final static String CREATED_AT_PROPERTY = "createdAt"; // FIXME: Get from external constant private final static String ACTIVE_DOCUMENT_WHERE_CLAUSE_FRAGMENT = "AND (ecm:currentLifeCycleState <> 'deleted') " + "AND ecm:isProxy = 0 " @@ -385,6 +387,10 @@ public abstract class AbstractUpdateObjectLocationValues implements EventListene // Iterate through related movement records, to find the related // Movement record with the most recent location date. GregorianCalendar mostRecentLocationDate = EARLIEST_COMPARISON_DATE; + // Note: the following value is used to compare any two records, rather + // than to identify the most recent value so far encountered. Thus, it may + // occasionally be set backward or forward in time, within the loop below. + GregorianCalendar comparisonCreationDate = EARLIEST_COMPARISON_DATE; DocumentModel movementDocModel; Set alreadyProcessedMovementCsids = new HashSet<>(); String relatedMovementCsid; @@ -429,12 +435,29 @@ public abstract class AbstractUpdateObjectLocationValues implements EventListene } GregorianCalendar locationDate = (GregorianCalendar) movementDocModel.getProperty(MOVEMENTS_COMMON_SCHEMA, LOCATION_DATE_PROPERTY); + // If the current Movement record lacks a location date, it cannot + // be established as the most recent Movement record; skip over it. if (locationDate == null) { continue; } + GregorianCalendar creationDate = + (GregorianCalendar) movementDocModel.getProperty(COLLECTIONSPACE_CORE_SCHEMA, CREATED_AT_PROPERTY); if (locationDate.after(mostRecentLocationDate)) { mostRecentLocationDate = locationDate; + if (creationDate != null) { + comparisonCreationDate = creationDate; + } mostRecentMovementDocModel = movementDocModel; + // If the current Movement record's location date is identical + // to that of the (at this time) most recent Movement record, then + // instead compare the two records using their creation date values + } else if (locationDate.compareTo(mostRecentLocationDate) == 0) { + if (creationDate != null && creationDate.after(comparisonCreationDate)) { + // The most recent location date value doesn't need to be + // updated here, as the two records' values are identical + comparisonCreationDate = creationDate; + mostRecentMovementDocModel = movementDocModel; + } } } return mostRecentMovementDocModel; diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml index 6a1faeebd..1aeec652b 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/listener-update-object-loc.xml @@ -419,7 +419,7 @@ 200 - + GET /cspace-services/collectionobjects/${createCollectionObject1.CSID} @@ -432,48 +432,87 @@ 200 - - - - - - + + + - - DELETE - /cspace-services/relations/${relateCollectionObject1ToMovement4.CSID} + + POST + /cspace-services/movements + listener/movement.xml + + urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Spokane1358215545524)'Spokane, WA, USA' + ${updateMovement3WithNonBlankCurrentLocation.locationDate} + + 201 + + + GET + /cspace-services/movements/${createMovement6.CSID} + + + listener/res/movement.res.xml + + ${createMovement6.currentLocation} + ${updateMovement3WithNonBlankCurrentLocation.got("//locationDate")} + + 200 - + + POST + /cspace-services/relations + listener/relation.xml + + ${createCollectionObject1.CSID} + CollectionObject + ${createMovement6.CSID} + Movement + + 201 + + + + + + PUT + /cspace-services/movements/${createMovement6.CSID} + listener/movement.xml + + ${createMovement6.currentLocation} + ${createMovement6.locationDate} + + 200 + + + GET /cspace-services/collectionobjects/${createCollectionObject1.CSID} listener/res/collectionobject.res.xml - ${createMovement3.currentLocation} + ${createMovement6.currentLocation} 200 - - PUT - /cspace-services/movements/${createMovement3.CSID}/workflow/delete + + + + + + + + + DELETE + /cspace-services/relations/${relateCollectionObject1ToMovement3.CSID} 200 - - - - - - relation/res/workflowState.res.xml - - deleted - - + GET /cspace-services/collectionobjects/${createCollectionObject1.CSID} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/movement.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/movement.res.xml new file mode 100644 index 000000000..903efa62d --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/listener/res/movement.res.xml @@ -0,0 +1,12 @@ + + + + + ${currentLocationValue} + ${locationDateValue} + + + + + -- 2.47.3