Search in sources :

Example 26 with ItemDefinition

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

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("name");
            if (variableName == null || variableName.isEmpty()) {
                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.setMetaData("MIInput", ((Element) subNode).getAttribute("id"));
                forEachNode.setVariable(variableName, dataType);
            }
        } else if ("outputDataItem".equals(nodeName)) {
            String variableName = ((Element) subNode).getAttribute("name");
            if (variableName == null || variableName.isEmpty()) {
                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.setMetaData("MIOutput", ((Element) subNode).getAttribute("id"));
                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 (COMPLETION_CONDITION.equals(nodeName)) {
            String expression = subNode.getTextContent();
            forEachNode.setCompletionConditionExpression(expression);
            String language = ((Element) subNode).getAttribute("language");
            forEachNode.setExpressionLang(language);
        }
        subNode = subNode.getNextSibling();
    }
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with ItemDefinition

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

the class AbstractNodeHandler method getDataType.

protected DataType getDataType(String itemSubjectRef, Map<String, ItemDefinition> itemDefinitions, ClassLoader cl) {
    DataType dataType = new ObjectDataType();
    if (itemDefinitions == null) {
        return dataType;
    }
    ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
    if (itemDefinition != null) {
        String structureRef = itemDefinition.getStructureRef();
        if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
            dataType = new BooleanDataType();
        } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
            dataType = new IntegerDataType();
        } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
            dataType = new FloatDataType();
        } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
            dataType = new StringDataType();
        } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
            dataType = new ObjectDataType(constructClass(structureRef), structureRef);
        } else {
            dataType = new ObjectDataType(constructClass(structureRef, cl), structureRef);
        }
    }
    return dataType;
}
Also used : StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)

Example 28 with ItemDefinition

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

the class DefinitionsHandler method end.

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) {
        ExecutableProcess ruleFlowProcess = (ExecutableProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
        postProcessNodes(ruleFlowProcess, Collections.emptyList(), parser);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : Element(org.w3c.dom.Element) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) LinkedList(java.util.LinkedList) List(java.util.List) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Map(java.util.Map) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface)

