Java Code Examples for org.flowable.engine.runtime.Execution#getParentId()
The following examples show how to use
org.flowable.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: RestResponseFactory.java From flowable-engine with Apache License 2.0 | 6 votes |
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 2
Source File: BaseExecutionVariableResource.java From flowable-engine with Apache License 2.0 | 6 votes |
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 FlowableException("Variable '" + name + "' is already present on execution '" + execution.getId() + "'."); } if (!isNew && !hasVariable) { throw new FlowableObjectNotFoundException("Execution '" + execution.getId() + "' does not 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 3
Source File: ExecutionQueryTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/multipleSubProcess.bpmn20.xml", "org/flowable/engine/test/api/runtime/subProcess.bpmn20.xml" }) public void testOnlySubProcessExecutions() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("multipleSubProcessTest"); List<Execution> executions = runtimeService.createExecutionQuery().onlySubProcessExecutions().list(); assertThat(executions).hasSize(2); for (Execution execution : executions) { if (execution.getParentId() == null) { assertThat(execution.getProcessInstanceId()).isNotSameAs(processInstance.getId()); } else if (execution.getParentId().equals(execution.getProcessInstanceId())) { assertThat(execution.getActivityId()).isEqualTo("embeddedSubprocess"); } else { fail(); } } }
Example 4
Source File: BaseExecutionVariableResource.java From flowable-engine with Apache License 2.0 | 5 votes |
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 5
Source File: ChangeConfigAndRebootEngineTest.java From flowable-engine with Apache License 2.0 | 5 votes |
protected void assertExecutions(ProcessInstance processInstance, boolean expectedCountIsEnabledFlag) { List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list(); assertThat(executions).hasSize(2); for (Execution execution : executions) { CountingExecutionEntity countingExecutionEntity = (CountingExecutionEntity) execution; assertThat(countingExecutionEntity.isCountEnabled()).isEqualTo(expectedCountIsEnabledFlag); if (expectedCountIsEnabledFlag && execution.getParentId() != null) { assertThat(countingExecutionEntity.getTaskCount()).isEqualTo(1); } } }
Example 6
Source File: AsyncTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment public void testFailingAsyncServiceTimer() { // start process runtimeService.startProcessInstanceByKey("asyncService"); // now there should be one job in the database, and it is a message assertThat(managementService.createJobQuery().count()).isEqualTo(1); Job job = managementService.createJobQuery().singleResult(); assertThatThrownBy(() -> managementService.executeJob(job.getId())) .isInstanceOf(FlowableException.class); // the service failed: the execution is still sitting in the service task: Execution execution = null; for (Execution e : runtimeService.createExecutionQuery().list()) { if (e.getParentId() != null) { execution = e; } } assertThat(execution).isNotNull(); // there is still a single job because the timer was created in the same // transaction as the service was executed (which rolled back) assertThat(managementService.createTimerJobQuery().count()).isEqualTo(1); runtimeService.deleteProcessInstance(execution.getId(), "dead"); }
Example 7
Source File: AsyncTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment public void testAsyncScript() { // start process ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncScript"); // now there should be one job in the database: assertThat(managementService.createJobQuery().count()).isEqualTo(1); Job job = managementService.createJobQuery().singleResult(); assertThat(job.getElementId()).isEqualTo("script"); assertThat(job.getElementName()).isEqualTo("Script"); // 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(); } } assertThat(runtimeService.getVariable(eid, "invoked")).isNull(); waitForJobExecutorToProcessAllJobs(7000L, 100L); // and the job is done assertThat(managementService.createJobQuery().count()).isZero(); // the script was invoked assertThat(runtimeService.getVariable(eid, "invoked")).isEqualTo("true"); runtimeService.trigger(eid); }
Example 8
Source File: BaseVariableCollectionResource.java From flowable-engine with Apache License 2.0 | 4 votes |
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<>(); List<RestVariable> resultVariables = new ArrayList<>(); 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 FlowableIllegalArgumentException("Failed to serialize to a RestVariable instance", e); } if (inputVariables == null || inputVariables.size() == 0) { throw new FlowableIllegalArgumentException("Request did not contain a list of variables to create."); } RestVariableScope sharedScope = null; RestVariableScope varScope = null; Map<String, Object> variablesToSet = new HashMap<>(); for (RestVariable var : inputVariables) { // Validate if scopes match varScope = var.getVariableScope(); if (var.getName() == null) { throw new FlowableIllegalArgumentException("Variable name is required"); } if (varScope == null) { varScope = RestVariableScope.LOCAL; } if (sharedScope == null) { sharedScope = varScope; } if (varScope != sharedScope) { throw new FlowableIllegalArgumentException("Only allowed to update multiple variables in the same scope."); } if (!override && hasVariableOnScope(execution, var.getName(), varScope)) { throw new FlowableConflictException("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 FlowableIllegalArgumentException("Cannot set global variables on execution '" + execution.getId() + "', task is not part of process."); } } } } response.setStatus(HttpStatus.CREATED.value()); return result; }
Example 9
Source File: BaseExecutionVariableResource.java From flowable-engine with Apache License 2.0 | 4 votes |
public RestVariable getVariableFromRequest(Execution execution, String variableName, String scope, boolean includeBinary) { boolean variableFound = false; Object value = null; if (execution == null) { throw new FlowableObjectNotFoundException("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 FlowableObjectNotFoundException("Execution '" + execution.getId() + "' does not have a variable with name: '" + variableName + "'.", VariableInstanceEntity.class); } else { return constructRestVariable(variableName, value, variableScope, execution.getId(), includeBinary); } }