Search in sources :

Example 1 with DataTransformer

use of io.automatiko.engine.api.runtime.process.DataTransformer in project automatiko-engine by automatiko-io.

the class CallActivityHandler method readDataOutputAssociation.

protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, SubProcessNode subProcessNode, Map<String, String> dataOutputs) {
    // sourceRef
    org.w3c.dom.Node subNode = xmlNode.getFirstChild();
    String from = subNode.getTextContent();
    // targetRef
    subNode = subNode.getNextSibling();
    String to = 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, from);
        subNode = subNode.getNextSibling();
    }
    subProcessNode.addOutMapping(dataOutputs.get(from), to, transformation);
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer)

Example 2 with DataTransformer

use of io.automatiko.engine.api.runtime.process.DataTransformer in project automatiko-engine by automatiko-io.

the class BusinessRuleTaskHandler method readDataInputAssociation.

protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, RuleSetNode ruleSetNode, 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();
        }
        ruleSetNode.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 ?
                ruleSetNode.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);
            }
            ruleSetNode.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 3 with DataTransformer

use of io.automatiko.engine.api.runtime.process.DataTransformer in project automatiko-engine by automatiko-io.

the class BusinessRuleTaskHandler method readDataOutputAssociation.

protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, RuleSetNode ruleSetNode, 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);
        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();
    }
    ruleSetNode.addOutAssociation(new DataAssociation(sources.stream().map(source -> dataOutputs.get(source)).collect(Collectors.toList()), target, assignments, transformation));
}
Also used : Text(org.w3c.dom.Text) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) NodeList(org.w3c.dom.NodeList) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) XmlDumper(io.automatiko.engine.workflow.compiler.xml.XmlDumper) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) List(java.util.List) Element(org.w3c.dom.Element) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ExtensibleXmlParser(io.automatiko.engine.workflow.compiler.xml.ExtensibleXmlParser) Map(java.util.Map) SAXException(org.xml.sax.SAXException) DMN_LANG(io.automatiko.engine.workflow.process.core.node.RuleSetNode.DMN_LANG) Attributes(org.xml.sax.Attributes) LinkedList(java.util.LinkedList) Node(io.automatiko.engine.workflow.process.core.Node) 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 4 with DataTransformer

use of io.automatiko.engine.api.runtime.process.DataTransformer in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method processInputMappings.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void processInputMappings() {
    VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
    for (DataAssociation association : getCompositeContextNode().getInAssociations()) {
        if (association.getTransformation() != null) {
            Transformation transformation = association.getTransformation();
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            if (transformer != null) {
                Object parameterValue = transformer.transform(transformation.getCompiledExpression(), getProcessInstance().getVariables());
                if (parameterValue != null) {
                    compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
                }
            }
        } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
            Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
                    logger.error("Continuing without setting parameter.");
                }
            }
            if (parameterValue != null) {
                compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
            }
        } else {
            association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
        }
    }
}
Also used : Context(io.automatiko.engine.workflow.base.core.Context) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) ContextInstanceFactoryRegistry(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactoryRegistry) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory) VARIABLE_SCOPE(io.automatiko.engine.workflow.base.core.context.variable.VariableScope.VARIABLE_SCOPE) Logger(org.slf4j.Logger) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Example 5 with DataTransformer

use of io.automatiko.engine.api.runtime.process.DataTransformer in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method triggerCompleted.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void triggerCompleted(String outType) {
    VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
    for (DataAssociation association : getCompositeContextNode().getOutAssociations()) {
        if (association.getTransformation() != null) {
            Transformation transformation = association.getTransformation();
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            if (transformer != null) {
                Object parameterValue = transformer.transform(transformation.getCompiledExpression(), compositeVariableScopeInstance.getVariables());
                if (parameterValue != null) {
                    getProcessInstance().setVariable(association.getTarget(), parameterValue);
                }
            }
        } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
            Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
                    logger.error("Continuing without setting parameter.");
                }
            }
            if (parameterValue != null) {
                getProcessInstance().setVariable(association.getTarget(), parameterValue);
            }
        } else {
            association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
        }
    }
    super.triggerCompleted(outType);
}
Also used : Context(io.automatiko.engine.workflow.base.core.Context) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) ContextInstanceFactoryRegistry(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactoryRegistry) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory) VARIABLE_SCOPE(io.automatiko.engine.workflow.base.core.context.variable.VariableScope.VARIABLE_SCOPE) Logger(org.slf4j.Logger) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Aggregations

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