--- /dev/null
+package org.collectionspace.services.batch.nuxeo;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.collectionspace.services.client.CollectionObjectClient;
+import org.collectionspace.services.client.CollectionObjectFactory;
+import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
+import org.collectionspace.services.collectionobject.InventoryStatusList;
+import org.collectionspace.services.common.api.RefNameUtils;
+import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
+import org.collectionspace.services.common.invocable.InvocationContext.Params.Param;
+import org.collectionspace.services.common.invocable.InvocationResults;
+import org.collectionspace.services.common.NuxeoBasedResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UpdateInventoryStatusBatchJob extends AbstractBatchJob {
+ final Logger logger = LoggerFactory.getLogger(UpdateInventoryStatusBatchJob.class);
+
+ public UpdateInventoryStatusBatchJob() {
+ setSupportedInvocationModes(Arrays.asList(INVOCATION_MODE_LIST));
+ }
+
+ @Override
+ public void run() {
+ setCompletionStatus(STATUS_MIN_PROGRESS);
+
+ try {
+ String mode = getInvocationContext().getMode();
+
+ if (mode.equalsIgnoreCase(INVOCATION_MODE_LIST)) {
+ List<String> csids = getInvocationContext().getListCSIDs().getCsid();
+ List<String> values = this.getValues();
+
+ setResults(updateRecords(csids, values));
+ }
+ else {
+ throw new Exception("Unsupported invocation mode: " + mode);
+ }
+
+ setCompletionStatus(STATUS_COMPLETE);
+ }
+ catch(Exception e) {
+ setCompletionStatus(STATUS_ERROR);
+ setErrorInfo(new InvocationError(INT_ERROR_STATUS, e.getMessage()));
+ }
+ }
+
+ private List<String> getValues() {
+ List<String> values = new ArrayList<String>();
+
+ for (Param param : this.getParams()) {
+ if (param.getKey().equals("inventoryStatus")) {
+ values.add(param.getValue());
+ }
+ }
+
+ return values;
+ }
+
+ public InvocationResults updateRecords(List<String> csids, List<String> values) throws Exception {
+ InvocationResults results = new InvocationResults();
+ int numAffected = 0;
+
+ ArrayList<String> displayNames = new ArrayList<String>();
+
+ for (String value : values) {
+ AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(value);
+ String displayName = termInfo.displayName;
+
+ displayNames.add(displayName);
+ }
+
+ for (String csid : csids) {
+ updateRecord(csid, values);
+
+ numAffected = numAffected + 1;
+ }
+
+ String userNote;
+
+ if (displayNames.size() > 0) {
+ userNote = "Inventory status changed to " + StringUtils.join(displayNames, ", ") + ".";
+ } else {
+ userNote = "Inventory status values removed.";
+ }
+
+ results.setNumAffected(numAffected);
+ results.setUserNote(userNote);
+
+ return results;
+ }
+
+ private void updateRecord(String csid, List<String> values) throws Exception {
+ CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
+ InventoryStatusList inventoryStatusList = new InventoryStatusList();
+
+ inventoryStatusList.getInventoryStatus().addAll(values);
+ collectionObject.setInventoryStatusList(inventoryStatusList);
+
+ CollectionObjectClient client = new CollectionObjectClient();
+ PoxPayloadOut payload = CollectionObjectFactory.createCollectionObjectInstance(client.getCommonPartName(), collectionObject);
+ NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(CollectionObjectClient.SERVICE_NAME);
+
+ resource.update(getResourceMap(), createUriInfo(), csid, payload.asXML());
+ }
+}
<!--
CollectionObject schema (XSD)
-
+
Entity : CollectionObject
Part : Common
Used for: JAXB binding between XML and Java objects
-
+
$LastChangedRevision$
$LastChangedDate$
-->
-<xs:schema
+<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="1.0" elementFormDefault="unqualified"
xmlns="http://collectionspace.org/services/collectionobject"
targetNamespace="http://collectionspace.org/services/collectionobject"
version="0.1">
-
+
<!--
Avoid XmlRootElement nightmare:
See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
<xs:complexType>
<xs:sequence>
<xs:element name="csid" type="xs:string"/>
-
+
<!-- Object Identification Information -->
<xs:element name="objectNumber" type="xs:string"/>
<xs:element name="otherNumberList" type="otherNumberList"/>
<xs:element name="briefDescriptions" type="briefDescriptionList"/>
+ <xs:element name="inventoryStatusList" type="inventoryStatusList"/>
<xs:element name="comments" type="commentList"/>
<xs:element name="distinguishingFeatures" type="xs:string"/>
<xs:element name="numberOfObjects" type="xs:integer"/>
<xs:element name="fieldCollectionSources" type="fieldCollectionSourceList"/>
<xs:element name="fieldCollectors" type="fieldCollectorList"/>
<xs:element name="fieldColEventNames" type="fieldColEventNameList"/>
-
+
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="titleType" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="titleTranslationSubGroupList">
<xs:sequence>
<xs:element name="titleTranslationSubGroup" type="titleTranslationSubGroup" minOccurs="0"
<xs:element name="contentObjectType" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="contentOtherGroupList">
<xs:sequence>
<xs:element name="contentOtherGroup" type="contentOtherGroup" minOccurs="0"
<xs:element name="comment" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="briefDescriptionList">
<xs:sequence>
<xs:element name="briefDescription" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
+ <xs:complexType name="inventoryStatusList">
+ <xs:sequence>
+ <xs:element name="inventoryStatus" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
<xs:complexType name="colorList">
<xs:sequence>
<xs:element name="color" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="contentActivityList">
<xs:sequence>
<xs:element name="contentActivity" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="dimensionNote" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<!-- Object description Inscription - Content Information -->
<xs:complexType name="textualInscriptionGroupList">
<xs:sequence>
<xs:element name="materialSource" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="objectStatusList">
<xs:sequence>
<xs:element name="objectStatus" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="objectProductionPeopleRole" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="objectProductionPersonGroupList">
<xs:sequence>
<xs:element name="objectProductionPersonGroup" type="objectProductionPersonGroup" minOccurs="0"
<xs:element name="assocDateNote" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="assocEventOrganizationList">
<xs:sequence>
<xs:element name="assocEventOrganization" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="assocEventPeopleList">
<xs:sequence>
<xs:element name="assocEventPeople" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="assocEventPersonList">
<xs:sequence>
<xs:element name="assocEventPerson" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="assocEventPlaceList">
<xs:sequence>
<xs:element name="assocEventPlace" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="assocPlaceNote" type="xs:string"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="ownershipDateGroupList">
<xs:sequence>
<xs:element name="ownershipDateGroup" type="structuredDateGroup" minOccurs="0"
<xs:element name="referenceGroup" type="referenceGroup" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="referenceGroup">
<xs:sequence>
<xs:element name="reference" type="xs:string"/>
<xs:element name="fieldColEventName" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
+
<xs:complexType name="structuredDateGroup">
<xs:sequence>
<xs:element name="dateDisplayDate" type="xs:string"/>
<xs:element name="scalarValuesComputed" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
-
-</xs:schema>
+</xs:schema>