]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
819197a65316ed6809ebc9792e448b5d1591eb43
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.listener;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.collectionspace.services.common.api.RefNameUtils;
6 import org.collectionspace.services.common.api.Tools;
7 import org.nuxeo.ecm.core.api.ClientException;
8 import org.nuxeo.ecm.core.api.DocumentModel;
9
10 public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValues {
11
12     // FIXME: We might experiment here with using log4j instead of Apache Commons Logging;
13     // am using the latter to follow Ray's pattern for now
14     private final Log logger = LogFactory.getLog(UpdateObjectLocationOnMove.class);
15
16     @Override
17     protected boolean updateCollectionObjectLocation(DocumentModel collectionObjectDocModel,
18                 DocumentModel movementDocModel,
19                 String movementRecordsLocation) throws ClientException {
20         boolean result = false;
21
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.
26         //
27         if (Tools.isBlank(movementRecordsLocation)) {
28             return result;
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));
32             return result;
33         }
34         
35         // Get the computed current location value of the CollectionObject.
36         String existingComputedCurrentLocation = (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
37                 COMPUTED_CURRENT_LOCATION_PROPERTY);
38
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.
44         }
45         
46         return result;
47     }
48 }