Search in sources :

Example 6 with Event

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

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

the class CancelEventDefinitionParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (parentElement instanceof Event == false)
        return;
    CancelEventDefinition eventDefinition = new CancelEventDefinition();
    BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
    ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
Also used : Event(org.activiti.bpmn.model.Event) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition)

Example 8 with Event

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

the class MessageEventDefinitionParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (parentElement instanceof Event == false)
        return;
    MessageEventDefinition eventDefinition = new MessageEventDefinition();
    BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
    eventDefinition.setMessageRef(xtr.getAttributeValue(null, ATTRIBUTE_MESSAGE_REF));
    if (!StringUtils.isEmpty(eventDefinition.getMessageRef())) {
        int indexOfP = eventDefinition.getMessageRef().indexOf(':');
        if (indexOfP != -1) {
            String prefix = eventDefinition.getMessageRef().substring(0, indexOfP);
            String resolvedNamespace = model.getNamespace(prefix);
            String messageRef = eventDefinition.getMessageRef().substring(indexOfP + 1);
            if (resolvedNamespace == null) {
                // if it's an invalid prefix will consider this is not a namespace prefix so will be used as part of the stringReference
                messageRef = prefix + ":" + messageRef;
            } else if (!resolvedNamespace.equalsIgnoreCase(model.getTargetNamespace())) {
                //  if it's a valid namespace prefix but it's not the targetNamespace then we'll use it as a valid namespace
                // (even out editor does not support defining namespaces it is still a valid xml file)
                messageRef = resolvedNamespace + ":" + messageRef;
            }
            eventDefinition.setMessageRef(messageRef);
        } else {
            eventDefinition.setMessageRef(eventDefinition.getMessageRef());
        }
    }
    BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_MESSAGEDEFINITION, eventDefinition, xtr, model);
    ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
Also used : Event(org.activiti.bpmn.model.Event) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition)

Example 9 with Event

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

the class SignalEventDefinitionParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (parentElement instanceof Event == false)
        return;
    SignalEventDefinition eventDefinition = new SignalEventDefinition();
    BpmnXMLUtil.addXMLLocation(eventDefinition, xtr);
    eventDefinition.setSignalRef(xtr.getAttributeValue(null, ATTRIBUTE_SIGNAL_REF));
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_ASYNCHRONOUS))) {
        eventDefinition.setAsync(Boolean.parseBoolean(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_ASYNCHRONOUS)));
    }
    BpmnXMLUtil.parseChildElements(ELEMENT_EVENT_SIGNALDEFINITION, eventDefinition, xtr, model);
    ((Event) parentElement).getEventDefinitions().add(eventDefinition);
}
Also used : Event(org.activiti.bpmn.model.Event) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition)

Example 10 with Event

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

the class BpmnJsonConverter method postProcessElements.

