]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
Support for workflow by transition ID now working. Also, more permission related...
authorRichard Millet <remillet@berkeley.edu>
Tue, 10 Apr 2012 23:07:52 +0000 (16:07 -0700)
committerRichard Millet <remillet@berkeley.edu>
Tue, 10 Apr 2012 23:07:52 +0000 (16:07 -0700)
12 files changed:
services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java
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/CollectionSpaceServiceContextListener.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java
services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationStore.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.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 6d9aa0f4d2a08bf8920752ad9e1e870f0fa410ff..e887e9886e1437b983ec7be1a2c8174a62196d8a 100644 (file)
@@ -27,6 +27,12 @@ public class PoxPayloadIn extends PoxPayload<PayloadInputPart> {
 \r
     private final Logger logger = LoggerFactory.getLogger(this.getClass());\r
 \r
+    public PoxPayloadIn(String payloadName, Object jaxbObject, String partLabel) {\r
+       setPayloadName(payloadName);\r
+       PayloadInputPart inputPart = createPart(partLabel, jaxbObject, null);\r
+       this.addPart(inputPart);\r
+    }\r
+    \r
        /*\r
         * Parse the POX 'xmlPayload' into individual parts.  Each part is saved\r
         * as a DOM4j Element and, if possible, a JAXB object instance as well.\r
index 4e5ddc2eb6cea4241ddbb648a80e0b99b97df821..6db639d37d84d893e50cd68c1dbe3733fdc22357 100644 (file)
@@ -41,7 +41,11 @@ public class WorkflowClient extends AbstractCommonListPoxServiceClientImpl<Workf
        //
        public static final String WORKFLOWSTATE_DELETED = "deleted";
        public static final String WORKFLOWSTATE_PROJECT = "project";
-       public static final String WORKFLOWSTATE_APPROVED = "approved"; 
+       public static final String WORKFLOWSTATE_APPROVED = "approved";
+       //
+       // DocumentHandler passed properties
+       //
+       public static final String TRANSITION_ID = "transition_id";
        //
        // Service Query Params
        //
index 0330e6e0769a57983921ceae912969203fffda8f..9728a8dc2fdff2cb0da1f3c6daae6ee4ff336fd0 100644 (file)
@@ -26,6 +26,9 @@
  */\r
 package org.collectionspace.services.common;\r
 \r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
 import javax.ws.rs.Consumes;\r
 import javax.ws.rs.GET;\r
 import javax.ws.rs.PUT;\r
@@ -35,6 +38,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;\r
 import javax.ws.rs.core.Response;\r
 \r
+import org.collectionspace.services.client.PayloadOutputPart;\r
 import org.collectionspace.services.client.PoxPayloadIn;\r
 import org.collectionspace.services.client.PoxPayloadOut;\r
 import org.collectionspace.services.client.workflow.WorkflowClient;\r
@@ -43,12 +47,13 @@ import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.context.ServiceContextFactory;\r
-import org.collectionspace.services.common.document.BadRequestException;\r
 import org.collectionspace.services.common.document.DocumentHandler;\r
-import org.collectionspace.services.common.document.DocumentNotFoundException;\r
-import org.collectionspace.services.common.security.UnauthorizedException;\r
 import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler;\r
+import org.collectionspace.services.lifecycle.Lifecycle;\r
+import org.collectionspace.services.lifecycle.TransitionDef;\r
+import org.collectionspace.services.lifecycle.TransitionDefList;\r
 import org.collectionspace.services.workflow.WorkflowCommon;\r
+import org.dom4j.DocumentException;\r
 import org.jboss.resteasy.client.ClientResponse;\r
 \r
 import org.slf4j.Logger;\r
@@ -137,6 +142,32 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
         return docHandler;\r
     }\r
 \r
+    /*\r
+     * JAX-RS Annotated methods\r
+     */\r
+    @GET\r
+    @Path(WorkflowClient.SERVICE_PATH)\r
+    public Lifecycle getWorkflow() {\r
+       Lifecycle result;\r
+\r
+        String documentType = "undefined";\r
+        MultipartServiceContext ctx = null;\r
+        try {\r
+            ctx = (MultipartServiceContext) createServiceContext();\r
+            DocumentHandler handler = ctx.getDocumentHandler();\r
+            result = handler.getLifecycle();\r
+        } catch (Exception e) {\r
+            throw bigReThrow(e, ServiceMessages.READ_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, ctx.getDocumentType());\r
+        }\r
+\r
+        if (result == null) {\r
+               result = new Lifecycle();\r
+               result.setName("No life cycle defined for:" + documentType);\r
+        }\r
+        \r
+        return result;\r
+    }\r
+    \r
     /*\r
      * JAX-RS Annotated methods\r
      */\r
