1 package org.collectionspace.services.listener;
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
6 import org.collectionspace.services.common.api.RefNameUtils;
7 import org.collectionspace.services.common.api.Tools;
9 import org.nuxeo.ecm.core.api.ClientException;
10 import org.nuxeo.ecm.core.api.DocumentModel;
12 public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValues {
14 private final Log logger = LogFactory.getLog(UpdateObjectLocationOnMove.class);
17 protected boolean updateCollectionObjectLocation(DocumentModel collectionObjectDocModel,
18 DocumentModel movementDocModel,
19 String movementRecordsLocation) throws ClientException {
20 boolean result = false;
22 // Check that the location value returned, which is expected to be a reference (refName) to an authority term (such as a storage
23 // location or organization term):
24 // * Ensure it is not blank.
25 // * Ensure it is successfully parsed by the authority item parser.
27 if (Tools.isBlank(movementRecordsLocation)) {
29 } else if (RefNameUtils.parseAuthorityTermInfo(movementRecordsLocation) == null) {
30 logger.warn(String.format("Ignoring movment record. Could not parse the location field's refName '%s'.",
31 movementRecordsLocation));
35 // Get the computed current location value of the CollectionObject.
36 String existingComputedCurrentLocation = (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
37 COMPUTED_CURRENT_LOCATION_PROPERTY);
39 // If the movement record's location is different than the existing catalog's then update it and return 'true'
40 if (movementRecordsLocation.equalsIgnoreCase(existingComputedCurrentLocation) == false) {
41 collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
42 COMPUTED_CURRENT_LOCATION_PROPERTY, movementRecordsLocation);
43 result = true; // We've updated the location field.
50 public Log getLogger() {