]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6965: Adding new workflow and lifecycle support for 'deprecated' state.
authorremillet <remillet@yahoo.com>
Tue, 28 Jun 2016 16:33:55 +0000 (09:33 -0700)
committerremillet <remillet@yahoo.com>
Tue, 28 Jun 2016 16:33:55 +0000 (09:33 -0700)
3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml
services/client/src/main/java/org/collectionspace/services/client/workflow/WorkflowClient.java
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/workflow/service/nuxeo/WorkflowDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

index fc2f23925cbe98771069f56d88f3c8b4235839c1..f1bb7a3f412afebb56a88b65a1bb771d470b89ce 100644 (file)
                <documentation>CollectionSpace "cs_replicating" life cycle definition.</documentation>
                <lifecycle name="cs_replicating" defaultInitial="project">
                        <transitions>
+                       
+                       <!-- State: Project -->
+                               
                                <!-- Transitions TO the "project" state -->
                                <transition name="unreplicate" destinationState="project">
                                        <description>Unreplicate the document back to project state.</description>
                                </transition>
+                               <transition name="undeprecate" destinationState="project">
+                                       <description>Undeprecate the document to the project state.</description>
+                               </transition>
                                <transition name="undelete" destinationState="project">
                                        <description>Undelete the document to the project state.</description>
                                </transition>
+                               
 
-                               <!-- Transitions FROM "project" state TO the "replicated" and the "deleted" states -->
+                               <!-- Transitions FROM "project" state -->
                                <transition name="replicate" destinationState="replicated">
                                        <description>Replicate a document from the project state</description>
                                </transition>
+                               <transition name="deprecate" destinationState="deprecated">
+                                       <description>Soft-delete the document from the project state</description>
+                               </transition>
                                <transition name="delete" destinationState="deleted">
                                        <description>Soft-delete the document from the project state</description>
                                </transition>
                                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
                        -->
+                       
+                       <!-- State: replicated_deleted -->
 
                                <!-- Transitions TO "replicated_deleted" state -->
-                               <transition name="delete_replicated" destinationState="replicated_deleted">
-                                       <description>Delete the replicated document from the "replicated" state</description>
-                               </transition>
                                <transition name="replicate_deleted" destinationState="replicated_deleted">
                                        <description>Replicate the deleted document from the "deleted" state.</description>
                                </transition>
+                               <transition name="delete_replicated" destinationState="replicated_deleted">
+                                       <description>Delete the replicated document from the "replicated" state</description>
+                               </transition>
 
                                <!-- Transitions FROM "replicated_deleted" state -->
+                               <transition name="unreplicate_deleted" destinationState="deleted">
+                                       <description>Unreplicate the deleted document.</description>
+                               </transition>
                                <transition name="undelete_replicated" destinationState="replicated">
                                        <description>Undelete the replicated document from replicated_deleted state</description>
                                </transition>
-                               <transition name="unreplicate_deleted" destinationState="deleted">
-                                       <description>Unreplicate the deleted document.</description>
+                               
+                       <!-- State: replicated_deprecated -->
+                               
+                               <!-- Transitions TO "replicated_deprecated" state -->
+                               <transition name="replicate_deprecated" destinationState="replicated_deprecated">
+                                       <description>Replicate the deprecated document from the "deprecated" state.</description>
+                               </transition>
+                               <transition name="deprecate_replicated" destinationState="replicated_deprecated">
+                                       <description>Deprecate the replicated document from the "replicated" state</description>
+                               </transition>
+
+                               <!-- Transitions FROM "replicated_deprecated" state -->
+                               <transition name="unreplicate_deprecated" destinationState="deprecated">
+                                       <description>Unreplicate the deprecated document.</description>
+                               </transition>
+                               <transition name="undeprecate_replicated" destinationState="replicated">
+                                       <description>Undelete the replicated document from replicated_deleted state</description>
+                               </transition>
+                               
+                       <!-- State: deprecated_deleted -->
+                               
+                               <!-- Transitions TO "deprecated_deleted" state -->
+                               <transition name="deprecate_deleted" destinationState="deprecated_deleted">
+                                       <description>Deprecate the deleted document from the "deleted" state</description>
+                               </transition>
+                               <transition name="delete_deprecated" destinationState="deprecated_deleted">
+                                       <description>Delete the deprecated document from the "deprecated" state.</description>
                                </transition>
 
