Search in sources :

Example 1 with BaseElement

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

the class FeedbackStepDefinitionConverter method createProcessArtifact.

@Override
protected Map<String, BaseElement> createProcessArtifact(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion) {
    // See feedback-step.png in the resource folder to get a graphical understanding of the conversion below
    Map<String, BaseElement> processElements = new HashMap<String, BaseElement>();
    // The first user task, responsible for configuring the feedback
    UserTask selectPeopleUserTask = createSelectPeopleUserTask(feedbackStepDefinition, conversion, processElements);
    // Parallel gateways (forking/joining)
    ParallelGateway fork = createForkParallelGateway(conversion, processElements);
    addSequenceFlow(conversion, selectPeopleUserTask, fork);
    // Gather feedback user task for the initiator of the feedback step
    UserTask gatherFeedbackUserTask = createGatherFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
    addSequenceFlow(conversion, fork, gatherFeedbackUserTask);
    // Global signal event
    Signal signal = createSignalDeclaration(conversion);
    // Signal throw event after the gather feedback task
    ThrowEvent signalThrowEvent = createSignalThrow(conversion, signal);
    addSequenceFlow(conversion, gatherFeedbackUserTask, signalThrowEvent);
    // Povide feedback step
    UserTask feedbackTask = createFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
    addSequenceFlow(conversion, fork, feedbackTask);
    // Boundary signal catch to shut down all tasks if the 'gather feedback' task is completed
    BoundaryEvent boundarySignalCatch = createBoundarySignalCatch(conversion, signal, feedbackTask);
    // Exclusive gateway after the feedback task, needed to correctly merge the sequence flow
    // such that the joining parallel gateway has exactly two incoming sequence flow
    ExclusiveGateway mergingExclusiveGateway = createMergingExclusiveGateway(conversion);
    addSequenceFlow(conversion, feedbackTask, mergingExclusiveGateway);
    addSequenceFlow(conversion, boundarySignalCatch, mergingExclusiveGateway);
    // Parallel gateway that will join  it all together
    ParallelGateway join = createJoinParallelGateway(conversion, processElements);
    addSequenceFlow(conversion, signalThrowEvent, join);
    addSequenceFlow(conversion, mergingExclusiveGateway, join);
    // Set the last activity id, such that next steps can connect correctly
    conversion.setLastActivityId(join.getId());
    return processElements;
}
Also used : ThrowEvent(org.activiti.bpmn.model.ThrowEvent) BaseElement(org.activiti.bpmn.model.BaseElement) ExclusiveGateway(org.activiti.bpmn.model.ExclusiveGateway) Signal(org.activiti.bpmn.model.Signal) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) HashMap(java.util.HashMap) ParallelGateway(org.activiti.bpmn.model.ParallelGateway) UserTask(org.activiti.bpmn.model.UserTask)

Example 2 with BaseElement

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

the class BpmnXMLConverter method convertToBpmnModel.

