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;
}
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");
}
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;
}
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));
}
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)));
}
Aggregations