Java Code Examples for org.activiti.engine.runtime.Execution#getParentId()

The following examples show how to use org.activiti.engine.runtime.Execution#getParentId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutionQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti/engine/test/api/runtime/multipleSubProcess.bpmn20.xml",
                 "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml"})
public void testOnlySubProcessExecutions() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("multipleSubProcessTest");

  List<Execution> executions = runtimeService.createExecutionQuery().onlySubProcessExecutions().list();
  assertEquals(2, executions.size());
  for (Execution execution : executions) {
    if (execution.getParentId() == null) {
      assertTrue(processInstance.getId() != execution.getProcessInstanceId());
    } else if (execution.getParentId().equals(execution.getProcessInstanceId())) {
      assertEquals("embeddedSubprocess" , execution.getActivityId());
    } else {
      fail();
    }
  }
}
 
Example 2
Source File: AsyncTaskTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testAsyncScript() {
  // start process
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncScript");
  // now there should be one job in the database:
  assertEquals(1, managementService.createJobQuery().count());
  // the script was not invoked:
  List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
  String eid = null;
  for (Execution e : executions) {
    if (e.getParentId() != null) {
      eid = e.getId();
    }
  }
  assertNull(runtimeService.getVariable(eid, "invoked"));

  waitForJobExecutorToProcessAllJobs(5000L, 100L);

  // and the job is done
  assertEquals(0, managementService.createJobQuery().count());

  // the script was invoked
  assertEquals("true", runtimeService.getVariable(eid, "invoked"));

  runtimeService.trigger(eid);
}
 
Example 3
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ExecutionResponse createExecutionResponse(Execution execution, RestUrlBuilder urlBuilder) {
  ExecutionResponse result = new ExecutionResponse();
  result.setActivityId(execution.getActivityId());
  result.setId(execution.getId());
  result.setUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION, execution.getId()));
  result.setSuspended(execution.isSuspended());
  result.setTenantId(execution.getTenantId());

  result.setParentId(execution.getParentId());
  if (execution.getParentId() != null) {
    result.setParentUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION, execution.getParentId()));
  }
  
  result.setSuperExecutionId(execution.getSuperExecutionId());
  if (execution.getSuperExecutionId() != null) {
    result.setSuperExecutionUrl(urlBuilder.buildUrl(RestUrls.URL_EXECUTION, execution.getSuperExecutionId()));
  }

  result.setProcessInstanceId(execution.getProcessInstanceId());
  if (execution.getProcessInstanceId() != null) {
    result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE, execution.getProcessInstanceId()));
  }
  return result;
}
 
Example 4
Source File: BaseExecutionVariableResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void setVariable(Execution execution, String name, Object value, RestVariableScope scope, boolean isNew) {
  // Create can only be done on new variables. Existing variables should
  // be updated using PUT
  boolean hasVariable = hasVariableOnScope(execution, name, scope);
  if (isNew && hasVariable) {
    throw new ActivitiException("Variable '" + name + "' is already present on execution '" + execution.getId() + "'.");
  }

  if (!isNew && !hasVariable) {
    throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + name + "'.", null);
  }

  if (scope == RestVariableScope.LOCAL) {
    runtimeService.setVariableLocal(execution.getId(), name, value);
  } else {
    if (execution.getParentId() != null) {
      runtimeService.setVariable(execution.getParentId(), name, value);
    } else {
      runtimeService.setVariable(execution.getId(), name, value);
    }
  }
}
 
Example 5
Source File: ChangeConfigAndRebootEngineTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void assertExecutions(ProcessInstance processInstance, boolean expectedCountIsEnabledFlag) {
  List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
  assertEquals(2, executions.size());
  for (Execution execution : executions) {
    CountingExecutionEntity countingExecutionEntity = (CountingExecutionEntity) execution;
    assertEquals(expectedCountIsEnabledFlag, countingExecutionEntity.isCountEnabled());
    
    if (expectedCountIsEnabledFlag && execution.getParentId() != null) {
      assertEquals(1, countingExecutionEntity.getTaskCount());
    }
  }
}
 