public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
    BpmnModel model = new BpmnModel();
    model.setStartEventFormTypes(startEventFormTypes);
    model.setUserTaskFormTypes(userTaskFormTypes);
    try {
        Process activeProcess = null;
        List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>();
        while (xtr.hasNext()) {
            try {
                xtr.next();
            } catch (Exception e) {
                LOGGER.debug("Error reading XML document", e);
                throw new XMLException("Error reading XML", e);
            }
            if (xtr.isEndElement() && ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }
            if (xtr.isEndElement() && ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
                activeSubProcessList.remove(activeSubProcessList.size() - 1);
            }
            if (xtr.isStartElement() == false) {
                continue;
            }
            if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
                definitionsParser.parse(xtr, model);
            } else if (ELEMENT_RESOURCE.equals(xtr.getLocalName())) {
                resourceParser.parse(xtr, model);
            } else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) {
                signalParser.parse(xtr, model);
            } else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) {
                messageParser.parse(xtr, model);
            } else if (ELEMENT_ERROR.equals(xtr.getLocalName())) {
                if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
                    model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID), xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE));
                }
            } else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) {
                importParser.parse(xtr, model);
            } else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) {
                itemDefinitionParser.parse(xtr, model);
            } else if (ELEMENT_DATA_STORE.equals(xtr.getLocalName())) {
                dataStoreParser.parse(xtr, model);
            } else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) {
                interfaceParser.parse(xtr, model);
            } else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) {
                ioSpecificationParser.parseChildElement(xtr, activeProcess, model);
            } else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {
                participantParser.parse(xtr, model);
            } else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) {
                messageFlowParser.parse(xtr, model);
            } else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) {
                Process process = processParser.parse(xtr, model);
                if (process != null) {
                    activeProcess = process;
                }
            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                potentialStarterParser.parse(xtr, activeProcess);
            } else if (ELEMENT_LANE.equals(xtr.getLocalName())) {
                laneParser.parse(xtr, activeProcess, model);
            } else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) {
                BaseElement parentElement = null;
                if (!activeSubProcessList.isEmpty()) {
                    parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
                } else if (activeProcess != null) {
                    parentElement = activeProcess;
                }
                documentationParser.parseChildElement(xtr, parentElement, model);
            } else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter().convertXMLToElement(xtr, model);
                textAnnotation.setId(elementId);
                model.getGlobalArtifacts().add(textAnnotation);
            } else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) {
                String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
                Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr, model);
                association.setId(elementId);
                model.getGlobalArtifacts().add(association);
            } else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model);
            } else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
            } else if (ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
                subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
            } else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) {
                bpmnShapeParser.parse(xtr, model);
            } else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) {
                bpmnEdgeParser.parse(xtr, model);
            } else {
                if (!activeSubProcessList.isEmpty() && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {
                    multiInstanceParser.parseChildElement(xtr, activeSubProcessList.get(activeSubProcessList.size() - 1), model);
                } else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) {
                    if (activeProcess != null) {
                        BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName());
                        converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
                    }
                }
            }
        }
        for (Process process : model.getProcesses()) {
            for (Pool pool : model.getPools()) {
                if (process.getId().equals(pool.getProcessRef())) {
                    pool.setExecutable(process.isExecutable());
                }
            }
            processFlowElements(process.getFlowElements(), process);
        }
    } catch (XMLException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("Error processing BPMN document", e);
        throw new XMLException("Error processing BPMN document", e);
    }
    return model;
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) ArrayList(java.util.ArrayList) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) XMLStreamException(javax.xml.stream.XMLStreamException) XMLException(org.activiti.bpmn.exceptions.XMLException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) BpmnModel(org.activiti.bpmn.model.BpmnModel) BaseElement(org.activiti.bpmn.model.BaseElement) XMLException(org.activiti.bpmn.exceptions.XMLException) Association(org.activiti.bpmn.model.Association) Pool(org.activiti.bpmn.model.Pool) TextAnnotation(org.activiti.bpmn.model.TextAnnotation)

Example 3 with BaseElement

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

the class BaseBpmnXMLConverter method convertToBpmnModel.

public void convertToBpmnModel(XMLStreamReader xtr, BpmnModel model, Process activeProcess, List<SubProcess> activeSubProcessList) throws Exception {
    String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
    String elementName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
    boolean async = parseAsync(xtr);
    boolean notExclusive = parseNotExclusive(xtr);
    String defaultFlow = xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT);
    boolean isForCompensation = parseForCompensation(xtr);
    BaseElement parsedElement = convertXMLToElement(xtr, model);
    if (parsedElement instanceof Artifact) {
        Artifact currentArtifact = (Artifact) parsedElement;
        currentArtifact.setId(elementId);
        if (!activeSubProcessList.isEmpty()) {
            activeSubProcessList.get(activeSubProcessList.size() - 1).addArtifact(currentArtifact);
        } else {
            activeProcess.addArtifact(currentArtifact);
        }
    }
    if (parsedElement instanceof FlowElement) {
        FlowElement currentFlowElement = (FlowElement) parsedElement;
        currentFlowElement.setId(elementId);
        currentFlowElement.setName(elementName);
        if (currentFlowElement instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) currentFlowElement;
            flowNode.setAsynchronous(async);
            flowNode.setNotExclusive(notExclusive);
            if (currentFlowElement instanceof Activity) {
                Activity activity = (Activity) currentFlowElement;
                activity.setForCompensation(isForCompensation);
                if (StringUtils.isNotEmpty(defaultFlow)) {
                    activity.setDefaultFlow(defaultFlow);
                }
            }
            if (currentFlowElement instanceof Gateway) {
                Gateway gateway = (Gateway) currentFlowElement;
                if (StringUtils.isNotEmpty(defaultFlow)) {
                    gateway.setDefaultFlow(defaultFlow);
                }
            }
        }
        if (currentFlowElement instanceof DataObject) {
            if (!activeSubProcessList.isEmpty()) {
                activeSubProcessList.get(activeSubProcessList.size() - 1).getDataObjects().add((ValuedDataObject) parsedElement);
            } else {
                activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
            }
        }
        if (!activeSubProcessList.isEmpty()) {
            activeSubProcessList.get(activeSubProcessList.size() - 1).addFlowElement(currentFlowElement);
        } else {
            activeProcess.addFlowElement(currentFlowElement);
        }
    }
}
Also used : BaseElement(org.activiti.bpmn.model.BaseElement) DataObject(org.activiti.bpmn.model.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway) Activity(org.activiti.bpmn.model.Activity) Artifact(org.activiti.bpmn.model.Artifact) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 4 with BaseElement

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

the class ExtensionElementsParser method parse.

