use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class JscriptWorkflowDefinition method getActiveInstances.
/**
* Get active workflow instances of this workflow definition
*
* @return the active workflow instances spawned from this workflow definition
*/
public synchronized Scriptable getActiveInstances() {
WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
List<WorkflowInstance> cmrWorkflowInstances = workflowService.getActiveWorkflows(this.id);
ArrayList<Serializable> activeInstances = new ArrayList<Serializable>();
for (WorkflowInstance cmrWorkflowInstance : cmrWorkflowInstances) {
activeInstances.add(new JscriptWorkflowInstance(cmrWorkflowInstance, this.serviceRegistry, this.scope));
}
Scriptable activeInstancesScriptable = (Scriptable) getValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, activeInstances);
return activeInstancesScriptable;
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class WorkflowFormProcessorTest method processPersist.
private void processPersist(String dataKey, String value) {
FormData data = new FormData();
data.addFieldData(dataKey, value);
WorkflowInstance persistedItem = (WorkflowInstance) processor.persist(item, data);
assertEquals(newInstance, persistedItem);
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method testAssociateWorkflowPackage.
public void testAssociateWorkflowPackage() {
// create workflow package
authenticationComponent.setSystemUserAsCurrentUser();
NodeRef rootNode = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
ChildAssociationRef childAssoc = nodeService.createNode(rootNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test"), ContentModel.TYPE_CONTENT, null);
NodeRef contentNode = childAssoc.getChildRef();
NodeRef pckgNode = workflowService.createPackage(null);
assertNotNull(pckgNode);
assertTrue(nodeService.hasAspect(pckgNode, WorkflowModel.ASPECT_WORKFLOW_PACKAGE));
List<WorkflowInstance> existingInstances = workflowService.getWorkflowsForContent(contentNode, true);
assertNotNull(existingInstances);
assertEquals(0, existingInstances.size());
existingInstances = workflowService.getWorkflowsForContent(contentNode, false);
assertNotNull(existingInstances);
assertEquals(0, existingInstances.size());
// Add content to the package
nodeService.addChild(pckgNode, contentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test123"));
// start workflow
WorkflowDefinition workflowDef = deployDefinition(getAdhocDefinitionPath());
Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
parameters.put(WorkflowModel.ASSOC_PACKAGE, pckgNode);
parameters.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
WorkflowPath path = workflowService.startWorkflow(workflowDef.getId(), parameters);
assertNotNull(path);
assertTrue(path.isActive());
assertNotNull(path.getNode());
assertNotNull(path.getInstance());
assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
String workflowDefId = (String) nodeService.getProperty(pckgNode, WorkflowModel.PROP_WORKFLOW_DEFINITION_ID);
assertEquals(workflowDefId, workflowDef.getId());
String workflowDefName = (String) nodeService.getProperty(pckgNode, WorkflowModel.PROP_WORKFLOW_DEFINITION_NAME);
assertEquals(workflowDefName, workflowDef.getName());
String workflowInstanceId = (String) nodeService.getProperty(pckgNode, WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
assertEquals(workflowInstanceId, path.getInstance().getId());
// get workflows for content
List<WorkflowInstance> instances = workflowService.getWorkflowsForContent(contentNode, true);
assertNotNull(instances);
assertEquals(1, instances.size());
WorkflowInstance newInstance = instances.get(0);
assertNotNull(newInstance);
assertEquals(path.getInstance().getId(), newInstance.getId());
List<WorkflowInstance> completedInstances = workflowService.getWorkflowsForContent(contentNode, false);
assertNotNull(completedInstances);
assertEquals(0, completedInstances.size());
// TODO End the workfow instance and test the completed workflow is returned
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowServiceIntegrationTest method testBuildWorkflowWithNoUserTasks.
@Test
public void testBuildWorkflowWithNoUserTasks() throws Exception {
// Deploy a definition containing only a service task
WorkflowDefinition testDefinition = deployDefinition("activiti/testWorkflowNoUserTasks.bpmn20.xml");
WorkflowBuilder builder = new WorkflowBuilder(testDefinition, workflowService, nodeService, null);
// Build a workflow
WorkflowInstance builtInstance = builder.build();
assertNotNull(builtInstance);
// Check that there is no active workflow for the deployed definition(it should have finished already due to absence of user tasks)
List<WorkflowInstance> activeInstances = workflowService.getActiveWorkflows(testDefinition.getId());
assertNotNull(activeInstances);
assertEquals(0, activeInstances.size());
// Check that there's a historic record of our 'only service task' workflow being run.
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().finishedAfter(builtInstance.getStartDate()).singleResult();
assertNotNull(historicProcessInstance);
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testCancelWorkflow.
@Test
public void testCancelWorkflow() throws Exception {
WorkflowDefinition def = deployTestAdhocDefinition();
ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId()));
// Validate if a workflow exists
List<WorkflowInstance> instances = workflowEngine.getActiveWorkflows(def.getId());
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(processInstance.getId(), BPMEngineRegistry.getLocalId(instances.get(0).getId()));
// Call cancel method on component
WorkflowInstance cancelledWorkflow = workflowEngine.cancelWorkflow(instances.get(0).getId());
assertFalse(cancelledWorkflow.isActive());
instances = workflowEngine.getActiveWorkflows(def.getId());
assertNotNull(instances);
assertEquals(0, instances.size());
// Histrotic process instance shouldn't be present
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
if (workflowEngine.activitiUtil.isRetentionHistoricProcessInstanceEnabled() == false) {
assertNull(historicProcessInstance);
}
}
Aggregations