Search in sources :

Example 1 with RuleSetNode

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

the class DmnDecisionInProcessTest method createProcess.

private ExecutableProcess createProcess(String namespace, String modelName, String decisionName) {
    DMNRuntime dmnRuntime = DmnRuntimeProvider.fromClassPath("PersonDecisions.dmn");
    DmnDecisionModel dmnDecisionModel = new DmnDecisionModel(dmnRuntime, namespace, modelName);
    ExecutableProcess process = new ExecutableProcess();
    process.setId("process");
    process.setName("Process");
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable1 = new Variable();
    variable1.setName("person");
    variable1.setType(new ObjectDataType(Person.class));
    variables.add(variable1);
    Variable variable2 = new Variable();
    variable2.setName("isAdult");
    variable2.setType(new BooleanDataType());
    variables.add(variable2);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    RuleSetNode ruleSetNode = new RuleSetNode();
    ruleSetNode.setName("RuleSetNode");
    ruleSetNode.setId(2);
    ruleSetNode.setRuleType(RuleSetNode.RuleType.decision(namespace, modelName, null));
    ruleSetNode.setLanguage(RuleSetNode.DMN_LANG);
    ruleSetNode.setDecisionModel(() -> dmnDecisionModel);
    ruleSetNode.addInMapping("Person", "person");
    ruleSetNode.addOutMapping("isAdult", "isAdult");
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, ruleSetNode);
    connect(ruleSetNode, endNode);
    process.addNode(startNode);
    process.addNode(ruleSetNode);
    process.addNode(endNode);
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) DmnDecisionModel(io.automatiko.engine.decision.dmn.DmnDecisionModel) ArrayList(java.util.ArrayList) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 2 with RuleSetNode

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

the class BusinessRuleTaskHandler method handleNode.

protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    RuleSetNode ruleSetNode = (RuleSetNode) node;
    String language = element.getAttribute("implementation");
    if (language == null || language.equalsIgnoreCase("##unspecified") || language.isEmpty()) {
        language = RuleSetNode.DMN_LANG;
    }
    ruleSetNode.setLanguage(language);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("ioSpecification".equals(nodeName)) {
            readIoSpecification(xmlNode, dataInputs, dataOutputs, dataInputTypes, dataOutputTypes);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, ruleSetNode, dataInputs);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, ruleSetNode, dataOutputs);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (language.equals(DMN_LANG)) {
        String namespace = (String) ruleSetNode.removeParameter(NAMESPACE_PROP);
        String model = (String) ruleSetNode.removeParameter(MODEL_PROP);
        String decision = (String) ruleSetNode.removeParameter(DECISION_PROP);
        String decisionService = (String) ruleSetNode.removeParameter(DECISION_SERVICE_PROP);
        ruleSetNode.setRuleType(RuleSetNode.RuleType.decision(namespace, model, decisionService != null ? decisionService : decision, decisionService != null));
    }
    handleScript(ruleSetNode, element, "onEntry");
    handleScript(ruleSetNode, element, "onExit");
}
Also used : RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode)

Example 3 with RuleSetNode

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

the class BusinessRuleTaskHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    // determine type of event definition, so the correct type of node can be generated
    handleNode(node, element, uri, localName, parser);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    int uniqueIdGen = 1;
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            forEachNode.setMetaData("UniqueId", uniqueId);
            node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
            forEachNode.addNode(node);
            forEachNode.linkIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.linkOutgoingConnections(node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.setSequential(Boolean.parseBoolean(((Element) xmlNode).getAttribute("isSequential")));
            Node orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // remove input/output collection data input/output of for each to avoid problems when running in variable strict mode
            if (orignalNode instanceof RuleSetNode) {
                adjustNodeConfiguration(orignalNode, forEachNode);
            }
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) Element(org.w3c.dom.Element) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) Node(io.automatiko.engine.workflow.process.core.Node) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer)

Example 4 with RuleSetNode

use of io.automatiko.engine.workflow.process.core.node.RuleSetNode 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 5 with RuleSetNode

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

the class RuleSetNodeVisitor method visitNode.

@Override
public void visitNode(WorkflowProcess process, String factoryField, RuleSetNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    String nodeName = node.getName();
    body.addStatement(getAssignedFactoryMethod(factoryField, RuleSetNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Rule"));
    RuleSetNode.RuleType ruleType = node.getRuleType();
    if (ruleType.getName().isEmpty()) {
        throw new IllegalArgumentException(MessageFormat.format("Rule task \"{0}\" is invalid: you did not set a unit name, a rule flow group or a decision model.", nodeName));
    }
    addNodeMappings(process, node, body, getNodeId(node));
    addParams(node, body, getNodeId(node));
    NameExpr methodScope = new NameExpr(getNodeId(node));
    MethodCallExpr m;
    if (ruleType.isDecision()) {
        m = handleDecision((RuleSetNode.RuleType.Decision) ruleType);
    } else {
        throw new IllegalArgumentException("Rule task " + nodeName + "is invalid: unsupported rule language " + node.getLanguage());
    }
    m.setScope(methodScope);
    body.addStatement(m);
    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
}
Also used : RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) NameExpr(com.github.javaparser.ast.expr.NameExpr) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

RuleSetNode (io.automatiko.engine.workflow.process.core.node.RuleSetNode)12 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)4 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)4 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)4 Node (io.automatiko.engine.api.definition.process.Node)3 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)3 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)3 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)3 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)3 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)3 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)3 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)3 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)3 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)3 ArrayList (java.util.ArrayList)3 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)2 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)2 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)2 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)2 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)2