Search in sources :

Example 6 with CompensateEventDefinition

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

the class BoundaryEventJsonConverter method convertJsonToElement.

protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
    BoundaryEvent boundaryEvent = new BoundaryEvent();
    String stencilId = BpmnJsonConverterUtil.getStencilId(elementNode);
    if (STENCIL_EVENT_BOUNDARY_TIMER.equals(stencilId)) {
        convertJsonToTimerDefinition(elementNode, boundaryEvent);
        boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
    } else if (STENCIL_EVENT_BOUNDARY_ERROR.equals(stencilId)) {
        convertJsonToErrorDefinition(elementNode, boundaryEvent);
    } else if (STENCIL_EVENT_BOUNDARY_SIGNAL.equals(stencilId)) {
        convertJsonToSignalDefinition(elementNode, boundaryEvent);
        boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
    } else if (STENCIL_EVENT_BOUNDARY_MESSAGE.equals(stencilId)) {
        convertJsonToMessageDefinition(elementNode, boundaryEvent);
        boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
    } else if (STENCIL_EVENT_BOUNDARY_CANCEL.equals(stencilId)) {
        CancelEventDefinition cancelEventDefinition = new CancelEventDefinition();
        boundaryEvent.getEventDefinitions().add(cancelEventDefinition);
        boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
    } else if (STENCIL_EVENT_BOUNDARY_COMPENSATION.equals(stencilId)) {
        CompensateEventDefinition compensateEventDefinition = new CompensateEventDefinition();
        boundaryEvent.getEventDefinitions().add(compensateEventDefinition);
        boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));
    }
    boundaryEvent.setAttachedToRefId(lookForAttachedRef(elementNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES)));
    return boundaryEvent;
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 7 with CompensateEventDefinition

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

the class BoundaryEventValidator method executeValidation.