+                               <!-- Transitions FROM "deprecated_deleted" state -->
+                               <transition name="undeprecate_deleted" destinationState="deleted">
+                                       <description>Undelete the replicated document from deprecated_deleted state</description>
+                               </transition>
+                               <transition name="undelete_deprecated" destinationState="deprecated">
+                                       <description>Undelete the deprecated document.</description>
+                               </transition>
+                               
+                       <!-- State: replicated_deprecated_deleted -->
+                               
+                               <!-- Transitions TO "replicated_deprecated_deleted" state -->
+                               <transition name="replicate_deprecated_deleted" destinationState="replicated_deprecated_deleted">
+                                       <description>Delete the deprecated document from the "deprecated" state.</description>
+                               </transition>
+                               <transition name="deprecate_replicated_deleted" destinationState="replicated_deprecated_deleted">
+                                       <description>Deprecate the deleted document from the "deleted" state</description>
+                               </transition>
+                               <transition name="delete_replicated_deprecated" destinationState="replicated_deprecated_deleted">
+                                       <description>Delete the deprecated document from the "deprecated" state.</description>
+                               </transition>                           
+
+                               <!-- Transitions FROM "replicated_deprecated_deleted" state -->
+                               <transition name="unreplicate_deprecated_deleted" destinationState="deprecated_deleted">
+                                       <description>Undelete the deprecated document.</description>
+                               </transition>
+                               <transition name="undeprecate_replicated_deleted" destinationState="replicated_deleted">
+                                       <description>Undelete the replicated document from deprecated_deleted state</description>
+                               </transition>
+                               <transition name="undelete_replicated_deprecated" destinationState="replicated_deprecated">
+                                       <description>Undelete the deprecated document.</description>
+                               </transition>
                        </transitions>
 
                        <states>
                                <state name="project" description="Default state" initial="true">
                                        <transitions>
-                                               <transition>delete</transition>
-                                               <!-- To "deleted" state -->
-                                               <transition>replicate</transition>
-                                               <!-- To "replicated" state -->
+                                               <transition>replicate</transition>      <!-- To "replicated" state -->
+                                               <transition>deprecate</transition>      <!-- To "deprecated" state -->
+                                               <transition>delete</transition>         <!-- To "deleted" state -->
                                        </transitions>
                                </state>
-                               <state name="replicated" description="Replicated state">
-                                       <transition>unreplicate</transition>
-                                       <!-- To "project" state -->
-                                       <transition>delete_replicated</transition>
-                                       <!-- To "replicated_deleted" state -->
-                               </state>
                                <state name="deleted" description="Document is deleted">
                                        <transitions>
-                                               <transition>undelete</transition>
-                                               <!-- To "project" state -->
-                                               <transition>replicate_deleted</transition>
-                                               <!-- To "replicated_deleted" state -->
+                                               <transition>replicate_deleted</transition>      <!-- To "replicated_deleted" state -->
+                                               <transition>deprecate_deleted</transition>      <!-- To "deprecated_deleted" state -->                                          
+                                               <transition>undelete</transition>                       <!-- To "project" state -->
+                                       </transitions>
+                               </state>
+                               <state name="replicated" description="Replicated state">
+                                       <transitions>
+                                               <transition>unreplicate</transition>            <!-- To "project" state -->
+                                               <transition>deprecate_replicated</transition>   <!-- To "replicated_deprecated" state -->                                                                                               
+                                               <transition>delete_replicated</transition>      <!-- To "replicated_deleted" state -->
                                        </transitions>
                                </state>
                                <state name="replicated_deleted" description="Document is replicated and deleted">
                                        <transitions>
-                                               <transition>unreplicate_deleted</transition>
-                                               <!-- To "deleted" state -->
-                                               <transition>undelete_replicated</transition>
-                                               <!-- To "replicated" state -->
+                                               <transition>unreplicate_deleted</transition>                    <!-- To "deleted" state -->
+                                               <transition>deprecate_replicated_deleted</transition>   <!-- To "replicated_deprecated_deleted state -->
+                                               <transition>undelete_replicated</transition>                    <!-- To "replicated" state -->
+                                       </transitions>
+                               </state>
+                               <state name="replicated_deprecated" description="Document is replicated and deprecated">
+                                       <transitions>
+                                               <transition>unreplicate_deprecated</transition>                 <!-- To "deprecated" state -->
+                                               <transition>undeprecate_replicated</transition>                 <!-- To "replicated" state -->
+                                               <transition>delete_replicated_deprecated</transition>   <!-- To "replicated_deprecated_deleted state -->
+                                       </transitions>
+                               </state>
+                               <state name="replicated_deprecated_deleted" description="Document is replicated, deprecated, and deleted">
+                                       <transitions>
+                                               <transition>unreplicate_deprecated_deleted</transition> <!-- To "deprecated_deleted" state -->
+                                               <transition>undeprecate_replicated_deleted</transition> <!-- To "replicated_deleted" state -->
+                                               <transition>undelete_replicated_deprecated</transition> <!-- To "replicated_deprecated" state -->
+                                       </transitions>
+                               </state>
+                               <state name="deprecated" description="Document is deprecated">
+                                       <transitions>
+                                               <transition>replicate_deprecated</transition>   <!-- To "replicated_deprecated" state -->
+                                               <transition>undeprecate</transition>                    <!-- To "project" state -->
+                                               <transition>delete_deprecated</transition>              <!-- To "deprecated_deleted" state -->
+                                       </transitions>
+                               </state>
+                               <state name="deprecated_deleted" description="Document is deprecated and deleted">
+                                       <transitions>
+                                               <transition>replicate_deprecated_deleted</transition>   <!-- To "replicated_deprecated_deleted state -->
+                                               <transition>undeprecate_deleted</transition>    <!-- To "deleted" state -->
+                                               <transition>undelete_deprecated</transition>    <!-- To "deprecated" state -->
                                        </transitions>
                                </state>
                        </states>