@@ -161,17 +192,61 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
 \r
         return result.getBytes();\r
     }\r
-\r
+    \r
+    private TransitionDef getTransitionDef(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String transition) {\r
+       TransitionDef result = null;\r
+       \r
+       try {\r
+                       Lifecycle lifecycle = ctx.getDocumentHandler().getLifecycle();\r
+                       List<TransitionDef> transitionDefList = lifecycle.getTransitionDefList().getTransitionDef();\r
+                       Iterator<TransitionDef> iter = transitionDefList.iterator();\r
+                       boolean found = false;\r
+                       while (iter.hasNext() && found == false) {\r
+                               TransitionDef transitionDef = iter.next();\r
+                               if (transitionDef.getName().equalsIgnoreCase(transition)) {\r
+                                       result = transitionDef;\r
+                                       found = true;\r
+                               }\r
+                       }\r
+               } catch (Exception e) {\r
+                       logger.error("Exception trying to retreive life cycle information for: " + ctx.getDocumentType());\r
+               }\r
+       \r
+       return result;\r
+    }\r
+    \r
+    private PoxPayloadIn synthEmptyWorkflowInput() {\r
+       PoxPayloadIn result = null;\r
+       \r
+        PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);\r
+       WorkflowCommon workflowCommons = new WorkflowCommon();\r
+        PayloadOutputPart commonPart = output.addPart(WorkflowClient.SERVICE_COMMONPART_NAME, workflowCommons);\r
+        String payloadXML = output.toXML();\r
+        try {\r
+                       result = new PoxPayloadIn(payloadXML);\r
+               } catch (DocumentException e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
+        \r
+       return result;\r
+    }\r
+    \r
     @PUT\r
-    @Path("{csid}" + WorkflowClient.SERVICE_PATH)\r
-    public byte[] updateWorkflow(@PathParam("csid") String csid, String xmlPayload) {\r
+    @Path("{csid}" + WorkflowClient.SERVICE_PATH + "/" + "{transition}")\r
+    public byte[] updateWorkflowWithTransition(@PathParam("csid") String csid,\r
+               @PathParam("transition") String transition) {\r
         PoxPayloadOut result = null;\r
         try {\r
+               PoxPayloadIn input = new PoxPayloadIn(WorkflowClient.SERVICE_PAYLOAD_NAME, new WorkflowCommon(), \r
+                               WorkflowClient.SERVICE_COMMONPART_NAME);\r
+               \r
             ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext();\r
             String parentWorkspaceName = parentCtx.getRepositoryWorkspaceName();\r
-\r
-            PoxPayloadIn workflowUpdate = new PoxPayloadIn(xmlPayload);\r
-            MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, workflowUpdate);\r
+               \r
+            TransitionDef transitionDef = getTransitionDef(parentCtx, transition);\r
+            MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input);\r
+            ctx.setProperty(WorkflowClient.TRANSITION_ID, transitionDef);\r
             WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);\r
             ctx.setRespositoryWorkspaceName(parentWorkspaceName); //find the document in the parent's workspace\r
             getRepositoryClient(ctx).update(ctx, csid, handler);\r
@@ -181,4 +256,5 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
         }\r
         return result.getBytes();\r
     }\r
+    \r
 }\r
