Search in sources :

Example 1 with EventDefinition

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

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

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

the class SimpleConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    assertThat(model.getDefinitionsAttributes()).hasSize(2);
    assertThat(model.getDefinitionsAttributeValue("http://activiti.com/modeler", "version")).isEqualTo("2.2A");
    assertThat(model.getDefinitionsAttributeValue("http://activiti.com/modeler", "exportDate")).isEqualTo("20140312T10:45:23");
    assertThat(model.getMainProcess().getId()).isEqualTo("simpleProcess");
    assertThat(model.getMainProcess().getName()).isEqualTo("Simple process");
    assertThat(model.getMainProcess().getDocumentation()).isEqualTo("simple doc");
    assertThat(model.getMainProcess().isExecutable()).isEqualTo(true);
    FlowElement flowElement = model.getMainProcess().getFlowElement("flow1");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(SequenceFlow.class);
    assertThat(flowElement.getId()).isEqualTo("flow1");
    flowElement = model.getMainProcess().getFlowElement("catchEvent");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(IntermediateCatchEvent.class);
    assertThat(flowElement.getId()).isEqualTo("catchEvent");
    IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) flowElement;
    assertThat(catchEvent.getEventDefinitions().size() == 1).isTrue();
    EventDefinition eventDefinition = catchEvent.getEventDefinitions().get(0);
    assertThat(eventDefinition).isInstanceOf(TimerEventDefinition.class);
    TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
    assertThat(timerDefinition.getTimeDuration()).isEqualTo("PT5M");
    flowElement = model.getMainProcess().getFlowElement("userTask1");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(UserTask.class);
    UserTask task = (UserTask) flowElement;
    assertThat(task.getDocumentation()).isEqualTo("task doc");
    flowElement = model.getMainProcess().getFlowElement("flow1Condition");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(SequenceFlow.class);
    assertThat(flowElement.getId()).isEqualTo("flow1Condition");
    SequenceFlow flow = (SequenceFlow) flowElement;
    assertThat(flow.getConditionExpression()).isEqualTo("${number <= 1}");
    flowElement = model.getMainProcess().getFlowElement("gateway1");
    assertThat(flowElement).isNotNull();
    assertThat(flowElement).isInstanceOf(ExclusiveGateway.class);
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) IntermediateCatchEvent(org.activiti.bpmn.model.IntermediateCatchEvent) UserTask(org.activiti.bpmn.model.UserTask) EventDefinition(org.activiti.bpmn.model.EventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition) TimerEventDefinition(org.activiti.bpmn.model.TimerEventDefinition)

Example 4 with EventDefinition

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

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

the class EventSubscriptionManager method addSignalEventSubscriptions.

protected void addSignalEventSubscriptions(CommandContext commandContext, ProcessDefinitionEntity processDefinition, Process process, BpmnModel bpmnModel) {
    if (CollectionUtil.isNotEmpty(process.getFlowElements())) {
        for (FlowElement element : process.getFlowElements()) {
            if (element instanceof StartEvent) {
                StartEvent startEvent = (StartEvent) element;
                if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
                    EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
                    if (eventDefinition instanceof SignalEventDefinition) {
                        SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
                        SignalEventSubscriptionEntity subscriptionEntity = commandContext.getEventSubscriptionEntityManager().createSignalEventSubscription();
                        Signal signal = bpmnModel.getSignal(signalEventDefinition.getSignalRef());
                        if (signal != null) {
                            subscriptionEntity.setEventName(signal.getName());
                        } else {
                            subscriptionEntity.setEventName(signalEventDefinition.getSignalRef());
                        }
                        subscriptionEntity.setActivityId(startEvent.getId());
                        subscriptionEntity.setProcessDefinitionId(processDefinition.getId());
                        if (processDefinition.getTenantId() != null) {
                            subscriptionEntity.setTenantId(processDefinition.getTenantId());
                        }
                        Context.getCommandContext().getEventSubscriptionEntityManager().insert(subscriptionEntity);
                    }
                }
            }
        }
    }
}
Also used : Signal(org.activiti.bpmn.model.Signal) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

Aggregations

EventDefinition (org.activiti.bpmn.model.EventDefinition)25 MessageEventDefinition (org.activiti.bpmn.model.MessageEventDefinition)17 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)16 FlowElement (org.activiti.bpmn.model.FlowElement)11 TimerEventDefinition (org.activiti.bpmn.model.TimerEventDefinition)11 ErrorEventDefinition (org.activiti.bpmn.model.ErrorEventDefinition)7 BpmnModel (org.activiti.bpmn.model.BpmnModel)5 CancelEventDefinition (org.activiti.bpmn.model.CancelEventDefinition)5 Message (org.activiti.bpmn.model.Message)5 StartEvent (org.activiti.bpmn.model.StartEvent)5 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)4 CompensateEventDefinition (org.activiti.bpmn.model.CompensateEventDefinition)3 Event (org.activiti.bpmn.model.Event)3 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)3 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)3 Signal (org.activiti.bpmn.model.Signal)3 TerminateEventDefinition (org.activiti.bpmn.model.TerminateEventDefinition)3 ArrayList (java.util.ArrayList)2 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)2 Process (org.activiti.bpmn.model.Process)2