use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testGetWorkflows.
@Test
public void testGetWorkflows() throws Exception {
WorkflowDefinition def = deployTestAdhocDefinition();
String activitiProcessDefinitionId = BPMEngineRegistry.getLocalId(def.getId());
ProcessInstance activeInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
ProcessInstance completedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
ProcessInstance cancelledInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
ProcessInstance deletedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
// Complete completedProcessInstance.
String completedId = completedInstance.getId();
boolean isActive = true;
while (isActive) {
Execution execution = runtime.createExecutionQuery().processInstanceId(completedId).singleResult();
runtime.signal(execution.getId());
ProcessInstance instance = runtime.createProcessInstanceQuery().processInstanceId(completedId).singleResult();
isActive = instance != null;
}
// Deleted and canceled instances shouldn't be returned
workflowEngine.cancelWorkflow(workflowEngine.createGlobalId(cancelledInstance.getId()));
workflowEngine.deleteWorkflow(workflowEngine.createGlobalId(deletedInstance.getId()));
// Validate if a workflow exists
List<WorkflowInstance> instances = workflowEngine.getWorkflows(def.getId());
assertNotNull(instances);
assertEquals(2, instances.size());
String instanceId = instances.get(0).getId();
assertEquals(activeInstance.getId(), BPMEngineRegistry.getLocalId(instanceId));
instanceId = instances.get(1).getId();
assertEquals(completedId, BPMEngineRegistry.getLocalId(instanceId));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testDeleteFinishedWorkflow.
@Test
public void testDeleteFinishedWorkflow() 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()));
WorkflowInstance instance = instances.get(0);
WorkflowTask startTask = workflowEngine.getStartTask(instance.getId());
workflowEngine.endTask(startTask.getId(), null);
WorkflowTask adhocTask = workflowEngine.getTasksForWorkflowPath(instance.getId()).get(0);
workflowEngine.endTask(adhocTask.getId(), null);
// Validate if workflow is ended and has history
instances = workflowEngine.getActiveWorkflows(def.getId());
assertNotNull(instances);
assertEquals(0, instances.size());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
assertNotNull(historicProcessInstance);
// Call delete method on component
workflowEngine.deleteWorkflow(instance.getId());
// Historic process instance shouldn't be present anymore
historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
assertNull(historicProcessInstance);
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testGetCompletedWorkflows.
@Test
public void testGetCompletedWorkflows() throws Exception {
WorkflowDefinition def = deployTestAdhocDefinition();
String activitiProcessDefinitionId = BPMEngineRegistry.getLocalId(def.getId());
runtime.startProcessInstanceById(activitiProcessDefinitionId);
ProcessInstance completedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
ProcessInstance cancelledInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
ProcessInstance deletedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
// Complete completedProcessInstance.
String completedId = completedInstance.getId();
boolean isActive = true;
while (isActive) {
Execution execution = runtime.createExecutionQuery().processInstanceId(completedId).singleResult();
runtime.signal(execution.getId());
ProcessInstance instance = runtime.createProcessInstanceQuery().processInstanceId(completedId).singleResult();
isActive = instance != null;
}
// Deleted and canceled instances shouldn't be returned
workflowEngine.cancelWorkflow(workflowEngine.createGlobalId(cancelledInstance.getId()));
workflowEngine.deleteWorkflow(workflowEngine.createGlobalId(deletedInstance.getId()));
// Validate if a workflow exists
List<WorkflowInstance> instances = workflowEngine.getCompletedWorkflows(def.getId());
assertNotNull(instances);
assertEquals(1, instances.size());
String instanceId = instances.get(0).getId();
assertEquals(completedId, BPMEngineRegistry.getLocalId(instanceId));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testGetCompletedWorkflowById.
@Test
public void testGetCompletedWorkflowById() throws Exception {
WorkflowDefinition def = deployTestAdhocDefinition();
Date startTime = new SimpleDateFormat("dd-MM-yyy hh:mm:ss").parse("01-01-2011 01:02:03");
// Add some variables which should be used in the WorkflowInstance
Map<String, Object> variables = new HashMap<String, Object>();
Date dueDate = Calendar.getInstance().getTime();
putVariable(variables, WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
putVariable(variables, WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "I'm the description");
putVariable(variables, WorkflowModel.PROP_CONTEXT, new ActivitiScriptNode(testWorkflowContext, serviceRegistry));
putVariable(variables, WorkflowModel.ASSOC_PACKAGE, new ActivitiScriptNode(testWorkflowPackage, serviceRegistry));
putVariable(variables, WorkflowModel.PROP_WORKFLOW_PRIORITY, 3);
variables.put(WorkflowConstants.PROP_INITIATOR, new ActivitiScriptNode(adminHomeNode, serviceRegistry));
ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId()), variables);
String globalProcessInstanceId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, processInstance.getProcessInstanceId());
Date endTime = new SimpleDateFormat("dd-MM-yyy hh:mm:ss").parse("01-01-2011 02:03:04");
// Finish the task
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
WorkflowInstance workflowInstance = workflowEngine.getWorkflowById(globalProcessInstanceId);
assertNotNull(workflowInstance);
assertEquals(globalProcessInstanceId, workflowInstance.getId());
assertEquals(endTime, workflowInstance.getEndDate());
assertFalse(workflowInstance.isActive());
assertEquals("I'm the description", workflowInstance.getDescription());
assertEquals(dueDate, workflowInstance.getDueDate());
assertEquals(def.getId(), workflowInstance.getDefinition().getId());
assertEquals(adminHomeNode, workflowInstance.getInitiator());
assertEquals(testWorkflowContext, workflowInstance.getContext());
assertEquals(testWorkflowPackage, workflowInstance.getWorkflowPackage());
assertNotNull(workflowInstance.getPriority());
assertEquals(3, workflowInstance.getPriority().intValue());
assertEquals(startTime, workflowInstance.getStartDate());
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testStartWorkflow.
@Test
public void testStartWorkflow() throws Exception {
WorkflowDefinition def = deployTestTaskDefinition();
// Fill a map of default properties to start the workflow with
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
Date dueDate = Calendar.getInstance().getTime();
properties.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "description123");
properties.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
properties.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 2);
// properties.put(WorkflowModel.ASSOC_PACKAGE, null);
// properties.put(WorkflowModel.PROP_CONTEXT, null);
// Call the start method
WorkflowPath path = workflowEngine.startWorkflow(def.getId(), properties);
assertNotNull("The workflow path is null!", path);
String executionId = BPMEngineRegistry.getLocalId(path.getId());
Execution execution = runtime.createExecutionQuery().executionId(executionId).singleResult();
assertNotNull("No execution was created int he DB!", execution);
WorkflowInstance instance = path.getInstance();
assertNotNull("The workflow instance is null!", instance);
String procInstanceId = BPMEngineRegistry.getLocalId(instance.getId());
ProcessInstance procInstance = runtime.createProcessInstanceQuery().processInstanceId(procInstanceId).singleResult();
assertNotNull("No process instance was created!", procInstance);
WorkflowNode node = path.getNode();
assertNotNull("The workflow node is null!", node);
String nodeName = node.getName();
assertEquals("task", nodeName);
// Check if company home is added as variable and can be fetched
ScriptNode companyHome = (ScriptNode) runtime.getVariable(procInstanceId, "companyhome");
assertNotNull(companyHome);
assertEquals("companyHome", companyHome.getNodeRef().getStoreRef().getIdentifier());
// Check if the initiator is added as variable
ScriptNode initiator = (ScriptNode) runtime.getVariable(procInstanceId, "initiator");
assertNotNull(initiator);
assertEquals("admin", initiator.getNodeRef().getStoreRef().getIdentifier());
// Check if the initiator home is also set as variable
ScriptNode initiatorHome = (ScriptNode) runtime.getVariable(procInstanceId, "initiatorhome");
assertNotNull(initiatorHome);
assertEquals("admin-home", initiatorHome.getNodeRef().getStoreRef().getIdentifier());
// Check if start-date is set and no end-date is set
assertNotNull(path.getInstance().getStartDate());
assertNull(path.getInstance().getEndDate());
// Also check if the task that is created, has all default properties initialised
Task task = taskService.createTaskQuery().processInstanceId(procInstanceId).singleResult();
assertNotNull("Task should have been created", task);
assertEquals("task", task.getTaskDefinitionKey());
String defaultSetVariable = (String) taskService.getVariableLocal(task.getId(), "test_myProp");
assertEquals("Default value", defaultSetVariable);
// Also check default value of task description is taken from WF-porps
assertEquals("description123", task.getDescription());
}
Aggregations