1 package org.collectionspace.services.listener;
3 import org.collectionspace.services.common.api.RefNameUtils;
4 import org.collectionspace.services.common.api.Tools;
5 import org.nuxeo.ecm.core.api.ClientException;
6 import org.nuxeo.ecm.core.api.DocumentModel;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValues {
11 private final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationOnMove.class);
14 protected boolean updateCollectionObjectLocation(DocumentModel collectionObjectDocModel,
15 DocumentModel movementDocModel,
16 String movementRecordsLocation) throws ClientException {
17 boolean result = false;
19 // Check that the location value returned, which is expected to be a reference (refName) to an authority term (such as a storage
20 // location or organization term):
21 // * Ensure it is not blank.
22 // * Ensure it is successfully parsed by the authority item parser.
24 if (Tools.isBlank(movementRecordsLocation)) {
26 } else if (RefNameUtils.parseAuthorityTermInfo(movementRecordsLocation) == null) {
27 logger.warn(String.format("Ignoring movment record. Could not parse the location field's refName '%s'.",
28 movementRecordsLocation));
32 // Get the computed current location value of the CollectionObject.
33 String existingComputedCurrentLocation = (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
34 COMPUTED_CURRENT_LOCATION_PROPERTY);
36 // If the movement record's location is different than the existing catalog's then update it and return 'true'
37 if (movementRecordsLocation.equalsIgnoreCase(existingComputedCurrentLocation) == false) {
38 collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
39 COMPUTED_CURRENT_LOCATION_PROPERTY, movementRecordsLocation);
40 result = true; // We've updated the location field.