Search in sources :

Example 6 with Activity

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

the class BaseBpmnXMLConverter method convertToXML.

public void convertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model) throws Exception {
    xtw.writeStartElement(getXMLElementName());
    boolean didWriteExtensionStartElement = false;
    writeDefaultAttribute(ATTRIBUTE_ID, baseElement.getId(), xtw);
    if (baseElement instanceof FlowElement) {
        writeDefaultAttribute(ATTRIBUTE_NAME, ((FlowElement) baseElement).getName(), xtw);
    }
    if (baseElement instanceof FlowNode) {
        final FlowNode flowNode = (FlowNode) baseElement;
        if (flowNode.isAsynchronous()) {
            writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
            if (flowNode.isNotExclusive()) {
                writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
            }
        }
        if (baseElement instanceof Activity) {
            final Activity activity = (Activity) baseElement;
            if (activity.isForCompensation()) {
                writeDefaultAttribute(ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION, ATTRIBUTE_VALUE_TRUE, xtw);
            }
            if (StringUtils.isNotEmpty(activity.getDefaultFlow())) {
                FlowElement defaultFlowElement = model.getFlowElement(activity.getDefaultFlow());
                if (defaultFlowElement instanceof SequenceFlow) {
                    writeDefaultAttribute(ATTRIBUTE_DEFAULT, activity.getDefaultFlow(), xtw);
                }
            }
        }
        if (baseElement instanceof Gateway) {
            final Gateway gateway = (Gateway) baseElement;
            if (StringUtils.isNotEmpty(gateway.getDefaultFlow())) {
                FlowElement defaultFlowElement = model.getFlowElement(gateway.getDefaultFlow());
                if (defaultFlowElement instanceof SequenceFlow) {
                    writeDefaultAttribute(ATTRIBUTE_DEFAULT, gateway.getDefaultFlow(), xtw);
                }
            }
        }
    }
    writeAdditionalAttributes(baseElement, model, xtw);
    if (baseElement instanceof FlowElement) {
        final FlowElement flowElement = (FlowElement) baseElement;
        if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
            xtw.writeStartElement(ELEMENT_DOCUMENTATION);
            xtw.writeCharacters(flowElement.getDocumentation());
            xtw.writeEndElement();
        }
    }
    didWriteExtensionStartElement = writeExtensionChildElements(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = writeListeners(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(baseElement, didWriteExtensionStartElement, model.getNamespaces(), xtw);
    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        FailedJobRetryCountExport.writeFailedJobRetryCount(activity, xtw);
    }
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        MultiInstanceExport.writeMultiInstance(activity, xtw);
    }
    writeAdditionalChildElements(baseElement, model, xtw);
    xtw.writeEndElement();
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) Gateway(org.activiti.bpmn.model.Gateway) Activity(org.activiti.bpmn.model.Activity) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 7 with Activity

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

the class BpmnXMLConverter method processFlowElements.

private void processFlowElements(Collection<FlowElement> flowElementList, BaseElement parentScope) {
    for (FlowElement flowElement : flowElementList) {
        if (flowElement instanceof SequenceFlow) {
            SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
            FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope);
            if (sourceNode != null) {
                sourceNode.getOutgoingFlows().add(sequenceFlow);
            }
            FlowNode targetNode = getFlowNodeFromScope(sequenceFlow.getTargetRef(), parentScope);
            if (targetNode != null) {
                targetNode.getIncomingFlows().add(sequenceFlow);
            }
        } else if (flowElement instanceof BoundaryEvent) {
            BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
            FlowElement attachedToElement = getFlowNodeFromScope(boundaryEvent.getAttachedToRefId(), parentScope);
            if (attachedToElement != null) {
                boundaryEvent.setAttachedToRef((Activity) attachedToElement);
                ((Activity) attachedToElement).getBoundaryEvents().add(boundaryEvent);
            }
        } else if (flowElement instanceof SubProcess) {
            SubProcess subProcess = (SubProcess) flowElement;
            processFlowElements(subProcess.getFlowElements(), subProcess);
        }
    }
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) FlowElement(org.activiti.bpmn.model.FlowElement) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) Activity(org.activiti.bpmn.model.Activity) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 8 with Activity

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