Example 29 with ItemDefinition

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

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 ("dataOutput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String outputName = ((Element) xmlNode).getAttribute("name");
            dataOutputs.put(id, outputName);
            populateDataOutputs(xmlNode, outputName, parser);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode, parser);
        } else 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 IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("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);
                if (error.getMetaData().get("retry") != null) {
                    eventNode.setMetaData("ErrorRetry", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retry"))).intValue());
                    if (error.getMetaData().get("retryLimit") != null) {
                        eventNode.setMetaData("ErrorRetryLimit", Integer.parseInt((String) error.getMetaData().get("retryLimit")));
                    }
                    if (error.getMetaData().get("retryIncrement") != null) {
                        eventNode.setMetaData("ErrorRetryIncrement", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retryIncrement"))).intValue());
                    }
                    if (error.getMetaData().get("retryMultiplier") != null) {
                        eventNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat((String) error.getMetaData().get("retryMultiplier")));
                    }
                }
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Error(io.automatiko.engine.workflow.bpmn2.core.Error) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 30 with ItemDefinition

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

the class XmlBPMNProcessDumper method visitProcess.

protected void visitProcess(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    String targetNamespace = (String) process.getMetaData().get("TargetNamespace");
    if (targetNamespace == null) {
        targetNamespace = "https://automatiko.io";
    }
    xmlDump.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + EOL + "<definitions id=\"Definition\"" + EOL + "             targetNamespace=\"" + targetNamespace + "\"" + EOL + "             typeLanguage=\"http://www.java.com/javaTypes\"" + EOL + "             expressionLanguage=\"http://www.mvel.org/2.0\"" + EOL + "             xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"" + EOL + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + EOL + "             xsi:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"" + EOL + "             xmlns:g=\"https://automatiko.io/flow/gpd\"" + EOL + (metaDataType == META_DATA_USING_DI ? "             xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"" + EOL + "             xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"" + EOL + "             xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"" + EOL : "") + "             xmlns:tns=\"https://automatiko.io\">" + EOL + EOL);
    // item definitions
    this.visitedVariables = new HashSet<String>();
    VariableScope variableScope = (VariableScope) ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<String> dumpedItemDefs = new HashSet<String>();
    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) process.getMetaData().get("ItemDefinitions");
    if (itemDefs != null) {
        for (ItemDefinition def : itemDefs.values()) {
            xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getId()) + "\" ");
            if (def.getStructureRef() != null && !"java.lang.Object".equals(def.getStructureRef())) {
                xmlDump.append("structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getStructureRef()) + "\" ");
            }
            xmlDump.append("/>" + EOL);
            dumpedItemDefs.add(def.getId().intern());
        }
    }
    visitVariableScope(variableScope, "_", xmlDump, dumpedItemDefs);
    visitSubVariableScopes(process.getNodes(), xmlDump, dumpedItemDefs);
    visitInterfaces(process.getNodes(), xmlDump);
    visitEscalations(process.getNodes(), xmlDump, new ArrayList<String>());
    Definitions def = (Definitions) process.getMetaData().get("Definitions");
    visitErrors(def, xmlDump);
    // data stores
    if (def != null && def.getDataStores() != null) {
        for (DataStore dataStore : def.getDataStores()) {
            visitDataStore(dataStore, xmlDump);
        }
    }
    // the process itself
    xmlDump.append("  <process processType=\"Private\" isExecutable=\"true\" ");
    if (process.getId() == null || process.getId().trim().length() == 0) {
        ((ProcessImpl) process).setId("com.sample.bpmn2");
    }
    xmlDump.append("id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" ");
    if (process.getName() != null) {
        xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getName()) + "\" ");
    }
    String packageName = process.getPackageName();
    if (packageName != null && !"io.automatiko.processes".equals(packageName)) {
        xmlDump.append("tns:packageName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(packageName) + "\" ");
    }
    if (((io.automatiko.engine.workflow.process.core.WorkflowProcess) process).isDynamic()) {
        xmlDump.append("tns:adHoc=\"true\" ");
    }
    String version = process.getVersion();
    if (version != null && !"".equals(version)) {
        xmlDump.append("tns:version=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(version) + "\" ");
    }
    // TODO: package, version
    xmlDump.append(">" + EOL + EOL);
    visitHeader(process, xmlDump, metaDataType);
    List<io.automatiko.engine.workflow.process.core.Node> processNodes = new ArrayList<io.automatiko.engine.workflow.process.core.Node>();
    for (Node procNode : process.getNodes()) {
        processNodes.add((io.automatiko.engine.workflow.process.core.Node) procNode);
    }
    visitNodes(processNodes, xmlDump, metaDataType);
    visitConnections(process.getNodes(), xmlDump, metaDataType);
    // add associations
    List<Association> associations = (List<Association>) process.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            visitAssociation(association, xmlDump);
        }
    }
    xmlDump.append("  </process>" + EOL + EOL);
    if (metaDataType == META_DATA_USING_DI) {
        xmlDump.append("  <bpmndi:BPMNDiagram>" + EOL + "    <bpmndi:BPMNPlane bpmnElement=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" >" + EOL);
        visitNodesDi(process.getNodes(), xmlDump);
        visitConnectionsDi(process.getNodes(), xmlDump);
        xmlDump.append("    </bpmndi:BPMNPlane>" + EOL + "  </bpmndi:BPMNDiagram>" + EOL + EOL);
    }
    xmlDump.append("</definitions>");
}
Also used : ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Association(io.automatiko.engine.workflow.bpmn2.core.Association) DataStore(io.automatiko.engine.workflow.bpmn2.core.DataStore) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) HashSet(java.util.HashSet) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ProcessImpl(io.automatiko.engine.workflow.base.core.impl.ProcessImpl) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

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