Search in sources :

Example 41 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 42 with WorkflowInstance

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

Example 43 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)

Example 44 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 45 with WorkflowInstance

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());
}
Also used : Serializable(java.io.Serializable) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) ScriptNode(org.alfresco.repo.jscript.ScriptNode) WorkflowNode(org.alfresco.service.cmr.workflow.WorkflowNode) Date(java.util.Date) Execution(org.activiti.engine.runtime.Execution) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) 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