Search in sources :

Example 1 with CompensateEventDefinition

use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.

the class IntermediateThrowEventParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, ThrowEvent intermediateEvent) {
    EventDefinition eventDefinition = null;
    if (!intermediateEvent.getEventDefinitions().isEmpty()) {
        eventDefinition = intermediateEvent.getEventDefinitions().get(0);
    }
    if (eventDefinition instanceof SignalEventDefinition) {
        SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowSignalEventActivityBehavior(intermediateEvent, signalEventDefinition, bpmnParse.getBpmnModel().getSignal(signalEventDefinition.getSignalRef())));
    } else if (eventDefinition instanceof CompensateEventDefinition) {
        CompensateEventDefinition compensateEventDefinition = (CompensateEventDefinition) eventDefinition;
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior(intermediateEvent, compensateEventDefinition));
    } else if (eventDefinition instanceof MessageEventDefinition) {
        MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
        Message message = bpmnParse.getBpmnModel().getMessage(messageEventDefinition.getMessageRef());
        BpmnModel bpmnModel = bpmnParse.getBpmnModel();
        if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
            messageEventDefinition.setMessageRef(message.getName());
            messageEventDefinition.setExtensionElements(message.getExtensionElements());
        }
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createThrowMessageEventActivityBehavior(intermediateEvent, messageEventDefinition, message));
    } else if (eventDefinition == null) {
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowNoneEventActivityBehavior(intermediateEvent));
    } else {
        logger.warn("Unsupported intermediate throw event type for throw event " + intermediateEvent.getId());
    }
}
Also used : Message(org.activiti.bpmn.model.Message) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 2 with CompensateEventDefinition

use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.

the class CompensateEventDefinitionParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (!(parentElement instanceof Event))
        return;
    CompensateEventDefinition eventDefinition = new CompensateEventDefinition();
    BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
    eventDefinition.setActivityRef(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_ACTIVITYREF));
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_WAITFORCOMPLETION))) {
        eventDefinition.setWaitForCompletion(Boolean.parseBoolean(xtr.getAttributeValue(null, ATTRIBUTE_COMPENSATE_WAITFORCOMPLETION)));
    }
    BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_COMPENSATEDEFINITION, eventDefinition, xtr, model);
    ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
Also used : Event(org.activiti.bpmn.model.Event) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 3 with CompensateEventDefinition

use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.

the class EndExecutionOperation method handleSubProcessEnd.

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;
                        }
                    }
                }
            }
        }
    }
    // The following method does exactly that, and moves the executions beneath the process instance.
    if (hasCompensation) {
        ScopeUtil.createCopyOfSubProcessExecutionForCompensation(parentExecution);
    }
    executionEntityManager.deleteChildExecutions(parentExecution, null);
    executionEntityManager.deleteExecutionAndRelatedData(parentExecution, null);
    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, subProcess.getId(), subProcess.getName(), parentExecution.getId(), parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId(), subProcess));
    return executionToContinue;
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Transaction(org.activiti.bpmn.model.Transaction) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) FlowElement(org.activiti.bpmn.model.FlowElement) Activity(org.activiti.bpmn.model.Activity) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 4 with CompensateEventDefinition

use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.

the class ParallelMultiInstanceBehavior method leave.

/**
 * Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method. Handles the completion of one of the parallel instances
 */