index 622fe101a6e71e9eea2dcc59763034a8d9c7db26..3e635851302438f653c7ce30e5056280c9a4d82a 100644 (file)
@@ -44,27 +44,62 @@ public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl<Workf
         */
        
        public static final String WORKFLOWSTATE_XML_ELEMENT_NAME = COLLECTIONSPACE_CORE_WORKFLOWSTATE;
+       public static final String WORKFLOWTRANSITION_TO = "to";  // Use for Nuxeo lifecycle event handling
+
        // common to all Nuxeo document lifecycle policies
        public static final String WORKFLOWSTATE_PROJECT = "project";
        public static final String WORKFLOWSTATE_DELETED = "deleted";
+
        // part of the "cs_replicating" Nuxeo document lifecycle policy
+       public static final String WORKFLOWSTATE_DEPRECATED = "deprecated";
+       public static final String WORKFLOWSTATE_DEPRECATED_DELETED = "deprecated_deleted";
        public static final String WORKFLOWSTATE_REPLICATED = "replicated";
        public static final String WORKFLOWSTATE_REPLICATED_DELETED = "replicated_deleted";
+       public static final String WORKFLOWSTATE_REPLICATED_DEPRECATED = "replicated_deprecated";
+       public static final String WORKFLOWSTATE_REPLICATED_DEPRECATED_DELETED = "replicated_deprecated_deleted";       
+       
        // part of the "cs_locking" Nuxeo document lifecycle policy
        public static final String WORKFLOWSTATE_LOCKED = "locked";
        public static final String WORKFLOWSTATE_LOCKED_DELETED = "locked_deleted";
        
        /*
-        * Nuxeo document workflow transition verbs
+        * Nuxeo document workflow transition verbs FOR "cs_replicating" Nuxeo document lifecycle policy
         */
-       public static final String WORKFLOWTRANSITION_DELETE = "delete";        
-       public static final String WORKFLOWTRANSITION_UNDELETE = "undelete";
-       public static final String WORKFLOWTRANSITION_LOCK = "lock";
-       public static final String WORKFLOWTRANSITION_UNLOCK = "unlock";
        public static final String WORKFLOWTRANSITION_REPLICATE = "replicate";
+       public static final String WORKFLOWTRANSITION_DEPRECATE = "deprecate";
+       public static final String WORKFLOWTRANSITION_DELETE = "delete"; // Also used for default lifecycle
+       
+       public static final String WORKFLOWTRANSITION_REPLICATE_DELETED = "replicate_deleted";
+       public static final String WORKFLOWTRANSITION_DEPRECATE_DELETED = "deprecate_deleted";
+       public static final String WORKFLOWTRANSITION_UNDELETE = "undelete"; // Also used for default lifecycle
+       
        public static final String WORKFLOWTRANSITION_UNREPLICATE = "unreplicate";
