Search in sources :

Example 31 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class TaskVariablesTest method testGetVariablesLocalByTaskIdsForScope.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/variableScope.bpmn20.xml" })
public void testGetVariablesLocalByTaskIdsForScope() {
    Map<String, Object> processVars = new HashMap<String, Object>();
    processVars.put("processVar", "processVar");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableScopeProcess", processVars);
    Set<String> executionIds = new HashSet<String>();
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    for (Execution execution : executions) {
        if (!processInstance.getId().equals(execution.getId())) {
            executionIds.add(execution.getId());
            runtimeService.setVariableLocal(execution.getId(), "executionVar", "executionVar");
        }
    }
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    Set<String> taskIds = new HashSet<String>();
    for (Task task : tasks) {
        taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
        taskIds.add(task.getId());
    }
    List<VariableInstance> variableInstances = taskService.getVariableInstancesLocalByTaskIds(taskIds);
    assertEquals(variableInstances.size(), 2);
    assertEquals(variableInstances.get(0).getName(), "taskVar");
    assertEquals(variableInstances.get(0).getValue(), "taskVar");
    assertEquals(variableInstances.get(1).getName(), "taskVar");
    assertEquals(variableInstances.get(1).getValue(), "taskVar");
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 32 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class TerminateEndEventTest method testThreeExecutionsArrivingInTerminateEndEvent.

// Unit test for ACT-4101 : NPE when there are multiple routes to terminateEndEvent, and both are reached
@Deployment
public void testThreeExecutionsArrivingInTerminateEndEvent() {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("passed_QC", false);
    variableMap.put("has_bad_pixel_pattern", true);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("skybox_image_pull_request", variableMap);
    String processInstanceId = processInstance.getId();
    assertNotNull(processInstance);
    while (processInstance != null) {
        List<Execution> executionList = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
        String activityId = "";
        for (Execution execution : executionList) {
            activityId = execution.getActivityId();
            if (activityId == null || activityId.equalsIgnoreCase("quality_control_passed_gateway") || activityId.equalsIgnoreCase("parallelgateway1") || activityId.equalsIgnoreCase("catch_bad_pixel_signal") || activityId.equalsIgnoreCase("throw_bad_pixel_signal") || activityId.equalsIgnoreCase("has_bad_pixel_pattern") || activityId.equalsIgnoreCase("")) {
                continue;
            }
            System.out.println("Current Activity:" + activityId);
            runtimeService.signal(execution.getId());
        }
        processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
    }
    assertProcessEnded(processInstanceId);
    assertHistoricProcessInstanceDetails(processInstanceId);
}
Also used : DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 33 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class Photo method launchPhotoProcess.

public void launchPhotoProcess(String... photoLabels) {
    List<Photo> photos = new ArrayList<Photo>();
    for (String l : photoLabels) {
        Photo x = this.photoRepository.save(new Photo(l));
        photos.add(x);
    }
    Map<String, Object> procVars = new HashMap<String, Object>();
    procVars.put("photos", photos);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dogeProcess", procVars);
    List<Execution> waitingExecutions = runtimeService.createExecutionQuery().activityId("wait").list();
    System.out.println("--> # executions = " + waitingExecutions.size());
    for (Execution execution : waitingExecutions) {
        runtimeService.signal(execution.getId());
    }
    Task reviewTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    taskService.complete(reviewTask.getId(), Collections.singletonMap("approved", (Object) true));
    long count = runtimeService.createProcessInstanceQuery().count();
    System.out.println("Proc count " + count);
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 34 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class HistoricVariableInstanceTest method testHistoricVariableQueryByExecutionIdsForScope.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/variableScope.bpmn20.xml" })
public void testHistoricVariableQueryByExecutionIdsForScope() {
    Map<String, Object> processVars = new HashMap<String, Object>();
    processVars.put("processVar", "processVar");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableScopeProcess", processVars);
    Set<String> executionIds = new HashSet<String>();
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
    for (Execution execution : executions) {
        if (!processInstance.getId().equals(execution.getId())) {
            executionIds.add(execution.getId());
            runtimeService.setVariableLocal(execution.getId(), "executionVar", "executionVar");
        }
    }
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    for (Task task : tasks) {
        taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
    }
    Set<String> processInstanceIds = new HashSet<String>();
    processInstanceIds.add(processInstance.getId());
    List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().executionIds(processInstanceIds).list();
    assertEquals(historicVariableInstances.size(), 1);
    assertEquals(historicVariableInstances.get(0).getVariableName(), "processVar");
    assertEquals(historicVariableInstances.get(0).getValue(), "processVar");
    historicVariableInstances = historyService.createHistoricVariableInstanceQuery().executionIds(executionIds).excludeTaskVariables().list();
    assertEquals(historicVariableInstances.size(), 2);
    assertEquals(historicVariableInstances.get(0).getVariableName(), "executionVar");
    assertEquals(historicVariableInstances.get(0).getValue(), "executionVar");
    assertEquals(historicVariableInstances.get(1).getVariableName(), "executionVar");
    assertEquals(historicVariableInstances.get(1).getValue(), "executionVar");
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 35 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class HistoricActivityInstanceTest method testEventBasedGateway.

/**
   * Test to validate fix for ACT-1399: Boundary-event and event-based auditing
   */
@Deployment
public void testEventBasedGateway() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
    Execution waitingExecution = runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").singleResult();
    assertNotNull(waitingExecution);
    runtimeService.signalEventReceived("alert", waitingExecution.getId());
    assertEquals(0L, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("eventBasedgateway").processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(historicActivityInstance);
}
Also used : Execution(org.activiti.engine.runtime.Execution) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5