Search in sources :

Example 6 with SignalEventDefinition

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

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

the class SignalAndMessageDefinitionExport method writeSignalsAndMessages.

public static void writeSignalsAndMessages(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    for (Process process : model.getProcesses()) {
        for (FlowElement flowElement : process.findFlowElementsOfType(Event.class)) {
            Event event = (Event) flowElement;
            if (!event.getEventDefinitions().isEmpty()) {
                EventDefinition eventDefinition = event.getEventDefinitions().get(0);
                if (eventDefinition instanceof SignalEventDefinition) {
                    SignalEventDefinition signalEvent = (SignalEventDefinition) eventDefinition;
                    if (StringUtils.isNotEmpty(signalEvent.getSignalRef())) {
                        if (model.containsSignalId(signalEvent.getSignalRef()) == false) {
                            Signal signal = new Signal(signalEvent.getSignalRef(), signalEvent.getSignalRef());
                            model.addSignal(signal);
                        }
                    }
                } else if (eventDefinition instanceof MessageEventDefinition) {
                    MessageEventDefinition messageEvent = (MessageEventDefinition) eventDefinition;
                    if (StringUtils.isNotEmpty(messageEvent.getMessageRef())) {
                        if (model.containsMessageId(messageEvent.getMessageRef()) == false) {
                            Message message = new Message(messageEvent.getMessageRef(), messageEvent.getMessageRef(), null);
                            model.addMessage(message);
                        }
                    }
                }
            }
        }
    }
    for (Signal signal : model.getSignals()) {
        xtw.writeStartElement(ELEMENT_SIGNAL);
        xtw.writeAttribute(ATTRIBUTE_ID, signal.getId());
        xtw.writeAttribute(ATTRIBUTE_NAME, signal.getName());
        if (signal.getScope() != null) {
            xtw.writeAttribute(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_SCOPE, signal.getScope());
        }
        xtw.writeEndElement();
    }
    for (Message message : model.getMessages()) {
        xtw.writeStartElement(ELEMENT_MESSAGE);
        String messageId = message.getId();
        // remove the namespace from the message id if set
        if (model.getTargetNamespace() != null && messageId.startsWith(model.getTargetNamespace())) {
            messageId = messageId.replace(model.getTargetNamespace(), "");
            messageId = messageId.replaceFirst(":", "");
        } else {
            for (String prefix : model.getNamespaces().keySet()) {
                String namespace = model.getNamespace(prefix);
                if (messageId.startsWith(namespace)) {
                    messageId = messageId.replace(model.getTargetNamespace(), "");
                    messageId = prefix + messageId;
                }
            }
        }
        xtw.writeAttribute(ATTRIBUTE_ID, messageId);
        if (StringUtils.isNotEmpty(message.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, message.getName());
        }
        if (StringUtils.isNotEmpty(message.getItemRef())) {
            // replace the namespace by the right prefix
            String itemRef = message.getItemRef();
            for (String prefix : model.getNamespaces().keySet()) {
                String namespace = model.getNamespace(prefix);
                if (itemRef.startsWith(namespace)) {
                    if (prefix.isEmpty()) {
                        itemRef = itemRef.replace(namespace + ":", "");
                    } else {
                        itemRef = itemRef.replace(namespace, prefix);
                    }
                    break;
                }
            }
            xtw.writeAttribute(ATTRIBUTE_ITEM_REF, itemRef);
        }
        xtw.writeEndElement();
    }
}
Also used : Signal(org.activiti.bpmn.model.Signal) Message(org.activiti.bpmn.model.Message) FlowElement(org.activiti.bpmn.model.FlowElement) Event(org.activiti.bpmn.model.Event) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) Process(org.activiti.bpmn.model.Process) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition)

Example 8 with SignalEventDefinition

use of org.activiti.bpmn.model.SignalEventDefinition 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.getErrorCode())) {
                propertiesNode.put(PROPERTY_ERRORREF, errorDefinition.getErrorCode());
            }
        } 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());
        }
    }
}
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 9 with SignalEventDefinition

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

the class BaseBpmnJsonConverter method convertJsonToSignalDefinition.

protected void convertJsonToSignalDefinition(JsonNode objectNode, Event event) {
    String signalRef = getPropertyValueAsString(PROPERTY_SIGNALREF, objectNode);
    SignalEventDefinition eventDefinition = new SignalEventDefinition();
    eventDefinition.setSignalRef(signalRef);
    event.getEventDefinitions().add(eventDefinition);
}
Also used : SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition)

Example 10 with SignalEventDefinition

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

SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)21 EventDefinition (org.activiti.bpmn.model.EventDefinition)13 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)11 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)7 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)6 FlowElement (org.activiti.bpmn.model.FlowElement)6 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)4 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)3 Event (org.activiti.bpmn.model.Event)3 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)3 SubProcess (org.activiti.bpmn.model.SubProcess)3 ThrowEvent (org.activiti.bpmn.model.ThrowEvent)3 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)3 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)2 Message (org.activiti.bpmn.model.Message)2 ReceiveTask (org.activiti.bpmn.model.ReceiveTask)2 Signal (org.activiti.bpmn.model.Signal)2 UserTask (org.activiti.bpmn.model.UserTask)2 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1