Search in sources :

Example 21 with ItemDefinition

use of io.automatiko.engine.workflow.bpmn2.core.ItemDefinition in project jbpm by kiegroup.

the class AbstractNodeHandler method readMultiInstanceLoopCharacteristics.

@SuppressWarnings("unchecked")
protected void readMultiInstanceLoopCharacteristics(org.w3c.dom.Node xmlNode, ForEachNode forEachNode, ExtensibleXmlParser parser) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    while (subNode != null) {
        String nodeName = subNode.getNodeName();
        if ("inputDataItem".equals(nodeName)) {
            String variableName = ((Element) subNode).getAttribute("id");
            String itemSubjectRef = ((Element) subNode).getAttribute("itemSubjectRef");
            DataType dataType = null;
            Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
            dataType = getDataType(itemSubjectRef, itemDefinitions, parser.getClassLoader());
            if (variableName != null && variableName.trim().length() > 0) {
                forEachNode.setVariable(variableName, dataType);
            }
        } else if ("outputDataItem".equals(nodeName)) {
            String variableName = ((Element) subNode).getAttribute("id");
            String itemSubjectRef = ((Element) subNode).getAttribute("itemSubjectRef");
            DataType dataType = null;
            Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
            dataType = getDataType(itemSubjectRef, itemDefinitions, parser.getClassLoader());
            if (variableName != null && variableName.trim().length() > 0) {
                forEachNode.setOutputVariable(variableName, dataType);
            }
        } else if ("loopDataOutputRef".equals(nodeName)) {
            String outputDataRef = ((Element) subNode).getTextContent();
            if (outputDataRef != null && outputDataRef.trim().length() > 0) {
                String collectionName = outputAssociation.get(outputDataRef);
                if (collectionName == null) {
                    collectionName = dataOutputs.get(outputDataRef);
                }
                forEachNode.setOutputCollectionExpression(collectionName);
            }
            forEachNode.setMetaData("MICollectionOutput", outputDataRef);
        } else if ("loopDataInputRef".equals(nodeName)) {
            String inputDataRef = ((Element) subNode).getTextContent();
            if (inputDataRef != null && inputDataRef.trim().length() > 0) {
                String collectionName = inputAssociation.get(inputDataRef);
                if (collectionName == null) {
                    collectionName = dataInputs.get(inputDataRef);
                }
                forEachNode.setCollectionExpression(collectionName);
            }
            forEachNode.setMetaData("MICollectionInput", inputDataRef);
        } else if ("completionCondition".equals(nodeName)) {
            String expression = subNode.getTextContent();
            forEachNode.setCompletionConditionExpression(expression);
        }
        subNode = subNode.getNextSibling();
    }
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) DataType(org.jbpm.process.core.datatype.DataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with ItemDefinition

use of io.automatiko.engine.workflow.bpmn2.core.ItemDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method readMultiInstanceSpecification.

// this is only for compiling purposes
protected MultiInstanceSpecification readMultiInstanceSpecification(ExtensibleXmlParser parser, org.w3c.dom.Node parent, IOSpecification ioSpecification) {
    MultiInstanceSpecification multiInstanceSpecification = new MultiInstanceSpecification();
    Optional<Element> multiInstanceParent = readSingleChildElementByTag(parent, "multiInstanceLoopCharacteristics");
    if (multiInstanceParent.isEmpty()) {
        return multiInstanceSpecification;
    }
    Element multiInstanceNode = multiInstanceParent.get();
    multiInstanceSpecification.setSequential(Boolean.parseBoolean(multiInstanceNode.getAttribute("isSequential")));
    readSingleChildElementByTag(multiInstanceNode, "inputDataItem").ifPresent(inputDataItem -> {
        String id = inputDataItem.getAttribute("id");
        String name = inputDataItem.getAttribute("name");
        String itemSubjectRef = inputDataItem.getAttribute("itemSubjectRef");
        ItemDefinition itemDefinition = getStructureRef(parser, itemSubjectRef);
        String structureRef = itemDefinition != null ? itemDefinition.getStructureRef() : null;
        DataDefinition input = new DataDefinition(id, name, structureRef);
        multiInstanceSpecification.setInputDataItem(input);
        if (!ioSpecification.containsInputLabel(input.getLabel())) {
            ioSpecification.getDataInputs().add(input);
        }
    });
    readSingleChildElementByTag(multiInstanceNode, "outputDataItem").ifPresent(outputDataItem -> {
        String id = outputDataItem.getAttribute("id");
        String name = outputDataItem.getAttribute("name");
        String itemSubjectRef = outputDataItem.getAttribute("itemSubjectRef");
        ItemDefinition itemDefinition = getStructureRef(parser, itemSubjectRef);
        String structureRef = itemDefinition != null ? itemDefinition.getStructureRef() : null;
        DataDefinition output = new DataDefinition(id, name, structureRef);
        multiInstanceSpecification.setOutputDataItem(output);
        if (!ioSpecification.containsOutputLabel(output.getLabel())) {
            ioSpecification.getDataOutputs().add(output);
        }
    });
    readSingleChildElementByTag(multiInstanceNode, "loopDataOutputRef").ifPresent(loopDataOutputRef -> {
        String expressiontOutput = loopDataOutputRef.getTextContent();
        if (expressiontOutput != null && !expressiontOutput.isEmpty()) {
            multiInstanceSpecification.setLoopDataOutputRef(ioSpecification.getDataOutput().get(expressiontOutput));
        }
    });
    readSingleChildElementByTag(multiInstanceNode, "loopDataInputRef").ifPresent(loopDataInputRef -> {
        String expressionInput = loopDataInputRef.getTextContent();
        if (expressionInput != null && !expressionInput.isEmpty()) {
            multiInstanceSpecification.setLoopDataInputRef(ioSpecification.getDataInput().get(expressionInput));
        }
    });
    readSingleChildElementByTag(multiInstanceNode, COMPLETION_CONDITION).ifPresent(completeCondition -> {
        String completion = completeCondition.getTextContent();
        if (completion != null && !completion.isEmpty()) {
            multiInstanceSpecification.setCompletionCondition(completion);
        }
    });
    return multiInstanceSpecification;
}
Also used : MultiInstanceSpecification(org.jbpm.workflow.core.impl.MultiInstanceSpecification) Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 23 with ItemDefinition

use of io.automatiko.engine.workflow.bpmn2.core.ItemDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method getStructureRef.

protected ItemDefinition getStructureRef(ExtensibleXmlParser parser, String id) {
    ProcessBuildData buildData = (ProcessBuildData) parser.getData();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) buildData.getMetaData("ItemDefinitions");
    return itemDefinitions.get(id);
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with ItemDefinition

use of io.automatiko.engine.workflow.bpmn2.core.ItemDefinition in project kogito-runtimes by kiegroup.

the class BoundaryEventHandler method handleErrorNode.

@SuppressWarnings("unchecked")
protected void handleErrorNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("errorEventDefinition".equals(nodeName)) {
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new ProcessParsingValidationException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new ProcessParsingValidationException("Could not find error " + errorRef);
                }
                String type = error.getErrorCode();
                boolean hasErrorCode = true;
                if (type == null) {
                    type = error.getId();
                    hasErrorCode = false;
                }
                String structureRef = error.getStructureRef();
                if (structureRef != null) {
                    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
                    if (itemDefs.containsKey(structureRef)) {
                        structureRef = itemDefs.get(structureRef).getStructureRef();
                    }
                }
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Error-" + attachedTo + "-" + type);
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("ErrorEvent", type);
                eventNode.setMetaData("HasErrorEvent", hasErrorCode);
                eventNode.setMetaData("ErrorStructureRef", structureRef);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Error(org.jbpm.bpmn2.core.Error) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 25 with ItemDefinition

use of io.automatiko.engine.workflow.bpmn2.core.ItemDefinition in project kogito-runtimes by kiegroup.

the class DefinitionsHandler method end.

@Override
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Definitions definitions = (Definitions) parser.getCurrent();
    String namespace = element.getAttribute("targetNamespace");
    List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    for (Process process : processes) {
        RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Element(org.w3c.dom.Element) Definitions(org.jbpm.bpmn2.core.Definitions) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) Map(java.util.Map) Interface(org.jbpm.bpmn2.core.Interface)

Aggregations

Map (java.util.Map)19 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)19 List (java.util.List)13 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)12 Element (org.w3c.dom.Element)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)6 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)6 DataType (org.jbpm.process.core.datatype.DataType)6 DataType (io.automatiko.engine.api.workflow.datatype.DataType)5 HashSet (java.util.HashSet)5 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)5 BooleanDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)4 FloatDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType)4 IntegerDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType)4 StringDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType)4 Definitions (org.jbpm.bpmn2.core.Definitions)4 Variable (org.jbpm.process.core.context.variable.Variable)4 BooleanDataType (org.jbpm.process.core.datatype.impl.type.BooleanDataType)4