the class IOSpecificationParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (parentElement instanceof Activity == false && parentElement instanceof Process == false)
        return;
    IOSpecification ioSpecification = new IOSpecification();
    BpmnXMLUtil.addXMLLocation(ioSpecification, xtr);
    boolean readyWithIOSpecification = false;
    try {
        while (readyWithIOSpecification == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_DATA_INPUT.equalsIgnoreCase(xtr.getLocalName())) {
                DataSpec dataSpec = new DataSpec();
                BpmnXMLUtil.addXMLLocation(dataSpec, xtr);
                dataSpec.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                dataSpec.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                dataSpec.setItemSubjectRef(parseItemSubjectRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_SUBJECT_REF), model));
                ioSpecification.getDataInputs().add(dataSpec);
            } else if (xtr.isStartElement() && ELEMENT_DATA_OUTPUT.equalsIgnoreCase(xtr.getLocalName())) {
                DataSpec dataSpec = new DataSpec();
                BpmnXMLUtil.addXMLLocation(dataSpec, xtr);
                dataSpec.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                dataSpec.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                dataSpec.setItemSubjectRef(parseItemSubjectRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_SUBJECT_REF), model));
                ioSpecification.getDataOutputs().add(dataSpec);
            } else if (xtr.isStartElement() && ELEMENT_DATA_INPUT_REFS.equalsIgnoreCase(xtr.getLocalName())) {
                String dataInputRefs = xtr.getElementText();
                if (StringUtils.isNotEmpty(dataInputRefs)) {
                    ioSpecification.getDataInputRefs().add(dataInputRefs.trim());
                }
            } else if (xtr.isStartElement() && ELEMENT_DATA_OUTPUT_REFS.equalsIgnoreCase(xtr.getLocalName())) {
                String dataOutputRefs = xtr.getElementText();
                if (StringUtils.isNotEmpty(dataOutputRefs)) {
                    ioSpecification.getDataOutputRefs().add(dataOutputRefs.trim());
                }
            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithIOSpecification = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing ioSpecification child elements", e);
    }
    if (parentElement instanceof Process) {
        ((Process) parentElement).setIoSpecification(ioSpecification);
    } else {
        ((Activity) parentElement).setIoSpecification(ioSpecification);
    }
}
Also used : IOSpecification(org.activiti.bpmn.model.IOSpecification) Activity(org.activiti.bpmn.model.Activity) DataSpec(org.activiti.bpmn.model.DataSpec) Process(org.activiti.bpmn.model.Process)

Example 9 with Activity

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

the class MultiInstanceParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (parentElement instanceof Activity == false)
        return;
    MultiInstanceLoopCharacteristics multiInstanceDef = new MultiInstanceLoopCharacteristics();
    BpmnXMLUtil.addXMLLocation(multiInstanceDef, xtr);
    if (xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL) != null) {
        multiInstanceDef.setSequential(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL)));
    }
    multiInstanceDef.setInputDataItem(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_COLLECTION));
    multiInstanceDef.setElementVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_VARIABLE));
    multiInstanceDef.setElementIndexVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_INDEX_VARIABLE));
    boolean readyWithMultiInstance = false;
    try {
        while (readyWithMultiInstance == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_CARDINALITY.equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setLoopCardinality(xtr.getElementText());
            } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_DATAINPUT.equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setInputDataItem(xtr.getElementText());
            } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_DATAITEM.equalsIgnoreCase(xtr.getLocalName())) {
                if (xtr.getAttributeValue(null, ATTRIBUTE_NAME) != null) {
                    multiInstanceDef.setElementVariable(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                }
            } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_CONDITION.equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setCompletionCondition(xtr.getElementText());
            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithMultiInstance = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing multi instance definition", e);
    }
    ((Activity) parentElement).setLoopCharacteristics(multiInstanceDef);
}
Also used : MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) Activity(org.activiti.bpmn.model.Activity)

Example 10 with Activity

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

the class FlowElementValidator method executeValidation.

@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
    for (FlowElement flowElement : process.getFlowElements()) {
        if (flowElement instanceof Activity) {
            Activity activity = (Activity) flowElement;
            handleConstraints(process, activity, errors);
            handleMultiInstanceLoopCharacteristics(process, activity, errors);
            handleDataAssociations(process, activity, errors);
        }
    }
}
Also used : FlowElement(org.activiti.bpmn.model.FlowElement) Activity(org.activiti.bpmn.model.Activity)

Aggregations

Activity (org.activiti.bpmn.model.Activity)15 FlowElement (org.activiti.bpmn.model.FlowElement)9 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)7 FlowNode (org.activiti.bpmn.model.FlowNode)6 Gateway (org.activiti.bpmn.model.Gateway)6 SubProcess (org.activiti.bpmn.model.SubProcess)5 MultiInstanceLoopCharacteristics (org.activiti.bpmn.model.MultiInstanceLoopCharacteristics)4 Artifact (org.activiti.bpmn.model.Artifact)3 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)3 DataAssociation (org.activiti.bpmn.model.DataAssociation)3 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)3 Process (org.activiti.bpmn.model.Process)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 BaseElement (org.activiti.bpmn.model.BaseElement)2 EventGateway (org.activiti.bpmn.model.EventGateway)2 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)2 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)2 XMLException (org.activiti.bpmn.exceptions.XMLException)1