Search in sources :

Example 21 with Transformation

use of io.automatiko.engine.workflow.process.core.node.Transformation in project automatiko-engine by automatiko-io.

the class EndEventHandler method handleSignalNode.

public void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    EndNode endNode = (EndNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String inputName = ((Element) xmlNode).getAttribute("name");
            dataInputs.put(id, inputName);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readEndDataInputAssociation(xmlNode, endNode);
        } else if ("signalEventDefinition".equals(nodeName)) {
            String signalName = ((Element) xmlNode).getAttribute("signalRef");
            String variable = (String) endNode.getMetaData("MappingVariable");
            signalName = checkSignalAndConvertToRealSignalNam(parser, signalName);
            endNode.setMetaData("EventType", "signal");
            endNode.setMetaData("Ref", signalName);
            endNode.setMetaData("Variable", variable);
            // check if signal should be send async
            if (dataInputs.containsValue("async")) {
                signalName = "ASYNC-" + signalName;
            }
            ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction(signalName, variable, (String) endNode.getMetaData("customScope"), (Transformation) endNode.getMetaData().get("Transformation")));
            List<ProcessAction> actions = new ArrayList<ProcessAction>();
            actions.add(action);
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ArrayList(java.util.ArrayList)

Example 22 with Transformation

use of io.automatiko.engine.workflow.process.core.node.Transformation in project automatiko-engine by automatiko-io.

the class ScriptTaskHandler method readDataInputAssociation.

protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, ActionNode actionNode, Map<String, String> dataInputs) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    if ("sourceRef".equals(subNode.getNodeName())) {
        List<String> sources = new ArrayList<>();
        sources.add(subNode.getTextContent());
        subNode = subNode.getNextSibling();
        while ("sourceRef".equals(subNode.getNodeName())) {
            sources.add(subNode.getTextContent());
            subNode = subNode.getNextSibling();
        }
        // targetRef
        String target = subNode.getTextContent();
        // transformation
        Transformation transformation = null;
        subNode = subNode.getNextSibling();
        if (subNode != null && "transformation".equals(subNode.getNodeName())) {
            String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
            String expression = subNode.getTextContent();
            DataTransformer transformer = transformerRegistry.find(lang);
            if (transformer == null) {
                throw new IllegalArgumentException("No transformer registered for language " + lang);
            }
            transformation = new Transformation(lang, expression);
            subNode = subNode.getNextSibling();
        }
        // assignments
        List<Assignment> assignments = new LinkedList<Assignment>();
        while (subNode != null) {
            String expressionLang = ((Element) subNode).getAttribute("expressionLanguage");
            if (expressionLang == null || expressionLang.trim().isEmpty()) {
                expressionLang = "XPath";
            }
            org.w3c.dom.Node ssubNode = subNode.getFirstChild();
            String from = ssubNode.getTextContent();
            String to = ssubNode.getNextSibling().getTextContent();
            assignments.add(new Assignment(expressionLang, from, to));
            subNode = subNode.getNextSibling();
        }
        actionNode.addInAssociation(new DataAssociation(sources, dataInputs.get(target), assignments, transformation));
    }
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer)

Example 23 with Transformation

use of io.automatiko.engine.workflow.process.core.node.Transformation in project automatiko-engine by automatiko-io.

the class TaskHandler method readDataInputAssociation.

protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, WorkItemNode workItemNode, Map<String, String> dataInputs) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    if ("sourceRef".equals(subNode.getNodeName())) {
        List<String> sources = new ArrayList<>();
        sources.add(subNode.getTextContent());
        subNode = subNode.getNextSibling();
        while ("sourceRef".equals(subNode.getNodeName())) {
            sources.add(subNode.getTextContent());
            subNode = subNode.getNextSibling();
        }
        // targetRef
        String target = subNode.getTextContent();
        // transformation
        Transformation transformation = null;
        subNode = subNode.getNextSibling();
        if (subNode != null && "transformation".equals(subNode.getNodeName())) {
            String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
            String expression = subNode.getTextContent();
            DataTransformer transformer = transformerRegistry.find(lang);
            if (transformer == null) {
                throw new IllegalArgumentException("No transformer registered for language " + lang);
            }
            transformation = new Transformation(lang, expression);
            // transformation.setCompiledExpression(transformer.compile(expression));
            subNode = subNode.getNextSibling();
        }
        // assignments
        List<Assignment> assignments = new LinkedList<Assignment>();
        while (subNode != null) {
            String expressionLang = ((Element) subNode).getAttribute("expressionLanguage");
            if (expressionLang == null || expressionLang.trim().isEmpty()) {
                expressionLang = "XPath";
            }
            org.w3c.dom.Node ssubNode = subNode.getFirstChild();
            String from = ssubNode.getTextContent();
            String to = ssubNode.getNextSibling().getTextContent();
            assignments.add(new Assignment(expressionLang, from, to));
            subNode = subNode.getNextSibling();
        }
        workItemNode.addInAssociation(new DataAssociation(sources, dataInputs.get(target), assignments, transformation));
    } else {
        // targetRef
        String to = subNode.getTextContent();
        // assignment
        subNode = subNode.getNextSibling();
        if (subNode != null) {
            org.w3c.dom.Node subSubNode = subNode.getFirstChild();
            NodeList nl = subSubNode.getChildNodes();
            if (nl.getLength() > 1) {
                // not supported ?
                workItemNode.getWork().setParameter(dataInputs.get(to), subSubNode.getTextContent());
                return;
            } else if (nl.getLength() == 0) {
                return;
            }
            Object result = null;
            Object from = nl.item(0);
            if (from instanceof Text) {
                String text = ((Text) from).getTextContent();
                if (text.startsWith("\"") && text.endsWith("\"")) {
                    result = text.substring(1, text.length() - 1);
                } else {
                    result = text;
                }
            } else {
                result = nl.item(0);
            }
            workItemNode.getWork().setParameter(dataInputs.get(to), result);
        }
    }
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) Text(org.w3c.dom.Text) LinkedList(java.util.LinkedList) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer)