index f7c0c251e95447413995ee4263a1aeeb7c860044..d9f857f5a36adfc1a0f894c813b3071fe079271b 100644 (file)
@@ -15,70 +15,22 @@ public class CollectionSpaceServiceContextListener implements ServletContextList
 
     @Override
     public void contextInitialized(ServletContextEvent event) {
-        try {
+        try {          
                //
                // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
                //
                ServletContext servletContext = event.getServletContext();
             ServiceMain svcMain = ServiceMain.getInstance(servletContext);
             
-               {
-                       System.out.print("About to retrieveAllWorkspaceIds - Pausing 4:5 seconds for you to attached the debugger");
-                       long startTime, currentTime;
-                       currentTime = startTime = System.currentTimeMillis();
-                       long stopTime = startTime + 5 * 1000; //5 seconds
-                       do {
-                               if (currentTime % 1000 == 0) {
-                                       System.out.print(".");
-                               }
-                               currentTime = System.currentTimeMillis();
-                       } while (currentTime < stopTime);
-                               
-                       System.out.println();
-                       System.out.println("Resuming cspace services initialization.");
-               }
-            
             svcMain.retrieveAllWorkspaceIds();
-
-               {
-                       System.out.print("About to firePostInitHandlers - Pausing 5:5 seconds for you to attached the debugger");
-                       long startTime, currentTime;
-                       currentTime = startTime = System.currentTimeMillis();
-                       long stopTime = startTime + 5 * 1000; //5 seconds
-                       do {
-                               if (currentTime % 1000 == 0) {
-                                       System.out.print(".");
-                               }
-                               currentTime = System.currentTimeMillis();
-                       } while (currentTime < stopTime);
-                               
-                       System.out.println();
-                       System.out.println("Resuming cspace services initialization.");
-               }
             
                //
                // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db.
                // Typically, these handlers modify column types and add indexes to the Nuxeo db schema.
                //
                svcMain.firePostInitHandlers();
-            
-               {
-                       System.out.print("Finished to firePostInitHandlers - Pausing 6:5 seconds for you to attached the debugger");
-                       long startTime, currentTime;
-                       currentTime = startTime = System.currentTimeMillis();
-                       long stopTime = startTime + 5 * 1000; //5 seconds
-                       do {
-                               if (currentTime % 1000 == 0) {
-                                       System.out.print(".");
-                               }
-                               currentTime = System.currentTimeMillis();
-                       } while (currentTime < stopTime);
-                               
-                       System.out.println();
-                       System.out.println("Resuming cspace services initialization.");
-               }
-               
-        } catch (Exception e) {
+                       
+        } catch (Throwable e) {
             e.printStackTrace();
             //fail here
             System.err.println("[ERROR] The CollectionSpace Services could not initialize.  Please see the log files for details.");
index 2634d46ab45286f2e31f9112d3b7416c556b7163..0c98156eeb68a3a973cfdd2131797960de4d3cba 100644 (file)
@@ -101,23 +101,6 @@ public class ServiceMain {
                     try {\r
                        //assume the worse\r
                        initFailed = true;\r
-                       \r
-                       {\r
-                               System.out.print("About to init ServiceMain - Pausing 3:5 seconds for you to attached the debugger");\r
-                               long startTime, currentTime;\r
-                               currentTime = startTime = System.currentTimeMillis();\r
-                               long stopTime = startTime + 5 * 1000; //5 seconds\r
-                               do {\r
-                                       if (currentTime % 1000 == 0) {\r
-                                               System.out.print(".");\r
-                                       }\r
-                                       currentTime = System.currentTimeMillis();\r
-                               } while (currentTime < stopTime);\r
-                                       \r
-                               System.out.println();\r
-                               System.out.println("Resuming cspace services initialization.");\r
-                       }\r
-                       \r
                         temp.initialize();\r
                        //celebrate success\r
                         initFailed = false;\r
@@ -142,41 +125,8 @@ public class ServiceMain {
     }\r
 \r
     private void initialize() throws Exception {\r
-       \r
-       setDataSources();\r
-       setServerRootDir();\r
-        readConfig();\r
-        propagateConfiguredProperties();\r
-        //\r
-        // Create all the default user accounts\r
-        //\r
-        try {\r
-               AuthorizationCommon.createDefaultPermissions(tenantBindingConfigReader);\r
-        \r
-               if (logger.isDebugEnabled() == true) {\r
-                       System.out.print("Pausing 1:5 seconds for you to attached the debugger");\r
-                       long startTime, currentTime;\r
-                       currentTime = startTime = System.currentTimeMillis();\r
-                       long stopTime = startTime + 5 * 1000; //5 seconds\r
-                       do {\r
-                               if (currentTime % 1000 == 0) {\r
-                                       System.out.print(".");\r
-                               }\r
-                               currentTime = System.currentTimeMillis();\r
-                       } while (currentTime < stopTime);\r
-                               \r
-                       System.out.println();\r
-                       System.out.println("Resuming cspace services initialization.");\r
-               }\r
-\r
-               AuthorizationCommon.createDefaultAccounts(tenantBindingConfigReader);\r
-        \r
-        } catch(Exception e) {\r
-               logger.error("Default accounts setup failed with exception(s): " + e.getLocalizedMessage());\r
-        }\r
-        \r
-       if (logger.isDebugEnabled() == true) {\r
-               System.out.print("Pausing 2:5 seconds for you to attached the debugger");\r
+       if (logger.isTraceEnabled() == true)            {\r
+               System.out.print("About to initialize ServiceMain singleton - Pausing 5 seconds for you to attached the debugger");\r
                long startTime, currentTime;\r
                currentTime = startTime = System.currentTimeMillis();\r
                long stopTime = startTime + 5 * 1000; //5 seconds\r
@@ -190,7 +140,11 @@ public class ServiceMain {
                System.out.println();\r
                System.out.println("Resuming cspace services initialization.");\r
        }\r
-        \r
+       \r
+       setDataSources();\r
+       setServerRootDir();\r
+        readConfig();\r
+        propagateConfiguredProperties();\r
         //\r
         // Start up and initialize our embedded Nuxeo server instance\r
         //\r
@@ -206,7 +160,15 @@ public class ServiceMain {
                //\r
                throw new RuntimeException("Unknown CollectionSpace services client type: " + getClientType());\r
         }\r
-\r
+        //\r
+        // Create all the default user accounts and permissions\r
+        //\r
+        try {\r
+               AuthorizationCommon.createDefaultPermissions(tenantBindingConfigReader);                \r
+               AuthorizationCommon.createDefaultAccounts(tenantBindingConfigReader);     \r
+        } catch(Throwable e) {         \r
+               logger.error("Default accounts and permissions setup failed with exception(s): " + e.getLocalizedMessage(), e);\r
+        }        \r
     }\r
 \r
     /**\r
index 0f1d9aa3f9f1b101894ef8ae4702f79e65f7eefc..bf4113d02fb238af47d3cdb7672d75e164dc5f57 100644 (file)
@@ -275,26 +275,37 @@ public class AuthorizationCommon {
                ActionGroup actionGroup)\r
     {\r
        Permission result = null;\r
+       String workFlowServiceSuffix;\r
+       String transitionName;\r
+       if (transitionDef != null) {\r
+               transitionName = transitionDef.getName();\r
+               workFlowServiceSuffix = WorkflowClient.SERVICE_AUTHZ_SUFFIX;\r
+       } else {\r
+               transitionName = ""; //since the transitionDef was null, we're assuming that this is the base workflow permission to be created                 \r
+               workFlowServiceSuffix = WorkflowClient.SERVICE_PATH;\r
+       }\r
        \r
        String tenantId = tenantBinding.getId();\r
        String resourceName = "/"\r
                        + serviceBinding.getName().toLowerCase().trim()\r
-                       + WorkflowClient.SERVICE_AUTHZ_SUFFIX\r
-                       + transitionDef.getName();\r
+                       + workFlowServiceSuffix\r
+                       + transitionName;\r
        String description = "A generated workflow permission for actiongroup " + actionGroup.name;\r
        result = createPermission(tenantId, resourceName, description, actionGroup);\r
        \r
        if (logger.isDebugEnabled() == true) {\r
                logger.debug("Generated a workflow permission: "\r
                                + result.getResourceName()\r
-                               + ":" + transitionDef.getName()\r
-                               + ":" + "tenant id=" + result.getTenantId());\r
+                               + ":" + transitionName\r
+                               + ":" + "tenant id=" + result.getTenantId()\r
+                               + ":" + actionGroup.name);\r
        }\r
        \r
        return result;\r
     }\r
     \r
-    private static PermissionRole createPermissionRole(Permission permission,\r
+    private static PermissionRole createPermissionRole(EntityManager em,\r
+               Permission permission,\r
                Role role,\r
                boolean enforceTenancy) throws Exception\r
     {\r
@@ -758,9 +769,10 @@ public class AuthorizationCommon {
        private static TransitionDefList getTransitionDefList(TenantBindingType tenantBinding, ServiceBindingType serviceBinding) {\r
                TransitionDefList result = null;\r
                try {\r
+                       String serviceObjectName = serviceBinding.getObject().getName();\r
                DocumentHandler docHandler = ServiceConfigUtils.createDocumentHandlerInstance(\r
                                tenantBinding, serviceBinding);\r
-               Lifecycle lifecycle = docHandler.getLifecycle();\r
+               Lifecycle lifecycle = docHandler.getLifecycle(serviceObjectName);\r
                if (lifecycle != null) {\r
                        result = lifecycle.getTransitionDefList();\r
                }\r
@@ -804,40 +816,46 @@ public class AuthorizationCommon {
                        Role readonlyRole = AuthorizationCommon.getRole(em, tenantBinding.getId(), ROLE_TENANT_READER);\r
                        for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {\r
                                try {\r
+                                       em.getTransaction().begin();\r
+                                       //\r
+                                       // For the default admin role, create the base workflow (aka, "/workflow" permissions for the service.\r
+                                       Permission baseAdminPerm = createWorkflowPermission(tenantBinding, serviceBinding, null, ACTIONGROUP_CRUDL);\r
+                                       persist(em, baseAdminPerm, adminRole, true);\r
+                                       //\r
+                                       // For the default read-only role, create the base workflow (aka, "/workflow" permissions for the service.\r
+                                       Permission baseReadonlyPerm = createWorkflowPermission(tenantBinding, serviceBinding, null, ACTIONGROUP_RL);\r
+                                       persist(em, baseReadonlyPerm, readonlyRole, true);                                      \r
+                                       //\r
+                                       // Next, create a permission for each workflow transition supported by the service's document type.\r
+                                       //\r
                                        TransitionDefList transitionDefList = getTransitionDefList(tenantBinding, serviceBinding);\r
                                        for (TransitionDef transitionDef : transitionDefList.getTransitionDef()) {\r
-                                               em.getTransaction().begin();\r
-                                               /*\r
                                                //\r
                                                // Create the permission for the admin role\r
-                                               //\r
                                                Permission adminPerm = createWorkflowPermission(tenantBinding, serviceBinding, transitionDef, ACTIONGROUP_CRUDL);\r
                                                persist(em, adminPerm, adminRole, true);\r
-                                               */\r
                                                //\r
                                                // Create the permission for the read-only role\r
                                                Permission readonlyPerm = createWorkflowPermission(tenantBinding, serviceBinding, transitionDef, ACTIONGROUP_RL);\r
                                                \r
                                                Profiler profiler = new Profiler(AuthorizationCommon.class, 1);\r
                                                profiler.start("createDefaultPermissions started:" + readonlyPerm.getCsid());\r
-                                               persist(em, readonlyPerm, readonlyRole, true);\r
+                                               persist(em, readonlyPerm, readonlyRole, true); // Persist/store the permission and permrole records and related Spring Security info\r
                                                profiler.stop();\r
                                                logger.debug("Finished full perm generation for "\r
                                                                + ":" + tenantBinding.getId()\r
                                                                + ":" + serviceBinding.getName()\r
                                                                + ":" + transitionDef.getName()\r
                                                                + ":" + ACTIONGROUP_RL\r
-                                                               + ":" + profiler.getCumulativeTime());\r
-                                               \r
+                                                               + ":" + profiler.getCumulativeTime());                                          \r
                                                /*\r
                                                //\r
                                                // Create the permission for the super-admin role.  Note we use the same "adminPerm" instance we used for the "adminPermRole" instance\r
                                                //\r
                                                persist(em, adminPerm, superRole, false);\r
-                                               \r
                                                */\r
-                                               em.getTransaction().commit();\r
                                        }\r
+                                       em.getTransaction().commit();\r
                                } catch (IllegalStateException e) {\r
                                        logger.debug(e.getLocalizedMessage(), e); //We end up here if there is no document handler for the service -this is ok for some of the services.\r
                                }\r
@@ -889,7 +907,7 @@ public class AuthorizationCommon {
                // Create a PermissionRoleRel (the database relation table for the permission and role)\r
                PermissionRoleRel permRoleRel = findPermRoleRel(em, permission.getCsid(), role.getCsid());\r
                if (permRoleRel == null) {\r
-                       PermissionRole permRole = createPermissionRole(permission, role, enforceTenancy);\r
+                       PermissionRole permRole = createPermissionRole(em, permission, role, enforceTenancy);\r
                List<PermissionRoleRel> permRoleRels = new ArrayList<PermissionRoleRel>();\r
                PermissionRoleUtil.buildPermissionRoleRel(em, permRole, SubjectType.ROLE, permRoleRels, false /*not for delete*/);\r
                for (PermissionRoleRel prr : permRoleRels) {\r
index 281b88756769251979bc2cffc8fedc75b207baeb..3ff03ee6db34aed43787e40b44ad0737756cf1e9 100644 (file)
@@ -162,7 +162,7 @@ public class AuthorizationStore {
         }
         
         if (entityExists == true) {
-               em.merge(entity);
+               //em.merge(entity); FIXME: Leave commented out until we address CSPACE-5031
         } else {
                em.persist(entity);
         }
index bc1c86e01ea8e5dcf0b5a933c746e00751028b12..e85acf763af0e778d76fca57d2a28c8218744d66 100644 (file)
@@ -46,6 +46,8 @@ public interface DocumentHandler<T, TL, WT, WTL> {
     }
     
     public Lifecycle getLifecycle();
+    
+    public Lifecycle getLifecycle(String serviceObjectName);
 
     /**
      * getServiceContext returns service context
index 6187754a88d9ff39fc5a803390e945ef48b86e3f..c6a3ef5e7daf63482cc91322b9187e195c84d4d6 100644 (file)
@@ -136,7 +136,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
                                // They passed the first round of security checks, so now let's check to see if they're trying
                                // to perform a workflow state change and make sure they are allowed to to this.
                                //
-                               if (uriPath.endsWith(WorkflowClient.SERVICE_PATH_COMPONENT) == true) {
+                               if (uriPath.contains(WorkflowClient.SERVICE_PATH_COMPONENT) == true) {
                                        String workflowSubResName = SecurityUtils.getResourceName(request.getUri());
                                        res = new URIResourceImpl(AuthN.get().getCurrentTenantId(), workflowSubResName, httpMethod);
                                        if (authZ.isAccessAllowed(res) == false) {
index 27a1c3a6d64cf2a6b293c8b7ff820501b49f20ec..ab9623b737385bbd6adccfcde7fc4a0befeb31da 100644 (file)
@@ -37,7 +37,14 @@ public abstract class JpaDocumentHandler<T, TL, WT, WLT>
         return (TL) commonList;\r
     }\r
     \r
+    public Lifecycle getLifecycle(String docTypeName) {\r
+       Lifecycle result = new Lifecycle();\r
+       result.setName("Life cycles are not supported by the JPA-based services.");\r
+       return result; // NOTE: As of 3/2012, none of the JPA-based services support a life cycle type.\r
+    }\r
+    \r
+    @Override\r
     public Lifecycle getLifecycle() {\r
-       return null; // NOTE: As of 3/2012, none of the JPA-based services support a life cycle type.\r
+       return getLifecycle(null); // NOTE: As of 3/2012, none of the JPA-based services support a life cycle type.\r
     }\r
 }\r
index 14a1e7801f10591a1a1df87a99db334335a1fb0c..29f297b5929e4431f535645e91504ee878ee242d 100644 (file)
@@ -23,6 +23,7 @@
  */
 package org.collectionspace.services.common.workflow.service.nuxeo;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -32,10 +33,13 @@ import org.collectionspace.services.client.PayloadInputPart;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.workflow.WorkflowClient;
+import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
 import org.collectionspace.services.common.workflow.jaxb.WorkflowJAXBSchema;
 import org.collectionspace.services.config.service.ObjectPartType;
+import org.collectionspace.services.lifecycle.TransitionDef;
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
 import org.collectionspace.services.workflow.WorkflowCommon;
 import org.nuxeo.ecm.core.api.ClientException;
@@ -135,26 +139,23 @@ public class WorkflowDocumentModelHandler
      */
 
     @Override
-    protected void fillPart(PayloadInputPart part, DocumentModel docModel,
-            ObjectPartType partMeta, Action action,
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx)
-            throws Exception {
-       String toState = null;
+    public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
+       String transitionToFollow = null;
+       
+        DocumentModel docModel = wrapDoc.getWrappedObject();
+        MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
        
        try {
-               WorkflowCommon workflowsCommon = (WorkflowCommon) part.getBody();
-               toState = getTransitionFromState(workflowsCommon.getCurrentLifeCycleState());
-               docModel.followTransition(toState);
+               TransitionDef transitionDef = (TransitionDef)this.getServiceContext().getProperty(WorkflowClient.TRANSITION_ID);
+               transitionToFollow = transitionDef.getName();
+               docModel.followTransition(transitionToFollow);
        } catch (Exception e) {
                String msg = "Unable to follow workflow transition to state = "
-                               + toState;
-               if (logger.isDebugEnabled() == true) {
-                       logger.debug(msg, e);
-               }
-               ClientException ce = new ClientException("Unable to follow workflow transition to state = "
-                               + toState);
+                               + transitionToFollow;
+               logger.error(msg, e);
+               ClientException ce = new ClientException("Unable to follow workflow transition: " + transitionToFollow);
                throw ce;
        }
-    }
+    }    
 }
 
index 3f21659aad2108f957db7e19e2aa12a6bf72dc32..9fb971bd5aec83c2b9532576f2ae84eede430a15 100644 (file)
  */
 package org.collectionspace.services.nuxeo.client.java;
 
+import java.util.Collection;
 import java.util.List;
 
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
-import org.collectionspace.services.common.api.FileTools;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
 import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.lifecycle.Lifecycle;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.common.profile.Profiler;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.repository.RepositoryClientFactory;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;
+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.nuxeo.ecm.core.NXCore;
 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.api.repository.RepositoryInstance;
+import org.nuxeo.ecm.core.lifecycle.LifeCycleService;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,14 +79,109 @@ public abstract class DocumentModelHandler<T, TL>
     public final static String COLLECTIONSPACE_CORE_CREATED_BY = "createdBy";
     public final static String COLLECTIONSPACE_CORE_UPDATED_BY = "updatedBy";
 
+    /*
+     * 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.
+     * (non-Javadoc)
+     * @see org.collectionspace.services.common.document.DocumentHandler#getLifecycle()
+     */
+    @Override
     public Lifecycle getLifecycle() {
        Lifecycle result = null;
        
+       String docTypeName = null;
        try {
-                       result = (Lifecycle)FileTools.getJaxbObjectFromFile(Lifecycle.class, "default-lifecycle.xml");
+               docTypeName = this.getServiceContext().getDocumentType();
+               result = getLifecycle(docTypeName);
+       } catch (Exception e) {
+               if (logger.isTraceEnabled() == true) {
+                       logger.trace("Could not retrieve lifecycle definition for Nuxeo doctype: " + docTypeName);
+               }
+       }
+       
+       return result;
+    }
+    
+    /*
+     * Returns the the life cycle definition of the related Nuxeo document type for this handler.
+     * (non-Javadoc)
+     * @see org.collectionspace.services.common.document.DocumentHandler#getLifecycle(java.lang.String)
+     */
+    @Override
+    public Lifecycle getLifecycle(String docTypeName) {
+       org.nuxeo.ecm.core.lifecycle.LifeCycle nuxeoLifecyle;
+       Lifecycle result = null;
+       
+       try {
+               LifeCycleService lifeCycleService = null;
+                       try {
+                               lifeCycleService = NXCore.getLifeCycleService();
+                       } catch (Exception e) {
+                               e.printStackTrace();
+                       }
+                       
+               String lifeCycleName; 
+               lifeCycleName = lifeCycleService.getLifeCycleNameFor(docTypeName);
+               nuxeoLifecyle = lifeCycleService.getLifeCycleByName(lifeCycleName);
+               
+               result = createCollectionSpaceLifecycle(nuxeoLifecyle); 
+//                     result = (Lifecycle)FileTools.getJaxbObjectFromFile(Lifecycle.class, "default-lifecycle.xml");
                } catch (Exception e) {
                        // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       logger.error("Could not retreive life cycle information for Nuxeo doctype: " + docTypeName, e);
                }
        
        return result;
@@ -242,5 +345,4 @@ public abstract class DocumentModelHandler<T, TL>
                     COLLECTIONSPACE_CORE_UPDATED_BY, userId);
        }
     }
-
 }