@Override public Map<String, Object> getVariablesByProcInstId(String procInstId) { List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procInstId).list(); String executionId = ""; for (Execution execution : executions) { if (StringUtils.isNullOrEmpty(execution.getParentId())) { executionId = execution.getId(); } } return runtimeService.getVariables(executionId); }
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; }
@ApiOperation(value = "Delete a variable", tags = {"Process Instances"}, nickname = "deleteProcessInstanceVariable") @ApiResponses(value = { @ApiResponse(code = 204, message = "Indicates the variable was found and has been deleted. Response-body is intentionally empty."), @ApiResponse(code = 404, message = "Indicates the requested variable was not found.") }) @RequestMapping(value = "/runtime/process-instances/{processInstanceId}/variables/{variableName}", method = RequestMethod.DELETE) public void deleteVariable(@ApiParam(name = "processInstanceId") @PathVariable("processInstanceId") String processInstanceId,@ApiParam(name = "variableName") @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletResponse response) { Execution execution = getProcessInstanceFromRequest(processInstanceId); // Determine scope RestVariableScope variableScope = RestVariableScope.LOCAL; if (scope != null) { variableScope = RestVariable.getScopeFromString(scope); } if (!hasVariableOnScope(execution, variableName, variableScope)) { throw new ActivitiObjectNotFoundException("Execution '" + execution.getId() + "' doesn't have a variable '" + variableName + "' in scope " + variableScope.name().toLowerCase(), VariableInstanceEntity.class); } if (variableScope == RestVariableScope.LOCAL) { runtimeService.removeVariableLocal(execution.getId(), variableName); } else { // Safe to use parentId, as the hasVariableOnScope would have // stopped a global-var update on a root-execution runtimeService.removeVariable(execution.getParentId(), variableName); } response.setStatus(HttpStatus.NO_CONTENT.value()); }
runtimeService.removeVariable(execution.getParentId(), variableName);
private String getExecutionId(String processId, String activityId, long timeoutInMillis) { long deadline = System.currentTimeMillis() + timeoutInMillis; while (true) { Execution execution = engine.getRuntimeService().createExecutionQuery().processInstanceId(processId).activityId( activityId).singleResult(); if (execution != null && execution.getParentId() != null) { return execution.getId(); } if (isPastDeadline(deadline)) { IllegalStateException timeoutException = new IllegalStateException( format(Messages.PROCESS_STEP_NOT_REACHED_BEFORE_TIMEOUT, activityId, processId)); LOGGER.error(timeoutException.toString(), timeoutException); throw timeoutException; } try { Thread.sleep(GET_EXECUTION_RETRY_INTERVAL_MS); } catch (InterruptedException e) { throw new IllegalStateException(e); } } }
private void dumpExecutionVariables(String executionId, DelegateExecution delegateExecution, Execution execution, Set<String> variablesSeen, RuntimeService runtimeService) { Map<String, Object> variablesLocal = runtimeService.getVariablesLocal(executionId); LOGGER.trace("Execution id={} ({} variables); class={}/{}", executionId, variablesLocal.size(), delegateExecution != null ? delegateExecution.getClass().getName() : null, execution != null ? execution.getClass().getName() : null); TreeSet<String> names = new TreeSet<>(variablesLocal.keySet()); names.forEach(n -> LOGGER.trace(" - {} = {} {}", n, variablesLocal.get(n), variablesSeen.contains(n) ? "(dup)":"")); variablesSeen.addAll(variablesLocal.keySet()); if (delegateExecution instanceof ExecutionEntity) { ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution; if (executionEntity.getParent() != null) { dumpExecutionVariables(executionEntity.getParentId(), executionEntity.getParent(), null, variablesSeen, runtimeService); } } else if (delegateExecution instanceof ExecutionImpl) { ExecutionImpl executionImpl = (ExecutionImpl) delegateExecution; if (executionImpl.getParent() != null) { dumpExecutionVariables(executionImpl.getParentId(), executionImpl.getParent(), null, variablesSeen, runtimeService); } } else { Execution execution1 = runtimeService.createExecutionQuery().executionId(executionId).singleResult(); if (execution1 == null) { LOGGER.trace("Execution with id {} was not found.", executionId); } else if (execution1.getParentId() != null) { Execution execution2 = runtimeService.createExecutionQuery().executionId(execution1.getParentId()).singleResult(); dumpExecutionVariables(execution.getParentId(), null, execution2, variablesSeen, runtimeService); } } }
@Override public Map<String, Object> getVariablesByProcInstId(String procInstId) { List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(procInstId).list(); String executionId = ""; for (Execution execution : executions) { if (StringUtils.isNullOrEmpty(execution.getParentId())) { executionId = execution.getId(); } } return runtimeService.getVariables(executionId); }
variableFound = true; } else { if (execution.getParentId() != null) { value = runtimeService.getVariable(execution.getParentId(), variableName); variableScope = RestVariableScope.GLOBAL; variableFound = true; if (execution.getParentId() != null) { value = runtimeService.getVariable(execution.getParentId(), variableName); variableScope = RestVariableScope.GLOBAL; variableFound = true;
runtimeService.setVariablesLocal(execution.getId(), variablesToSet); } else { if (execution.getParentId() != null) { runtimeService.setVariables(execution.getParentId(), variablesToSet); } else {
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); } } }
builder.append(" execution.getId():").append(execution.getId()).append('\n'); builder.append(" execution.getActivityId():").append(execution.getActivityId()).append('\n'); builder.append(" execution.getParentId():").append(execution.getParentId()).append('\n'); builder.append(" execution.getProcessInstanceId():").append(execution.getProcessInstanceId()).append('\n'); builder.append(" execution.isEnded():").append(execution.isEnded()).append('\n');
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; }