import org.collectionspace.services.client.TaxonomyAuthorityClient;
import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectConstants;
+import org.collectionspace.services.common.CollectionSpaceResource;
import org.collectionspace.services.common.NuxeoBasedResource;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.UriTemplateRegistry;
final Logger logger = LoggerFactory.getLogger(AbstractBatchJob.class);
private Map<String, String> authorityServiceNamesByDocType;
-
+
protected String getFieldXml(Map<String, String> fields, String fieldName) {
return getFieldXml(fieldName, fields.get(fieldName));
}
protected String getFieldXml(Map<String, String> fields) {
StringBuffer xmlBuffer = new StringBuffer();
-
+
for (String fieldName : fields.keySet()) {
xmlBuffer.append(getFieldXml(fields, fieldName));
}
-
+
return xmlBuffer.toString();
}
-
+
protected String getFieldXml(String fieldName, String fieldValue) {
String xml = "<" + fieldName + ">" + (fieldValue == null ? "" : StringEscapeUtils.escapeXml(fieldValue)) + "</" + fieldName + ">";
-
+
return xml;
}
-
+
protected String createRelation(String subjectCsid, String subjectDocType, String objectCsid, String objectDocType, String relationshipType) throws ResourceException {
String relationCsid = null;
/**
* Return related records, based on the supplied search criteria. Soft-deleted relations
* are filtered from the list, but soft-deleted subject/object records are not.
- *
+ *
* @param subjectCsid The csid of the subject record. If null or empty, match any subject.
* @param subjectDocType The document type of the subject record. If null or empty, match any subject type.
* @param predicate The predicate of the relation. If null or empty, match any predicate.
return relationList.getRelationListItem();
}
-
+
protected List<String> findRelatedObjects(String subjectCsid, String subjectDocType, String predicate, String objectCsid, String objectDocType) throws URISyntaxException {
List<String> csids = new ArrayList<String>();
for (RelationsCommonList.RelationListItem item : findRelated(subjectCsid, subjectDocType, predicate, objectCsid, objectDocType)) {
csids.add(item.getObjectCsid());
}
-
+
return csids;
}
for (RelationsCommonList.RelationListItem item : findRelated(subjectCsid, subjectDocType, predicate, objectCsid, objectDocType)) {
csids.add(item.getSubjectCsid());
}
-
+
return csids;
}
// There should be only one broader object.
String broader = relatedObjects.size() > 0 ? relatedObjects.get(0) : null;
-
+
return broader;
}
/**
* Returns the movement record related to the specified record, if there is only one.
* Returns null if there are zero or more than one related movement records.
- *
+ *
* @param subjectCsid The csid of the record
* @return
* @throws URISyntaxException
protected String findSingleRelatedMovement(String subjectCsid) throws URISyntaxException, DocumentException {
String foundMovementCsid = null;
List<String> movementCsids = findRelatedMovements(subjectCsid);
-
+
for (String movementCsid : movementCsids) {
PoxPayloadOut movementPayload = findMovementByCsid(movementCsid);
String movementWorkflowState = getFieldValue(movementPayload, CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA, CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE);
-
+
if (!movementWorkflowState.equals(WorkflowClient.WORKFLOWSTATE_DELETED)) {
if (foundMovementCsid != null) {
return null;
}
-
+
foundMovementCsid = movementCsid;
}
}
protected PoxPayloadOut findByUri(String uri) throws URISyntaxException, DocumentException {
PoxPayloadOut payload = null;
String[] uriParts = uri.split("/");
-
+
if (uriParts.length == 3) {
String serviceName = uriParts[1];
String csid = uriParts[2];
-
+
payload = findByCsid(serviceName, csid);
}
else if (uriParts.length == 5) {
String vocabularyCsid = uriParts[2];
String items = uriParts[3];
String csid = uriParts[4];
-
+
if (items.equals("items")) {
payload = findAuthorityItemByCsid(serviceName, vocabularyCsid, csid);
}
protected PoxPayloadOut findMovementByCsid(String csid) throws URISyntaxException, DocumentException {
return findByCsid(MovementClient.SERVICE_NAME, csid);
}
-
+
protected List<String> findAll(String serviceName, int pageSize, int pageNum) throws URISyntaxException, DocumentException {
return findAll(serviceName, pageSize, pageNum, null);
}
-
+
protected List<String> findAll(String serviceName, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
- NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(serviceName);
+ NuxeoBasedResource resource = (NuxeoBasedResource) getResourceMap().get(serviceName);
return findAll(resource, pageSize, pageNum, null);
}
-
+
protected List<String> findAll(NuxeoBasedResource resource, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
AbstractCommonList list = resource.getList(createPagedListUriInfo(resource.getServiceName(), pageNum, pageSize, sortBy));
List<String> csids = new ArrayList<String>();
else {
for (AbstractCommonList.ListItem item : list.getListItem()) {
for (org.w3c.dom.Element element : item.getAny()) {
-
+
if (element.getTagName().equals("csid")) {
csids.add(element.getTextContent());
break;
}
}
}
-
+
return csids;
- }
-
+ }
+
protected List<String> findAllCollectionObjects(int pageSize, int pageNum) throws URISyntaxException, DocumentException {
return findAll(CollectionObjectClient.SERVICE_NAME, pageSize, pageNum);
}
-
+
protected List<String> getVocabularyCsids(String serviceName) throws URISyntaxException {
AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
protected List<String> getVocabularyCsids(AuthorityResource<?, ?> resource) throws URISyntaxException {
AbstractCommonList vocabularyList = resource.getAuthorityList(createDeleteFilterUriInfo());
List<String> csids = new ArrayList<String>();
-
+
for (AbstractCommonList.ListItem item : vocabularyList.getListItem()) {
for (org.w3c.dom.Element element : item.getAny()) {
if (element.getTagName().equals("csid")) {
return csids;
}
-
+
protected List<String> findAllAuthorityItems(String serviceName, String vocabularyCsid, int pageSize, int pageNum) throws URISyntaxException, DocumentException {
return findAllAuthorityItems(serviceName, vocabularyCsid, pageSize, pageNum, null);
}
-
+
protected List<String> findAllAuthorityItems(String serviceName, String vocabularyCsid, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
return findAllAuthorityItems(resource, vocabularyCsid, pageSize, pageNum, sortBy);
}
-
+
protected List<String> findAllAuthorityItems(AuthorityResource<?, ?> resource, String vocabularyCsid, int pageSize, int pageNum, String sortBy) throws URISyntaxException, DocumentException {
AbstractCommonList list = resource.getAuthorityItemList(vocabularyCsid, createPagedListUriInfo(resource.getServiceName(), pageNum, pageSize, sortBy));
- List<String> csids = new ArrayList<String>();
-
+ List<String> csids = new ArrayList<String>();
+
for (AbstractCommonList.ListItem item : list.getListItem()) {
for (org.w3c.dom.Element element : item.getAny()) {
-
+
if (element.getTagName().equals("csid")) {
csids.add(element.getTextContent());
break;
}
}
}
-
+
return csids;
- }
-
+ }
+
protected PoxPayloadOut findAuthorityItemByCsid(String serviceName, String csid) throws URISyntaxException, DocumentException {
List<String> vocabularyCsids = getVocabularyCsids(serviceName);
PoxPayloadOut itemPayload = null;
-
+
for (String vocabularyCsid : vocabularyCsids) {
logger.debug("vocabularyCsid=" + vocabularyCsid);
-
+
// FIXME: This throws DocumentNotFoundException, so will never go to the next vocabulary
itemPayload = findAuthorityItemByCsid(serviceName, vocabularyCsid, csid);
-
+
if (itemPayload != null) {
break;
}
}
-
+
return itemPayload;
}
-
+
protected PoxPayloadOut findAuthorityItemByCsid(String serviceName, String vocabularyCsid, String csid) throws URISyntaxException, DocumentException {
AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
byte[] response = resource.getAuthorityItem(null, createDeleteFilterUriInfo(), getResourceMap(), vocabularyCsid, csid);
-
+
PoxPayloadOut payload = new PoxPayloadOut(response);
return payload;
}
-
+
protected String getAuthorityServiceNameForDocType(String authorityDocType) {
if (authorityServiceNamesByDocType == null) {
authorityServiceNamesByDocType = new HashMap<String, String>();
-
+
for (String serviceName : getResourceMap().keySet()) {
- AuthorityResource resource = (AuthorityResource) getResourceMap().get(serviceName);
-
+ CollectionSpaceResource<?, ?> resource = (CollectionSpaceResource<?, ?>) getResourceMap().get(serviceName);
+
if (resource instanceof AuthorityResource) {
AuthorityResource<?, ?> authorityResource = (AuthorityResource<?, ?>) resource;
String docType = authorityResource.getItemDocType(getTenantId());
-
+
authorityServiceNamesByDocType.put(docType, serviceName);
}
}
}
-
+
return authorityServiceNamesByDocType.get(authorityDocType);
}
-
+
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 {
AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
byte[] response = resource.getAuthorityItem(null, createDeleteFilterUriInfo(), getResourceMap(), "urn:cspace:name(" + vocabularyShortId + ")", "urn:cspace:name(" + itemShortId + ")");
-
+
PoxPayloadOut payload = new PoxPayloadOut(response);
return payload;
}
-
+
protected PoxPayloadOut findAuthorityItemByRefName(String serviceName, String refName) throws URISyntaxException, DocumentException {
RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
-
+
String vocabularyShortId = item.getParentShortIdentifier();
String itemShortId = item.getShortIdentifier();
-
+
return findAuthorityItemByShortId(serviceName, vocabularyShortId, itemShortId);
}
protected PoxPayloadOut findPlaceByRefName(String refName) throws URISyntaxException, DocumentException {
return findAuthorityItemByRefName(PlaceAuthorityClient.SERVICE_NAME, refName);
}
-
+
protected PoxPayloadOut findTaxonByRefName(String refName) throws URISyntaxException, DocumentException {
return findAuthorityItemByRefName(TaxonomyAuthorityClient.SERVICE_NAME, refName);
}
-
+
protected List<AuthorityRefDocList.AuthorityRefDocItem> findReferencingFields(String serviceName, String parentCsid, String csid, String type, int pageNum, int pageSize) throws URISyntaxException {
AuthorityResource<?, ?> resource = (AuthorityResource<?, ?>) getResourceMap().get(serviceName);
// More items than the pageSize might be returned, and the next page may
// contain repeats of items already returned on the previous page. Any
// code that uses this function should be aware of this.
-
+
AuthorityRefDocList refDocList = resource.getReferencingObjects(parentCsid, csid, createRefSearchFilterUriInfo(type, pageNum, pageSize));
-
+
return refDocList.getAuthorityRefDocItem();
}
/**
* Finds records that reference a given authority item. Soft-deleted records are not included.
- *
+ *
* @param serviceName The name of the authority service, e.g. "personauthorities"
* @param parentCsid The csid of the authority instance (aka vocabulary). This may be a guid or a urn,
* e.g. "7a4981c4-77b7-433b-8086", "urn:cspace:name(person)"
List<AuthorityRefDocList.AuthorityRefDocItem> items = findReferencingFields(serviceName, parentCsid, csid, type, 0, 0);
List<String> csids = new ArrayList<String>();
-
+
for (AuthorityRefDocList.AuthorityRefDocItem item : items) {
/*
* If a multivalue field contains a reference to the object multiple times, the referencing object
* seems to get returned multiple times in the list, but only the first has a non-null workflow state.
* A bug? Handle this by discarding list items with a null workflow state.
*/
-
+
if (item.getWorkflowState() != null && !item.getWorkflowState().equals(WorkflowClient.WORKFLOWSTATE_DELETED) && (sourceField == null || item.getSourceField().equals(sourceField))) {
csids.add(item.getDocId());
}
return csids;
}
-
+
protected List<String> findReferencingObjects(String serviceName, String csid, String type, String sourceField) throws URISyntaxException, DocumentException {
logger.debug("findReferencingObjects serviceName=" + serviceName + " csid=" + csid + " type=" + type + " sourceField=" + sourceField);
List<String> vocabularyCsids = getVocabularyCsids(serviceName);
String parentCsid = null;
-
+
if (vocabularyCsids.size() == 1) {
parentCsid = vocabularyCsids.get(0);
}
else {
for (String vocabularyCsid : vocabularyCsids) {
PoxPayloadOut itemPayload = findAuthorityItemByCsid(serviceName, vocabularyCsid, csid);
-
+
if (itemPayload != null) {
parentCsid = vocabularyCsid;
break;
}
}
}
-
+
return findReferencingObjects(serviceName, parentCsid, csid, type, sourceField);
}
protected List<String> findReferencingCollectionObjects(String serviceName, String vocabularyShortId, String csid, String sourceField) throws URISyntaxException, DocumentException {
return findReferencingObjects(serviceName, "urn:cspace:name(" + vocabularyShortId + ")", csid, ServiceBindingUtils.SERVICE_TYPE_OBJECT, sourceField);
}
-
+
/**
* Create a stub UriInfo
- *
- * @throws URISyntaxException
+ *
+ * @throws URISyntaxException
*/
protected UriInfo createUriInfo() throws URISyntaxException {
return createUriInfo("");
}
protected UriInfo createUriInfo(String queryString) throws URISyntaxException {
- return createUriInfo(queryString, Collections.<PathSegment> emptyList());
+ List<PathSegment> pathSegments = new ArrayList<PathSegment>();
+
+ // Some code in services assumes pathSegments will have at least one element,
+ // so add an empty one.
+
+ pathSegments.add(new PathSegmentImpl("", false));
+
+ return createUriInfo(queryString, pathSegments);
}
-
+
protected UriInfo createUriInfo(String queryString, List<PathSegment> pathSegments) throws URISyntaxException {
queryString = escapeQueryString(queryString);
-
+
URI absolutePath = new URI("");
URI baseUri = new URI("");
return new UriInfoImpl(absolutePath, baseUri, "", queryString, pathSegments);
}
-
+
protected UriInfo createDeleteFilterUriInfo() throws URISyntaxException {
return createUriInfo("wf_deleted=false&pgSz=0");
}
protected UriInfo createRelationSearchUriInfo(String subjectCsid, String subjectDocType, String predicate, String objectCsid, String objectDocType) throws URISyntaxException {
List<String> queryParams = new ArrayList<String>(6);
-
+
if (StringUtils.isNotEmpty(subjectCsid)) {
queryParams.add(IRelationsManager.SUBJECT_QP + "=" + subjectCsid);
}
if (StringUtils.isNotEmpty(objectCsid)) {
queryParams.add(IRelationsManager.OBJECT_QP + "=" + objectCsid);
}
-
+
if (StringUtils.isNotEmpty(objectDocType)) {
queryParams.add(IRelationsManager.OBJECT_TYPE_QP + "=" + objectDocType);
}
-
+
queryParams.add("wf_deleted=false");
queryParams.add("pgSz=0");
-
+
return createUriInfo(StringUtils.join(queryParams, "&"));
}
-
+
protected UriInfo createRefSearchFilterUriInfo(String type) throws URISyntaxException {
return createRefSearchFilterUriInfo(type, 1, 0);
}
protected UriInfo createRefSearchFilterUriInfo(String type, int pageNum, int pageSize) throws URISyntaxException {
String queryString = "wf_deleted=false&pgSz=" + pageSize + "&pgNum=" + pageNum;
-
+
if (type != null) {
queryString = "type=" + type + "&" + queryString;
}
-
+
return createUriInfo(queryString);
}
protected UriInfo createPagedListUriInfo(String serviceName, int pageNum, int pageSize) throws URISyntaxException {
return createPagedListUriInfo(serviceName, pageNum, pageSize, null);
}
-
+
protected UriInfo createPagedListUriInfo(String serviceName, int pageNum, int pageSize, String sortBy) throws URISyntaxException {
List<PathSegment> pathSegments = new ArrayList<PathSegment>(1);
pathSegments.add(new PathSegmentImpl(serviceName, false));
-
+
return createUriInfo("pgSz=" + pageSize + "&pgNum=" + pageNum + (sortBy != null ? "&sortBy=" + sortBy : "") + "&wf_deleted=false", pathSegments);
}
return uri.getRawQuery();
}
-
+
/**
* Get a field value from a PoxPayloadOut, given a part name and xpath expression.
*/
return value;
}
-
+
protected String getFieldValue(PoxPayloadOut payload, String fieldPath) {
String value = null;
break;
}
}
-
+
return value;
}
protected boolean getBooleanFieldValue(PoxPayloadOut payload, String partLabel, String fieldPath) {
String value = getFieldValue(payload, partLabel, fieldPath);
-
+
return (value != null && value.equals("true"));
}
-
+
protected List<String> getFieldValues(PoxPayloadOut payload, String partLabel, String fieldPath) {
List<String> values = new ArrayList<String>();
PayloadOutputPart part = payload.getPart(partLabel);
return values;
}
-
+
protected String getDisplayNameFromRefName(String refName) {
RefName.AuthorityItem item = RefName.AuthorityItem.parse(refName);
return (item == null ? refName : item.displayName);
}
-
+
protected String getCsid(PoxPayloadOut payload) {
String uri = getFieldValue(payload, CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA, CollectionSpaceClient.COLLECTIONSPACE_CORE_URI);
String[] elements = StringUtils.split(uri, '/');
String csid = elements[elements.length - 1];
-
+
return csid;
}
private static final long serialVersionUID = 1L;
private Response response;
-
+
public ResourceException(Response response, String message) {
super(message);
this.setResponse(response);
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
setCompletionStatus(STATUS_MIN_PROGRESS);
try {
- String docType = null;
- String targetCsid = null;
- List<String> sourceCsids = new ArrayList<String>();
+ String target = null;
+ Set<String> sourceCsids = new LinkedHashSet<String>();
+ String docType = this.getDocType();
+
+ if (this.requestIsForInvocationModeSingle()) {
+ String singleCsid = this.getSingleCsid();
+
+ if (singleCsid != null) {
+ sourceCsids.add(singleCsid);
+ }
+ } else if (this.requestIsForInvocationModeList()) {
+ sourceCsids.addAll(this.getListCsids());
+ }
for (Param param : this.getParams()) {
String key = param.getKey();
if (key.equals("docType")) {
docType = param.getValue();
}
+ else if (key.equals("target")) {
+ target = param.getValue();
+ }
else if (key.equals("targetCSID")) {
- targetCsid = param.getValue();
+ target = param.getValue();
}
else if (key.equals("sourceCSID")) {
sourceCsids.add(param.getValue());
}
}
- if (docType == null || docType.equals("")) {
- throw new Exception("a docType must be supplied");
- }
-
- if (targetCsid == null || targetCsid.equals("")) {
- throw new Exception("a target csid parameter (targetCSID) must be supplied");
+ if (target == null || target.equals("")) {
+ throw new Exception("a target or targetCSID parameter must be supplied");
}
if (sourceCsids.size() == 0) {
throw new Exception("a source csid must be supplied");
}
- InvocationResults results = merge(docType, targetCsid, sourceCsids);
+ InvocationResults results = merge(docType, target, sourceCsids);
setResults(results);
setCompletionStatus(STATUS_COMPLETE);
}
}
- public InvocationResults merge(String docType, String targetCsid, String sourceCsid) throws URISyntaxException, DocumentException {
- return merge(docType, targetCsid, Arrays.asList(sourceCsid));
+ public InvocationResults merge(String docType, String target, String sourceCsid) throws URISyntaxException, DocumentException {
+ return merge(docType, target, new LinkedHashSet<String>(Arrays.asList(sourceCsid)));
}
- public InvocationResults merge(String docType, String targetCsid, List<String> sourceCsids) throws URISyntaxException, DocumentException {
- logger.debug("Merging docType=" + docType + " targetCsid=" + targetCsid + " sourceCsids=" + StringUtils.join(sourceCsids, ","));
+ public InvocationResults merge(String docType, String target, Set<String> sourceCsids) throws URISyntaxException, DocumentException {
+ logger.debug("Merging docType=" + docType + " target=" + target + " sourceCsids=" + StringUtils.join(sourceCsids, ","));
String serviceName = getAuthorityServiceNameForDocType(docType);
- PoxPayloadOut targetItemPayload = findAuthorityItemByCsid(serviceName, targetCsid);
+ PoxPayloadOut targetItemPayload = RefNameUtils.isTermRefname(target)
+ ? findAuthorityItemByRefName(serviceName, target)
+ : findAuthorityItemByCsid(serviceName, target);
+
List<PoxPayloadOut> sourceItemPayloads = new ArrayList<PoxPayloadOut>();
for (String sourceCsid : sourceCsids) {
updateAuthorityItem(docType, inAuthority, targetCsid, getUpdatePayload(targetTermGroupListElement, mergedTermGroupListElement));
- userNotes.add("The target record with CSID " + targetCsid + " (" + targetRefName + ") was updated.");
+ String targetDisplayName = RefNameUtils.getDisplayName(targetRefName);
+
+ userNotes.add("Updated the target record, " + targetDisplayName + ".");
numAffected++;
String serviceName = getAuthorityServiceNameForDocType(docType);
String sourceCsid = getCsid(sourceItemPayload);
String sourceRefName = getRefName(sourceItemPayload);
- InvocationResults results = deleteAuthorityItem(docType, getFieldValue(sourceItemPayload, "inAuthority"), sourceCsid);
+ InvocationResults results = deleteAuthorityItem(docType, getFieldValue(sourceItemPayload, "inAuthority"), sourceCsid, sourceRefName);
userNotes.add(results.getUserNote());
numAffected += results.getNumAffected();
private InvocationResults updateReferences(String serviceName, String inAuthority, String sourceCsid, String sourceRefName, String targetRefName) throws URISyntaxException, DocumentException {
logger.debug("Updating references: serviceName=" + serviceName + " inAuthority=" + inAuthority + " sourceCsid=" + sourceCsid + " sourceRefName=" + sourceRefName + " targetRefName=" + targetRefName);
+ String sourceDisplayName = RefNameUtils.getDisplayName(sourceRefName);
+
int pageNum = 0;
int pageSize = 100;
List<AuthorityRefDocList.AuthorityRefDocItem> items;
InvocationResults results = new InvocationResults();
results.setNumAffected(numUpdated);
- results.setUserNote(numUpdated > 0 ?
- numUpdated + " records that referenced the source record with CSID " + sourceCsid + " were updated." :
- "No records referenced the source record with CSID " + sourceCsid + ".");
+
+ if (numUpdated > 0) {
+ results.setUserNote(
+ "Updated "
+ + numUpdated
+ + (numUpdated == 1 ? " record " : " records ")
+ + "that referenced the source record, "
+ + sourceDisplayName + "."
+ );
+ } else {
+ results.setUserNote("No records referenced the source record, " + sourceDisplayName + ".");
+ }
return results;
}
resource.updateAuthorityItem(getResourceMap(), createUriInfo(), inAuthority, csid, payload);
}
- private InvocationResults deleteAuthorityItem(String docType, String inAuthority, String csid) throws URISyntaxException {
+ private InvocationResults deleteAuthorityItem(String docType, String inAuthority, String csid, String refName) throws URISyntaxException {
int numAffected = 0;
List<String> userNotes = new ArrayList<String>();
+ String displayName = RefNameUtils.getDisplayName(refName);
// If the item is the broader context of any items, warn and do nothing.
if (narrowerItemCsids.size() > 0) {
logger.debug("Item " + csid + " has narrower items -- not deleting");
- userNotes.add("The source record with CSID " + csid + " was not deleted because it has narrower context items.");
+ userNotes.add("The source record, " + displayName + ", was not deleted because it has narrower items in its hierarchy.");
}
else {
// If the item has a broader context, delete the relation.
- List<String> relationCsids = new ArrayList<String>();
+ List<RelationsCommonList.RelationListItem> relationItems = new ArrayList<RelationsCommonList.RelationListItem>();
for (RelationsCommonList.RelationListItem item : findRelated(csid, null, "hasBroader", null, null)) {
- relationCsids.add(item.getCsid());
+ relationItems.add(item);
}
- if (relationCsids.size() > 0) {
+ if (relationItems.size() > 0) {
RelationResource relationResource = (RelationResource) getResourceMap().get(RelationClient.SERVICE_NAME);
- for (String relationCsid : relationCsids) {
+ for (RelationsCommonList.RelationListItem item : relationItems) {
+ String relationCsid = item.getCsid();
+
+ String subjectRefName = item.getSubject().getRefName();
+ String subjectDisplayName = RefNameUtils.getDisplayName(subjectRefName);
+
+ String objectRefName = item.getObject().getRefName();
+ String objectDisplayName = RefNameUtils.getDisplayName(objectRefName);
+
logger.debug("Deleting hasBroader relation " + relationCsid);
relationResource.delete(relationCsid);
- userNotes.add("The broader relation with CSID " + relationCsid + " was deleted.");
+ userNotes.add("Deleted the \"has broader\" relation from " + subjectDisplayName + " to " + objectDisplayName + ".");
numAffected++;
}
}
resource.updateItemWorkflowWithTransition(null, inAuthority, csid, "delete");
- userNotes.add("The source record with CSID " + csid + " was soft deleted.");
+ userNotes.add("Deleted the source record, " + displayName + ".");
numAffected++;
}