private void postProcessElements(FlowElementsContainer parentContainer, Collection<FlowElement> flowElementList, Map<String, JsonNode> edgeMap, BpmnModel bpmnModel, Map<String, FlowWithContainer> allFlowMap, List<Gateway> gatewayWithOrderList) {
    for (FlowElement flowElement : flowElementList) {
        if (flowElement instanceof Event) {
            Event event = (Event) flowElement;
            if (CollectionUtils.isNotEmpty(event.getEventDefinitions())) {
                EventDefinition eventDef = event.getEventDefinitions().get(0);
                if (eventDef instanceof SignalEventDefinition) {
                    SignalEventDefinition signalEventDef = (SignalEventDefinition) eventDef;
                    if (StringUtils.isNotEmpty(signalEventDef.getSignalRef())) {
                        if (bpmnModel.getSignal(signalEventDef.getSignalRef()) == null) {
                            bpmnModel.addSignal(new Signal(signalEventDef.getSignalRef(), signalEventDef.getSignalRef()));
                        }
                    }
                } else if (eventDef instanceof MessageEventDefinition) {
                    MessageEventDefinition messageEventDef = (MessageEventDefinition) eventDef;
                    if (StringUtils.isNotEmpty(messageEventDef.getMessageRef())) {
                        if (bpmnModel.getMessage(messageEventDef.getMessageRef()) == null) {
                            bpmnModel.addMessage(new Message(messageEventDef.getMessageRef(), messageEventDef.getMessageRef(), null));
                        }
                    }
                }
            }
        }
        if (flowElement instanceof BoundaryEvent) {
            BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
            Activity activity = retrieveAttachedRefObject(boundaryEvent.getAttachedToRefId(), parentContainer.getFlowElements());
            if (activity == null) {
                LOGGER.warn("Boundary event " + boundaryEvent.getId() + " is not attached to any activity");
            } else {
                boundaryEvent.setAttachedToRef(activity);
                activity.getBoundaryEvents().add(boundaryEvent);
            }
        } else if (flowElement instanceof Gateway) {
            if (flowElement.getExtensionElements().containsKey("EDITOR_FLOW_ORDER")) {
                gatewayWithOrderList.add((Gateway) flowElement);
            }
        } else if (flowElement instanceof SubProcess) {
            SubProcess subProcess = (SubProcess) flowElement;
            postProcessElements(subProcess, subProcess.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
        } else if (flowElement instanceof SequenceFlow) {
            SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
            FlowElement sourceFlowElement = parentContainer.getFlowElement(sequenceFlow.getSourceRef());
            if (sourceFlowElement != null && sourceFlowElement instanceof FlowNode) {
                FlowWithContainer flowWithContainer = new FlowWithContainer(sequenceFlow, parentContainer);
                if (sequenceFlow.getExtensionElements().get("EDITOR_RESOURCEID") != null && sequenceFlow.getExtensionElements().get("EDITOR_RESOURCEID").size() > 0) {
                    allFlowMap.put(sequenceFlow.getExtensionElements().get("EDITOR_RESOURCEID").get(0).getElementText(), flowWithContainer);
                    sequenceFlow.getExtensionElements().remove("EDITOR_RESOURCEID");
                }
                ((FlowNode) sourceFlowElement).getOutgoingFlows().add(sequenceFlow);
                JsonNode edgeNode = edgeMap.get(sequenceFlow.getId());
                if (edgeNode != null) {
                    boolean isDefault = JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_SEQUENCEFLOW_DEFAULT, edgeNode);
                    if (isDefault) {
                        if (sourceFlowElement instanceof Activity) {
                            ((Activity) sourceFlowElement).setDefaultFlow(sequenceFlow.getId());
                        } else if (sourceFlowElement instanceof Gateway) {
                            ((Gateway) sourceFlowElement).setDefaultFlow(sequenceFlow.getId());
                        }
                    }
                }
            }
            FlowElement targetFlowElement = parentContainer.getFlowElement(sequenceFlow.getTargetRef());
            if (targetFlowElement != null && targetFlowElement instanceof FlowNode) {
                ((FlowNode) targetFlowElement).getIncomingFlows().add(sequenceFlow);
            }
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) Message(org.activiti.bpmn.model.Message) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) Activity(org.activiti.bpmn.model.Activity) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) Signal(org.activiti.bpmn.model.Signal) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway) Event(org.activiti.bpmn.model.Event) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) FlowNode(org.activiti.bpmn.model.FlowNode)

Aggregations

Event (org.activiti.bpmn.model.Event)11 FlowElement (org.activiti.bpmn.model.FlowElement)4 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)3 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)3 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)3 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)3 EventDefinition (org.activiti.bpmn.model.EventDefinition)2 Gateway (org.activiti.bpmn.model.Gateway)2 Message (org.activiti.bpmn.model.Message)2 Signal (org.activiti.bpmn.model.Signal)2 SubProcess (org.activiti.bpmn.model.SubProcess)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 com.mxgraph.view.mxGraph (com.mxgraph.view.mxGraph)1 ArrayList (java.util.ArrayList)1 Activity (org.activiti.bpmn.model.Activity)1 Artifact (org.activiti.bpmn.model.Artifact)1 Association (org.activiti.bpmn.model.Association)1 CallActivity (org.activiti.bpmn.model.CallActivity)1 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)1 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)1