@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    List<BoundaryEvent> boundaryEvents = process.findFlowElementsOfType(BoundaryEvent.class);
    // Only one boundary event of type 'cancel' can be attached to the same
    // element, so we store the count temporarily here
    HashMap<String, Integer> cancelBoundaryEventsCounts = new HashMap<String, Integer>();
    // Only one boundary event of type 'compensate' can be attached to the
    // same element, so we store the count temporarily here
    HashMap<String, Integer> compensateBoundaryEventsCounts = new HashMap<String, Integer>();
    for (int i = 0; i < boundaryEvents.size(); i++) {
        BoundaryEvent boundaryEvent = boundaryEvents.get(i);
        if (boundaryEvent.getEventDefinitions() != null && !boundaryEvent.getEventDefinitions().isEmpty()) {
            EventDefinition eventDefinition = boundaryEvent.getEventDefinitions().get(0);
            if (!(eventDefinition instanceof TimerEventDefinition) && !(eventDefinition instanceof ErrorEventDefinition) && !(eventDefinition instanceof SignalEventDefinition) && !(eventDefinition instanceof CancelEventDefinition) && !(eventDefinition instanceof MessageEventDefinition) && !(eventDefinition instanceof CompensateEventDefinition)) {
                addError(errors, Problems.BOUNDARY_EVENT_INVALID_EVENT_DEFINITION, process, boundaryEvent, "Invalid or unsupported event definition");
            }
            if (eventDefinition instanceof CancelEventDefinition) {
                FlowElement attachedToFlowElement = bpmnModel.getFlowElement(boundaryEvent.getAttachedToRefId());
                if (!(attachedToFlowElement instanceof Transaction)) {
                    addError(errors, Problems.BOUNDARY_EVENT_CANCEL_ONLY_ON_TRANSACTION, process, boundaryEvent, "boundary event with cancelEventDefinition only supported on transaction subprocesses");
                } else {
                    if (!cancelBoundaryEventsCounts.containsKey(attachedToFlowElement.getId())) {
                        cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(0));
                    }
                    cancelBoundaryEventsCounts.put(attachedToFlowElement.getId(), new Integer(cancelBoundaryEventsCounts.get(attachedToFlowElement.getId()) + 1));
                }
            } else if (eventDefinition instanceof CompensateEventDefinition) {
                if (!compensateBoundaryEventsCounts.containsKey(boundaryEvent.getAttachedToRefId())) {
                    compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), new Integer(0));
                }
                compensateBoundaryEventsCounts.put(boundaryEvent.getAttachedToRefId(), compensateBoundaryEventsCounts.get(boundaryEvent.getAttachedToRefId()) + 1);
            } else if (eventDefinition instanceof MessageEventDefinition) {
                // id
                for (int j = 0; j < boundaryEvents.size(); j++) {
                    if (j != i) {
                        BoundaryEvent otherBoundaryEvent = boundaryEvents.get(j);
                        if (otherBoundaryEvent.getAttachedToRefId() != null && otherBoundaryEvent.getAttachedToRefId().equals(boundaryEvent.getAttachedToRefId())) {
                            if (otherBoundaryEvent.getEventDefinitions() != null && !otherBoundaryEvent.getEventDefinitions().isEmpty()) {
                                EventDefinition otherEventDefinition = otherBoundaryEvent.getEventDefinitions().get(0);
                                if (otherEventDefinition instanceof MessageEventDefinition) {
                                    MessageEventDefinition currentMessageEventDefinition = (MessageEventDefinition) eventDefinition;
                                    MessageEventDefinition otherMessageEventDefinition = (MessageEventDefinition) otherEventDefinition;
                                    if (otherMessageEventDefinition.getMessageRef() != null && otherMessageEventDefinition.getMessageRef().equals(currentMessageEventDefinition.getMessageRef())) {
                                        addError(errors, Problems.MESSAGE_EVENT_MULTIPLE_ON_BOUNDARY_SAME_MESSAGE_ID, process, boundaryEvent, "Multiple message events with same message id not supported");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            addError(errors, Problems.BOUNDARY_EVENT_NO_EVENT_DEFINITION, process, boundaryEvent, "Event definition is missing from boundary event");
        }
    }
    for (String elementId : cancelBoundaryEventsCounts.keySet()) {
        if (cancelBoundaryEventsCounts.get(elementId) > 1) {
            addError(errors, Problems.BOUNDARY_EVENT_MULTIPLE_CANCEL_ON_TRANSACTION, process, bpmnModel.getFlowElement(elementId), "multiple boundary events with cancelEventDefinition not supported on same transaction subprocess.");
        }
    }
    for (String elementId : compensateBoundaryEventsCounts.keySet()) {
        if (compensateBoundaryEventsCounts.get(elementId) > 1) {
            addError(errors, Problems.COMPENSATE_EVENT_MULTIPLE_ON_BOUNDARY, process, bpmnModel.getFlowElement(elementId), "Multiple boundary events of type 'compensate' is invalid");
        }
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) HashMap(java.util.HashMap) 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) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) Transaction(org.activiti.bpmn.model.Transaction) FlowElement(org.activiti.bpmn.model.FlowElement) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 8 with CompensateEventDefinition

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

the class AbstractBpmnActivityBehavior method executeCompensateBoundaryEvents.

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);
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityBehavior(org.activiti.engine.impl.delegate.ActivityBehavior) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 9 with CompensateEventDefinition

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

the class ContinueProcessOperation method executeBoundaryEvents.

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);
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) MultiInstanceActivityBehavior(org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior) ActivityBehavior(org.activiti.engine.impl.delegate.ActivityBehavior) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition)

Example 10 with CompensateEventDefinition

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

the class MultiInstanceActivityBehavior method executeCompensationBoundaryEvents.

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);
            }
        }
    }
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) SubProcessActivityBehavior(org.activiti.engine.impl.delegate.SubProcessActivityBehavior) ActivityBehavior(org.activiti.engine.impl.delegate.ActivityBehavior) 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