Search in sources :

Example 1 with CancelEventDefinition

use of org.activiti.bpmn.model.CancelEventDefinition 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) {
                // Check if other message boundary events with same message 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 2 with CancelEventDefinition

use of org.activiti.bpmn.model.CancelEventDefinition 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)

Example 3 with CancelEventDefinition

use of org.activiti.bpmn.model.CancelEventDefinition 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 4 with CancelEventDefinition

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

the class BoundaryEventParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, BoundaryEvent boundaryEvent) {
    ActivityImpl parentActivity = findActivity(bpmnParse, boundaryEvent.getAttachedToRefId());
    if (parentActivity == null) {
        logger.warn("Invalid reference in boundary event. Make sure that the referenced activity is defined in the same scope as the boundary event " + boundaryEvent.getId());
        return;
    }
    ActivityImpl nestedActivity = createActivityOnScope(bpmnParse, boundaryEvent, BpmnXMLConstants.ELEMENT_EVENT_BOUNDARY, parentActivity);
    bpmnParse.setCurrentActivity(nestedActivity);
    EventDefinition eventDefinition = null;
    if (!boundaryEvent.getEventDefinitions().isEmpty()) {
        eventDefinition = boundaryEvent.getEventDefinitions().get(0);
    }
    if (eventDefinition instanceof TimerEventDefinition || eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition || eventDefinition instanceof SignalEventDefinition || eventDefinition instanceof CancelEventDefinition || eventDefinition instanceof MessageEventDefinition || eventDefinition instanceof org.activiti.bpmn.model.CompensateEventDefinition) {
        bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
    } else {
        logger.warn("Unsupported boundary event type for boundary event " + boundaryEvent.getId());
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Example 5 with CancelEventDefinition

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

the class EndEventParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, EndEvent endEvent) {
    ActivityImpl endEventActivity = createActivityOnCurrentScope(bpmnParse, endEvent, BpmnXMLConstants.ELEMENT_EVENT_END);
    EventDefinition eventDefinition = null;
    if (!endEvent.getEventDefinitions().isEmpty()) {
        eventDefinition = endEvent.getEventDefinitions().get(0);
    }
    // Error end event
    if (eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition) {
        org.activiti.bpmn.model.ErrorEventDefinition errorDefinition = (org.activiti.bpmn.model.ErrorEventDefinition) eventDefinition;
        if (bpmnParse.getBpmnModel().containsErrorRef(errorDefinition.getErrorCode())) {
            String errorCode = bpmnParse.getBpmnModel().getErrors().get(errorDefinition.getErrorCode());
            if (StringUtils.isEmpty(errorCode)) {
                logger.warn("errorCode is required for an error event " + endEvent.getId());
            }
            endEventActivity.setProperty("type", "errorEndEvent");
            errorDefinition.setErrorCode(errorCode);
        }
        endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createErrorEndEventActivityBehavior(endEvent, errorDefinition));
    // Cancel end event      
    } else if (eventDefinition instanceof CancelEventDefinition) {
        ScopeImpl scope = bpmnParse.getCurrentScope();
        if (scope.getProperty("type") == null || !scope.getProperty("type").equals("transaction")) {
            logger.warn("end event with cancelEventDefinition only supported inside transaction subprocess (id=" + endEvent.getId() + ")");
        } else {
            endEventActivity.setProperty("type", "cancelEndEvent");
            endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createCancelEndEventActivityBehavior(endEvent));
        }
    // Terminate end event  
    } else if (eventDefinition instanceof TerminateEventDefinition) {
        endEventActivity.setAsync(endEvent.isAsynchronous());
        endEventActivity.setExclusive(!endEvent.isNotExclusive());
        endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createTerminateEndEventActivityBehavior(endEvent));
    // None end event  
    } else if (eventDefinition == null) {
        endEventActivity.setAsync(endEvent.isAsynchronous());
        endEventActivity.setExclusive(!endEvent.isNotExclusive());
        endEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createNoneEndEventActivityBehavior(endEvent));
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) TerminateEventDefinition(org.activiti.bpmn.model.TerminateEventDefinition) TerminateEventDefinition(org.activiti.bpmn.model.TerminateEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl)

Aggregations

CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)8 EventDefinition (org.activiti.bpmn.model.EventDefinition)5 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)3 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)3 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)3 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)3 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)3 TerminateEventDefinition (org.activiti.bpmn.model.TerminateEventDefinition)3 EndEvent (org.activiti.bpmn.model.EndEvent)2 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)2 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)2 HashMap (java.util.HashMap)1 Event (org.activiti.bpmn.model.Event)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 Transaction (org.activiti.bpmn.model.Transaction)1 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)1