use of io.automatiko.engine.workflow.process.core.node.DataAssociation 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);
}
}
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation 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));
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class AbstractNodeVisitor method addNodeMappings.
protected void addNodeMappings(WorkflowProcess process, Mappable node, BlockStmt body, String variableName) {
boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
if (serverless) {
for (DataAssociation association : node.getInAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
TaskInputJqAssignmentAction action = (TaskInputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String inputFilter = action.getInputFilterExpression();
Set<String> params = action.getParamNames();
List<Expression> expressions = new ArrayList<>();
expressions.add(inputFilter != null ? new StringLiteralExpr().setString(inputFilter) : new NullLiteralExpr());
for (String param : params) {
expressions.add(param != null ? new StringLiteralExpr().setString(param) : new NullLiteralExpr());
}
body.addStatement(getFactoryMethod(variableName, METHOD_IN_JQ_MAPPING, expressions.toArray(Expression[]::new)));
}
}
for (DataAssociation association : node.getOutAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
TaskOutputJqAssignmentAction action = (TaskOutputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String outputFilter = action.getOutputFilterExpression();
String scopeFilter = action.getScopeFilter();
body.addStatement(getFactoryMethod(variableName, METHOD_OUT_JQ_MAPPING, (outputFilter != null ? new StringLiteralExpr().setString(outputFilter) : new NullLiteralExpr()), (scopeFilter != null ? new StringLiteralExpr().setString(scopeFilter) : new NullLiteralExpr()), new BooleanLiteralExpr(action.isIgnoreScopeFilter())));
}
}
} else {
for (Entry<String, String> entry : node.getInMappings().entrySet()) {
body.addStatement(getFactoryMethod(variableName, METHOD_IN_MAPPING, new StringLiteralExpr(entry.getKey()), new StringLiteralExpr(entry.getValue())));
}
for (Entry<String, String> entry : node.getOutMappings().entrySet()) {
body.addStatement(getFactoryMethod(variableName, METHOD_OUT_MAPPING, new StringLiteralExpr(entry.getKey()), new StringLiteralExpr(entry.getValue())));
}
}
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class CompositeContextNodeVisitor method visitDataMapping.
protected void visitDataMapping(WorkflowProcess process, String contextNode, T node, BlockStmt body) {
boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
if (serverless) {
for (DataAssociation association : node.getInAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
InputJqAssignmentAction action = (InputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String inputFilter = action.getInputFilterExpression();
body.addStatement(getFactoryMethod(contextNode, METHOD_JQ_IN_MAPPING, (inputFilter != null ? new StringLiteralExpr().setString(inputFilter) : new NullLiteralExpr())));
}
}
for (DataAssociation association : node.getOutAssociations()) {
if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
OutputJqAssignmentAction action = (OutputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
String outputFilter = action.getOutputFilterExpression();
body.addStatement(getFactoryMethod(contextNode, METHOD_JQ_OUT_MAPPING, (outputFilter != null ? new StringLiteralExpr().setString(outputFilter) : new NullLiteralExpr())));
}
}
}
}
use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.
the class CompositeContextNodeFactory method outMappingWithJqAssignment.
public CompositeContextNodeFactory outMappingWithJqAssignment(String stateDataFilter) {
Assignment outputAssignment = new Assignment("jq", "", "");
outputAssignment.setMetaData("Action", new OutputJqAssignmentAction(stateDataFilter));
getCompositeNode().addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outputAssignment), null));
return this;
}
Aggregations