Example 6
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testParallelSubProcessCompletionCondition() {
  String procId = runtimeService.startProcessInstanceByKey("miParallelSubprocessCompletionCondition").getId();
  List<Task> tasks = taskService.createTaskQuery().list();
  assertEquals(4, tasks.size());
  
  List<Task> subProcessTasks1 = taskService.createTaskQuery().taskDefinitionKey("subProcessTask1").list();
  assertEquals(2, subProcessTasks1.size());
  
  List<Task> subProcessTasks2 = taskService.createTaskQuery().taskDefinitionKey("subProcessTask2").list();
  assertEquals(2, subProcessTasks2.size());
  
  Execution taskExecution = runtimeService.createExecutionQuery().executionId(subProcessTasks1.get(0).getExecutionId()).singleResult();
  String parentExecutionId = taskExecution.getParentId();
  
  Task subProcessTask2 = null;
  for (Task task : subProcessTasks2) {
    Execution toFindExecution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
    if (toFindExecution.getParentId().equals(parentExecutionId)) {
      subProcessTask2 = task;
      break;
    }
  }

  assertNotNull(subProcessTask2);
  taskService.complete(tasks.get(0).getId());
  taskService.complete(subProcessTask2.getId());
  
  assertProcessEnded(procId);
}
 
Example 7
Source File: BaseExecutionVariableResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean hasVariableOnScope(Execution execution, String variableName, RestVariableScope scope) {
  boolean variableFound = false;

  if (scope == RestVariableScope.GLOBAL) {
    if (execution.getParentId() != null && runtimeService.hasVariable(execution.getParentId(), variableName)) {
      variableFound = true;
    }

  } else if (scope == RestVariableScope.LOCAL) {
    if (runtimeService.hasVariableLocal(execution.getId(), variableName)) {
      variableFound = true;
    }
  }
  return variableFound;
}
 
Example 8
Source File: InclusiveGatewayTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test for ACT-1216: When merging a concurrent execution the parent is not activated correctly
 */
@Deployment
public void testParentActivationOnNonJoiningEnd() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("parentActivationOnNonJoiningEnd");

  List<Execution> executionsBefore = runtimeService.createExecutionQuery().list();
  assertEquals(3, executionsBefore.size());

  // start first round of tasks
  List<Task> firstTasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  assertEquals(2, firstTasks.size());

  for (Task t : firstTasks) {
    taskService.complete(t.getId());
  }

  // start second round of tasks
  List<Task> secondTasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  assertEquals(2, secondTasks.size());

  // complete one task
  Task task = secondTasks.get(0);
  taskService.complete(task.getId());

  List<Execution> executionsAfter = runtimeService.createExecutionQuery().list();
  assertEquals(2, executionsAfter.size());

  Execution execution = null;
  for (Execution e : executionsAfter) {
    if (e.getParentId() != null) {
      execution = e;
    }
  }

  // and should have one active activity
  List<String> activeActivityIds = runtimeService.getActiveActivityIds(execution.getId());
  assertEquals(1, activeActivityIds.size());

  // Completing last task should finish the process instance

  Task lastTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  taskService.complete(lastTask.getId());

  assertEquals(0l, runtimeService.createProcessInstanceQuery().active().count());
}
 
