Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#setCurrentFlowElement()
The following examples show how to use
org.activiti.engine.impl.persistence.entity.ExecutionEntity#setCurrentFlowElement() .
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: ContinueProcessOperation.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void executeBoundaryEvents(Collection<BoundaryEvent> boundaryEvents, ExecutionEntity execution) { // The parent execution becomes a scope, and a child execution is created for each of the boundary events for (BoundaryEvent boundaryEvent : boundaryEvents) { if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions()) || (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition)) { continue; } // A Child execution of the current execution is created to represent the boundary event being active ExecutionEntity childExecutionEntity = commandContext.getExecutionEntityManager().createChildExecution((ExecutionEntity) execution); childExecutionEntity.setParentId(execution.getId()); childExecutionEntity.setCurrentFlowElement(boundaryEvent); childExecutionEntity.setScope(false); ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior()); logger.debug("Executing boundary event activityBehavior {} with execution {}", boundaryEventBehavior.getClass(), childExecutionEntity.getId()); boundaryEventBehavior.execute(childExecutionEntity); } }
Example 2
Source File: EventSubProcessErrorStartEventActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void execute(DelegateExecution execution) { StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement(); EventSubProcess eventSubProcess = (EventSubProcess) startEvent.getSubProcess(); execution.setCurrentFlowElement(eventSubProcess); execution.setScope(true); // initialize the template-defined data objects as variables Map<String, Object> dataObjectVars = processDataObjects(eventSubProcess.getDataObjects()); if (dataObjectVars != null) { execution.setVariablesLocal(dataObjectVars); } ExecutionEntity startSubProcessExecution = Context.getCommandContext() .getExecutionEntityManager().createChildExecution((ExecutionEntity) execution); startSubProcessExecution.setCurrentFlowElement(startEvent); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(startSubProcessExecution, true); }
Example 3
Source File: TerminateEndEventActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void terminateMultiInstanceRoot(DelegateExecution execution, CommandContext commandContext, ExecutionEntityManager executionEntityManager) { // When terminateMultiInstance is 'true', we look for the multi instance root and delete it from there. ExecutionEntity miRootExecutionEntity = executionEntityManager.findFirstMultiInstanceRoot((ExecutionEntity) execution); if (miRootExecutionEntity != null) { // Create sibling execution to continue process instance execution before deletion ExecutionEntity siblingExecution = executionEntityManager.createChildExecution(miRootExecutionEntity.getParent()); siblingExecution.setCurrentFlowElement(miRootExecutionEntity.getCurrentFlowElement()); deleteExecutionEntities(executionEntityManager, miRootExecutionEntity, createDeleteReason(miRootExecutionEntity.getActivityId())); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(siblingExecution, true); } else { defaultTerminateEndEventBehaviour(execution, commandContext, executionEntityManager); } }
Example 4
Source File: AbstractBpmnActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void executeCompensateBoundaryEvents(Collection<BoundaryEvent> boundaryEvents, DelegateExecution execution) { // The parent execution becomes a scope, and a child execution is created for each of the boundary events for (BoundaryEvent boundaryEvent : boundaryEvents) { if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) { continue; } if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition == false) { continue; } ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager().createChildExecution((ExecutionEntity) execution); childExecutionEntity.setParentId(execution.getId()); childExecutionEntity.setCurrentFlowElement(boundaryEvent); childExecutionEntity.setScope(false); ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior()); boundaryEventBehavior.execute(childExecutionEntity); } }
Example 5
Source File: MultiInstanceActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void executeCompensationBoundaryEvents(FlowElement flowElement, DelegateExecution execution) { //Execute compensation boundary events Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), flowElement); if (CollectionUtil.isNotEmpty(boundaryEvents)) { // The parent execution becomes a scope, and a child execution is created for each of the boundary events for (BoundaryEvent boundaryEvent : boundaryEvents) { if (CollectionUtil.isEmpty(boundaryEvent.getEventDefinitions())) { continue; } if (boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) { ExecutionEntity childExecutionEntity = Context.getCommandContext().getExecutionEntityManager() .createChildExecution((ExecutionEntity) execution); childExecutionEntity.setParentId(execution.getId()); childExecutionEntity.setCurrentFlowElement(boundaryEvent); childExecutionEntity.setScope(false); ActivityBehavior boundaryEventBehavior = ((ActivityBehavior) boundaryEvent.getBehavior()); boundaryEventBehavior.execute(childExecutionEntity); } } } }
Example 6
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 7
Source File: EndExecutionOperation.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void handleMultiInstanceSubProcess(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution) { List<ExecutionEntity> activeChildExecutions = getActiveChildExecutionsForExecution(executionEntityManager, parentExecution.getId()); boolean containsOtherChildExecutions = false; for (ExecutionEntity activeExecution : activeChildExecutions) { if (activeExecution.getId().equals(execution.getId()) == false) { containsOtherChildExecutions = true; } } if (!containsOtherChildExecutions) { // Destroy the current scope (subprocess) and leave via the subprocess ScopeUtil.createCopyOfSubProcessExecutionForCompensation(parentExecution); Context.getAgenda().planDestroyScopeOperation(parentExecution); SubProcess subProcess = execution.getCurrentFlowElement().getSubProcess(); MultiInstanceActivityBehavior multiInstanceBehavior = (MultiInstanceActivityBehavior) subProcess.getBehavior(); parentExecution.setCurrentFlowElement(subProcess); multiInstanceBehavior.leave(parentExecution); } }
Example 8
Source File: ExecuteActivityForAdhocSubProcessCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public Execution execute(CommandContext commandContext) { ExecutionEntity execution = commandContext.getExecutionEntityManager().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"); } FlowNode foundNode = null; AdhocSubProcess adhocSubProcess = (AdhocSubProcess) execution.getCurrentFlowElement(); // if sequential ordering, only one child execution can be active if (adhocSubProcess.hasSequentialOrdering()) { if (execution.getExecutions().size() > 0) { throw new ActivitiException("Sequential ad-hoc sub process already has an active execution"); } } for (FlowElement flowElement : adhocSubProcess.getFlowElements()) { if (activityId.equals(flowElement.getId()) && flowElement instanceof FlowNode) { FlowNode flowNode = (FlowNode) flowElement; if (flowNode.getIncomingFlows().size() == 0) { foundNode = flowNode; } } } if (foundNode == null) { throw new ActivitiException("The requested activity with id " + activityId + " can not be enabled"); } ExecutionEntity activityExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(execution); activityExecution.setCurrentFlowElement(foundNode); Context.getAgenda().planContinueProcessOperation(activityExecution); return activityExecution; }
Example 9
Source File: ScopeUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * Creates a new event scope execution and moves existing event subscriptions to this new execution */ public static void createCopyOfSubProcessExecutionForCompensation(ExecutionEntity subProcessExecution) { EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager(); List<EventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.findEventSubscriptionsByExecutionAndType(subProcessExecution.getId(), "compensate"); List<CompensateEventSubscriptionEntity> compensateEventSubscriptions = new ArrayList<CompensateEventSubscriptionEntity>(); for (EventSubscriptionEntity event : eventSubscriptions) { if (event instanceof CompensateEventSubscriptionEntity) { compensateEventSubscriptions.add((CompensateEventSubscriptionEntity) event); } } if (CollectionUtil.isNotEmpty(compensateEventSubscriptions)) { ExecutionEntity processInstanceExecutionEntity = subProcessExecution.getProcessInstance(); ExecutionEntity eventScopeExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(processInstanceExecutionEntity); eventScopeExecution.setActive(false); eventScopeExecution.setEventScope(true); eventScopeExecution.setCurrentFlowElement(subProcessExecution.getCurrentFlowElement()); // copy local variables to eventScopeExecution by value. This way, // the eventScopeExecution references a 'snapshot' of the local variables new SubProcessVariableSnapshotter().setVariablesSnapshots(subProcessExecution, eventScopeExecution); // set event subscriptions to the event scope execution: for (CompensateEventSubscriptionEntity eventSubscriptionEntity : compensateEventSubscriptions) { eventSubscriptionEntityManager.delete(eventSubscriptionEntity); CompensateEventSubscriptionEntity newSubscription = eventSubscriptionEntityManager.insertCompensationEvent( eventScopeExecution, eventSubscriptionEntity.getActivityId()); newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration()); newSubscription.setCreated(eventSubscriptionEntity.getCreated()); } CompensateEventSubscriptionEntity eventSubscription = eventSubscriptionEntityManager.insertCompensationEvent( processInstanceExecutionEntity, eventScopeExecution.getCurrentFlowElement().getId()); eventSubscription.setConfiguration(eventScopeExecution.getId()); } }
Example 10
Source File: SubProcessActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { SubProcess subProcess = getSubProcessFromExecution(execution); FlowElement startElement = null; if (CollectionUtil.isNotEmpty(subProcess.getFlowElements())) { for (FlowElement subElement : subProcess.getFlowElements()) { if (subElement instanceof StartEvent) { StartEvent startEvent = (StartEvent) subElement; // start none event if (CollectionUtil.isEmpty(startEvent.getEventDefinitions())) { startElement = startEvent; break; } } } } if (startElement == null) { throw new ActivitiException("No initial activity found for subprocess " + subProcess.getId()); } ExecutionEntity executionEntity = (ExecutionEntity) execution; executionEntity.setScope(true); // initialize the template-defined data objects as variables Map<String, Object> dataObjectVars = processDataObjects(subProcess.getDataObjects()); if (dataObjectVars != null) { executionEntity.setVariablesLocal(dataObjectVars); } ExecutionEntity startSubProcessExecution = Context.getCommandContext().getExecutionEntityManager() .createChildExecution(executionEntity); startSubProcessExecution.setCurrentFlowElement(startElement); Context.getAgenda().planContinueProcessOperation(startSubProcessExecution); }
Example 11
Source File: SequentialMultiInstanceBehavior.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * Handles the sequential case of spawning the instances. Will only create one instance, since at most one instance can be active. */ protected int createInstances(DelegateExecution multiInstanceExecution) { int nrOfInstances = resolveNrOfInstances(multiInstanceExecution); if (nrOfInstances == 0) { return nrOfInstances; } else if (nrOfInstances < 0) { throw new ActivitiIllegalArgumentException("Invalid number of instances: must be a non-negative integer value" + ", but was " + nrOfInstances); } // Create child execution that will execute the inner behavior ExecutionEntity childExecution = Context.getCommandContext().getExecutionEntityManager() .createChildExecution((ExecutionEntity) multiInstanceExecution); childExecution.setCurrentFlowElement(multiInstanceExecution.getCurrentFlowElement()); multiInstanceExecution.setMultiInstanceRoot(true); multiInstanceExecution.setActive(false); // Set Multi-instance variables setLoopVariable(multiInstanceExecution, NUMBER_OF_INSTANCES, nrOfInstances); setLoopVariable(multiInstanceExecution, NUMBER_OF_COMPLETED_INSTANCES, 0); setLoopVariable(multiInstanceExecution, NUMBER_OF_ACTIVE_INSTANCES, 1); setLoopVariable(childExecution, getCollectionElementIndexVariable(), 0); logLoopDetails(multiInstanceExecution, "initialized", 0, 0, 1, nrOfInstances); if (nrOfInstances > 0) { executeOriginalBehavior(childExecution, 0); } return nrOfInstances; }
Example 12
Source File: EndExecutionOperation.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected ExecutionEntity handleRegularExecutionEnd(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution) { ExecutionEntity executionToContinue = null; if (!parentExecution.isProcessInstanceType() && !(parentExecution.getCurrentFlowElement() instanceof SubProcess)) { parentExecution.setCurrentFlowElement(execution.getCurrentFlowElement()); } if (execution.getCurrentFlowElement() instanceof SubProcess) { SubProcess currentSubProcess = (SubProcess) execution.getCurrentFlowElement(); if (currentSubProcess.getOutgoingFlows().size() > 0) { // create a new execution to take the outgoing sequence flows executionToContinue = executionEntityManager.createChildExecution(parentExecution); executionToContinue.setCurrentFlowElement(execution.getCurrentFlowElement()); } else { if (parentExecution.getId().equals(parentExecution.getProcessInstanceId()) == false) { // create a new execution to take the outgoing sequence flows executionToContinue = executionEntityManager.createChildExecution(parentExecution.getParent()); executionToContinue.setCurrentFlowElement(parentExecution.getCurrentFlowElement()); executionEntityManager.deleteChildExecutions(parentExecution, null, false); executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null, false); } else { executionToContinue = parentExecution; } } } else { executionToContinue = parentExecution; } return executionToContinue; }
Example 13
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 14
Source File: EventSubProcessMessageStartEventActivityBehavior.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void trigger(DelegateExecution execution, String triggerName, Object triggerData) { CommandContext commandContext = Context.getCommandContext(); ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); ExecutionEntity executionEntity = (ExecutionEntity) execution; StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement(); if (startEvent.isInterrupting()) { List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(executionEntity.getParentId()); for (ExecutionEntity childExecution : childExecutions) { if (childExecution.getId().equals(executionEntity.getId()) == false) { executionEntityManager.deleteExecutionAndRelatedData(childExecution, DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(" + startEvent.getId() + ")", false); } } } EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager(); List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions(); for (EventSubscriptionEntity eventSubscription : eventSubscriptions) { if (eventSubscription instanceof MessageEventSubscriptionEntity && eventSubscription.getEventName().equals(messageEventDefinition.getMessageRef())) { eventSubscriptionEntityManager.delete(eventSubscription); } } executionEntity.setCurrentFlowElement((SubProcess) executionEntity.getCurrentFlowElement().getParentContainer()); executionEntity.setScope(true); ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(executionEntity); outgoingFlowExecution.setCurrentFlowElement(startEvent); leave(outgoingFlowExecution); }
Example 15
Source File: ContinueProcessOperation.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void createChildExecutionForSubProcess(SubProcess subProcess) { ExecutionEntity parentScopeExecution = findFirstParentScopeExecution(execution); // Create the sub process execution that can be used to set variables // We create a new execution and delete the incoming one to have a proper scope that // does not conflict anything with any existing scopes ExecutionEntity subProcessExecution = commandContext.getExecutionEntityManager().createChildExecution(parentScopeExecution); subProcessExecution.setCurrentFlowElement(subProcess); subProcessExecution.setScope(true); commandContext.getExecutionEntityManager().deleteExecutionAndRelatedData(execution, null, false); execution = subProcessExecution; }
Example 16
Source File: ProcessInstanceHelper.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public void startProcessInstance(ExecutionEntity processInstance, CommandContext commandContext, Map<String, Object> variables) { Process process = ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId()); // Event sub process handling List<MessageEventSubscriptionEntity> messageEventSubscriptions = new LinkedList<>(); for (FlowElement flowElement : process.getFlowElements()) { if (flowElement instanceof EventSubProcess) { EventSubProcess eventSubProcess = (EventSubProcess) flowElement; for (FlowElement subElement : eventSubProcess.getFlowElements()) { if (subElement instanceof StartEvent) { StartEvent startEvent = (StartEvent) subElement; if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) { EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0); if (eventDefinition instanceof MessageEventDefinition) { MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition; BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processInstance.getProcessDefinitionId()); if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) { messageEventDefinition.setMessageRef(bpmnModel.getMessage(messageEventDefinition.getMessageRef()).getName()); } ExecutionEntity messageExecution = commandContext.getExecutionEntityManager().createChildExecution(processInstance); messageExecution.setCurrentFlowElement(startEvent); messageExecution.setEventScope(true); messageEventSubscriptions .add(commandContext.getEventSubscriptionEntityManager().insertMessageEvent(messageEventDefinition.getMessageRef(), messageExecution)); } } } } } } ExecutionEntity execution = processInstance.getExecutions().get(0); // There will always be one child execution created commandContext.getAgenda().planContinueProcessOperation(execution); if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher(); eventDispatcher.dispatchEvent(ActivitiEventBuilder.createProcessStartedEvent(execution, variables, false)); for (MessageEventSubscriptionEntity messageEventSubscription : messageEventSubscriptions) { commandContext.getProcessEngineConfiguration().getEventDispatcher() .dispatchEvent(ActivitiEventBuilder.createMessageEvent(ActivitiEventType.ACTIVITY_MESSAGE_WAITING, messageEventSubscription.getActivityId(), messageEventSubscription.getEventName(), null, messageEventSubscription.getExecution().getId(), messageEventSubscription.getProcessInstanceId(), messageEventSubscription.getProcessDefinitionId())); } } }
Example 17
Source File: CompensationEventHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, CommandContext commandContext) { String configuration = eventSubscription.getConfiguration(); if (configuration == null) { throw new ActivitiException("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId()); } ExecutionEntity compensatingExecution = commandContext.getExecutionEntityManager().findById(configuration); String processDefinitionId = compensatingExecution.getProcessDefinitionId(); Process process = ProcessDefinitionUtil.getProcess(processDefinitionId); if (process == null) { throw new ActivitiException("Cannot start process instance. Process model (id = " + processDefinitionId + ") could not be found"); } FlowElement flowElement = process.getFlowElement(eventSubscription.getActivityId(), true); if (flowElement instanceof SubProcess && ((SubProcess) flowElement).isForCompensation() == false) { // descend into scope: compensatingExecution.setScope(true); List<CompensateEventSubscriptionEntity> eventsForThisScope = commandContext.getEventSubscriptionEntityManager().findCompensateEventSubscriptionsByExecutionId(compensatingExecution.getId()); ScopeUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false); } else { try { if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPENSATE, flowElement.getId(), flowElement.getName(), compensatingExecution.getId(), compensatingExecution.getProcessInstanceId(), compensatingExecution.getProcessDefinitionId(), flowElement)); } compensatingExecution.setCurrentFlowElement(flowElement); Context.getAgenda().planContinueProcessInCompensation(compensatingExecution); } catch (Exception e) { throw new ActivitiException("Error while handling compensation event " + eventSubscription, e); } } }
Example 18
Source File: ErrorPropagation.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected static void executeEventHandler(Event event, ExecutionEntity parentExecution, ExecutionEntity currentExecution, String errorId) { if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(parentExecution.getProcessDefinitionId()); if (bpmnModel != null) { String errorCode = bpmnModel.getErrors().get(errorId); if (errorCode == null) { errorCode = errorId; } Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createErrorEvent(ActivitiEventType.ACTIVITY_ERROR_RECEIVED, event.getId(), errorId, errorCode, parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId())); } } if (event instanceof StartEvent) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); if (currentExecution.getParentId().equals(parentExecution.getId()) == false) { Context.getAgenda().planDestroyScopeOperation(currentExecution); } else { executionEntityManager.deleteExecutionAndRelatedData(currentExecution, null, false); } ExecutionEntity eventSubProcessExecution = executionEntityManager.createChildExecution(parentExecution); eventSubProcessExecution.setCurrentFlowElement(event); Context.getAgenda().planContinueProcessOperation(eventSubProcessExecution); } else { ExecutionEntity boundaryExecution = null; List<? extends ExecutionEntity> childExecutions = parentExecution.getExecutions(); for (ExecutionEntity childExecution : childExecutions) { if (childExecution.getActivityId().equals(event.getId())) { boundaryExecution = childExecution; } } Context.getAgenda().planTriggerExecutionOperation(boundaryExecution); } }
Example 19
Source File: SequentialMultiInstanceBehavior.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
/** * Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method. Handles the completion of one instance, and executes the logic for * the sequential behavior. */ public void leave(DelegateExecution childExecution) { DelegateExecution multiInstanceRootExecution = getMultiInstanceRootExecution(childExecution); int nrOfInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_INSTANCES); int loopCounter = getLoopVariable(childExecution, getCollectionElementIndexVariable()) + 1; int nrOfCompletedInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_COMPLETED_INSTANCES) + 1; int nrOfActiveInstances = getLoopVariable(multiInstanceRootExecution, NUMBER_OF_ACTIVE_INSTANCES); setLoopVariable(multiInstanceRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances); setLoopVariable(childExecution, getCollectionElementIndexVariable(), loopCounter); logLoopDetails(childExecution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances); Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) childExecution, null); callActivityEndListeners(childExecution); //executeCompensationBoundaryEvents(execution.getCurrentFlowElement(), execution); if (loopCounter >= nrOfInstances || completionConditionSatisfied(multiInstanceRootExecution)) { removeLocalLoopVariable(childExecution, getCollectionElementIndexVariable()); multiInstanceRootExecution.setMultiInstanceRoot(false); multiInstanceRootExecution.setScope(false); multiInstanceRootExecution.setCurrentFlowElement(childExecution.getCurrentFlowElement()); Context.getCommandContext().getExecutionEntityManager().deleteChildExecutions((ExecutionEntity) multiInstanceRootExecution, "MI_END", false); super.leave(multiInstanceRootExecution); } else { try { if (childExecution.getCurrentFlowElement() instanceof SubProcess) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); ExecutionEntity executionToContinue = executionEntityManager.createChildExecution((ExecutionEntity) multiInstanceRootExecution); executionToContinue.setCurrentFlowElement(childExecution.getCurrentFlowElement()); executionToContinue.setScope(true); setLoopVariable(executionToContinue, getCollectionElementIndexVariable(), loopCounter); executeOriginalBehavior(executionToContinue, loopCounter); } else { executeOriginalBehavior(childExecution, loopCounter); } } catch (BpmnError error) { // re-throw business fault so that it can be caught by an Error // Intermediate Event or Error Event Sub-Process in the process throw error; } catch (Exception e) { throw new ActivitiException("Could not execute inner activity behavior of multi instance behavior", e); } } }
Example 20
Source File: EndExecutionOperation.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected ExecutionEntity handleSubProcessEnd(ExecutionEntityManager executionEntityManager, ExecutionEntity parentExecution, SubProcess subProcess) { ExecutionEntity executionToContinue = null; // create a new execution to take the outgoing sequence flows executionToContinue = executionEntityManager.createChildExecution(parentExecution.getParent()); executionToContinue.setCurrentFlowElement(subProcess); boolean hasCompensation = false; if (subProcess instanceof Transaction) { hasCompensation = true; } else { for (FlowElement subElement : subProcess.getFlowElements()) { if (subElement instanceof Activity) { Activity subActivity = (Activity) subElement; if (CollectionUtil.isNotEmpty(subActivity.getBoundaryEvents())) { for (BoundaryEvent boundaryEvent : subActivity.getBoundaryEvents()) { if (CollectionUtil.isNotEmpty(boundaryEvent.getEventDefinitions()) && boundaryEvent.getEventDefinitions().get(0) instanceof CompensateEventDefinition) { hasCompensation = true; break; } } } } } } // All executions will be cleaned up afterwards. However, for compensation we need // a copy of these executions so we can use them later on when the compensation is thrown. // The following method does exactly that, and moves the executions beneath the process instance. if (hasCompensation) { ScopeUtil.createCopyOfSubProcessExecutionForCompensation(parentExecution); } executionEntityManager.deleteChildExecutions(parentExecution, null, false); executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null, false); Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, subProcess.getId(), subProcess.getName(), parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId(), subProcess)); return executionToContinue; }