From: Aron Roberts Date: Wed, 27 Apr 2011 23:34:17 +0000 (+0000) Subject: CSPACE-3806: Can now undelete a resource (Nuxeo document) that is in the 'soft' delet... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=26e5066deb98ab7e70efb41cf2827e69e59892de;p=tmp%2Fjakarta-migration.git CSPACE-3806: Can now undelete a resource (Nuxeo document) that is in the 'soft' deleted workflow state by applying the 'undelete' transition in Nuxeo's default lifecycle. This moves the resource back to its 'project' state. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java index 60339293c..71ae9c1b7 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java @@ -52,29 +52,34 @@ import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class WorkflowDocumentModelHandler - extends DocHandlerBase { +public class WorkflowDocumentModelHandler + extends DocHandlerBase { /** The logger. */ private static final Logger logger = LoggerFactory.getLogger(WorkflowDocumentModelHandler.class); - /* * Workflow transitions + * + * See the "Nuxeo core default life cycle definition", an XML configuration + * for Nuxeo's "lifecycle" extension point that specifies valid workflow + * states and the operations that transition documents to those states, via: + * + * org.nuxeo.ecm.core.LifecycleCoreExtensions--lifecycle (as opposed to --types) */ private static final String TRANSITION_DELETE = "delete"; private static final String TRANSITION_APPROVE = "approve"; + private static final String TRANSITION_UNDELETE = "undelete"; private static final String TRANSITION_UNKNOWN = "unknown"; /* - * Handle read (GET) - */ - - @Override - protected Map extractPart(DocumentModel docModel, + * Handle read (GET) + */ + @Override + protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta, Map addToMap) - throws Exception { + throws Exception { Map result = null; MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); //FIXME: REM - This is no longer needed. Everything is POX @@ -88,7 +93,7 @@ public class WorkflowDocumentModelHandler return result; } - + @Override public void extractAllParts(DocumentWrapper wrapDoc) throws Exception { @@ -104,27 +109,42 @@ public class WorkflowDocumentModelHandler addOutputPart(unQObjectProperties, schema, partMeta); } } - + + /** + * Get the identifier for the transition that sets a document to + * the supplied, destination workflow state. + * + * @param state a destination workflow state. + * @return an identifier for the transition required to + * place the document in that workflow state. + */ private String getTransitionFromState(String state) { - String result = TRANSITION_UNKNOWN; - if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_DELETED)) { - result = TRANSITION_DELETE; - } else if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_APPROVED)) { - result = TRANSITION_APPROVE; - } - return result; + String result = TRANSITION_UNKNOWN; + + // FIXME We may wish to add calls, such as those in + // org.nuxeo.ecm.core.lifecycle.impl.LifeCycleImpl, to validate incoming + // destination workflow state and the set of allowable state transitions. + + if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_DELETED)) { + result = TRANSITION_DELETE; + } else if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_APPROVED)) { + result = TRANSITION_APPROVE; + } else if (state.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_PROJECT)) { + result = TRANSITION_UNDELETE; + } + return result; } /* * Handle Update (PUT) */ - + @Override - protected void fillPart(PayloadInputPart part, DocumentModel docModel, - ObjectPartType partMeta, Action action, - ServiceContext ctx) - throws Exception { - WorkflowCommon workflowsCommon = (WorkflowCommon)part.getBody(); - docModel.followTransition(getTransitionFromState(workflowsCommon.getCurrentLifeCycleState())); - } + protected void fillPart(PayloadInputPart part, DocumentModel docModel, + ObjectPartType partMeta, Action action, + ServiceContext ctx) + throws Exception { + WorkflowCommon workflowsCommon = (WorkflowCommon) part.getBody(); + docModel.followTransition(getTransitionFromState(workflowsCommon.getCurrentLifeCycleState())); + } }