From 281ef8c12cdfc685c0c768576ed0edcc6717dcd4 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Wed, 19 Feb 2014 17:22:09 -0800 Subject: [PATCH] CSPACE-6129: When computing a Cataloging record's current location from related L/M/I (Movement) records, if two or more such records have identical location dates, use their update timestamps as a tiebreaker. --- .../batch/batch-update-object-loc.xml | 202 ++++++++++++++++++ .../nuxeo/UpdateObjectLocationBatchJob.java | 17 ++ 2 files changed, 219 insertions(+) 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 index d2033a1c1..d68b1ac5c 100644 --- 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 @@ -7,6 +7,7 @@ + @@ -282,6 +283,207 @@ + + + + POST + /cspace-services/batch + batch/batch-create-updateobjloc.xml + 201 + + + + POST + /cspace-services/collectionobjects + batch/collObj1.xml + 201 + + + + POST + /cspace-services/movements + batch/movement.xml + + location-1-with-tiebreaker + 1900-01-01 + + 201 + + + + POST + /cspace-services/movements + batch/movement.xml + + location-2-with-tiebreaker + ${createMovement1WithTiebreaker.locationDate} + + 201 + + + + POST + /cspace-services/movements + batch/movement.xml + + location-3-with-tiebreaker + ${createMovement1WithTiebreaker.locationDate} + + 201 + + + + POST + /cspace-services/relations + batch/relation.xml + + ${createCollectionObjectWithTiebreaker.CSID} + CollectionObject + ${createMovement1WithTiebreaker.CSID} + Movement + + 201 + + + + POST + /cspace-services/relations + batch/relation.xml + + ${createCollectionObjectWithTiebreaker.CSID} + CollectionObject + ${createMovement2WithTiebreaker.CSID} + Movement + + 201 + + + + POST + /cspace-services/relations + batch/relation.xml + + ${createCollectionObjectWithTiebreaker.CSID} + CollectionObject + ${createMovement3WithTiebreaker.CSID} + Movement + + 201 + + + + PUT + /cspace-services/movements/${createMovement1WithTiebreaker.CSID} + batch/movement.xml + + location-1-modified-with-tiebreaker + ${createMovement1WithTiebreaker.locationDate} + + 200 + + + + POST + /cspace-services/batch/${createBatchRecordWithTiebreaker.CSID} + batch/batch-invoke-updateobjloc-single.xml + + ${createCollectionObjectWithTiebreaker.CSID} + + 200 + + + + + + + + + + GET + /cspace-services/collectionobjects/${createCollectionObjectWithTiebreaker.CSID} + batch/updateobjloc.xml + + + batch/res/collectionobject.res.xml + + ${modifyMovement1WithTiebreaker.currentLocation} + + + 200 + + + + PUT + /cspace-services/movements/${createMovement2WithTiebreaker.CSID} + batch/movement.xml + + location-2-modified-with-tiebreaker + ${createMovement1WithTiebreaker.locationDate} + + 200 + + + + POST + /cspace-services/batch/${createBatchRecordWithTiebreaker.CSID} + batch/batch-invoke-updateobjloc-single.xml + + ${createCollectionObjectWithTiebreaker.CSID} + + 200 + + + + GET + /cspace-services/collectionobjects/${createCollectionObjectWithTiebreaker.CSID} + batch/updateobjloc.xml + + + batch/res/collectionobject.res.xml + + ${modifyMovement2WithTiebreaker.currentLocation} + + + 200 + + + + PUT + /cspace-services/movements/${createMovement3WithTiebreaker.CSID} + batch/movement.xml + + location-3-modified-with-tiebreaker + ${createMovement1WithTiebreaker.locationDate} + + 200 + + + + POST + /cspace-services/batch/${createBatchRecordWithTiebreaker.CSID} + batch/batch-invoke-updateobjloc-single.xml + + ${createCollectionObjectWithTiebreaker.CSID} + + 200 + + + + GET + /cspace-services/collectionobjects/${createCollectionObjectWithTiebreaker.CSID} + batch/updateobjloc.xml + + + batch/res/collectionobject.res.xml + + ${modifyMovement3WithTiebreaker.currentLocation} + + + 200 + + + + 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 index 36ef17097..590f0cac8 100644 --- 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 @@ -41,6 +41,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { private final static String LIFECYCLE_STATE_ELEMENT_NAME = "currentLifeCycleState"; private final static String LOCATION_DATE_ELEMENT_NAME = "locationDate"; private final static String OBJECT_NUMBER_ELEMENT_NAME = "objectNumber"; + private final static String UPDATE_DATE_ELEMENT_NAME = "updatedAt"; private final static String WORKFLOW_COMMON_SCHEMA_NAME = "workflow_common"; private final static String WORKFLOW_COMMON_NAMESPACE_PREFIX = "ns2"; private final static String WORKFLOW_COMMON_NAMESPACE_URI = @@ -200,7 +201,9 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { String movementCsid; String currentLocation; String locationDate; + String updateDate; String mostRecentLocationDate = ""; + String comparisonUpdateDate = ""; for (AbstractCommonList.ListItem movementListItem : relatedMovements.getListItem()) { movementCsid = AbstractCommonListUtils.ListItemGetElementValue(movementListItem, CSID_ELEMENT_NAME); if (Tools.isBlank(movementCsid)) { @@ -218,6 +221,10 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { if (Tools.isBlank(locationDate)) { continue; } + updateDate = AbstractCommonListUtils.ListItemGetElementValue(movementListItem, UPDATE_DATE_ELEMENT_NAME); + if (Tools.isBlank(updateDate)) { + continue; + } currentLocation = AbstractCommonListUtils.ListItemGetElementValue(movementListItem, CURRENT_LOCATION_ELEMENT_NAME); if (Tools.isBlank(currentLocation)) { continue; @@ -229,6 +236,7 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { // value of a parameter passed in during batch job invocation. if (logger.isTraceEnabled()) { logger.trace("Location date value = " + locationDate); + logger.trace("Update date value = " + updateDate); logger.trace("Current location value = " + currentLocation); } // If this record's location date value is more recent than that of other @@ -244,6 +252,15 @@ public class UpdateObjectLocationBatchJob extends AbstractBatchInvocable { if (locationDate.compareTo(mostRecentLocationDate) > 0) { mostRecentLocationDate = locationDate; mostRecentMovement = movementListItem; + comparisonUpdateDate = updateDate; + } else if (locationDate.compareTo(mostRecentLocationDate) == 0) { + // If the two location dates match, then use a tiebreaker + if (updateDate.compareTo(comparisonUpdateDate) > 0) { + // The most recent location date value doesn't need to be + // updated here, as the two records' values are identical + mostRecentMovement = movementListItem; + comparisonUpdateDate = updateDate; + } } } -- 2.47.3