Search in sources :

Example 1 with ErrorEventDefinition

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

the class ErrorEventDefinitionParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (!(parentElement instanceof Event)) {
        return;
    }
    ErrorEventDefinition eventDefinition = new ErrorEventDefinition();
    BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
    eventDefinition.setErrorRef(xtr.getAttributeValue(null, ATTRIBUTE_ERROR_REF));
    BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_ERRORDEFINITION, eventDefinition, xtr, model);
    ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
Also used : ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) Event(org.activiti.bpmn.model.Event)

Example 2 with ErrorEventDefinition

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

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

the class BaseBpmnJsonConverter method addEventProperties.

protected void addEventProperties(Event event, ObjectNode propertiesNode) {
    List<EventDefinition> eventDefinitions = event.getEventDefinitions();
    if (eventDefinitions.size() == 1) {
        EventDefinition eventDefinition = eventDefinitions.get(0);
        if (eventDefinition instanceof ErrorEventDefinition) {
            ErrorEventDefinition errorDefinition = (ErrorEventDefinition) eventDefinition;
            if (StringUtils.isNotEmpty(errorDefinition.getErrorRef())) {
                propertiesNode.put(PROPERTY_ERRORREF, errorDefinition.getErrorRef());
            }
        } else if (eventDefinition instanceof SignalEventDefinition) {
            SignalEventDefinition signalDefinition = (SignalEventDefinition) eventDefinition;
            if (StringUtils.isNotEmpty(signalDefinition.getSignalRef())) {
                propertiesNode.put(PROPERTY_SIGNALREF, signalDefinition.getSignalRef());
            }
        } else if (eventDefinition instanceof MessageEventDefinition) {
            MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
            if (StringUtils.isNotEmpty(messageDefinition.getMessageRef())) {
                propertiesNode.put(PROPERTY_MESSAGEREF, messageDefinition.getMessageRef());
            }
        } else if (eventDefinition instanceof TimerEventDefinition) {
            TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
            if (StringUtils.isNotEmpty(timerDefinition.getTimeDuration())) {
                propertiesNode.put(PROPERTY_TIMER_DURATON, timerDefinition.getTimeDuration());
            }
            if (StringUtils.isNotEmpty(timerDefinition.getTimeCycle())) {
                propertiesNode.put(PROPERTY_TIMER_CYCLE, timerDefinition.getTimeCycle());
            }
            if (StringUtils.isNotEmpty(timerDefinition.getTimeDate())) {
                propertiesNode.put(PROPERTY_TIMER_DATE, timerDefinition.getTimeDate());
            }
            if (StringUtils.isNotEmpty(timerDefinition.getEndDate())) {
                propertiesNode.put(PROPERTY_TIMER_CYCLE_END_DATE, timerDefinition.getEndDate());
            }
        } else if (eventDefinition instanceof TerminateEventDefinition) {
            TerminateEventDefinition terminateEventDefinition = (TerminateEventDefinition) eventDefinition;
            propertiesNode.put(PROPERTY_TERMINATE_ALL, terminateEventDefinition.isTerminateAll());
            propertiesNode.put(PROPERTY_TERMINATE_MULTI_INSTANCE, terminateEventDefinition.isTerminateMultiInstance());
        }
    }
}
Also used : ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) TerminateEventDefinition(org.activiti.bpmn.model.TerminateEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) TerminateEventDefinition(org.activiti.bpmn.model.TerminateEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Example 4 with ErrorEventDefinition

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

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

the class BoundaryEventConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    BoundaryEvent errorElement = (BoundaryEvent) model.getMainProcess().getFlowElement("errorEvent", true);
    ErrorEventDefinition errorEvent = (ErrorEventDefinition) extractEventDefinition(errorElement);
    // always true
    assertThat(errorElement.isCancelActivity()).isTrue();
    assertThat(errorEvent.getErrorRef()).isEqualTo("errorRef");
    assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
    BoundaryEvent signalElement = (BoundaryEvent) model.getMainProcess().getFlowElement("signalEvent", true);
    SignalEventDefinition signalEvent = (SignalEventDefinition) extractEventDefinition(signalElement);
    assertThat(signalElement.isCancelActivity()).isFalse();
    assertThat(signalEvent.getSignalRef()).isEqualTo("signalRef");
    assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
    BoundaryEvent messageElement = (BoundaryEvent) model.getMainProcess().getFlowElement("messageEvent", true);
    MessageEventDefinition messageEvent = (MessageEventDefinition) extractEventDefinition(messageElement);
    assertThat(messageElement.isCancelActivity()).isFalse();
    assertThat(messageEvent.getMessageRef()).isEqualTo("messageRef");
    assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
    BoundaryEvent timerElement = (BoundaryEvent) model.getMainProcess().getFlowElement("timerEvent", true);
    TimerEventDefinition timerEvent = (TimerEventDefinition) extractEventDefinition(timerElement);
    assertThat(timerElement.isCancelActivity()).isFalse();
    assertThat(timerEvent.getTimeDuration()).isEqualTo("PT5M");
    assertThat(errorElement.getAttachedToRefId()).isEqualTo("sid-F21E9F4D-EA19-44DF-B1D3-14663A809CAE");
}
Also used : BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Aggregations

ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)12 EventDefinition (org.activiti.bpmn.model.EventDefinition)7 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)6 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)4 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)4 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)4 TerminateEventDefinition (org.activiti.bpmn.model.TerminateEventDefinition)3 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)2 EndEvent (org.activiti.bpmn.model.EndEvent)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 Message (org.activiti.bpmn.model.Message)2 HashMap (java.util.HashMap)1 Error (org.activiti.bpmn.model.Error)1 Event (org.activiti.bpmn.model.Event)1 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)1 Transaction (org.activiti.bpmn.model.Transaction)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)1