protected void logLoopDetails(DelegateExecution execution, String custom, int loopCounter, int nrOfCompletedInstances, int nrOfActiveInstances, int nrOfInstances) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Multi-instance '{}' {}. Details: loopCounter={}, nrOrCompletedInstances={},nrOfActiveInstances={},nrOfInstances={}", execution.getCurrentFlowElement() != null ? execution.getCurrentFlowElement().getId() : "", custom, loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances); } }
protected SubProcess getSubProcessFromExecution(DelegateExecution execution) { FlowElement flowElement = execution.getCurrentFlowElement(); SubProcess subProcess = null; if (flowElement instanceof SubProcess) { subProcess = (SubProcess) flowElement; } else { throw new ActivitiException("Programmatic error: sub process behaviour can only be applied" + " to a SubProcess instance, but got an instance of " + flowElement); } return subProcess; }
protected SubProcess getSubProcessFromExecution(DelegateExecution execution) { FlowElement flowElement = execution.getCurrentFlowElement(); SubProcess subProcess = null; if (flowElement instanceof SubProcess) { subProcess = (SubProcess) flowElement; } else { throw new ActivitiException("Programmatic error: sub process behaviour can only be applied" + " to a SubProcess instance, but got an instance of " + flowElement); } return subProcess; }
private String getServiceTaskImplementation(DelegateExecution execution) { return ((ServiceTask) execution.getCurrentFlowElement()).getImplementation(); }
protected EventGateway getPrecedingEventBasedGateway(DelegateExecution execution) { FlowElement currentFlowElement = execution.getCurrentFlowElement(); if (currentFlowElement instanceof IntermediateCatchEvent) { IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) currentFlowElement; List<SequenceFlow> incomingSequenceFlow = intermediateCatchEvent.getIncomingFlows(); // If behind an event based gateway, there is only one incoming sequence flow that originates from said gateway if (incomingSequenceFlow != null && incomingSequenceFlow.size() == 1) { SequenceFlow sequenceFlow = incomingSequenceFlow.get(0); FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement(); if (sourceFlowElement instanceof EventGateway) { return (EventGateway) sourceFlowElement; } } } return null; }
protected DelegateExecution findMultiInstanceParentExecution(DelegateExecution execution) { DelegateExecution multiInstanceExecution = null; DelegateExecution parentExecution = execution.getParent(); if (parentExecution != null && parentExecution.getCurrentFlowElement() != null) { FlowElement flowElement = parentExecution.getCurrentFlowElement(); if (flowElement instanceof Activity) { Activity activity = (Activity) flowElement; if (activity.getLoopCharacteristics() != null) { multiInstanceExecution = parentExecution; } } if (multiInstanceExecution == null) { DelegateExecution potentialMultiInstanceExecution = findMultiInstanceParentExecution(parentExecution); if (potentialMultiInstanceExecution != null) { multiInstanceExecution = potentialMultiInstanceExecution; } } } return multiInstanceExecution; }
protected void dispatchActivityCancelled(DelegateExecution execution, FlowElement terminateEndEvent) { Context.getProcessEngineConfiguration() .getEventDispatcher() .dispatchEvent( ActivitiEventBuilder.createActivityCancelledEvent(execution.getCurrentFlowElement().getId(), execution.getCurrentFlowElement().getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), parseActivityType((FlowNode) execution.getCurrentFlowElement()), terminateEndEvent)); }
public void execute(DelegateExecution execution) { StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement(); EventSubProcess eventSubProcess = (EventSubProcess) startEvent.getSubProcess(); execution.setScope(true); // initialize the template-defined data objects as variables Map<String, Object> dataObjectVars = processDataObjects(eventSubProcess.getDataObjects()); if (dataObjectVars != null) { execution.setVariablesLocal(dataObjectVars); } }
@Override public void trigger(DelegateExecution execution, String triggerName, Object triggerData) { ExecutionEntity executionEntity = (ExecutionEntity) execution; BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement(); if (boundaryEvent.isCancelActivity()) { EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager(); List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions(); for (EventSubscriptionEntity eventSubscription : eventSubscriptions) { if (eventSubscription instanceof CompensateEventSubscriptionEntity && eventSubscription.getActivityId().equals(compensateEventDefinition.getActivityRef())) { eventSubscriptionEntityManager.delete(eventSubscription); } } } super.trigger(executionEntity, triggerName, triggerData); } }
@Override public void execute(DelegateExecution execution) { ExecutionEntity executionEntity = (ExecutionEntity) execution; if (!(execution.getCurrentFlowElement() instanceof BoundaryEvent)) { throw new ActivitiException("Programmatic error: " + this.getClass() + " should not be used for anything else than a boundary event"); } JobManager jobManager = Context.getCommandContext().getJobManager(); TimerJobEntity timerJob = jobManager.createTimerJob(timerEventDefinition, interrupting, executionEntity, TriggerTimerEventJobHandler.TYPE, TimerEventHandler.createConfiguration(execution.getCurrentActivityId(), timerEventDefinition.getEndDate(), timerEventDefinition.getCalendarName())); if (timerJob != null) { jobManager.scheduleTimerJob(timerJob); } }
@Override public void trigger(DelegateExecution execution, String triggerName, Object triggerData) { ExecutionEntity executionEntity = (ExecutionEntity) execution; BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement(); if (boundaryEvent.isCancelActivity()) { 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); } } } super.trigger(executionEntity, triggerName, triggerData); } }
protected void planTransactionDependentExecutionListener(ListenerFactory listenerFactory, DelegateExecution execution, TransactionDependentExecutionListener executionListener, ActivitiListener activitiListener) { Map<String, Object> executionVariablesToUse = execution.getVariables(); CustomPropertiesResolver customPropertiesResolver = createCustomPropertiesResolver(activitiListener); Map<String, Object> customPropertiesMapToUse = invokeCustomPropertiesResolver(execution, customPropertiesResolver); TransactionDependentExecutionListenerExecutionScope scope = new TransactionDependentExecutionListenerExecutionScope( execution.getProcessInstanceId(), execution.getId(), execution.getCurrentFlowElement(), executionVariablesToUse, customPropertiesMapToUse); addTransactionListener(activitiListener, new ExecuteExecutionListenerTransactionListener(executionListener, scope)); }
protected void planTransactionDependentTaskListener(DelegateExecution execution, TransactionDependentTaskListener taskListener, ActivitiListener activitiListener) { Map<String, Object> executionVariablesToUse = execution.getVariables(); CustomPropertiesResolver customPropertiesResolver = createCustomPropertiesResolver(activitiListener); Map<String, Object> customPropertiesMapToUse = invokeCustomPropertiesResolver(execution, customPropertiesResolver); TransactionDependentTaskListenerExecutionScope scope = new TransactionDependentTaskListenerExecutionScope( execution.getProcessInstanceId(), execution.getId(), (Task) execution.getCurrentFlowElement(), executionVariablesToUse, customPropertiesMapToUse); addTransactionListener(activitiListener, new ExecuteTaskListenerTransactionListener(taskListener, scope)); }
@Override public void trigger(DelegateExecution execution, String triggerName, Object triggerData) { ExecutionEntity executionEntity = (ExecutionEntity) execution; BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement(); if (boundaryEvent.isCancelActivity()) { String eventName = null; if (signal != null) { eventName = signal.getName(); } else { eventName = signalEventDefinition.getSignalRef(); } EventSubscriptionEntityManager eventSubscriptionEntityManager = Context.getCommandContext().getEventSubscriptionEntityManager(); List<EventSubscriptionEntity> eventSubscriptions = executionEntity.getEventSubscriptions(); for (EventSubscriptionEntity eventSubscription : eventSubscriptions) { if (eventSubscription instanceof SignalEventSubscriptionEntity && eventSubscription.getEventName().equals(eventName)) { eventSubscriptionEntityManager.delete(eventSubscription); } } } super.trigger(executionEntity, triggerName, triggerData); } }
/** * Subclasses that call leave() will first pass through this method, before the regular {@link FlowNodeActivityBehavior#leave(ActivityExecution)} is called. This way, we can check if the activity * has loop characteristics, and delegate to the behavior if this is the case. */ public void leave(DelegateExecution execution) { FlowElement currentFlowElement = execution.getCurrentFlowElement(); Collection<BoundaryEvent> boundaryEvents = findBoundaryEventsForFlowNode(execution.getProcessDefinitionId(), currentFlowElement); if (CollectionUtil.isNotEmpty(boundaryEvents)) { executeCompensateBoundaryEvents(boundaryEvents, execution); } if (!hasLoopCharacteristics()) { super.leave(execution); } else if (hasMultiInstanceCharacteristics()) { multiInstanceActivityBehavior.leave(execution); } }
protected void dispatchExecutionCancelled(DelegateExecution execution, FlowElement terminateEndEvent) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); // subprocesses for (DelegateExecution subExecution : executionEntityManager.findChildExecutionsByParentExecutionId(execution.getId())) { dispatchExecutionCancelled(subExecution, terminateEndEvent); } // call activities ExecutionEntity subProcessInstance = Context.getCommandContext().getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId()); if (subProcessInstance != null) { dispatchExecutionCancelled(subProcessInstance, terminateEndEvent); } // activity with message/signal boundary events FlowElement currentFlowElement = execution.getCurrentFlowElement(); if (currentFlowElement instanceof FlowNode) { dispatchActivityCancelled(execution, terminateEndEvent); } }
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); }
private IntegrationContextImpl buildFromExecution(DelegateExecution execution, ActionDefinition actionDefinition) { IntegrationContextImpl integrationContext = new IntegrationContextImpl(); integrationContext.setProcessInstanceId(execution.getProcessInstanceId()); integrationContext.setProcessDefinitionId(execution.getProcessDefinitionId()); integrationContext.setActivityElementId(execution.getCurrentActivityId()); integrationContext.setBusinessKey(execution.getProcessInstanceBusinessKey()); if(ExecutionEntity.class.isInstance(execution)) { ExecutionEntity processInstance = ExecutionEntity.class.cast(execution) .getProcessInstance(); if(processInstance != null) { integrationContext.setProcessDefinitionKey(processInstance.getProcessDefinitionKey()); integrationContext.setProcessDefinitionVersion(processInstance.getProcessDefinitionVersion()); integrationContext.setParentProcessInstanceId(processInstance.getParentProcessInstanceId()); } } String implementation = ((ServiceTask) execution.getCurrentFlowElement()).getImplementation(); integrationContext.setConnectorType(implementation); integrationContext.setInBoundVariables(buildInBoundVariables( actionDefinition, execution)); return integrationContext; }
protected void sendProcessInstanceCancelledEvent(DelegateExecution execution, FlowElement terminateEndEvent) { if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { if ((execution.isProcessInstanceType() && execution.getSuperExecutionId() == null) || (execution.getParentId() == null && execution.getSuperExecutionId() != null)) { Context.getProcessEngineConfiguration().getEventDispatcher() .dispatchEvent(ActivitiEventBuilder.createCancelledEvent(execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), execution.getCurrentFlowElement())); } } dispatchExecutionCancelled(execution, terminateEndEvent); }
ExecutionEntity executionEntity = (ExecutionEntity) execution; StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement(); if (startEvent.isInterrupting()) { List<ExecutionEntity> childExecutions = executionEntityManager.findChildExecutionsByParentExecutionId(executionEntity.getParentId());