public void leave(DelegateExecution execution) {
    boolean zeroNrOfInstances = false;
    if (resolveNrOfInstances(execution) == 0) {
        // Empty collection, just leave.
        zeroNrOfInstances = true;
        removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
        // Plan the default leave
        super.leave(execution);
        execution.setMultiInstanceRoot(false);
    }
    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
    int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
    int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;
    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution, null);
    callActivityEndListeners(execution);
    if (zeroNrOfInstances) {
        return;
    }
    DelegateExecution miRootExecution = getMultiInstanceRootExecution(execution);
    if (miRootExecution != null) {
        // will be null in case of empty collection
        setLoopVariable(miRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
        setLoopVariable(miRootExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
    }
    updateResultCollection(execution, miRootExecution);
    // executeCompensationBoundaryEvents(execution.getCurrentFlowElement(), execution);
    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    if (executionEntity.getParent() != null) {
        executionEntity.inactivate();
        lockFirstParentScope(executionEntity);
        if (nrOfCompletedInstances >= nrOfInstances || completionConditionSatisfied(execution.getParent())) {
            ExecutionEntity executionToUse = null;
            if (nrOfInstances > 0) {
                executionToUse = executionEntity.getParent();
            } else {
                executionToUse = executionEntity;
            }
            propagateLoopDataOutputRefToProcessInstance(executionToUse);
            boolean hasCompensation = false;
            Activity activity = (Activity) execution.getCurrentFlowElement();
            if (activity instanceof Transaction) {
                hasCompensation = true;
            } else if (activity instanceof SubProcess) {
                SubProcess subProcess = (SubProcess) activity;
                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;
                                }
                            }
                        }
                    }
                }
            }
            if (hasCompensation) {
                ScopeUtil.createCopyOfSubProcessExecutionForCompensation(executionToUse);
            }
            if (activity instanceof CallActivity) {
                ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
                if (executionToUse != null) {
                    List<String> callActivityExecutionIds = new ArrayList<String>();
                    // Find all execution entities that are at the call activity
                    List<ExecutionEntity> childExecutions = executionEntityManager.collectChildren(executionToUse);
                    if (childExecutions != null) {
                        for (ExecutionEntity childExecution : childExecutions) {
                            if (activity.getId().equals(childExecution.getCurrentActivityId())) {
                                callActivityExecutionIds.add(childExecution.getId());
                            }
                        }
                        // Now all call activity executions have been collected, loop again and check which should be removed
                        for (int i = childExecutions.size() - 1; i >= 0; i--) {
                            ExecutionEntity childExecution = childExecutions.get(i);
                            if (StringUtils.isNotEmpty(childExecution.getSuperExecutionId()) && callActivityExecutionIds.contains(childExecution.getSuperExecutionId())) {
                                executionEntityManager.deleteProcessInstanceExecutionEntity(childExecution.getId(), activity.getId(), "call activity completion condition met", true, true);
                            }
                        }
                    }
                }
            }
            deleteChildExecutions(executionToUse, false, Context.getCommandContext());
            removeLocalLoopVariable(executionToUse, getCollectionElementIndexVariable());
            executionToUse.setScope(false);
            executionToUse.setMultiInstanceRoot(false);
            Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionToUse, true);
        }
        dispatchActivityCompletedEvent(executionEntity);
    } else {
        dispatchActivityCompletedEvent(executionEntity);
        removeLocalLoopVariable(execution, getCollectionElementIndexVariable());
        execution.setMultiInstanceRoot(false);
        super.leave(execution);
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ArrayList(java.util.ArrayList) CallActivity(org.activiti.bpmn.model.CallActivity) Activity(org.activiti.bpmn.model.Activity) CallActivity(org.activiti.bpmn.model.CallActivity) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Transaction(org.activiti.bpmn.model.Transaction) FlowElement(org.activiti.bpmn.model.FlowElement) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 5 with CompensateEventDefinition

use of org.activiti.bpmn.model.CompensateEventDefinition in project Activiti by Activiti.

the class BoundaryEventJsonConverter method getStencilId.

protected String getStencilId(BaseElement baseElement) {
    BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
    List<EventDefinition> eventDefinitions = boundaryEvent.getEventDefinitions();
    if (eventDefinitions.size() != 1) {
        // return timer event as default;
        return STENCIL_EVENT_BOUNDARY_TIMER;
    }
    EventDefinition eventDefinition = eventDefinitions.get(0);
    if (eventDefinition instanceof ErrorEventDefinition) {
        return STENCIL_EVENT_BOUNDARY_ERROR;
    } else if (eventDefinition instanceof SignalEventDefinition) {
        return STENCIL_EVENT_BOUNDARY_SIGNAL;
    } else if (eventDefinition instanceof MessageEventDefinition) {
        return STENCIL_EVENT_BOUNDARY_MESSAGE;
    } else if (eventDefinition instanceof CancelEventDefinition) {
        return STENCIL_EVENT_BOUNDARY_CANCEL;
    } else if (eventDefinition instanceof CompensateEventDefinition) {
        return STENCIL_EVENT_BOUNDARY_COMPENSATION;
    } else {
        return STENCIL_EVENT_BOUNDARY_TIMER;
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Aggregations

CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)10 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)8 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)5 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)3 EventDefinition (org.activiti.bpmn.model.EventDefinition)3 FlowElement (org.activiti.bpmn.model.FlowElement)3 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)3 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)3 Transaction (org.activiti.bpmn.model.Transaction)3 ActivityBehavior (org.activiti.engine.impl.delegate.ActivityBehavior)3 Activity (org.activiti.bpmn.model.Activity)2 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 CallActivity (org.activiti.bpmn.model.CallActivity)1 Event (org.activiti.bpmn.model.Event)1 Message (org.activiti.bpmn.model.Message)1 SubProcess (org.activiti.bpmn.model.SubProcess)1 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)1