Example 24 with Transformation

use of io.automatiko.engine.workflow.process.core.node.Transformation in project automatiko-engine by automatiko-io.

the class TaskHandler method readDataOutputAssociation.

protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, WorkItemNode workItemNode, Map<String, String> dataOutputs) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    List<String> sources = new ArrayList<>();
    sources.add(subNode.getTextContent());
    subNode = subNode.getNextSibling();
    while ("sourceRef".equals(subNode.getNodeName())) {
        sources.add(subNode.getTextContent());
        subNode = subNode.getNextSibling();
    }
    // targetRef
    String target = subNode.getTextContent();
    // transformation
    Transformation transformation = null;
    subNode = subNode.getNextSibling();
    if (subNode != null && "transformation".equals(subNode.getNodeName())) {
        String lang = subNode.getAttributes().getNamedItem("language").getNodeValue();
        String expression = subNode.getTextContent();
        DataTransformer transformer = transformerRegistry.find(lang);
        if (transformer == null) {
            throw new IllegalArgumentException("No transformer registered for language " + lang);
        }
        transformation = new Transformation(lang, expression);
        // transformation.setCompiledExpression(transformer.compile(expression));
        subNode = subNode.getNextSibling();
    }
    // assignments
    List<Assignment> assignments = new LinkedList<Assignment>();
    while (subNode != null) {
        String expressionLang = ((Element) subNode).getAttribute("expressionLanguage");
        if (expressionLang == null || expressionLang.trim().isEmpty()) {
            expressionLang = "XPath";
        }
        org.w3c.dom.Node ssubNode = subNode.getFirstChild();
        String from = ssubNode.getTextContent();
        String to = ssubNode.getNextSibling().getTextContent();
        assignments.add(new Assignment(expressionLang, from, to));
        subNode = subNode.getNextSibling();
    }
    workItemNode.addOutAssociation(new DataAssociation(sources.stream().map(source -> dataOutputs.get(source)).collect(Collectors.toList()), target, assignments, transformation));
}
Also used : Text(org.w3c.dom.Text) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) LinkedHashMap(java.util.LinkedHashMap) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Map(java.util.Map) Attributes(org.xml.sax.Attributes) LinkedList(java.util.LinkedList) Node(io.automatiko.engine.workflow.process.core.Node) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) NodeList(org.w3c.dom.NodeList) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) Collectors(java.util.stream.Collectors) ClassUtils.constructClass(io.automatiko.engine.workflow.compiler.util.ClassUtils.constructClass) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) Element(org.w3c.dom.Element) ExtensibleXmlParser(io.automatiko.engine.workflow.compiler.xml.ExtensibleXmlParser) SAXException(org.xml.sax.SAXException) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Entry(java.util.Map.Entry) CONDITION(io.automatiko.engine.workflow.process.executable.core.Metadata.CONDITION) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) Work(io.automatiko.engine.workflow.base.core.Work) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer)

Aggregations

Transformation (io.automatiko.engine.workflow.process.core.node.Transformation)24 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)21 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)15 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)9 Element (org.w3c.dom.Element)9 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)8 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)8 NodeInstanceResolverFactory (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory)7 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)6 LinkedList (java.util.LinkedList)6 DataTransformerRegistry (io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry)5 Node (io.automatiko.engine.workflow.process.core.Node)5 Matcher (java.util.regex.Matcher)5 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)4 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)4 List (java.util.List)4 NodeList (org.w3c.dom.NodeList)4