From: Ray Lee Date: Sun, 28 Jul 2019 02:34:47 +0000 (-0700) Subject: DRYD-701: Implement update inventory status batch job. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=da0d9e48db80c544bb4609e19c8c63af8caee8cc;p=tmp%2Fjakarta-migration.git DRYD-701: Implement update inventory status batch job. --- diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateInventoryStatusBatchJob.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateInventoryStatusBatchJob.java new file mode 100644 index 000000000..bbb0325a3 --- /dev/null +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/UpdateInventoryStatusBatchJob.java @@ -0,0 +1,111 @@ +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 csids = getInvocationContext().getListCSIDs().getCsid(); + List 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 getValues() { + List values = new ArrayList(); + + for (Param param : this.getParams()) { + if (param.getKey().equals("inventoryStatus")) { + values.add(param.getValue()); + } + } + + return values; + } + + public InvocationResults updateRecords(List csids, List values) throws Exception { + InvocationResults results = new InvocationResults(); + int numAffected = 0; + + ArrayList displayNames = new ArrayList(); + + 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 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()); + } +} diff --git a/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd b/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd index a73ad6475..ee8cc3033 100644 --- a/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd +++ b/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd @@ -2,16 +2,16 @@ - - + + @@ -167,7 +168,7 @@ - + @@ -217,7 +218,7 @@ - + - + - + + + + + + + - + @@ -382,7 +389,7 @@ - + @@ -452,7 +459,7 @@ - + @@ -524,7 +531,7 @@ - + - + - + - + - + @@ -727,7 +734,7 @@ - + - + @@ -802,7 +809,7 @@ - + @@ -830,6 +837,5 @@ - - +