Example 9
Source File: BaseVariableCollectionResource.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected Object createExecutionVariable(Execution execution, boolean override, int variableType, HttpServletRequest request, HttpServletResponse response) {

    Object result = null;
    if (request instanceof MultipartHttpServletRequest) {
      result = setBinaryVariable((MultipartHttpServletRequest) request, execution, variableType, true);
    } else {

      List<RestVariable> inputVariables = new ArrayList<RestVariable>();
      List<RestVariable> resultVariables = new ArrayList<RestVariable>();
      result = resultVariables;

      try {
        @SuppressWarnings("unchecked")
        List<Object> variableObjects = (List<Object>) objectMapper.readValue(request.getInputStream(), List.class);
        for (Object restObject : variableObjects) {
          RestVariable restVariable = objectMapper.convertValue(restObject, RestVariable.class);
          inputVariables.add(restVariable);
        }
      } catch (Exception e) {
        throw new ActivitiIllegalArgumentException("Failed to serialize to a RestVariable instance", e);
      }

      if (inputVariables == null || inputVariables.size() == 0) {
        throw new ActivitiIllegalArgumentException("Request didn't contain a list of variables to create.");
      }

      RestVariableScope sharedScope = null;
      RestVariableScope varScope = null;
      Map<String, Object> variablesToSet = new HashMap<String, Object>();

      for (RestVariable var : inputVariables) {
        // Validate if scopes match
        varScope = var.getVariableScope();
        if (var.getName() == null) {
          throw new ActivitiIllegalArgumentException("Variable name is required");
        }

        if (varScope == null) {
          varScope = RestVariableScope.LOCAL;
        }
        if (sharedScope == null) {
          sharedScope = varScope;
        }
        if (varScope != sharedScope) {
          throw new ActivitiIllegalArgumentException("Only allowed to update multiple variables in the same scope.");
        }

        if (!override && hasVariableOnScope(execution, var.getName(), varScope)) {
          throw new ActivitiConflictException("Variable '" + var.getName() + "' is already present on execution '" + execution.getId() + "'.");
        }

        Object actualVariableValue = restResponseFactory.getVariableValue(var);
        variablesToSet.put(var.getName(), actualVariableValue);
        resultVariables.add(restResponseFactory.createRestVariable(var.getName(), actualVariableValue, varScope, execution.getId(), variableType, false));
      }

      if (!variablesToSet.isEmpty()) {
        if (sharedScope == RestVariableScope.LOCAL) {
          runtimeService.setVariablesLocal(execution.getId(), variablesToSet);
        } else {
          if (execution.getParentId() != null) {
            // Explicitly set on parent, setting non-local variables
            // on execution itself will override local-variables if
            // exists
            runtimeService.setVariables(execution.getParentId(), variablesToSet);
          } else {
            // Standalone task, no global variables possible
            throw new ActivitiIllegalArgumentException("Cannot set global variables on execution '" + execution.getId() + "', task is not part of process.");
          }
        }
      }
    }
    response.setStatus(HttpStatus.CREATED.value());
    return result;
  }
 
Example 10
Source File: BaseExecutionVariableResource.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary) {

    boolean variableFound = false;
    Object value = null;

    if (execution == null) {
      throw new ActivitiObjectNotFoundException("Could not find an execution", Execution.class);
    }

    RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    if (variableScope == null) {
      // First, check local variables (which have precedence when no scope
      // is supplied)
      if (runtimeService.hasVariableLocal(execution.getId(), variableName)) {
        value = runtimeService.getVariableLocal(execution.getId(), variableName);
        variableScope = RestVariableScope.LOCAL;
        variableFound = true;
      } else {
        if (execution.getParentId() != null) {
          value = runtimeService.getVariable(execution.getParentId(), variableName);
          variableScope = RestVariableScope.GLOBAL;
          variableFound = true;
        }
      }
    } else if (variableScope == RestVariableScope.GLOBAL) {
      // Use parent to get variables
      if (execution.getParentId() != null) {
        value = runtimeService.getVariable(execution.getParentId(), variableName);
        variableScope = RestVariableScope.GLOBAL;
        variableFound = true;
      }
    } else if (variableScope == RestVariableScope.LOCAL) {

      value = runtimeService.getVariableLocal(execution.getId(), variableName);
      variableScope = RestVariableScope.LOCAL;
      variableFound = true;
    }

    if (!variableFound) {
      throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class);
    } else {
      return constructRestVariable(variableName, value, variableScope, execution.getId(), includeBinary);
    }
  }