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();
}
}
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations