]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
6004819270287ae57d8ce788d8d2f5349756767a
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.listener;
2
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;
9
10 public class UpdateObjectLocationOnMove extends AbstractUpdateObjectLocationValues {
11     private final Logger logger = LoggerFactory.getLogger(UpdateObjectLocationOnMove.class);
12
13     @Override
14     protected boolean updateCollectionObjectLocation(DocumentModel collectionObjectDocModel,
15                 DocumentModel movementDocModel,
16                 String movementRecordsLocation) throws ClientException {
17         boolean result = false;
18
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.
23         //
24         if (Tools.isBlank(movementRecordsLocation)) {
25             return result;
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));
29             return result;
30         }
31
32         // Get the computed current location value of the CollectionObject.
33         String existingComputedCurrentLocation = (String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
34                 COMPUTED_CURRENT_LOCATION_PROPERTY);
35
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.
41         }
42
43         return result;
44     }
45 }