use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method testGetWorkflows.
public void testGetWorkflows() throws Exception {
String fakeDefId = getEngine() + "$9999999999999";
List<WorkflowInstance> workflows = workflowService.getActiveWorkflows(fakeDefId);
assertTrue(workflows.isEmpty());
workflows = workflowService.getCompletedWorkflows(fakeDefId);
assertTrue(workflows.isEmpty());
workflows = workflowService.getWorkflows(fakeDefId);
assertTrue(workflows.isEmpty());
WorkflowDefinition definition = deployDefinition(getTestDefinitionPath());
String defId = definition.getId();
workflows = workflowService.getActiveWorkflows(defId);
assertTrue(workflows.isEmpty());
workflows = workflowService.getCompletedWorkflows(defId);
assertTrue(workflows.isEmpty());
workflows = workflowService.getWorkflows(defId);
assertTrue(workflows.isEmpty());
// Create workflow parameters
Date dueDate = new Date();
String description = "Some Description";
NodeRef assignee = personManager.get(USER2);
Serializable wfPackage1 = workflowService.createPackage(null);
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage1);
// task instance field
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
// task instance field
params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1);
// task instance field
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, description);
// task instance field
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
// Start workflow 1
WorkflowPath path1 = workflowService.startWorkflow(defId, params);
String instance1 = path1.getInstance().getId();
checkActiveWorkflows(defId, instance1);
checkCompletedWorkflows(defId);
checkWorkflows(defId, instance1);
// Start workflow 2
Serializable wfPackage2 = workflowService.createPackage(null);
params = new HashMap<QName, Serializable>();
params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage2);
// task instance field
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
// task instance field
params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1);
// task instance field
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, description);
// task instance field
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
WorkflowPath path2 = workflowService.startWorkflow(defId, params);
String instance2 = path2.getInstance().getId();
checkActiveWorkflows(defId, instance1, instance2);
checkCompletedWorkflows(defId);
checkWorkflows(defId, instance1, instance2);
// End workflow 1
WorkflowTask startTask1 = workflowService.getStartTask(instance1);
workflowService.endTask(startTask1.getId(), null);
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path1.getId());
assertEquals(1, tasks.size());
WorkflowTask task1 = tasks.get(0);
workflowService.endTask(task1.getId(), null);
checkActiveWorkflows(defId, instance2);
checkCompletedWorkflows(defId, instance1);
checkWorkflows(defId, instance1, instance2);
checkWorkflowsContains(workflowService.getActiveWorkflows(), instance2);
checkWorkflowsDontContain(workflowService.getActiveWorkflows(), instance1);
checkWorkflowsContains(workflowService.getCompletedWorkflows(), instance1);
checkWorkflowsDontContain(workflowService.getCompletedWorkflows(), instance2);
checkWorkflowsContains(workflowService.getWorkflows(), instance1, instance2);
// End workflow 2
WorkflowTask startTask2 = workflowService.getStartTask(instance2);
workflowService.endTask(startTask2.getId(), null);
tasks = workflowService.getTasksForWorkflowPath(path2.getId());
assertEquals(1, tasks.size());
WorkflowTask task2 = tasks.get(0);
workflowService.endTask(task2.getId(), null);
checkActiveWorkflows(defId);
checkCompletedWorkflows(defId, instance1, instance2);
checkWorkflows(defId, instance1, instance2);
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method checkWorkflows.
private void checkWorkflows(List<WorkflowInstance> workflows, String... expectedIds) {
assertEquals(expectedIds.length, workflows.size());
List<String> expIds = Arrays.asList(expectedIds);
for (WorkflowInstance workflow : workflows) {
String workflowId = workflow.getId();
assertTrue("The id: " + workflowId + " was not expected! Expected Ids: " + expIds, expIds.contains(workflowId));
}
}
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 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 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));
}
Aggregations