package org.collectionspace.services.listener;
+import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.collectionspace.services.common.api.RefNameUtils;
DocumentModel movementDocModel)
throws ClientException {
- // Get the current location value from the Movement.
+ // Get the current location value from the Movement (the "new" value)
String currentLocationRefName =
(String) movementDocModel.getProperty(MOVEMENTS_COMMON_SCHEMA, CURRENT_LOCATION_PROPERTY);
// Check that the value returned, which is expected to be a
// reference (refName) to an authority term (such as a storage
- // location or organization term) is, at a minimum:
+ // location or organization term):
//
- // * Non-null and non-blank.
- // (Note: we need to verify this assumption; can a CollectionObject's
- // computed current location value ever meaningfully be 'un-set'
- // by returning it to a null value?)
- //
- // * Capable of being successfully parsed by an authority item parser;
- // that is, returning a non-null parse result.
- if ((Tools.isBlank(currentLocationRefName)
- || (RefNameUtils.parseAuthorityTermInfo(currentLocationRefName) == null))) {
+ // * If it is not blank ...
+ // * Is then capable of being successfully parsed by an authority item parser.
+ if ((Tools.notBlank(currentLocationRefName)
+ && (RefNameUtils.parseAuthorityTermInfo(currentLocationRefName) == null))) {
logger.warn("Could not parse current location refName '" + currentLocationRefName + "'");
return collectionObjectDocModel;
} else {
logger.trace("currentLocation refName=" + currentLocationRefName);
}
}
- // If the value returned from the function passes validation,
- // compare it to the value in the computed current location
- // field of the CollectionObject.
+
+ // Get the computed current location value of the CollectionObject
+ // (the "existing" value)
String existingComputedCurrentLocationRefName =
(String) collectionObjectDocModel.getProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
COMPUTED_CURRENT_LOCATION_PROPERTY);
logger.trace("Existing computedCurrentLocation refName=" + existingComputedCurrentLocationRefName);
}
- // If the CollectionObject lacks a computed current location value,
- // or if the new value differs from its existing value ...
- if (Tools.isBlank(existingComputedCurrentLocationRefName)
+ // If the new value is blank, the existing value should always be
+ // overwritten ('nulled out') with a blank value.
+ if (Tools.isBlank(currentLocationRefName)) {
+ collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
+ COMPUTED_CURRENT_LOCATION_PROPERTY, (Serializable) null);
+ // Otherwise, if the existing value is blank, or if the new value
+ // is different than the existing value ...
+ } else if (Tools.isBlank(existingComputedCurrentLocationRefName)
|| (!currentLocationRefName.equals(existingComputedCurrentLocationRefName))) {
if (logger.isTraceEnabled()) {
logger.trace("computedCurrentLocation refName requires updating.");
}
- // ... update that value.
+ // ... update the existing value in the CollectionObject with the
+ // new value from the Movement.
collectionObjectDocModel.setProperty(COLLECTIONOBJECTS_COMMON_SCHEMA,
COMPUTED_CURRENT_LOCATION_PROPERTY, currentLocationRefName);
+
} else {
if (logger.isTraceEnabled()) {
logger.trace("computedCurrentLocation refName does NOT require updating.");
<expectedCodes>200</expectedCodes>
</test>
+ <test ID="updateMovement3WithBlankCurrentLocation">
+ <method>PUT</method>
+ <uri>/cspace-services/movements/${createMovement2.CSID}</uri>
+ <filename>listener/movement.xml</filename>
+ <vars>
+ <var ID="currentLocation"></var>
+ <var ID="locationDate">1800-02-01</var>
+ </vars>
+ <expectedCodes>200</expectedCodes>
+ </test>
+
+ <!--
+ This test verifies that the computedCurrentLocation field
+ value has been set to null, because that field will *not*
+ be emitted in the response payload when it has a null value.
+
+ This is an inherently fragile test, in comparing tree structures,
+ and will break if there are any changes to any of the relevant
+ schemas, including collectionspace_core, collectionobjects_common,
+ and account_permission.
+
+ Uncomment only when working on the computed current location
+ event listener / handler. - ADR - 2013-02-14
+ -->
+ <!--
+ <test ID="readCollectionObject1AfterMovement3BlankCurrentLocationUpdate">
+ <method>GET</method>
+ <uri>/cspace-services/collectionobjects/${createCollectionObject1.CSID}</uri>
+ <response>
+ <filename>listener/res/collectionobject-without-current-location.res.xml</filename>
+ <expected level="TREE" />
+ <parts>
+ <part>
+ <label>collectionobjects_common</label>
+ </part>
+ </parts>
+ </response>
+ <expectedCodes>200</expectedCodes>
+ </test>
+ -->
+
+ <test ID="updateMovement3WithNonBlankCurrentLocation">
+ <method>PUT</method>
+ <uri>/cspace-services/movements/${createMovement2.CSID}</uri>
+ <filename>listener/movement.xml</filename>
+ <vars>
+ <var ID="currentLocation">urn:cspace:core.collectionspace.org:locationauthorities:name(offsite_sla):item:name(Ottawa1358215545567)'Ottawa, ON, Canada'</var>
+ <var ID="locationDate">1800-02-01</var>
+ </vars>
+ <expectedCodes>200</expectedCodes>
+ </test>
+
+ <test ID="readCollectionObject1AfterMovement3BlankCurrentLocationUpdate">
+ <method>GET</method>
+ <uri>/cspace-services/collectionobjects/${createCollectionObject1.CSID}</uri>
+ <response>
+ <expected level="ADDOK" />
+ <filename>listener/res/collectionobject.res.xml</filename>
+ <vars>
+ <var ID="computedCurrentLocationValue">${updateMovement3WithNonBlankCurrentLocation.currentLocation}</var>
+ </vars>
+ </response>
+ <expectedCodes>200</expectedCodes>
+ </test>
+
</testGroup>
+ <!-- Some of the following tests pertain to CSPACE-5793, not yet -->
+ <!-- resolved as of this writing. - ADR 2013-02-14 -->
+
<testGroup ID="TestsStillUnderDevelopment">
<test ID="deleteRelationBetweenCollectionObject1AndMovement4">
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="collectionobjects">
+
+ <ns2:collectionspace_core
+ xmlns:ns2="http://collectionspace.org/collectionspace_core/">
+ <tenantId></tenantId>
+ <updatedAt></updatedAt>
+ <workflowState></workflowState>
+ <createdBy></createdBy>
+ <createdAt></createdAt>
+ <refName></refName>
+ <uri></uri>
+ <updatedBy></updatedBy>
+ </ns2:collectionspace_core>
+
+ <ns2:collectionobjects_common
+ xmlns:ns2="http://collectionspace.org/services/collectionobject">
+ <objectProductionDateGroupList/>
+ <fieldCollectionMethods/>
+ <titleGroupList/>
+ <assocEventPeoples/>
+ <nonTextualInscriptionGroupList/>
+ <assocActivityGroupList/>
+ <responsibleDepartments/>
+ <assocOrganizationGroupList/>
+ <measuredPartGroupList/>
+ <contentPositions/>
+ <styles/>
+ <assocObjectGroupList/>
+ <assocPeopleGroupList/>
+ <objectProductionOrganizationGroupList/>
+ <ownershipDateGroupList/>
+ <owners/>
+ <objectProductionReasons/>
+ <contentLanguages/>
+ <otherNumberList/>
+ <assocCulturalContextGroupList/>
+ <objectProductionPersonGroupList/>
+ <objectNameList/>
+ <objectStatusList/>
+ <assocDateGroupList/>
+ <viewersReferences/>
+ <assocEventPersons/>
+ <assocPlaceGroupList/>
+ <comments/>
+ <textualInscriptionGroupList/>
+ <briefDescriptions/>
+ <contentOrganizations/>
+ <objectProductionPlaceGroupList/>
+ <contentActivities/>
+ <contentPersons/>
+ <contentScripts/>
+ <objectNumber>objectNumber</objectNumber>
+ <colors/>
+ <ownersReferences/>
+ <contentConcepts/>
+ <fieldColEventNames/>
+ <techniqueGroupList/>
+ <assocEventPlaces/>
+ <fieldCollectionDateGroup>
+ <dateEarliestSingleQualifier/>
+ <scalarValuesComputed/>
+ <dateLatestDay/>
+ <dateLatestYear/>
+ <dateAssociation/>
+ <dateEarliestSingleEra/>
+ <dateDisplayDate/>
+ <dateEarliestSingleCertainty/>
+ <dateLatestEra/>
+ <dateEarliestSingleQualifierValue/>
+ <dateLatestCertainty/>
+ <dateEarliestSingleYear/>
+ <dateLatestQualifier/>
+ <dateLatestQualifierValue/>
+ <dateEarliestSingleQualifierUnit/>
+ <datePeriod/>
+ <dateEarliestScalarValue/>
+ <dateLatestMonth/>
+ <dateNote/>
+ <dateLatestScalarValue/>
+ <dateLatestQualifierUnit/>
+ <dateEarliestSingleDay/>
+ <dateEarliestSingleMonth/>
+ </fieldCollectionDateGroup>
+ <contentPlaces/>
+ <contentPeoples/>
+ <objectComponentGroupList/>
+ <technicalAttributeGroupList/>
+ <referenceGroupList/>
+ <fieldCollectionSources/>
+ <forms/>
+ <assocConceptGroupList/>
+ <contentDateGroup>
+ <dateEarliestSingleQualifier/>
+ <scalarValuesComputed/>
+ <dateLatestDay/>
+ <dateLatestYear/>
+ <dateAssociation/>
+ <dateEarliestSingleEra/>
+ <dateDisplayDate/>
+ <dateEarliestSingleCertainty/>
+ <dateLatestEra/>
+ <dateEarliestSingleQualifierValue/>
+ <dateLatestCertainty/>
+ <dateEarliestSingleYear/>
+ <dateLatestQualifier/>
+ <dateLatestQualifierValue/>
+ <dateEarliestSingleQualifierUnit/>
+ <datePeriod/>
+ <dateEarliestScalarValue/>
+ <dateLatestMonth/>
+ <dateNote/>
+ <dateLatestScalarValue/>
+ <dateLatestQualifierUnit/>
+ <dateEarliestSingleDay/>
+ <dateEarliestSingleMonth/>
+ </contentDateGroup>
+ <usageGroupList/>
+ <fieldCollectors/>
+ <assocPersonGroupList/>
+ <assocEventOrganizations/>
+ <contentEventNameGroupList/>
+ <contentOtherGroupList/>
+ <materialGroupList/>
+ <contentObjectGroupList/>
+ <objectProductionPeopleGroupList/>
+ </ns2:collectionobjects_common>
+
+ <ns2:account_permission
+ xmlns:ns2="http://collectionspace.org/services/authorization">
+ <account>
+ <accountId></accountId>
+ <screenName></screenName>
+ <userId></userId>
+ <tenantId></tenantId>
+ </account>
+ </ns2:account_permission>
+
+</document>
\ No newline at end of file