Search in sources :

Example 1 with Assignment

use of org.jbpm.workflow.core.node.Assignment in project jbpm by kiegroup.

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())) {
        String source = subNode.getTextContent();
        // targetRef
        subNode = subNode.getNextSibling();
        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) {
            org.w3c.dom.Node ssubNode = subNode.getFirstChild();
            String from = ssubNode.getTextContent();
            String to = ssubNode.getNextSibling().getTextContent();
            assignments.add(new Assignment("XPath", from, to));
            subNode = subNode.getNextSibling();
        }
        workItemNode.addInAssociation(new DataAssociation(source, 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(org.jbpm.workflow.core.node.Transformation) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) LinkedList(java.util.LinkedList) Assignment(org.jbpm.workflow.core.node.Assignment) DataTransformer(org.kie.api.runtime.process.DataTransformer)

Example 2 with Assignment

use of org.jbpm.workflow.core.node.Assignment in project jbpm by kiegroup.

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())) {
        String source = subNode.getTextContent();
        // targetRef
        subNode = subNode.getNextSibling();
        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) {
            org.w3c.dom.Node ssubNode = subNode.getFirstChild();
            String from = ssubNode.getTextContent();
            String to = ssubNode.getNextSibling().getTextContent();
            assignments.add(new Assignment("XPath", from, to));
            subNode = subNode.getNextSibling();
        }
        ruleSetNode.addInAssociation(new DataAssociation(source, 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(org.jbpm.workflow.core.node.Transformation) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text) LinkedList(java.util.LinkedList) Assignment(org.jbpm.workflow.core.node.Assignment) DataTransformer(org.kie.api.runtime.process.DataTransformer)

Example 3 with Assignment

use of org.jbpm.workflow.core.node.Assignment in project jbpm by kiegroup.

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();
    String source = subNode.getTextContent();
    // targetRef
    subNode = subNode.getNextSibling();
    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, source);
        subNode = subNode.getNextSibling();
    }
    // assignments
    List<Assignment> assignments = new LinkedList<Assignment>();
    while (subNode != null) {
        org.w3c.dom.Node ssubNode = subNode.getFirstChild();
        String from = ssubNode.getTextContent();
        String to = ssubNode.getNextSibling().getTextContent();
        assignments.add(new Assignment("XPath", from, to));
        subNode = subNode.getNextSibling();
    }
    ruleSetNode.addOutAssociation(new DataAssociation(dataOutputs.get(source), target, assignments, transformation));
}
Also used : Assignment(org.jbpm.workflow.core.node.Assignment) Transformation(org.jbpm.workflow.core.node.Transformation) DataTransformer(org.kie.api.runtime.process.DataTransformer) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) LinkedList(java.util.LinkedList)

Example 4 with Assignment

use of org.jbpm.workflow.core.node.Assignment in project jbpm by kiegroup.

the class WorkItemNodeBuilder method build.

public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
    super.build(process, processDescr, context, node);
    WorkflowProcess wfProcess = (WorkflowProcess) process;
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("imports", wfProcess.getImports());
    parameters.put("classloader", context.getConfiguration().getClassLoader());
    for (DataAssociation dataAssociation : ((WorkItemNode) node).getInAssociations()) {
        Transformation transformation = dataAssociation.getTransformation();
        if (transformation != null) {
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters));
        }
        List<Assignment> assignments = dataAssociation.getAssignments();
        if (assignments != null) {
            for (Assignment assignment : assignments) {
                ProcessDialect dialect = ProcessDialectRegistry.getDialect(assignment.getDialect());
                dialect.getAssignmentBuilder().build(context, assignment, dataAssociation.getSources().get(0), dataAssociation.getTarget(), ((WorkItemNode) node), true);
            }
        }
    }
    for (DataAssociation dataAssociation : ((WorkItemNode) node).getOutAssociations()) {
        Transformation transformation = dataAssociation.getTransformation();
        if (transformation != null) {
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters));
        }
        List<Assignment> assignments = dataAssociation.getAssignments();
        if (assignments != null) {
            for (Assignment assignment : assignments) {
                ProcessDialect dialect = ProcessDialectRegistry.getDialect(assignment.getDialect());
                dialect.getAssignmentBuilder().build(context, assignment, dataAssociation.getSources().get(0), dataAssociation.getTarget(), ((WorkItemNode) node), false);
            }
        }
    }
}
Also used : Assignment(org.jbpm.workflow.core.node.Assignment) Transformation(org.jbpm.workflow.core.node.Transformation) DataTransformer(org.kie.api.runtime.process.DataTransformer) HashMap(java.util.HashMap) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess)

Example 5 with Assignment

use of org.jbpm.workflow.core.node.Assignment in project jbpm by kiegroup.

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();
    String source = subNode.getTextContent();
    // targetRef
    subNode = subNode.getNextSibling();
    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, source);
        // transformation.setCompiledExpression(transformer.compile(expression));
        subNode = subNode.getNextSibling();
    }
    // assignments
    List<Assignment> assignments = new LinkedList<Assignment>();
    while (subNode != null) {
        org.w3c.dom.Node ssubNode = subNode.getFirstChild();
        String from = ssubNode.getTextContent();
        String to = ssubNode.getNextSibling().getTextContent();
        assignments.add(new Assignment("XPath", from, to));
        subNode = subNode.getNextSibling();
    }
    workItemNode.addOutAssociation(new DataAssociation(dataOutputs.get(source), target, assignments, transformation));
}
Also used : Assignment(org.jbpm.workflow.core.node.Assignment) Transformation(org.jbpm.workflow.core.node.Transformation) DataTransformer(org.kie.api.runtime.process.DataTransformer) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) LinkedList(java.util.LinkedList)

Aggregations

Assignment (org.jbpm.workflow.core.node.Assignment)5 DataAssociation (org.jbpm.workflow.core.node.DataAssociation)5 Transformation (org.jbpm.workflow.core.node.Transformation)5 DataTransformer (org.kie.api.runtime.process.DataTransformer)5 LinkedList (java.util.LinkedList)4 NodeList (org.w3c.dom.NodeList)2 Text (org.w3c.dom.Text)2 HashMap (java.util.HashMap)1 ProcessDialect (org.jbpm.process.builder.dialect.ProcessDialect)1 WorkflowProcess (org.jbpm.workflow.core.WorkflowProcess)1 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)1