\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
//
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
//
*/\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
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
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
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
\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
}\r
return result.getBytes();\r
}\r
+ \r
}\r
@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.");
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
}\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
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
//\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
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
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
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
// 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
}
if (entityExists == true) {
- em.merge(entity);
+ //em.merge(entity); FIXME: Leave commented out until we address CSPACE-5031
} else {
em.persist(entity);
}
}
public Lifecycle getLifecycle();
+
+ public Lifecycle getLifecycle(String serviceObjectName);
/**
* getServiceContext returns service context
// 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) {
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
*/
package org.collectionspace.services.common.workflow.service.nuxeo;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
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;
*/
@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;
}
- }
+ }
}
*/
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;
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;
COLLECTIONSPACE_CORE_UPDATED_BY, userId);
}
}
-
}