From 356095f9caaf870f94099c6c054f6e69b3da9c98 Mon Sep 17 00:00:00 2001 From: remillet Date: Tue, 28 Jun 2016 09:33:55 -0700 Subject: [PATCH] CSPACE-6965: Adding new workflow and lifecycle support for 'deprecated' state. --- .../OSGI-INF/default-life-cycle-contrib.xml | 145 +++++++++++++++--- .../client/workflow/WorkflowClient.java | 49 +++++- ...tMultiPartCollectionSpaceResourceImpl.java | 20 +-- .../common/CollectionSpaceResource.java | 2 - .../nuxeo/WorkflowDocumentModelHandler.java | 2 +- .../client/java/DocumentModelHandler.java | 76 +-------- .../services/nuxeo/util/NuxeoUtils.java | 110 +++++++++++++ 7 files changed, 282 insertions(+), 122 deletions(-) diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml index fc2f23925..f1bb7a3f4 100644 --- a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml @@ -87,18 +87,28 @@ CollectionSpace "cs_replicating" life cycle definition. + + + Unreplicate the document back to project state. + + Undeprecate the document to the project state. + Undelete the document to the project state. + - + Replicate a document from the project state + + Soft-delete the document from the project state + Soft-delete the document from the project state @@ -107,54 +117,141 @@ Notice the convention used in the transition names below. {transition-verb)_{lifecycle-state} -e.g., delete_replicated, replicate_deleted This convention is critical to the code here: org.collectionspace.services.client.AuthorityClient.AuthorityItemDocumentModelHandler --> + + - - Delete the replicated document from the "replicated" state - Replicate the deleted document from the "deleted" state. + + Delete the replicated document from the "replicated" state + + + Unreplicate the deleted document. + Undelete the replicated document from replicated_deleted state - - Unreplicate the deleted document. + + + + + + Replicate the deprecated document from the "deprecated" state. + + + Deprecate the replicated document from the "replicated" state + + + + + Unreplicate the deprecated document. + + + Undelete the replicated document from replicated_deleted state + + + + + + + Deprecate the deleted document from the "deleted" state + + + Delete the deprecated document from the "deprecated" state. + + + Undelete the replicated document from deprecated_deleted state + + + Undelete the deprecated document. + + + + + + + Delete the deprecated document from the "deprecated" state. + + + Deprecate the deleted document from the "deleted" state + + + Delete the deprecated document from the "deprecated" state. + + + + + Undelete the deprecated document. + + + Undelete the replicated document from deprecated_deleted state + + + Undelete the deprecated document. + - delete - - replicate - + replicate + deprecate + delete - - unreplicate - - delete_replicated - - - undelete - - replicate_deleted - + replicate_deleted + deprecate_deleted + undelete + + + + + unreplicate + deprecate_replicated + delete_replicated - unreplicate_deleted - - undelete_replicated - + unreplicate_deleted + deprecate_replicated_deleted + undelete_replicated + + + + + unreplicate_deprecated + undeprecate_replicated + delete_replicated_deprecated + + + + + unreplicate_deprecated_deleted + undeprecate_replicated_deleted + undelete_replicated_deprecated + + + + + replicate_deprecated + undeprecate + delete_deprecated + + + + + replicate_deprecated_deleted + undeprecate_deleted + undelete_deprecated diff --git a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java index 622fe101a..3e6358513 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java @@ -44,27 +44,62 @@ public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl ctx, String transition) { TransitionDef result = null; - try { - Lifecycle lifecycle = ctx.getDocumentHandler().getLifecycle(); - List transitionDefList = lifecycle.getTransitionDefList().getTransitionDef(); - Iterator iter = transitionDefList.iterator(); - boolean found = false; - while (iter.hasNext() && found == false) { - TransitionDef transitionDef = iter.next(); - if (transitionDef.getName().equalsIgnoreCase(transition)) { - result = transitionDef; - found = true; - } - } + Lifecycle lifecycle; + try { + lifecycle = ctx.getDocumentHandler().getLifecycle(); + result = NuxeoUtils.getTransitionDef(lifecycle, transition); } catch (Exception e) { - logger.error("Exception trying to retreive life cycle information for: " + ctx.getDocumentType()); + logger.error("Failed to get transition definition.", e); } return result; diff --git a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java index f91d0c698..2c06dd3e4 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java @@ -23,7 +23,6 @@ */ package org.collectionspace.services.common; -import java.lang.reflect.Method; import java.util.Map; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; @@ -34,7 +33,6 @@ import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.storage.StorageClient; //import org.jboss.resteasy.core.ResourceMethod; import org.jboss.resteasy.spi.HttpRequest; -import org.jboss.resteasy.spi.metadata.ResourceMethod; /** * The Interface CollectionSpaceResource. 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 d9d805962..10e3ab8e1 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 @@ -137,7 +137,7 @@ public class WorkflowDocumentModelHandler * their current state. Without this mapping, REST API clients would need to calculate this on their own and use the longer forms like: * "delete_replicated", "undelete_replicated", "lock_deleted", "unlock_deleted", etc. */ - String getQualifiedTransitionName(DocumentWrapper wrapDoc, TransitionDef transitionDef) { + public static String getQualifiedTransitionName(DocumentWrapper wrapDoc, TransitionDef transitionDef) { String result = null; String currentTransitionName = result = transitionDef.getName(); // begin with result set to the current name diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index cf9bd22de..9e0895af6 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -86,59 +86,6 @@ public abstract class DocumentModelHandler protected String oldRefNameOnUpdate = null; // FIXME: REM - We should have setters and getters for these protected String newRefNameOnUpdate = null; // FIXME: two fields. - /* - * Map Nuxeo's life cycle object to our JAX-B based life cycle object - */ - private Lifecycle createCollectionSpaceLifecycle(org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle) { - Lifecycle result = null; - - if (nuxeoLifecyle != null) { - // - // Copy the life cycle's name - result = new Lifecycle(); - result.setName(nuxeoLifecyle.getName()); - - // We currently support only one initial state, so take the first one from Nuxeo - Collection initialStateNames = nuxeoLifecyle.getInitialStateNames(); - result.setDefaultInitial(initialStateNames.iterator().next()); - - // Next, we copy the state and corresponding transition lists - StateList stateList = new StateList(); - List states = stateList.getState(); - Collection nuxeoStates = nuxeoLifecyle.getStates(); - for (org.nuxeo.ecm.core.lifecycle.LifeCycleState nuxeoState : nuxeoStates) { - State tempState = new State(); - tempState.setDescription(nuxeoState.getDescription()); - tempState.setInitial(nuxeoState.isInitial()); - tempState.setName(nuxeoState.getName()); - // Now get the list of transitions - TransitionList transitionList = new TransitionList(); - List transitions = transitionList.getTransition(); - Collection nuxeoTransitions = nuxeoState.getAllowedStateTransitions(); - for (String nuxeoTransition : nuxeoTransitions) { - transitions.add(nuxeoTransition); - } - tempState.setTransitionList(transitionList); - states.add(tempState); - } - result.setStateList(stateList); - - // Finally, we create the transition definitions - TransitionDefList transitionDefList = new TransitionDefList(); - List transitionDefs = transitionDefList.getTransitionDef(); - Collection nuxeoTransitionDefs = nuxeoLifecyle.getTransitions(); - for (org.nuxeo.ecm.core.lifecycle.LifeCycleTransition nuxeoTransitionDef : nuxeoTransitionDefs) { - TransitionDef tempTransitionDef = new TransitionDef(); - tempTransitionDef.setDescription(nuxeoTransitionDef.getDescription()); - tempTransitionDef.setDestinationState(nuxeoTransitionDef.getDestinationStateName()); - tempTransitionDef.setName(nuxeoTransitionDef.getName()); - transitionDefs.add(tempTransitionDef); - } - result.setTransitionDefList(transitionDefList); - } - - return result; - } /* * Returns the the life cycle definition of the related Nuxeo document type for this handler. @@ -168,27 +115,8 @@ public abstract class DocumentModelHandler * @see org.collectionspace.services.common.document.DocumentHandler#getLifecycle(java.lang.String) */ @Override - public Lifecycle getLifecycle(String docTypeName) { - Lifecycle result = null; - - try { - LifeCycleService lifeCycleService = null; - try { - lifeCycleService = NXCore.getLifeCycleService(); - } catch (Exception e) { - e.printStackTrace(); - } - - String lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName); - org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName); - - result = createCollectionSpaceLifecycle(nuxeoLifecyle); - } catch (Exception e) { - // TODO Auto-generated catch block - logger.error("Could not retreive life cycle information for Nuxeo doctype: " + docTypeName, e); - } - - return result; + public Lifecycle getLifecycle(String docTypeName) { + return NuxeoUtils.getLifecycle(docTypeName); } /* diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 0308fcd6f..67153aeba 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -22,6 +22,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.File; import java.lang.reflect.Field; +import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.StringTokenizer; @@ -44,12 +46,19 @@ import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthorityItemSpecifier; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.Specifier; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.SpecifierForm; +import org.collectionspace.services.lifecycle.Lifecycle; +import org.collectionspace.services.lifecycle.State; +import org.collectionspace.services.lifecycle.StateList; +import org.collectionspace.services.lifecycle.TransitionDef; +import org.collectionspace.services.lifecycle.TransitionDefList; +import org.collectionspace.services.lifecycle.TransitionList; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentException; import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface; import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentFilter; import org.dom4j.Document; import org.dom4j.io.SAXReader; import org.mortbay.log.Log; +import org.nuxeo.ecm.core.NXCore; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.ClientException; @@ -66,6 +75,7 @@ import org.nuxeo.ecm.core.io.DocumentWriter; import org.nuxeo.ecm.core.io.impl.DocumentPipeImpl; import org.nuxeo.ecm.core.io.impl.plugins.SingleDocumentReader; import org.nuxeo.ecm.core.io.impl.plugins.XMLDocumentWriter; +import org.nuxeo.ecm.core.lifecycle.LifeCycleService; import org.nuxeo.ecm.core.schema.SchemaManager; import org.nuxeo.ecm.core.storage.StorageBlob; import org.nuxeo.ecm.core.storage.binary.Binary; @@ -139,6 +149,106 @@ public class NuxeoUtils { return result; } + static public Lifecycle getLifecycle(String docTypeName) { + Lifecycle result = null; + + try { + LifeCycleService lifeCycleService = null; + try { + lifeCycleService = NXCore.getLifeCycleService(); + } catch (Exception e) { + e.printStackTrace(); + } + + String lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName); + org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName); + + result = createCollectionSpaceLifecycle(nuxeoLifecyle); + } catch (Exception e) { + // TODO Auto-generated catch block + logger.error("Could not retreive life cycle information for Nuxeo doctype: " + docTypeName, e); + } + + return result; + } + + static public TransitionDef getTransitionDef(Lifecycle lifecycle, String transition) { + TransitionDef result = null; + + try { + List transitionDefList = lifecycle.getTransitionDefList().getTransitionDef(); + Iterator iter = transitionDefList.iterator(); + boolean found = false; + while (iter.hasNext() && found == false) { + TransitionDef transitionDef = iter.next(); + if (transitionDef.getName().equalsIgnoreCase(transition)) { + result = transitionDef; + found = true; + } + } + } catch (Exception e) { + logger.error(String.format("Exception trying to retreive lifecycle transition def from '%s' for transition '%s'.", + lifecycle.getName(), transition)); + } + + return result; + } + + + /* + * Map Nuxeo's life cycle object to our JAX-B based life cycle object + */ + static private Lifecycle createCollectionSpaceLifecycle(org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle) { + Lifecycle result = null; + + if (nuxeoLifecyle != null) { + // + // Copy the life cycle's name + result = new Lifecycle(); + result.setName(nuxeoLifecyle.getName()); + + // We currently support only one initial state, so take the first one from Nuxeo + Collection initialStateNames = nuxeoLifecyle.getInitialStateNames(); + result.setDefaultInitial(initialStateNames.iterator().next()); + + // Next, we copy the state and corresponding transition lists + StateList stateList = new StateList(); + List states = stateList.getState(); + Collection nuxeoStates = nuxeoLifecyle.getStates(); + for (org.nuxeo.ecm.core.lifecycle.LifeCycleState nuxeoState : nuxeoStates) { + State tempState = new State(); + tempState.setDescription(nuxeoState.getDescription()); + tempState.setInitial(nuxeoState.isInitial()); + tempState.setName(nuxeoState.getName()); + // Now get the list of transitions + TransitionList transitionList = new TransitionList(); + List transitions = transitionList.getTransition(); + Collection nuxeoTransitions = nuxeoState.getAllowedStateTransitions(); + for (String nuxeoTransition : nuxeoTransitions) { + transitions.add(nuxeoTransition); + } + tempState.setTransitionList(transitionList); + states.add(tempState); + } + result.setStateList(stateList); + + // Finally, we create the transition definitions + TransitionDefList transitionDefList = new TransitionDefList(); + List transitionDefs = transitionDefList.getTransitionDef(); + Collection nuxeoTransitionDefs = nuxeoLifecyle.getTransitions(); + for (org.nuxeo.ecm.core.lifecycle.LifeCycleTransition nuxeoTransitionDef : nuxeoTransitionDefs) { + TransitionDef tempTransitionDef = new TransitionDef(); + tempTransitionDef.setDescription(nuxeoTransitionDef.getDescription()); + tempTransitionDef.setDestinationState(nuxeoTransitionDef.getDestinationStateName()); + tempTransitionDef.setName(nuxeoTransitionDef.getName()); + transitionDefs.add(tempTransitionDef); + } + result.setTransitionDefList(transitionDefList); + } + + return result; + } + static public Thread deleteFileOfBlobAsync(Blob blob) { Thread result = null; -- 2.47.3