Search in sources :

Example 1 with MessageEventDefinition

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

the class StartEventParseHandler method createScopeStartEvent.

protected void createScopeStartEvent(BpmnParse bpmnParse, ActivityImpl startEventActivity, StartEvent startEvent) {
    ScopeImpl scope = bpmnParse.getCurrentScope();
    Object triggeredByEvent = scope.getProperty("triggeredByEvent");
    boolean isTriggeredByEvent = triggeredByEvent != null && ((Boolean) triggeredByEvent == true);
    if (isTriggeredByEvent) {
        // event subprocess
        // all start events of an event subprocess share common behavior
        EventSubProcessStartEventActivityBehavior activityBehavior = bpmnParse.getActivityBehaviorFactory().createEventSubProcessStartEventActivityBehavior(startEvent, startEventActivity.getId());
        startEventActivity.setActivityBehavior(activityBehavior);
        if (!startEvent.getEventDefinitions().isEmpty()) {
            EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
            if (eventDefinition instanceof org.activiti.bpmn.model.ErrorEventDefinition || eventDefinition instanceof MessageEventDefinition || eventDefinition instanceof SignalEventDefinition) {
                bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
            } else {
                logger.warn("start event of event subprocess must be of type 'error', 'message' or 'signal' for start event " + startEvent.getId());
            }
        }
    } else {
        if (!startEvent.getEventDefinitions().isEmpty()) {
            logger.warn("event definitions only allowed on start event if subprocess is an event subprocess " + bpmnParse.getCurrentSubProcess().getId());
        }
        if (scope.getProperty(PROPERTYNAME_INITIAL) == null) {
            scope.setProperty(PROPERTYNAME_INITIAL, startEventActivity);
            startEventActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createNoneStartEventActivityBehavior(startEvent));
        } else {
            logger.warn("multiple start events not supported for subprocess", bpmnParse.getCurrentSubProcess().getId());
        }
    }
}
Also used : EventSubProcessStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition)

Example 2 with MessageEventDefinition

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

the class IntermediateCatchEventParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, IntermediateCatchEvent event) {
    ActivityImpl nestedActivity = null;
    EventDefinition eventDefinition = null;
    if (!event.getEventDefinitions().isEmpty()) {
        eventDefinition = event.getEventDefinitions().get(0);
    }
    if (eventDefinition == null) {
        nestedActivity = createActivityOnCurrentScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH);
        nestedActivity.setAsync(event.isAsynchronous());
        nestedActivity.setExclusive(!event.isNotExclusive());
    } else {
        ScopeImpl scope = bpmnParse.getCurrentScope();
        String eventBasedGatewayId = getPrecedingEventBasedGateway(bpmnParse, event);
        if (eventBasedGatewayId != null) {
            ActivityImpl gatewayActivity = scope.findActivity(eventBasedGatewayId);
            nestedActivity = createActivityOnScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH, gatewayActivity);
        } else {
            nestedActivity = createActivityOnScope(bpmnParse, event, BpmnXMLConstants.ELEMENT_EVENT_CATCH, scope);
        }
        nestedActivity.setAsync(event.isAsynchronous());
        nestedActivity.setExclusive(!event.isNotExclusive());
        // Catch event behavior is the same for all types
        nestedActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateCatchEventActivityBehavior(event));
        if (eventDefinition instanceof TimerEventDefinition || eventDefinition instanceof SignalEventDefinition || eventDefinition instanceof MessageEventDefinition) {
            bpmnParse.getBpmnParserHandlers().parseElement(bpmnParse, eventDefinition);
        } else {
            logger.warn("Unsupported intermediate catch event type for event " + event.getId());
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Example 3 with MessageEventDefinition

use of org.activiti.bpmn.model.MessageEventDefinition 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())) {
                            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())) {
                            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(BPMN2_PREFIX, ELEMENT_MESSAGE, BPMN2_NAMESPACE);
        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 MessageEventDefinition

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

the class IntermediateThrowEventParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, ThrowEvent intermediateEvent) {
    EventDefinition eventDefinition = null;
    if (!intermediateEvent.getEventDefinitions().isEmpty()) {
        eventDefinition = intermediateEvent.getEventDefinitions().get(0);
    }
    if (eventDefinition instanceof SignalEventDefinition) {
        SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowSignalEventActivityBehavior(intermediateEvent, signalEventDefinition, bpmnParse.getBpmnModel().getSignal(signalEventDefinition.getSignalRef())));
    } else if (eventDefinition instanceof CompensateEventDefinition) {
        CompensateEventDefinition compensateEventDefinition = (CompensateEventDefinition) eventDefinition;
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowCompensationEventActivityBehavior(intermediateEvent, compensateEventDefinition));
    } else if (eventDefinition instanceof MessageEventDefinition) {
        MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
        Message message = bpmnParse.getBpmnModel().getMessage(messageEventDefinition.getMessageRef());
        BpmnModel bpmnModel = bpmnParse.getBpmnModel();
        if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
            messageEventDefinition.setMessageRef(message.getName());
            messageEventDefinition.setExtensionElements(message.getExtensionElements());
        }
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createThrowMessageEventActivityBehavior(intermediateEvent, messageEventDefinition, message));
    } else if (eventDefinition == null) {
        intermediateEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateThrowNoneEventActivityBehavior(intermediateEvent));
    } else {
        logger.warn("Unsupported intermediate throw event type for throw event " + intermediateEvent.getId());
    }
}
Also used : Message(org.activiti.bpmn.model.Message) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition) CompensateEventDefinition(org.activiti.bpmn.model.CompensateEventDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 5 with MessageEventDefinition

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

Aggregations

MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)23 EventDefinition (org.activiti.bpmn.model.EventDefinition)16 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)14 Message (org.activiti.bpmn.model.Message)8 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)8 BpmnModel (org.activiti.bpmn.model.BpmnModel)7 FlowElement (org.activiti.bpmn.model.FlowElement)7 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)6 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)4 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)4 StartEvent (org.activiti.bpmn.model.StartEvent)4 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)3 Event (org.activiti.bpmn.model.Event)3 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)3 Process (org.activiti.bpmn.model.Process)3 Signal (org.activiti.bpmn.model.Signal)2 TerminateEventDefinition (org.activiti.bpmn.model.TerminateEventDefinition)2 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)2 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)2