]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6937: Added the ability to put a record in both a locked state and a deleted...
authorremillet <remillet@yahoo.com>
Fri, 15 Apr 2016 22:16:27 +0000 (15:16 -0700)
committerremillet <remillet@yahoo.com>
Fri, 15 Apr 2016 22:16:27 +0000 (15:16 -0700)
3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.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

index ecfbcbd3e5b4ec64877a22b6d18a1b805e7b51f6..5c3f95e90932f74f8245495b133b67346d2d1a53 100644 (file)
           <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_locked
+                       This convention is critical to the code here: org.collectionspace.services.client.AuthorityClient.AuthorityItemDocumentModelHandler
+               -->
+               
                <!-- Transitions TO "locked_deleted" state -->
         <transition name="delete_locked" destinationState="locked_deleted">
           <description>Delete the locked document from the "locked" state</description>
index a6cf7781bfd331df5c0255a3d64b7d8c1a860ce7..e5762339ad89e4d0db654f48ef1fd9f7659f91d5 100644 (file)
@@ -68,6 +68,7 @@ import org.slf4j.LoggerFactory;
 import javax.ws.rs.core.MultivaluedMap;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -180,7 +181,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         this.inAuthority = inAuthority;
     }
     
-   public String getInAuthority() {
+   public String getInAuthorityCsid() {
         return this.inAuthority;
     }
 
@@ -350,15 +351,16 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     
     /**
      * We consider workflow state changes as a change that should bump the revision number.
+     * Warning: This method might change the transitionDef's transtionName value
      */
     @Override
     public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) throws Exception {
-       // Update the revision number
+       // Decide whether or not to update the revision number
        if (this.getShouldUpdateRevNumber() == true) { // We don't update the rev number of synchronization requests
                updateRevNumbers(wrapDoc);
        }
     }
-    
+        
     /**
      * This method synchronizes/updates a single authority item resource.
      */
@@ -549,8 +551,12 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
        //
        // Next, update the inAuthority (the parent's) rev number
        //
-       String inAuthority = (String)documentModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY);
-       DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), inAuthority);
+       String inAuthorityCsid = this.getInAuthorityCsid();
+       if (inAuthorityCsid == null) {
+               // When inAuthorityCsid is null, it usually means we're performing and update or synch with the SAS
+               inAuthorityCsid = (String)documentModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY);
+       }
+       DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), inAuthorityCsid);
        Long parentRev = (Long)inAuthorityDocModel.getProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV);
        if (parentRev == null) {
                parentRev = new Long(0);
@@ -980,7 +986,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     }
     
     protected String getInAuthorityValue() {
-        String inAuthorityValue = getInAuthority();
+        String inAuthorityValue = getInAuthorityCsid();
         if (Tools.notBlank(inAuthorityValue)) {
             return inAuthorityValue;
         } else {
index 02193d1b05d60b999596888e36658759ce833a13..ade28820ca01d5f34b32204205d1db416a4f1002 100644 (file)
@@ -215,7 +215,7 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
        
        return result;
     }
-    
+        
     private PoxPayloadIn synthEmptyWorkflowInput() {
        PoxPayloadIn result = null;
        
index 14b773cec67037439e438c090fcee3c592e68b42..c65da9b96c59017f45fa386ab75078ceae76357f 100644 (file)
@@ -23,6 +23,7 @@
  */
 package org.collectionspace.services.common.workflow.service.nuxeo;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -153,6 +154,31 @@ public class WorkflowDocumentModelHandler
         return result;
     }
     
+    /*
+     * Maps the transition name to handle existing states like "locked" and "deleted".  This allows us to do things like lock "deleted"
+     * records, delete "locked" records, etc.  For example, this code maps the transition name "delete" to "delete_locked" on records in the "locked" state.
+     * As another example, it would map "undelete" to "undelete_locked" for locked records and just "undelete" for records in any other state.
+     * 
+     * Essentially, this mapping allows REST API clients to use the "delete", "undelete", "lock", "unlock", etc transitions on records no matter what
+     * their current state.  Without this mapping, REST API clients would need to calculate this on their own and use the longer forms like:
+     * "delete_locked", "undelete_locked", "lock_deleted", "unlocked_deleted", etc. 
+     */
+    String getQualifiedTransitionName(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef) {
+       String result = null;
+       
+       String currentTransitionName = result = transitionDef.getName(); // begin with result set to the current name
+       DocumentModel docModel = wrapDoc.getWrappedObject();
+       Collection<String> allowedTransitionList = docModel.getAllowedStateTransitions();
+       for (String allowedTransitionName:allowedTransitionList) {
+               if (allowedTransitionName.startsWith(currentTransitionName)) {
+                       result = allowedTransitionName;
+                       break; // we found a mapping
+               }
+       }
+
+       return result;
+    }
+    
     /*
      * Handle Update (PUT)
      */
@@ -166,7 +192,7 @@ public class WorkflowDocumentModelHandler
        
        try {
                TransitionDef transitionDef = (TransitionDef)this.getServiceContext().getProperty(WorkflowClient.TRANSITION_ID);
-               transitionToFollow = transitionDef.getName();
+               transitionToFollow = getQualifiedTransitionName(wrapDoc, transitionDef);
                docModel.followTransition(transitionToFollow);
        } catch (Exception e) {
                String msg = "Unable to follow workflow transition to state = "
index a1c33595a63d67759de8f04915a4abe789d16532..cf9bd22defee720994465fbab117ba067bed1a7d 100644 (file)
@@ -65,6 +65,7 @@ import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.model.PropertyException;
+import org.nuxeo.ecm.core.lifecycle.LifeCycle;
 import org.nuxeo.ecm.core.lifecycle.LifeCycleService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -168,7 +169,6 @@ public abstract class DocumentModelHandler<T, TL>
      */
     @Override
     public Lifecycle getLifecycle(String docTypeName) {
-       org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle;
        Lifecycle result = null;
        
        try {
@@ -179,12 +179,10 @@ public abstract class DocumentModelHandler<T, TL>
                                e.printStackTrace();
                        }
                        
-               String lifeCycleName; 
-               lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName);
-               nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName);
+               String lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName);
+               org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName);
                
                result = createCollectionSpaceLifecycle(nuxeoLifecyle); 
-//                     result = (Lifecycle)FileTools.getJaxbObjectFromFile(Lifecycle.class, "default-lifecycle.xml");
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        logger.error("Could not retreive life cycle information for Nuxeo doctype: " + docTypeName, e);