public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess, BpmnModel model) throws Exception {
    BaseElement parentElement = null;
    if (!activeSubProcessList.isEmpty()) {
        parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
    } else {
        parentElement = activeProcess;
    }
    boolean readyWithChildElements = false;
    while (readyWithChildElements == false && xtr.hasNext()) {
        xtr.next();
        if (xtr.isStartElement()) {
            if (ELEMENT_EXECUTION_LISTENER.equals(xtr.getLocalName())) {
                new ExecutionListenerParser().parseChildElement(xtr, parentElement, model);
            } else if (ELEMENT_EVENT_LISTENER.equals(xtr.getLocalName())) {
                new ActivitiEventListenerParser().parseChildElement(xtr, parentElement, model);
            } else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
                new PotentialStarterParser().parse(xtr, activeProcess);
            } else {
                ExtensionElement extensionElement = BpmnXMLUtil.parseExtensionElement(xtr);
                parentElement.addExtensionElement(extensionElement);
            }
        } else if (xtr.isEndElement()) {
            if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
                readyWithChildElements = true;
            }
        }
    }
}
Also used : BaseElement(org.activiti.bpmn.model.BaseElement) ExecutionListenerParser(org.activiti.bpmn.converter.child.ExecutionListenerParser) ActivitiEventListenerParser(org.activiti.bpmn.converter.child.ActivitiEventListenerParser) ExtensionElement(org.activiti.bpmn.model.ExtensionElement)

Example 5 with BaseElement

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

the class BaseBpmnJsonConverter method convertToBpmnModel.

public void convertToBpmnModel(JsonNode elementNode, JsonNode modelNode, ActivityProcessor processor, BaseElement parentElement, Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
    this.processor = processor;
    this.model = bpmnModel;
    BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
    baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
        flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));
        BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);
        if (baseElement instanceof Activity) {
            Activity activity = (Activity) baseElement;
            activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
            activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));
            String multiInstanceType = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
            String multiInstanceCardinality = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
            String multiInstanceCollection = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
            String multiInstanceCondition = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);
            if (StringUtils.isNotEmpty(multiInstanceType) && "none".equalsIgnoreCase(multiInstanceType) == false) {
                String multiInstanceVariable = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);
                MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();
                if ("sequential".equalsIgnoreCase(multiInstanceType)) {
                    multiInstanceObject.setSequential(true);
                } else {
                    multiInstanceObject.setSequential(false);
                }
                multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
                multiInstanceObject.setInputDataItem(multiInstanceCollection);
                multiInstanceObject.setElementVariable(multiInstanceVariable);
                multiInstanceObject.setCompletionCondition(multiInstanceCondition);
                activity.setLoopCharacteristics(multiInstanceObject);
            }
        } else if (baseElement instanceof Gateway) {
            JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
            if (flowOrderNode != null) {
                flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
                JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
                if (orderArray != null && orderArray.size() > 0) {
                    for (JsonNode orderNode : orderArray) {
                        ExtensionElement orderElement = new ExtensionElement();
                        orderElement.setName("EDITOR_FLOW_ORDER");
                        orderElement.setElementText(orderNode.asText());
                        flowElement.addExtensionElement(orderElement);
                    }
                }
            }
        }
    }
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        if (flowElement instanceof SequenceFlow) {
            ExtensionElement idExtensionElement = new ExtensionElement();
            idExtensionElement.setName("EDITOR_RESOURCEID");
            idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
            flowElement.addExtensionElement(idExtensionElement);
        }
        if (parentElement instanceof Process) {
            ((Process) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(flowElement.getId());
            lane.getParentProcess().addFlowElement(flowElement);
        }
    } else if (baseElement instanceof Artifact) {
        Artifact artifact = (Artifact) baseElement;
        if (parentElement instanceof Process) {
            ((Process) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(artifact.getId());
            lane.getParentProcess().addArtifact(artifact);
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) Lane(org.activiti.bpmn.model.Lane) Activity(org.activiti.bpmn.model.Activity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) BaseElement(org.activiti.bpmn.model.BaseElement) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway)

Aggregations

BaseElement (org.activiti.bpmn.model.BaseElement)5 Activity (org.activiti.bpmn.model.Activity)2 Artifact (org.activiti.bpmn.model.Artifact)2 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 Gateway (org.activiti.bpmn.model.Gateway)2 Process (org.activiti.bpmn.model.Process)2 SubProcess (org.activiti.bpmn.model.SubProcess)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ActivitiEventListenerParser (org.activiti.bpmn.converter.child.ActivitiEventListenerParser)1 ExecutionListenerParser (org.activiti.bpmn.converter.child.ExecutionListenerParser)1 XMLException (org.activiti.bpmn.exceptions.XMLException)1 Association (org.activiti.bpmn.model.Association)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1