Search in sources :

Example 1 with Message

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

the class BpmnParse method createMessages.

public void createMessages() {
    for (Message messageElement : bpmnModel.getMessages()) {
        MessageDefinition messageDefinition = new MessageDefinition(messageElement.getId(), name);
        if (StringUtils.isNotEmpty(messageElement.getItemRef())) {
            if (this.itemDefinitions.containsKey(messageElement.getItemRef())) {
                ItemDefinition itemDefinition = this.itemDefinitions.get(messageElement.getItemRef());
                messageDefinition.setItemDefinition(itemDefinition);
            }
        }
        this.messages.put(messageDefinition.getId(), messageDefinition);
    }
}
Also used : MessageDefinition(org.activiti.engine.impl.bpmn.webservice.MessageDefinition) Message(org.activiti.bpmn.model.Message) ItemDefinition(org.activiti.engine.impl.bpmn.data.ItemDefinition)

Example 2 with Message

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

the class MessageEventDefinitionWithExtensionElementsTest method testParseMessagedDefinitionWithExtension.

@Test
public void testParseMessagedDefinitionWithExtension() {
    BpmnParse bpmnParseMock = Mockito.mock(BpmnParse.class);
    MessageEventDefinition messageEventDefinitionMock = Mockito.mock(MessageEventDefinition.class);
    BpmnModel bpmnModelMock = Mockito.mock(BpmnModel.class);
    Message messageMock = Mockito.mock(Message.class);
    @SuppressWarnings("unchecked") Map<String, List<ExtensionElement>> extensionElementMap = Mockito.mock(Map.class);
    Mockito.when(bpmnParseMock.getBpmnModel()).thenReturn(bpmnModelMock);
    Mockito.when(messageEventDefinitionMock.getMessageRef()).thenReturn("messageId");
    Mockito.when(bpmnModelMock.containsMessageId("messageId")).thenReturn(true);
    Mockito.when(bpmnModelMock.getMessage("messageId")).thenReturn(messageMock);
    Mockito.when(messageMock.getName()).thenReturn("MessageWithExtensionElements");
    Mockito.when(messageMock.getExtensionElements()).thenReturn(extensionElementMap);
    MessageEventDefinitionParseHandler handler = new MessageEventDefinitionParseHandler();
    handler.parse(bpmnParseMock, messageEventDefinitionMock);
    Mockito.verify(messageEventDefinitionMock).setMessageRef("MessageWithExtensionElements");
    Mockito.verify(messageEventDefinitionMock).setExtensionElements(extensionElementMap);
}
Also used : Message(org.activiti.bpmn.model.Message) MessageEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.MessageEventDefinitionParseHandler) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) List(java.util.List) BpmnParse(org.activiti.engine.impl.bpmn.parser.BpmnParse) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Example 3 with Message

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

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

the class MessageParser method parse.

public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
        String messageId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
        String messageName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
        String itemRef = parseItemRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_REF), model);
        Message message = new Message(messageId, messageName, itemRef);
        BpmnXMLUtil.addXMLLocation(message, xtr);
        BpmnXMLUtil.parseChildElements(ELEMENT_MESSAGE, message, xtr, model);
        model.addMessage(message);
    }
}
Also used : Message(org.activiti.bpmn.model.Message)

Example 5 with Message

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

the class BpmnJsonConverterUtil method convertMessagesToJson.

public static void convertMessagesToJson(Collection<Message> messages, ObjectNode propertiesNode) {
    String propertyName = "messages";
    ArrayNode messagesNode = objectMapper.createArrayNode();
    for (Message message : messages) {
        ObjectNode propertyItemNode = objectMapper.createObjectNode();
        propertyItemNode.put(PROPERTY_MESSAGE_ID, message.getId());
        propertyItemNode.put(PROPERTY_MESSAGE_NAME, message.getName());
        propertyItemNode.put(PROPERTY_MESSAGE_ITEM_REF, message.getItemRef());
        messagesNode.add(propertyItemNode);
    }
    propertiesNode.put(propertyName, messagesNode);
}
Also used : Message(org.activiti.bpmn.model.Message) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

Message (org.activiti.bpmn.model.Message)10 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 Event (org.activiti.bpmn.model.Event)2 EventDefinition (org.activiti.bpmn.model.EventDefinition)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 Signal (org.activiti.bpmn.model.Signal)2 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)2 List (java.util.List)1 Activity (org.activiti.bpmn.model.Activity)1 FlowNode (org.activiti.bpmn.model.FlowNode)1 Gateway (org.activiti.bpmn.model.Gateway)1 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)1 Process (org.activiti.bpmn.model.Process)1 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)1 StartEvent (org.activiti.bpmn.model.StartEvent)1