Search in sources :

Example 21 with EventDefinition

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

the class ThrowEventJsonConverter method getStencilId.

protected String getStencilId(BaseElement baseElement) {
    ThrowEvent throwEvent = (ThrowEvent) baseElement;
    List<EventDefinition> eventDefinitions = throwEvent.getEventDefinitions();
    if (eventDefinitions.size() != 1) {
        // return none event as default;
        return STENCIL_EVENT_THROW_NONE;
    }
    EventDefinition eventDefinition = eventDefinitions.get(0);
    if (eventDefinition instanceof SignalEventDefinition) {
        return STENCIL_EVENT_THROW_SIGNAL;
    } else {
        return STENCIL_EVENT_THROW_NONE;
    }
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition)

Example 22 with EventDefinition

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

the class ProcessInstanceHelper method startProcessInstance.

public void startProcessInstance(ExecutionEntity processInstance, CommandContext commandContext, Map<String, Object> variables, FlowElement initialFlowElement, Map<String, Object> transientVariables) {
    Process process = ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId());
    createProcessVariables(processInstance, variables, transientVariables, process);
    recordStartProcessInstance(commandContext, initialFlowElement, processInstance);
    // Event sub process handling
    List<MessageEventSubscriptionEntity> messageEventSubscriptions = new LinkedList<>();
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof EventSubProcess) {
            EventSubProcess eventSubProcess = (EventSubProcess) flowElement;
            for (FlowElement subElement : eventSubProcess.getFlowElements()) {
                if (subElement instanceof StartEvent) {
                    StartEvent startEvent = (StartEvent) subElement;
                    if (CollectionUtil.isNotEmpty(startEvent.getEventDefinitions())) {
                        EventDefinition eventDefinition = startEvent.getEventDefinitions().get(0);
                        if (eventDefinition instanceof MessageEventDefinition) {
                            MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
                            BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processInstance.getProcessDefinitionId());
                            if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
                                messageEventDefinition.setMessageRef(bpmnModel.getMessage(messageEventDefinition.getMessageRef()).getName());
                            }
                            ExecutionEntity messageExecution = commandContext.getExecutionEntityManager().createChildExecution(processInstance);
                            messageExecution.setCurrentFlowElement(startEvent);
                            messageExecution.setEventScope(true);
                            String messageName = getMessageName(commandContext, messageEventDefinition, messageExecution);
                            MessageEventSubscriptionEntity subscription = commandContext.getEventSubscriptionEntityManager().insertMessageEvent(messageName, messageExecution);
                            Optional<String> correlationKey = getCorrelationKey(commandContext, messageEventDefinition, messageExecution);
                            correlationKey.ifPresent(subscription::setConfiguration);
                            messageEventSubscriptions.add(subscription);
                        }
                    }
                }
            }
        }
    }
    // There will always be one child execution created
    ExecutionEntity execution = processInstance.getExecutions().get(0);
    execution.setAppVersion(processInstance.getAppVersion());
    commandContext.getAgenda().planContinueProcessOperation(execution);
    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createProcessStartedEvent(execution, variables, false));
        for (MessageEventSubscriptionEntity messageEventSubscription : messageEventSubscriptions) {
            commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createMessageWaitingEvent(messageEventSubscription.getExecution(), messageEventSubscription.getEventName(), messageEventSubscription.getConfiguration()));
        }
    }
}
Also used : Process(org.activiti.bpmn.model.Process) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) LinkedList(java.util.LinkedList) BpmnModel(org.activiti.bpmn.model.BpmnModel) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Example 23 with EventDefinition

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

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

the class EndEventJsonConverter method getStencilId.

protected String getStencilId(BaseElement baseElement) {
    EndEvent endEvent = (EndEvent) baseElement;
    List<EventDefinition> eventDefinitions = endEvent.getEventDefinitions();
    if (eventDefinitions.size() != 1) {
        return STENCIL_EVENT_END_NONE;
    }
    EventDefinition eventDefinition = eventDefinitions.get(0);
    if (eventDefinition instanceof ErrorEventDefinition) {
        return STENCIL_EVENT_END_ERROR;
    } else if (eventDefinition instanceof CancelEventDefinition) {
        return STENCIL_EVENT_END_CANCEL;
    } else if (eventDefinition instanceof TerminateEventDefinition) {
        return STENCIL_EVENT_END_TERMINATE;
    } else {
        return STENCIL_EVENT_END_NONE;
    }
}
Also used : ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) EndEvent(org.activiti.bpmn.model.EndEvent) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) TerminateEventDefinition(org.activiti.bpmn.model.TerminateEventDefinition) TerminateEventDefinition(org.activiti.bpmn.model.TerminateEventDefinition) ErrorEventDefinition(org.activiti.bpmn.model.ErrorEventDefinition) CancelEventDefinition(org.activiti.bpmn.model.CancelEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition)

Example 25 with EventDefinition

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

the class EventSubscriptionManager method addMessageEventSubscriptions.

protected void addMessageEventSubscriptions(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 MessageEventDefinition) {
                        MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
                        insertMessageEvent(messageEventDefinition, startEvent, processDefinition, bpmnModel);
                    }
                }
            }
        }
    }
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition) SignalEventDefinition(org.activiti.bpmn.model.SignalEventDefinition) EventDefinition(org.activiti.bpmn.model.EventDefinition) MessageEventDefinition(org.activiti.bpmn.model.MessageEventDefinition)

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