Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#setScope()
The following examples show how to use
org.activiti.engine.impl.persistence.entity.ExecutionEntity#setScope() .
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: 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 3
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 4
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 5
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 6
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 7
Source File: CounterSignCmd.java From lemon with Apache License 2.0 | 5 votes |
/** * <li>添加一条并行实例 */ private void addParallelInstance() { ExecutionEntity parentExecutionEntity = commandContext .getExecutionEntityManager() .findExecutionById(processInstanceId).findExecution(activityId); ActivityImpl activity = getActivity(); ExecutionEntity execution = parentExecutionEntity.createExecution(); execution.setActive(true); execution.setConcurrent(true); execution.setScope(false); if (getActivity().getProperty("type").equals("subProcess")) { ExecutionEntity extraScopedExecution = execution.createExecution(); extraScopedExecution.setActive(true); extraScopedExecution.setConcurrent(false); extraScopedExecution.setScope(true); execution = extraScopedExecution; } setLoopVariable(parentExecutionEntity, "nrOfInstances", (Integer) parentExecutionEntity .getVariableLocal("nrOfInstances") + 1); setLoopVariable(parentExecutionEntity, "nrOfActiveInstances", (Integer) parentExecutionEntity .getVariableLocal("nrOfActiveInstances") + 1); setLoopVariable(execution, "loopCounter", parentExecutionEntity .getExecutions().size() + 1); setLoopVariable(execution, collectionElementVariableName, assignee); execution.executeActivity(activity); }
Example 8
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 9
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 10
Source File: BoundaryEventActivityBehavior.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public void execute(DelegateExecution execution) { ExecutionEntity executionEntity = (ExecutionEntity) execution; ActivityImpl boundaryActivity = executionEntity.getProcessDefinition().findActivity(activityId); ActivityImpl interruptedActivity = executionEntity.getActivity(); List<PvmTransition> outgoingTransitions = boundaryActivity.getOutgoingTransitions(); List<ExecutionEntity> interruptedExecutions = null; if (interrupting) { // Call activity if (executionEntity.getSubProcessInstance() != null) { executionEntity.getSubProcessInstance().deleteCascade(executionEntity.getDeleteReason()); } else { Context.getCommandContext().getHistoryManager().recordActivityEnd(executionEntity); } executionEntity.setActivity(boundaryActivity); interruptedExecutions = new ArrayList<>(executionEntity.getExecutions()); for (ExecutionEntity interruptedExecution : interruptedExecutions) { interruptedExecution.deleteCascade("interrupting boundary event '" + executionEntity.getActivity().getId() + "' fired"); } executionEntity.takeAll(outgoingTransitions, (List) interruptedExecutions); } else { // non interrupting event, introduced with BPMN 2.0, we need to create a new execution in this case // create a new execution and move it out from the timer activity ExecutionEntity concurrentRoot = executionEntity.getParent().isConcurrent() ? executionEntity.getParent() : executionEntity; ExecutionEntity outgoingExecution = concurrentRoot.createExecution(); outgoingExecution.setActive(true); outgoingExecution.setScope(false); outgoingExecution.setConcurrent(true); outgoingExecution.takeAll(outgoingTransitions, Collections.EMPTY_LIST); outgoingExecution.remove(); // now we have to move the execution back to the real activity // since the execution stays there (non interrupting) and it was // set to the boundary event before executionEntity.setActivity(interruptedActivity); } }