Search in sources :

Example 6 with Message

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

the class MessageEventDefinitionParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, MessageEventDefinition messageDefinition) {
    BpmnModel bpmnModel = bpmnParse.getBpmnModel();
    String messageRef = messageDefinition.getMessageRef();
    if (bpmnModel.containsMessageId(messageRef)) {
        Message message = bpmnModel.getMessage(messageRef);
        messageDefinition.setMessageRef(message.getName());
        messageDefinition.setExtensionElements(message.getExtensionElements());
    }
    EventSubscriptionDeclaration eventSubscription = new EventSubscriptionDeclaration(messageDefinition.getMessageRef(), "message");
    ScopeImpl scope = bpmnParse.getCurrentScope();
    ActivityImpl activity = bpmnParse.getCurrentActivity();
    if (bpmnParse.getCurrentFlowElement() instanceof StartEvent && bpmnParse.getCurrentSubProcess() != null) {
        // the scope of the event subscription is the parent of the event
        // subprocess (subscription must be created when parent is initialized)
        ScopeImpl catchingScope = ((ActivityImpl) scope).getParent();
        EventSubscriptionDeclaration eventSubscriptionDeclaration = new EventSubscriptionDeclaration(messageDefinition.getMessageRef(), "message");
        eventSubscriptionDeclaration.setActivityId(activity.getId());
        eventSubscriptionDeclaration.setStartEvent(false);
        addEventSubscriptionDeclaration(bpmnParse, eventSubscriptionDeclaration, messageDefinition, catchingScope);
    } else if (bpmnParse.getCurrentFlowElement() instanceof StartEvent) {
        activity.setProperty("type", "messageStartEvent");
        eventSubscription.setStartEvent(true);
        eventSubscription.setActivityId(activity.getId());
        addEventSubscriptionDeclaration(bpmnParse, eventSubscription, messageDefinition, bpmnParse.getCurrentProcessDefinition());
    } else if (bpmnParse.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
        activity.setProperty("type", "intermediateMessageCatch");
        if (getPrecedingEventBasedGateway(bpmnParse, (IntermediateCatchEvent) bpmnParse.getCurrentFlowElement()) != null) {
            eventSubscription.setActivityId(activity.getId());
            addEventSubscriptionDeclaration(bpmnParse, eventSubscription, messageDefinition, activity.getParent());
        } else {
            activity.setScope(true);
            addEventSubscriptionDeclaration(bpmnParse, eventSubscription, messageDefinition, activity);
        }
    } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
        BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
        boolean interrupting = boundaryEvent.isCancelActivity();
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryEventActivityBehavior(boundaryEvent, interrupting, activity));
        activity.setProperty("type", "boundaryMessage");
        EventSubscriptionDeclaration eventSubscriptionDeclaration = new EventSubscriptionDeclaration(messageDefinition.getMessageRef(), "message");
        eventSubscriptionDeclaration.setActivityId(activity.getId());
        addEventSubscriptionDeclaration(bpmnParse, eventSubscriptionDeclaration, messageDefinition, activity.getParent());
        if (activity.getParent() instanceof ActivityImpl) {
            ((ActivityImpl) activity.getParent()).setScope(true);
        }
    } else {
    // What to do here?
    }
}
Also used : Message(org.activiti.bpmn.model.Message) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) IntermediateCatchEvent(org.activiti.bpmn.model.IntermediateCatchEvent) StartEvent(org.activiti.bpmn.model.StartEvent) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) EventSubscriptionDeclaration(org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 7 with Message

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

the class MessageConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    Message message = model.getMessage("writeReport");
    assertNotNull(message);
    assertEquals("Examples:writeReportItem", message.getItemRef());
    assertEquals("newWriteReport", message.getName());
    assertEquals("writeReport", message.getId());
    Message message2 = model.getMessage("writeReport2");
    assertNotNull(message2);
    assertEquals("http://foo.bar.com/Examples:writeReportItem2", message2.getItemRef());
    assertEquals("newWriteReport2", message2.getName());
    assertEquals("writeReport2", message2.getId());
}
Also used : Message(org.activiti.bpmn.model.Message)

Example 8 with Message

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

Example 9 with Message

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

the class BpmnJsonConverterUtil method parseMessages.

protected static void parseMessages(JsonNode messagesNode, BpmnModel element) {
    if (messagesNode == null)
        return;
    for (JsonNode messageNode : messagesNode) {
        Message message = new Message();
        String messageId = getValueAsString(PROPERTY_MESSAGE_DEFINITION_ID, messageNode);
        if (StringUtils.isNotEmpty(messageId)) {
            message.setId(messageId);
        }
        String messageName = getValueAsString(PROPERTY_MESSAGE_DEFINITION_NAME, messageNode);
        if (StringUtils.isNotEmpty(messageName)) {
            message.setName(messageName);
        }
        String messageItemRef = getValueAsString(PROPERTY_MESSAGE_DEFINITION_ITEM_REF, messageNode);
        if (StringUtils.isNotEmpty(messageItemRef)) {
            message.setItemRef(messageItemRef);
        }
        if (StringUtils.isNotEmpty(messageId)) {
            element.addMessage(message);
        }
    }
}
Also used : Message(org.activiti.bpmn.model.Message) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 10 with Message

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

the class BpmnJsonConverterUtil method convertMessagesToJson.

public static void convertMessagesToJson(BpmnModel bpmnModel, ObjectNode propertiesNode) {
    if (bpmnModel.getMessages() != null) {
        ArrayNode messageDefinitions = objectMapper.createArrayNode();
        for (Message message : bpmnModel.getMessages()) {
            ObjectNode messageNode = messageDefinitions.addObject();
            messageNode.put(PROPERTY_MESSAGE_DEFINITION_ID, message.getId());
            messageNode.put(PROPERTY_MESSAGE_DEFINITION_NAME, message.getName());
        }
        propertiesNode.put(PROPERTY_MESSAGE_DEFINITIONS, messageDefinitions);
    }
}
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