Search in sources :

Example 46 with WorkflowInstance

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);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Date(java.util.Date) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Example 47 with WorkflowInstance

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));
    }
}
Also used : WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 48 with WorkflowInstance

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());
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 49 with WorkflowInstance

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));
}
Also used : Execution(org.activiti.engine.runtime.Execution) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Test(org.junit.Test)

Example 50 with WorkflowInstance

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));
}
Also used : Execution(org.activiti.engine.runtime.Execution) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Test(org.junit.Test)

Aggregations

WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)56 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)26 HashMap (java.util.HashMap)22 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)19 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)16 QName (org.alfresco.service.namespace.QName)16 Serializable (java.io.Serializable)15 Date (java.util.Date)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)13 Test (org.junit.Test)13 Map (java.util.Map)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 ArrayList (java.util.ArrayList)9 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)7 WorkflowNode (org.alfresco.service.cmr.workflow.WorkflowNode)5 Execution (org.activiti.engine.runtime.Execution)4 List (java.util.List)3 ActivitiException (org.activiti.engine.ActivitiException)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3