Java Code Examples for org.flowable.bpmn.model.BpmnModel#getMessage()

The following examples show how to use org.flowable.bpmn.model.BpmnModel#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeploymentEntityManagerImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void restoreMessageStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
    MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
    if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
        Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
        messageEventDefinition.setMessageRef(message.getName());
    }

    CommandContext commandContext = Context.getCommandContext();
    MessageEventSubscriptionEntity newSubscription = CommandContextUtil.getEventSubscriptionService(commandContext).createMessageEventSubscription();
    String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, null);
    newSubscription.setEventName(messageName);
    newSubscription.setActivityId(startEvent.getId());
    newSubscription.setConfiguration(previousProcessDefinition.getId());
    newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());

    if (previousProcessDefinition.getTenantId() != null) {
        newSubscription.setTenantId(previousProcessDefinition.getTenantId());
    }

    CommandContextUtil.getEventSubscriptionService().insertEventSubscription(newSubscription);
    CountingEntityUtil.handleInsertEventSubscriptionEntityCount(newSubscription);
}
 
Example 2
Source File: StartEventParseHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected MessageEventDefinition fillMessageRef(BpmnParse bpmnParse, EventDefinition eventDefinition) {
    MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
    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());
    }
    
    return messageDefinition;
}
 
Example 3
Source File: MessageEventDefinitionParseHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
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());

        for(List<ExtensionElement> extensionElementList : message.getExtensionElements().values()) {
            for(ExtensionElement extensionElement : extensionElementList) {
                messageDefinition.addExtensionElement(extensionElement);
            }
        }
    }

    if (bpmnParse.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
        IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) bpmnParse.getCurrentFlowElement();
        intermediateCatchEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createIntermediateCatchMessageEventActivityBehavior(intermediateCatchEvent, messageDefinition));

    } else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
        BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
        boundaryEvent.setBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryMessageEventActivityBehavior(boundaryEvent, messageDefinition, boundaryEvent.isCancelActivity()));
    }

    else {
        // What to do here?
    }

}
 
Example 4
Source File: OperationValidator.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(BpmnModel bpmnModel, List<ValidationError> errors) {
    if (bpmnModel.getInterfaces() != null) {
        for (Interface bpmnInterface : bpmnModel.getInterfaces()) {
            if (bpmnInterface.getOperations() != null) {
                for (Operation operation : bpmnInterface.getOperations()) {
                    if (bpmnModel.getMessage(operation.getInMessageRef()) == null) {
                        addError(errors, Problems.OPERATION_INVALID_IN_MESSAGE_REFERENCE, null, operation, "Invalid inMessageRef for operation");
                    }
                }
            }
        }
    }
}
 
Example 5
Source File: MessageConverterTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void validateModel(BpmnModel model) {
    Message message = model.getMessage("writeReport");
    assertThat(message).isNotNull();
    assertThat(message)
            .extracting(Message::getItemRef, Message::getName, Message::getId)
            .containsExactly("Examples:writeReportItem", "newWriteReport", "writeReport");

    Message message2 = model.getMessage("writeReport2");
    assertThat(message2).isNotNull();
    assertThat(message2)
            .extracting(Message::getItemRef, Message::getName, Message::getId)
            .containsExactly("http://foo.bar.com/Examples:writeReportItem2", "newWriteReport2", "writeReport2");
}
 
Example 6
Source File: BpmnJsonConverter.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
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) {

        parentContainer.addFlowElementToMap(flowElement);

        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 {} is not attached to any activity", boundaryEvent.getId());
            } 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 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 instanceof FlowNode) {
                ((FlowNode) targetFlowElement).getIncomingFlows().add(sequenceFlow);
            }
        }
    }
}