private Map<String, String> authorityServiceNamesByDocType;
@SuppressWarnings("unchecked")
- protected static <T> Set<T> convertListToSet(List<T> list)
- {
- // create a set from the List
- return (Set<T>) list.stream().collect(Collectors.toSet());
+ protected static <T> Set<T> convertListToSet(List<T> list)
+ {
+ // create a set from the List
+ return (Set<T>) list.stream().collect(Collectors.toSet());
}
-
+
@Override
public void run(BatchCommon batchCommon) {
String errMsg = String.format("%s class does not support run(BatchCommon batchCommon) method.", getClass().getName());
protected PoxPayloadOut findTaxonByCsid(String csid) throws URISyntaxException, DocumentException {
return findAuthorityItemByCsid(TaxonomyAuthorityClient.SERVICE_NAME, csid);
}
-
+
protected PoxPayloadOut findAuthorityItemByShortId(String serviceName, String vocabularyShortId, String itemShortId) throws URISyntaxException, DocumentException, Exception {
AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
- PoxPayloadOut payload = resource.getAuthorityItemWithExistingContext(getServiceContext(), createDeleteFilterUriInfo(), getResourceMap(),
+ PoxPayloadOut payload = resource.getAuthorityItemWithExistingContext(getServiceContext(), createDeleteFilterUriInfo(), getResourceMap(),
"urn:cspace:name(" + vocabularyShortId + ")", "urn:cspace:name(" + itemShortId + ")");
return payload;
* Only records that reference the given item in the specified field are returned.
* If null, returns records that reference the item in any field.
* @return A List containing the csids of referencing records.
- * @throws URISyntaxException
+ * @throws URISyntaxException
*/
protected List<String> findReferencingObjects(String serviceName, String parentCsid, String csid, String type, String sourceField) throws URISyntaxException, Exception {
logger.debug("findReferencingObjects serviceName=" + serviceName + " parentCsid=" + parentCsid + " csid=" + csid + " type=" + type + " sourceField=" + sourceField);
import org.apache.commons.lang.StringUtils;
+import org.collectionspace.services.batch.BatchCommon;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.common.NuxeoBasedResource;
+import org.collectionspace.services.common.api.RefName;
import org.collectionspace.services.common.api.RefNameUtils;
+import org.collectionspace.services.common.api.RefNameUtils.AuthorityInfo;
import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
import org.collectionspace.services.common.invocable.InvocationContext.Params.Param;
@Override
public void run() {
+ run(null);
+ }
+
+ @Override
+ public void run(BatchCommon batchCommon) {
setCompletionStatus(STATUS_MIN_PROGRESS);
try {
logger.debug("Merging docType=" + docType + " target=" + target + " sourceCsids=" + StringUtils.join(sourceCsids, ","));
String serviceName = getAuthorityServiceNameForDocType(docType);
+ PoxPayloadOut targetItemPayload;
+
+ if (RefNameUtils.isTermRefname(target)) {
+ AuthorityTermInfo termInfo = RefNameUtils.parseAuthorityTermInfo(target);
+ AuthorityInfo authorityInfo = termInfo.inAuthority;
+ String targetServiceName = authorityInfo.resource;
+
+ if (!targetServiceName.equals(serviceName)) {
+ throw new DocumentException("Source item and target item must be the same record type.");
+ }
- PoxPayloadOut targetItemPayload = RefNameUtils.isTermRefname(target)
- ? findAuthorityItemByRefName(serviceName, target)
- : findAuthorityItemByCsid(serviceName, target);
+ targetItemPayload = findAuthorityItemByRefName(serviceName, target);
+ } else {
+ targetItemPayload = findAuthorityItemByCsid(serviceName, target);
+ }
String targetItemCsid = getCsid(targetItemPayload);
}
}
+ String targetDocName = getFieldValue(targetItemPayload, "/document/@name");
+
List<PoxPayloadOut> sourceItemPayloads = new ArrayList<PoxPayloadOut>();
for (String sourceCsid : sourceCsids) {
- sourceItemPayloads.add(findAuthorityItemByCsid(serviceName, sourceCsid));
+ PoxPayloadOut sourceItemPayload = findAuthorityItemByCsid(serviceName, sourceCsid);
+ String sourceDocName = getFieldValue(sourceItemPayload, "/document/@name");
+
+ if (!sourceDocName.equals(targetDocName)) {
+ throw new DocumentException("Source item and target item must be the same record type.");
+ }
+
+ sourceItemPayloads.add(sourceItemPayload);
}
return merge(docType, targetItemPayload, sourceItemPayloads);
INVOCATION_MODE_GROUP, INVOCATION_MODE_NO_CONTEXT));
}
- @Override
- public void run(BatchCommon batchCommon) {
- String errMsg = String.format("%s class does not support run(BatchCommon batchCommon) method.", getClass().getName());
- throw new java.lang.UnsupportedOperationException(errMsg);
- }
+ @Override
+ public void run() {
+ run(null);
+ }
/**
* The main work logic of the batch job. Will be called after setContext.
*/
@Override
- public void run() {
+ public void run(BatchCommon batchCommon) {
setCompletionStatus(STATUS_MIN_PROGRESS);
// For each CollectionObject record
for (String collectionObjectCsid : csids) {
-
+
// Log progress at INFO level
if (processed % logInterval == 0) {
logger.info(String.format("Recalculated computed location for %d of %d cataloging records.",
getResults().setNumAffected(numUpdated);
return getResults();
}
-
+
//
// Returns the number of distinct/unique CSID values in the list
//
private int getNumberOfDistinceRecords(AbstractCommonList abstractCommonList) {
Set<String> resultSet = new HashSet<String>();
-
+
for (AbstractCommonList.ListItem listItem : abstractCommonList.getListItem()) {
String csid = AbstractCommonListUtils.ListItemGetElementValue(listItem, CSID_ELEMENT_NAME);
if (!Tools.isBlank(csid)) {
resultSet.add(csid);
}
}
-
+
return resultSet.size();
}
String updateDate;
String mostRecentLocationDate = "";
String comparisonUpdateDate = "";
-
+
//
// If there is only one related movement record, then return it as the most recent
// movement record -if it's current location element is not empty.
}
return mostRecentMovement;
}
-
+
for (AbstractCommonList.ListItem movementListItem : relatedMovements.getListItem()) {
movementCsid = AbstractCommonListUtils.ListItemGetElementValue(movementListItem, CSID_ELEMENT_NAME);
if (Tools.isBlank(movementCsid)) {
currentLocation));
continue;
}
-
+
if (logger.isTraceEnabled()) {
logger.trace("Location date value = " + locationDate);
logger.trace("Update date value = " + updateDate);
logger.trace("Current location value = " + currentLocation);
}
-
+
// If this record's location date value is more recent than that of other
// Movement records processed so far, set the current Movement record
// as the most recent Movement.
}
}
-
+
return mostRecentMovement;
}
if (!shouldUpdateLocation(previousComputedCurrentLocation, computedCurrentLocation)) {
return numUpdated;
}
-
+
// Perform the update only if there is a non-blank object number available.
//
// In the default CollectionObject validation handler, the object number
if (logger.isTraceEnabled()) {
logger.trace("Update payload: " + "\n" + collectionObjectUpdatePayload);
}
-
+
//
// Update the record and save the response for debugging message
//
if (logger.isDebugEnabled()) {
logger.debug(String.format("Batch resource: Resonse from collectionobject (cataloging record) update: %s", new String(responseBytes)));
}
-
+
if (logger.isTraceEnabled()) {
logger.trace("Computed current location value for CollectionObject " + collectionObjectCsid
+ " was set to " + computedCurrentLocation);
return numUpdated;
}
-
+
protected boolean shouldUpdateLocation(String previousLocation, String currentLocation) {
boolean shouldUpdate = true;
if (Tools.isBlank(previousLocation) && Tools.isBlank(currentLocation)) {
protected PoxPayloadOut findByCsid(NuxeoBasedResource resource, String csid) throws URISyntaxException, DocumentException {
PoxPayloadOut result = null;
-
+
try {
result = resource.getWithParentCtx(getServiceContext(), csid);
} catch (Exception e) {
logger.error(msg);
}
}
-
+
return result;
}
URI uri = new URI(null, null, null, queryString, null);
return createUriInfo(uri.getRawQuery());
}
-
+
protected UriInfo setupQueryParamForUpdateRecords() throws URISyntaxException {
UriInfo result = null;
-
+
//
// Check first to see if we've got a query param. It will override any invocation context value
//
//
// Since there is no query param, let's check the invocation context
//
- updateCoreValues = getInvocationContext().getUpdateCoreValues();
+ updateCoreValues = getInvocationContext().getUpdateCoreValues();
}
-
+
//
// If we found a value, then use it to create a query parameter
//
if (Tools.notBlank(updateCoreValues)) {
result = createUriInfo(IClientQueryParams.UPDATE_CORE_VALUES + "=" + updateCoreValues);
}
-
+
return result;
}
private boolean isRecordDeleted(NuxeoBasedResource resource, String collectionObjectCsid)
throws URISyntaxException, DocumentException {
boolean isDeleted = false;
-
+
byte[] workflowResponse = resource.getWorkflowWithExistingContext(getServiceContext(), createUriInfo(), collectionObjectCsid);
if (workflowResponse != null) {
PoxPayloadOut payloadOut = new PoxPayloadOut(workflowResponse);
isDeleted = true;
}
}
-
+
return isDeleted;
}
uriInfo.getQueryParameters().add(WorkflowClient.WORKFLOW_QUERY_DELETED_QP, Boolean.FALSE.toString());
return uriInfo;
}
-
+
private UriInfo addFilterForPageSize(UriInfo uriInfo, long startPage, long pageSize) throws URISyntaxException {
if (uriInfo == null) {
uriInfo = createUriInfo();
}
return csids;
}
-
+
private void appendItemsToCsidsList(List<String> existingList, AbstractCommonList abstractCommonList) {
for (AbstractCommonList.ListItem listitem : abstractCommonList.getListItem()) {
existingList.add(AbstractCommonListUtils.ListItemGetCSID(listitem));
}
}
-
+
private List<String> getMemberCsidsFromGroup(String serviceName, String groupCsid) throws URISyntaxException, DocumentException {
ResourceMap resourcemap = getResourceMap();
NuxeoBasedResource resource = (NuxeoBasedResource) resourcemap.get(serviceName);
long currentPage = 0;
long pageSize = DEFAULT_PAGE_SIZE;
List<String> noContextCsids = new ArrayList<String>();
-
+
while (morePages == true) {
uriInfo = addFilterForPageSize(uriInfo, currentPage, pageSize);
AbstractCommonList collectionObjects = collectionObjectResource.getList(getServiceContext(), uriInfo);
appendItemsToCsidsList(noContextCsids, collectionObjects);
-
+
if (collectionObjects.getItemsInPage() == pageSize) { // We know we're at the last page when the number of items returned in the last request is less than the page size.
currentPage++;
} else {
- morePages = false;
+ morePages = false;
}
}
-
+
return noContextCsids;
}
}