Search in sources :

Example 1 with WorkflowDeployment

use of org.alfresco.service.cmr.workflow.WorkflowDeployment in project alfresco-repository by Alfresco.

the class WorkflowDeployer method init.

/**
 * Deploy the Workflow Definitions
 */
public void init() {
    PropertyCheck.mandatory(this, "transactionService", transactionService);
    PropertyCheck.mandatory(this, "authenticationContext", authenticationContext);
    PropertyCheck.mandatory(this, "workflowService", workflowService);
    String currentUser = authenticationContext.getCurrentUserName();
    if (currentUser == null) {
        authenticationContext.setSystemUserAsCurrentUser();
    }
    if ((!transactionService.getAllowWrite()) && (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE)) {
        if (logger.isWarnEnabled())
            logger.warn("Repository is in read-only mode; not deploying workflows.");
        return;
    }
    UserTransaction userTransaction = transactionService.getUserTransaction();
    try {
        userTransaction.begin();
        // bootstrap the workflow models and static labels (from classpath)
        if (models != null && resourceBundles != null && ((models.size() > 0) || (resourceBundles.size() > 0))) {
            DictionaryBootstrap dictionaryBootstrap = new DictionaryBootstrap();
            dictionaryBootstrap.setDictionaryDAO(dictionaryDAO);
            dictionaryBootstrap.setTenantService(tenantService);
            dictionaryBootstrap.setModels(models);
            dictionaryBootstrap.setLabels(resourceBundles);
            // also registers with dictionary
            dictionaryBootstrap.bootstrap();
            // MNT-10537 fix, since new model was deployed we need to destroy dictionary to force lazy re-init
            AlfrescoTransactionSupport.bindListener(this.workflowDeployerTransactionListener);
        }
        // bootstrap the workflow definitions (from classpath)
        if (workflowDefinitions != null) {
            for (Properties workflowDefinition : workflowDefinitions) {
                // retrieve workflow specification
                String engineId = workflowDefinition.getProperty(ENGINE_ID);
                if (engineId == null || engineId.length() == 0) {
                    throw new WorkflowException("Workflow Engine Id must be provided");
                }
                String location = workflowDefinition.getProperty(LOCATION);
                if (location == null || location.length() == 0) {
                    throw new WorkflowException("Workflow definition location must be provided");
                }
                if (workflowAdminService.isEngineEnabled(engineId)) {
                    Boolean redeploy = Boolean.valueOf(workflowDefinition.getProperty(REDEPLOY));
                    String mimetype = workflowDefinition.getProperty(MIMETYPE);
                    // retrieve input stream on workflow definition
                    ClassPathResource workflowResource = new ClassPathResource(location);
                    // deploy workflow definition
                    if (!redeploy && workflowService.isDefinitionDeployed(engineId, workflowResource.getInputStream(), mimetype)) {
                        if (logger.isDebugEnabled())
                            logger.debug("Workflow deployer: Definition '" + location + "' already deployed");
                    } else {
                        WorkflowDeployment deployment = workflowService.deployDefinition(engineId, workflowResource.getInputStream(), mimetype, workflowResource.getFilename());
                        logDeployment(location, deployment);
                    }
                } else {
                    if (logger.isDebugEnabled())
                        logger.debug("Workflow deployer: Definition '" + location + "' not deployed as the '" + engineId + "' engine is disabled");
                }
            }
        }
        // deploy workflow definitions from repository (if any)
        if (repoWorkflowDefsLocation != null) {
            StoreRef storeRef = repoWorkflowDefsLocation.getStoreRef();
            NodeRef rootNode = nodeService.getRootNode(storeRef);
            List<NodeRef> nodeRefs = searchService.selectNodes(rootNode, repoWorkflowDefsLocation.getPath() + CRITERIA_ALL + "[" + defaultSubtypeOfWorkflowDefinitionType + "]", null, namespaceService, false);
            if (nodeRefs.size() > 0) {
                for (NodeRef nodeRef : nodeRefs) {
                    deploy(nodeRef, false);
                }
            }
        }
        userTransaction.commit();
    } catch (Throwable e) {
        // rollback the transaction
        try {
            if (userTransaction != null) {
                userTransaction.rollback();
            }
        } catch (Exception ex) {
        // NOOP
        }
        throw new AlfrescoRuntimeException("Workflow deployment failed", e);
    } finally {
        if (currentUser == null) {
            authenticationContext.clearCurrentSecurityContext();
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) WorkflowDeployment(org.alfresco.service.cmr.workflow.WorkflowDeployment) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryBootstrap(org.alfresco.repo.dictionary.DictionaryBootstrap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 2 with WorkflowDeployment

use of org.alfresco.service.cmr.workflow.WorkflowDeployment in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method deployDefinition.

/**
 * {@inheritDoc}
 */
public WorkflowDeployment deployDefinition(InputStream workflowDefinition, String mimetype, String name) {
    try {
        String resourceName = GUID.generate() + BpmnDeployer.BPMN_RESOURCE_SUFFIXES[0];
        Deployment deployment = repoService.createDeployment().addInputStream(resourceName, workflowDefinition).name(name).deploy();
        List<ProcessDefinition> definitionList = repoService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
        if (definitionList != null && definitionList.size() > 0) {
            boolean internalCategory = true;
            for (ProcessDefinition processDefinition : definitionList) {
                if (WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL.equals(processDefinition.getCategory()) == false) {
                    internalCategory = false;
                    break;
                }
            }
            if (internalCategory) {
                repoService.setDeploymentCategory(deployment.getId(), WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL);
            }
        }
        // not exposed
        return typeConverter.convert(deployment);
    } catch (Exception ae) {
        String msg = messageService.getMessage(ERR_DEPLOY_WORKFLOW);
        if (logger.isDebugEnabled()) {
            logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
Also used : WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) Deployment(org.activiti.engine.repository.Deployment) WorkflowDeployment(org.alfresco.service.cmr.workflow.WorkflowDeployment) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ReadOnlyProcessDefinition(org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition) ActivitiException(org.activiti.engine.ActivitiException) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) IOException(java.io.IOException)

Example 3 with WorkflowDeployment

use of org.alfresco.service.cmr.workflow.WorkflowDeployment in project alfresco-repository by Alfresco.

the class WorkflowServiceImpl method deployDefinition.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.service.cmr.workflow.WorkflowService#deployDefinition(java
     * .lang.String, java.io.InputStream, java.lang.String, java.lang.String)
     */
public WorkflowDeployment deployDefinition(String engineId, InputStream workflowDefinition, String mimetype, String name) {
    WorkflowComponent component = getWorkflowComponent(engineId);
    WorkflowDeployment deployment = component.deployDefinition(workflowDefinition, mimetype, name);
    if (logger.isDebugEnabled() && deployment.getProblems().length > 0) {
        for (String problem : deployment.getProblems()) {
            logger.debug("Workflow definition '" + deployment.getDefinition().getTitle() + "' problem: " + problem);
        }
    }
    return deployment;
}
Also used : WorkflowDeployment(org.alfresco.service.cmr.workflow.WorkflowDeployment)

Example 4 with WorkflowDeployment

use of org.alfresco.service.cmr.workflow.WorkflowDeployment in project alfresco-repository by Alfresco.

the class ActivitiWorkflowServiceIntegrationTest method testWorkflowWithNodes.

@Test
public void testWorkflowWithNodes() throws Exception {
    authenticationComponent.setSystemUserAsCurrentUser();
    FileInfo incorrectNode = serviceRegistry.getFileFolderService().create(companyHome, "NO_WORKFLOW" + GUID.generate() + ".xml", ContentModel.TYPE_CONTENT);
    FileInfo fileInfo = serviceRegistry.getFileFolderService().create(companyHome, "workflow" + GUID.generate() + ".xml", WorkflowModel.TYPE_WORKFLOW_DEF);
    NodeRef workflowNode = fileInfo.getNodeRef();
    nodeService.setProperty(workflowNode, WorkflowModel.PROP_WORKFLOW_DEF_ENGINE_ID, getEngine());
    InputStream input = getInputStream("activiti/testDiagram.bpmn20.xml");
    ContentWriter contentWriter = serviceRegistry.getContentService().getWriter(fileInfo.getNodeRef(), ContentModel.TYPE_CONTENT, true);
    contentWriter.setEncoding("UTF-8");
    contentWriter.putContent(input);
    try {
        workflowService.isDefinitionDeployed(incorrectNode.getNodeRef());
        fail("The content type is incorrect, it should not get here");
    } catch (WorkflowException we) {
        assertTrue(we.getMessage().contains(" is not of type 'bpm:workflowDefinition'"));
    }
    boolean isDeployed = workflowService.isDefinitionDeployed(workflowNode);
    try {
        workflowService.deployDefinition(incorrectNode.getNodeRef());
        fail("The content type is incorrect, it should not get here");
    } catch (WorkflowException we) {
        assertTrue(we.getMessage().contains(" is not of type 'bpm:workflowDefinition'"));
    }
    assertFalse(workflowService.isDefinitionDeployed(workflowNode));
    WorkflowDeployment workflowDeployment = workflowService.deployDefinition(workflowNode);
    assertNotNull(workflowDeployment);
    assertTrue(workflowService.isDefinitionDeployed(workflowNode));
    List<WorkflowDefinition> defs = workflowService.getAllDefinitionsByName(workflowDeployment.getDefinition().getName());
    assertNotNull(defs);
    assertEquals(1, defs.size());
    workflowService.undeployDefinition(workflowDeployment.getDefinition().getId());
    assertFalse(workflowService.isDefinitionDeployed(workflowNode));
    try {
        workflowService.startWorkflowFromTemplate(incorrectNode.getNodeRef());
        fail("This method hasn't be implemented");
    } catch (UnsupportedOperationException we) {
    }
    boolean multi = workflowService.isMultiTenantWorkflowDeploymentEnabled();
    assertTrue(multi);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileInfo(org.alfresco.service.cmr.model.FileInfo) InputStream(java.io.InputStream) WorkflowException(org.alfresco.service.cmr.workflow.WorkflowException) WorkflowDeployment(org.alfresco.service.cmr.workflow.WorkflowDeployment) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) AbstractWorkflowServiceIntegrationTest(org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest) Test(org.junit.Test)

Example 5 with WorkflowDeployment

use of org.alfresco.service.cmr.workflow.WorkflowDeployment in project alfresco-repository by Alfresco.

the class AbstractMultitenantWorkflowTest method deployDefinition.

protected WorkflowDefinition deployDefinition(String resource) {
    InputStream input = getInputStream(resource);
    WorkflowDeployment deployment = workflowService.deployDefinition(getEngine(), input, XML);
    WorkflowDefinition definition = deployment.getDefinition();
    return definition;
}
Also used : InputStream(java.io.InputStream) WorkflowDeployment(org.alfresco.service.cmr.workflow.WorkflowDeployment) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition)

Aggregations

WorkflowDeployment (org.alfresco.service.cmr.workflow.WorkflowDeployment)11 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)8 InputStream (java.io.InputStream)7 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)4 Serializable (java.io.Serializable)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 QName (org.alfresco.service.namespace.QName)3 FileInfo (org.alfresco.service.cmr.model.FileInfo)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 UserTransaction (javax.transaction.UserTransaction)1 ActivitiException (org.activiti.engine.ActivitiException)1