Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntityManager#findById()
The following examples show how to use
org.activiti.engine.impl.persistence.entity.ExecutionEntityManager#findById() .
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: AddIdentityLinkForProcessInstanceCmd.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public Void execute(CommandContext commandContext) { ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity processInstance = executionEntityManager.findById(processInstanceId); if (processInstance == null) { throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class); } if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) { Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); activiti5CompatibilityHandler.addIdentityLinkForProcessInstance(processInstanceId, userId, groupId, type); return null; } IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager(); identityLinkEntityManager.addIdentityLink(processInstance, userId, groupId, type); commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true); return null; }
Example 2
Source File: CompleteAdhocSubProcessCmd.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public Void execute(CommandContext commandContext) { ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity execution = executionEntityManager.findById(executionId); if (execution == null) { throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class); } if (execution.getCurrentFlowElement() instanceof AdhocSubProcess == false) { throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process"); } List<? extends ExecutionEntity> childExecutions = execution.getExecutions(); if (childExecutions.size() > 0) { throw new ActivitiException("Ad-hoc sub process has running child executions that need to be completed first"); } ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent()); outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement()); executionEntityManager.deleteExecutionAndRelatedData(execution, null, false); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true); return null; }
Example 3
Source File: SetProcessInstanceBusinessKeyCmd.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public Void execute(CommandContext commandContext) { ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager(); ExecutionEntity processInstance = executionManager.findById(processInstanceId); if (processInstance == null) { throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class); } else if (!processInstance.isProcessInstanceType()) { throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id."); } if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) { commandContext.getProcessEngineConfiguration().getActiviti5CompatibilityHandler().updateBusinessKey(processInstanceId, businessKey); return null; } executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey); return null; }
Example 4
Source File: GatewayActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void lockFirstParentScope(DelegateExecution execution) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); boolean found = false; ExecutionEntity parentScopeExecution = null; ExecutionEntity currentExecution = (ExecutionEntity) execution; while (!found && currentExecution != null && currentExecution.getParentId() != null) { parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId()); if (parentScopeExecution != null && parentScopeExecution.isScope()) { found = true; } currentExecution = parentScopeExecution; } parentScopeExecution.forceUpdate(); }
Example 5
Source File: ParallelMultiInstanceBehavior.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void lockFirstParentScope(DelegateExecution execution) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); boolean found = false; ExecutionEntity parentScopeExecution = null; ExecutionEntity currentExecution = (ExecutionEntity) execution; while (!found && currentExecution != null && currentExecution.getParentId() != null) { parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId()); if (parentScopeExecution != null && parentScopeExecution.isScope()) { found = true; } currentExecution = parentScopeExecution; } parentScopeExecution.forceUpdate(); }
Example 6
Source File: AbstractOperation.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * Returns the first parent execution of the provided execution that is a scope. */ protected ExecutionEntity findFirstParentScopeExecution(ExecutionEntity executionEntity) { ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity parentScopeExecution = null; ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(executionEntity.getParentId()); while (currentlyExaminedExecution != null && parentScopeExecution == null) { if (currentlyExaminedExecution.isScope()) { parentScopeExecution = currentlyExaminedExecution; } else { currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId()); } } return parentScopeExecution; }
Example 7
Source File: FindActiveActivityIdsCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public List<String> execute(CommandContext commandContext) { if (executionId == null) { throw new ActivitiIllegalArgumentException("executionId is null"); } ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity execution = executionEntityManager.findById(executionId); if (execution == null) { throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class); } return findActiveActivityIds(execution); }
Example 8
Source File: SetProcessDefinitionVersionCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public Void execute(CommandContext commandContext) { // check that the new process definition is just another version of the same // process definition that the process instance is using ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager(); ExecutionEntity processInstance = executionManager.findById(processInstanceId); if (processInstance == null) { throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class); } else if (!processInstance.isProcessInstanceType()) { throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id."); } DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager(); ProcessDefinition currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId()); ProcessDefinition newProcessDefinition = deploymentCache .findDeployedProcessDefinitionByKeyAndVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId()); validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition); // switch the historic process instance to the new process definition version commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId()); // switch all sub-executions of the process instance to the new process definition version Collection<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId); for (ExecutionEntity executionEntity : childExecutions) { validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition); } return null; }
Example 9
Source File: ScopeUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * we create a separate execution for each compensation handler invocation. */ public static void throwCompensationEvent(List<CompensateEventSubscriptionEntity> eventSubscriptions, DelegateExecution execution, boolean async) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); // first spawn the compensating executions for (EventSubscriptionEntity eventSubscription : eventSubscriptions) { ExecutionEntity compensatingExecution = null; // check whether compensating execution is already created (which is the case when compensating an embedded subprocess, // where the compensating execution is created when leaving the subprocess and holds snapshot data). if (eventSubscription.getConfiguration() != null) { compensatingExecution = executionEntityManager.findById(eventSubscription.getConfiguration()); compensatingExecution.setParent(compensatingExecution.getProcessInstance()); compensatingExecution.setEventScope(false); } else { compensatingExecution = executionEntityManager.createChildExecution((ExecutionEntity) execution); eventSubscription.setConfiguration(compensatingExecution.getId()); } } // signal compensation events in reverse order of their 'created' timestamp Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() { public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) { return o2.getCreated().compareTo(o1.getCreated()); } }); for (CompensateEventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) { Context.getCommandContext().getEventSubscriptionEntityManager().eventReceived(compensateEventSubscriptionEntity, null, async); } }
Example 10
Source File: BoundaryEventActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void executeInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) { // The destroy scope operation will look for the parent execution and // destroy the whole scope, and leave the boundary event using this parent execution. // // The take outgoing seq flows operation below (the non-interrupting else clause) on the other hand uses the // child execution to leave, which keeps the scope alive. // Which is what we need here. ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity attachedRefScopeExecution = executionEntityManager.findById(executionEntity.getParentId()); ExecutionEntity parentScopeExecution = null; ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(attachedRefScopeExecution.getParentId()); while (currentlyExaminedExecution != null && parentScopeExecution == null) { if (currentlyExaminedExecution.isScope()) { parentScopeExecution = currentlyExaminedExecution; } else { currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId()); } } if (parentScopeExecution == null) { throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event"); } deleteChildExecutions(attachedRefScopeExecution, executionEntity, commandContext); // set new parent for boundary event execution executionEntity.setParent(parentScopeExecution); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true); }
Example 11
Source File: BoundaryEventActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void executeNonInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) { // Non-interrupting: the current execution is given the first parent // scope (which isn't its direct parent) // // Why? Because this execution does NOT have anything to do with // the current parent execution (the one where the boundary event is on): when it is deleted or whatever, // this does not impact this new execution at all, it is completely independent in that regard. // Note: if the parent of the parent does not exists, this becomes a concurrent execution in the process instance! ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity parentExecutionEntity = executionEntityManager.findById(executionEntity.getParentId()); ExecutionEntity scopeExecution = null; ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(parentExecutionEntity.getParentId()); while (currentlyExaminedExecution != null && scopeExecution == null) { if (currentlyExaminedExecution.isScope()) { scopeExecution = currentlyExaminedExecution; } else { currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId()); } } if (scopeExecution == null) { throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event"); } ExecutionEntity nonInterruptingExecution = executionEntityManager.createChildExecution(scopeExecution); nonInterruptingExecution.setCurrentFlowElement(executionEntity.getCurrentFlowElement()); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(nonInterruptingExecution, true); }
Example 12
Source File: EndExecutionOperation.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected void handleRegularExecution() { ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); // There will be a parent execution (or else we would be in the process instance handling method) ExecutionEntity parentExecution = executionEntityManager.findById(execution.getParentId()); // If the execution is a scope, all the child executions must be deleted first. if (execution.isScope()) { executionEntityManager.deleteChildExecutions(execution, null, false); } // Delete current execution logger.debug("Ending execution {}", execution.getId()); executionEntityManager.deleteExecutionAndRelatedData(execution, null, false); logger.debug("Parent execution found. Continuing process using execution {}", parentExecution.getId()); // When ending an execution in a multi instance subprocess , special care is needed if (isEndEventInMultiInstanceSubprocess(execution)) { handleMultiInstanceSubProcess(executionEntityManager, parentExecution); return; } SubProcess subProcess = execution.getCurrentFlowElement().getSubProcess(); // If there are no more active child executions, the process can be continued // If not (eg an embedded subprocess still has active elements, we cannot continue) if (getNumberOfActiveChildExecutionsForExecution(executionEntityManager, parentExecution.getId()) == 0 || isAllEventScopeExecutions(executionEntityManager, parentExecution)) { ExecutionEntity executionToContinue = null; if (subProcess != null) { // In case of ending a subprocess: go up in the scopes and continue via the parent scope // unless its a compensation, then we don't need to do anything and can just end it if (subProcess.isForCompensation()) { Context.getAgenda().planEndExecutionOperation(parentExecution); } else { executionToContinue = handleSubProcessEnd(executionEntityManager, parentExecution, subProcess); } } else { // In the 'regular' case (not being in a subprocess), we use the parent execution to // continue process instance execution executionToContinue = handleRegularExecutionEnd(executionEntityManager, parentExecution); } if (executionToContinue != null) { // only continue with outgoing sequence flows if the execution is // not the process instance root execution (otherwise the process instance is finished) if (executionToContinue.isProcessInstanceType()) { handleProcessInstanceExecution(executionToContinue); } else { Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionToContinue, true); } } } }
Example 13
Source File: ErrorPropagation.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public static void propagateError(String errorCode, DelegateExecution execution) { Map<String, List<Event>> eventMap = findCatchingEventsForProcess(execution.getProcessDefinitionId(), errorCode); if (eventMap.size() > 0) { executeCatch(eventMap, execution, errorCode); } else if (!execution.getProcessInstanceId().equals(execution.getRootProcessInstanceId())) { // Call activity ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); ExecutionEntity processInstanceExecution = executionEntityManager.findById(execution.getProcessInstanceId()); if (processInstanceExecution != null) { ExecutionEntity parentExecution = processInstanceExecution.getSuperExecution(); Set<String> toDeleteProcessInstanceIds = new HashSet<String>(); toDeleteProcessInstanceIds.add(execution.getProcessInstanceId()); while (parentExecution != null && eventMap.size() == 0) { eventMap = findCatchingEventsForProcess(parentExecution.getProcessDefinitionId(), errorCode); if (eventMap.size() > 0) { for (String processInstanceId : toDeleteProcessInstanceIds) { ExecutionEntity processInstanceEntity = executionEntityManager.findById(processInstanceId); // Delete executionEntityManager.deleteProcessInstanceExecutionEntity(processInstanceEntity.getId(), execution.getCurrentFlowElement() != null ? execution.getCurrentFlowElement().getId() : null, "ERROR_EVENT " + errorCode, false, false); // Event if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { Context.getProcessEngineConfiguration().getEventDispatcher() .dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT, processInstanceEntity)); } } executeCatch(eventMap, parentExecution, errorCode); } else { toDeleteProcessInstanceIds.add(parentExecution.getProcessInstanceId()); ExecutionEntity superExecution = parentExecution.getSuperExecution(); if (superExecution != null) { parentExecution = superExecution; } else if (!parentExecution.getId().equals(parentExecution.getRootProcessInstanceId())) { // stop at the root parentExecution = parentExecution.getProcessInstance(); } else { parentExecution = null; } } } } } if (eventMap.size() == 0) { throw new BpmnError(errorCode, "No catching boundary event found for error with errorCode '" + errorCode + "', neither in same process nor in parent process"); } }