-        
-    public static final String WORKFLOWTRANSITION_TO = "to";
+       public static final String WORKFLOWTRANSITION_DEPRECATE_REPLICATED = "deprecate_replicated";
+       public static final String WORKFLOWTRANSITION_DELETE_REPLICATED = "delete_replicated";
+               
+       public static final String WORKFLOWTRANSITION_UNREPLICATE_DELETED = "unreplicate_deleted";
+       public static final String WORKFLOWTRANSITION_DEPRECATE_REPLICATED_DELETED = "deprecate_replicated_deleted";
+       public static final String WORKFLOWTRANSITION_UNDELETE_REPLICATED = "undelete_replicated";
+
+       public static final String WORKFLOWTRANSITION_UNREPLICATE_DEPRECATED = "unreplicate_deprecated";
+       public static final String WORKFLOWTRANSITION_UNDEPRECATE_REPLICATED = "undeprecate_replicated";
+       public static final String WORKFLOWTRANSITION_DELETE_REPLICATED_DEPRECATED = "delete_replicated_deprecated";
+
+       public static final String WORKFLOWTRANSITION_UNREPLICATE_DEPRECATED_DELETED = "unreplicate_deprecated_deleted";
+       public static final String WORKFLOWTRANSITION_UNDEPRECATE_REPLICATED_DELETED = "undeprecate_replicated_deleted";
+       public static final String WORKFLOWTRANSITION_UNDELETE_REPLICATED_DEPRECATED = "undelete_replicated_deprecated";
+       
+       public static final String WORKFLOWTRANSITION_REPLICATE_DEPRECATED = "replicate_deprecated";
+       public static final String WORKFLOWTRANSITION_UNDEPRECATE = "undeprecate";
+       public static final String WORKFLOWTRANSITION_DELETE_DEPRECATED = "delete_deprecated";  
+
+       public static final String WORKFLOWTRANSITION_REPLICATE_DEPRECATED_DELETED = "replicate_deprecated_deleted";
+       public static final String WORKFLOWTRANSITION_UNDEPRECATE_DELETED = "undeprecate_deleted";
+       public static final String WORKFLOWTRANSITION_UNDELETE_DEPRECATED = "undelete_deprecated";
+
+       public static final String WORKFLOWTRANSITION_LOCK = "lock";
+       public static final String WORKFLOWTRANSITION_UNLOCK = "unlock";
+   
        //
        // DocumentHandler workflow-related passed in context properties
        //
index 03e9ccfadd18e2b297bf2f88809d1b92e3fd6693..5b69b050198b54d8ef17920f58168aa6e4e130bd 100644 (file)
@@ -49,8 +49,8 @@ import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler;
 import org.collectionspace.services.lifecycle.Lifecycle;
 import org.collectionspace.services.lifecycle.TransitionDef;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.workflow.WorkflowCommon;
-
 import org.dom4j.DocumentException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -196,20 +196,12 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
     protected TransitionDef getTransitionDef(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String transition) {
        TransitionDef result = null;
        
-       try {
-                       Lifecycle lifecycle = ctx.getDocumentHandler().getLifecycle();
-                       List<TransitionDef> transitionDefList = lifecycle.getTransitionDefList().getTransitionDef();
-                       Iterator<TransitionDef> 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;
index f91d0c6983d50e48260828e5b1b07b168e71f453..2c06dd3e430433208e927c17937d4e09db3fd0f7 100644 (file)
@@ -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.
index d9d80596296ec25fb346ec10aa1ea4948e225cd5..10e3ab8e1545feac16cd5accf792434fac16163f 100644 (file)
@@ -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<DocumentModel> wrapDoc, TransitionDef transitionDef) {
+    public static String getQualifiedTransitionName(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) {
        String result = null;
        
        String currentTransitionName = result = transitionDef.getName(); // begin with result set to the current name
index cf9bd22defee720994465fbab117ba067bed1a7d..9e0895af6f0c372ee33abc3413ad42a69596b573 100644 (file)
@@ -86,59 +86,6 @@ public abstract class DocumentModelHandler<T, TL>
     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<String> initialStateNames = nuxeoLifecyle.getInitialStateNames();
-               result.setDefaultInitial(initialStateNames.iterator().next());
-               
-               // Next, we copy the state and corresponding transition lists
-               StateList stateList = new StateList();
-               List<State> states = stateList.getState();
-               Collection<org.nuxeo.ecm.core.lifecycle.LifeCycleState> 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<String> transitions = transitionList.getTransition();
-                       Collection<String> 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<TransitionDef> transitionDefs = transitionDefList.getTransitionDef();
-               Collection<org.nuxeo.ecm.core.lifecycle.LifeCycleTransition> 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<T, TL>
      * @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);
     }
     
     /*
index 0308fcd6f1dcc806c40d2e594ef9ba9ed1160b95..67153aeba8f45d3a6176d50cca954613eefacf35 100644 (file)
@@ -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<TransitionDef> transitionDefList = lifecycle.getTransitionDefList().getTransitionDef();
+                       Iterator<TransitionDef> 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<String> initialStateNames = nuxeoLifecyle.getInitialStateNames();
+               result.setDefaultInitial(initialStateNames.iterator().next());
+               
+               // Next, we copy the state and corresponding transition lists
+               StateList stateList = new StateList();
+               List<State> states = stateList.getState();
+               Collection<org.nuxeo.ecm.core.lifecycle.LifeCycleState> 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<String> transitions = transitionList.getTransition();
+                       Collection<String> 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<TransitionDef> transitionDefs = transitionDefList.getTransitionDef();
+               Collection<org.nuxeo.ecm.core.lifecycle.LifeCycleTransition> 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;