* @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- public void handleDelete(DocumentWrapper<List<AccountRoleRel>> wrapDoc) throws Exception {
+ public boolean handleDelete(DocumentWrapper<List<AccountRoleRel>> wrapDoc) throws Exception {
fillCommonPart(getCommonPart(), wrapDoc, true);
+ return true;
}
/* (non-Javadoc)
@PUT
@Path("{csid}/items/{itemcsid}" + WorkflowClient.SERVICE_PATH + "/{transition}")
public byte[] updateItemWorkflowWithTransition(
+ @Context UriInfo uriInfo,
@PathParam("csid") String parentIdentifier,
@PathParam("itemcsid") String itemIdentifier,
@PathParam("transition") String transition) {
PoxPayloadOut result = null;
- try {
- result = updateItemWorkflowWithTransition(NULL_CONTEXT,
+ try {
+ ServiceContext ctx = createServiceContext(getItemServiceName(), uriInfo);
+ result = updateItemWorkflowWithTransition(ctx,
parentIdentifier, itemIdentifier, transition, AuthorityServiceUtils.UPDATE_REV);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, parentIdentifier);
@DELETE
@Path("{csid}/items/{itemcsid}")
public Response deleteAuthorityItem(
+ @Context UriInfo uriInfo,
@PathParam("csid") String parentIdentifier,
@PathParam("itemcsid") String itemIdentifier) {
Response result = null;
}
try {
- deleteAuthorityItem(null, parentIdentifier, itemIdentifier);
+ ServiceContext ctx = createServiceContext(getItemServiceName(), uriInfo);
+ deleteAuthorityItem(ctx, parentIdentifier, itemIdentifier);
result = Response.status(HttpResponseCodes.SC_OK).build();
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.DELETE_FAILED + " itemcsid: " + itemIdentifier + " parentcsid:" + parentIdentifier);
String itemIdentifier) throws Exception {
Response result = null;
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName());
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), existingCtx.getUriInfo());
String parentcsid = lookupParentCSID(ctx, parentIdentifier, "deleteAuthorityItem(parent)", "DELETE_ITEM", null);
String itemCsid = lookupItemCSID(ctx, itemIdentifier, parentcsid, "deleteAuthorityItem(item)", "DELETE_ITEM"); //use itemServiceCtx if it is not null
long result = 0;
ArrayList<String> failureList = new ArrayList<String>();
+ ctx.setProperty(AuthorityServiceUtils.SHOULD_UPDATE_REV_PROPERTY, false);
+
for (String refName:refNameList) {
AuthorityTermInfo itemInfo = RefNameUtils.parseAuthorityTermInfo(refName);
AuthorityResource authorityResource = (AuthorityResource) ctx.getResource();
//
DocumentModel docModel = wrapDoc.getWrappedObject();
if (transitionDef.getName().equalsIgnoreCase(WorkflowClient.WORKFLOWTRANSITION_DELETE)) {
- if (hasReferencingObjects(this.getServiceContext(), docModel, false) == true) {
- throw new DocumentReferenceException(String.format("Cannot delete authority item '%s' because it still has records in the system that are referencing it. See the service layer log file for details.",
- docModel.getName()));
- }
+ long refsToAllObjects = hasReferencingObjects(ctx, docModel, false);
+ long refsToSoftDeletedObjects = hasReferencingObjects(ctx, docModel, true);
+ if (refsToAllObjects > 0) {
+ if (refsToAllObjects > refsToSoftDeletedObjects) {
+ //
+ // If the number of refs to active objects is greater than the number of refs to
+ // soft deleted objects then we can't delete the item.
+ //
+ throw new DocumentReferenceException(String.format("Cannot delete authority item '%s' because it still has records in the system that are referencing it. See the service layer log file for details.",
+ docModel.getName()));
+ }
+ }
}
}
* (non-Javadoc)
*/
@Override
- public void handleDelete(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ public boolean handleDelete(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ boolean result = true;
+
ServiceContext ctx = getServiceContext();
DocumentModel docModel = wrapDoc.getWrappedObject();
- long refsToObjects = hasReferencingObjects(ctx, docModel, false);
+ long refsToAllObjects = hasReferencingObjects(ctx, docModel, false);
long refsToSoftDeletedObjects = hasReferencingObjects(ctx, docModel, true);
-
- if (refsToObjects > refsToSoftDeletedObjects) {
- throw new DocumentReferenceException(String.format("Cannot delete authority item '%s' because it still has records in the system that are referencing it. See the service layer log file for details.",
- docModel.getName()));
+ if (refsToAllObjects > 0) {
+ if (refsToAllObjects > refsToSoftDeletedObjects) {
+ //
+ // If the number of refs to active objects is greater than the number of refs to
+ // soft deleted objects then we can't delete the item.
+ //
+ throw new DocumentReferenceException(String.format("Cannot delete authority item '%s' because it still has records in the system that are referencing it. See the service layer log file for details.",
+ docModel.getName()));
+ } else {
+ //
+ // If all the refs are to soft-deleted objects, we should soft-delete this authority item instead of hard-deleting it and instead of failing.
+ //
+ Boolean shouldUpdateRev = (Boolean) ctx.getProperty(AuthorityServiceUtils.SHOULD_UPDATE_REV_PROPERTY);
+ String parentCsid = (String) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.IN_AUTHORITY);
+ String itemCsid = docModel.getName();
+ AuthorityResource authorityResource = (AuthorityResource) ctx.getResource(getAuthorityServicePath());
+ authorityResource.updateItemWorkflowWithTransition(ctx, parentCsid, itemCsid, WorkflowClient.WORKFLOWTRANSITION_DELETE,
+ shouldUpdateRev != null ? shouldUpdateRev : true);
+ result = false; // Don't delete since we just soft-deleted it.
+ }
}
+
+ return result;
}
/**
AuthorityResource authorityResource = (AuthorityResource)ctx.getResource(getAuthorityServicePath());
String itemCsid = docModel.getName();
UriTemplateRegistry uriTemplateRegistry = ServiceMain.getInstance().getUriTemplateRegistry();
- ctx.getUriInfo().getQueryParameters().add(WorkflowClient.WORKFLOW_QUERY_ONLY_DELETED, Boolean.toString(onlyRefsToDeletedObjects)); // Add the wf_deleted query param to the resource call
+ if (ctx.getUriInfo() == null) {
+ //
+ // We need a UriInfo object so we can pass "query" params to the AuthorityResource's getReferencingObjects() method
+ //
+ ctx.setUriInfo(this.getServiceContext().getUriInfo()); // try to get a UriInfo instance from the handler's context
+ }
+ ctx.getUriInfo().getQueryParameters().addFirst(WorkflowClient.WORKFLOW_QUERY_ONLY_DELETED, Boolean.toString(onlyRefsToDeletedObjects)); // Add the wf_deleted query param to the resource call
AuthorityRefDocList refObjs = authorityResource.getReferencingObjects(ctx, inAuthorityCsid, itemCsid,
uriTemplateRegistry, ctx.getUriInfo());
* @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- public void handleDelete(DocumentWrapper<List<PermissionRoleRel>> wrapDoc) throws Exception {
+ public boolean handleDelete(DocumentWrapper<List<PermissionRoleRel>> wrapDoc) throws Exception {
fillCommonPart(getCommonPart(), wrapDoc, true);
+ return true;
}
/* (non-Javadoc)
break;
case DELETE:
- handleDelete((DocumentWrapper<WT>) wrapDoc);
+ result = handleDelete((DocumentWrapper<WT>) wrapDoc);
break;
case SYNC:
* @see org.collectionspace.services.common.document.DocumentHandler#handleDelete(org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
- // Do nothing. Subclasses can override if they want/need to.
+ public boolean handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception {
+ return true;
}
/* (non-Javadoc)
* @param wrapDoc
* @throws Exception
*/
- public void handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception;
+ public boolean handleDelete(DocumentWrapper<WT> wrapDoc) throws Exception;
/**
* complete is called by the client to provide an opportunity to the handler
DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
wrapDoc = new DocumentWrapperImpl<DocumentModel>(repoSession.getDocument(docRef));
((DocumentModelHandler) handler).setRepositorySession(repoSession);
- handler.handle(Action.DELETE, wrapDoc);
- repoSession.removeDocument(docRef);
+ if (handler.handle(Action.DELETE, wrapDoc)) {
+ repoSession.removeDocument(docRef);
+ }
} catch (ClientException ce) {
String msg = logException(ce, "Could not find document to delete with CSID=" + id);
throw new DocumentNotFoundException(msg, ce);
}
@Override
- public void handleDelete(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ public boolean handleDelete(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ boolean result = true;
+
String workflowState = WorkflowClient.WORKFLOWSTATE_LOCKED;
// Neither the subject nor the object can be locked
if (subjectOrObjectInWorkflowState(wrapDoc, workflowState) == false) {
throw new ServiceException(HttpURLConnection.HTTP_FORBIDDEN,
"Cannot delete a relationship if either end is in the workflow state: " + workflowState);
}
+
+ return result;
}
private void populateSubjectAndObjectValues(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {