use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method serviceNode.
public WorkItemNode serviceNode(long id, Action action, FunctionDefinition function, NodeContainer nodeContainer) {
String actionName = action.getName();
String[] operationParts = function.getOperation().split("#");
String interfaceStr = operationParts[0];
String operationStr = operationParts[1];
WorkItemNode workItemNode = new WorkItemNode();
workItemNode.setId(id);
workItemNode.setName(actionName);
workItemNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
workItemNode.setMetaData("Type", SERVICE_TASK_TYPE);
workItemNode.setMetaData("Implementation", "##WebService");
Work work = new WorkImpl();
workItemNode.setWork(work);
work.setName(SERVICE_TASK_TYPE);
work.setParameter("Interface", interfaceStr);
work.setParameter("Operation", operationStr);
work.setParameter("interfaceImplementationRef", interfaceStr);
work.setParameter("implementation", "##WebService");
JsonNode params = action.getFunctionRef().getArguments();
String inputFilter = null;
String outputFilter = null;
String scopeFilter = null;
if (action.getActionDataFilter() != null) {
inputFilter = unwrapExpression(action.getActionDataFilter().getFromStateData());
outputFilter = unwrapExpression(action.getActionDataFilter().getResults());
scopeFilter = unwrapExpression(action.getActionDataFilter().getToStateData());
}
Set<String> paramNames = new LinkedHashSet<>();
if (params != null) {
Iterator<String> it = params.fieldNames();
while (it.hasNext()) {
String name = it.next();
String value = params.get(name).toString();
work.setParameter(name, unwrapExpression(value));
paramNames.add(name);
work.addParameterDefinition(new ParameterDefinitionImpl(name, new JsonNodeDataType()));
}
} else {
work.setParameter("ParameterType", JSON_NODE);
}
Assignment assignment = new Assignment("jq", null, null);
assignment.setMetaData("Action", new TaskInputJqAssignmentAction(inputFilter, paramNames));
workItemNode.addInAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(assignment), null));
Assignment outAssignment = new Assignment("jq", null, null);
outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter));
workItemNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
nodeContainer.addNode(workItemNode);
return workItemNode;
}
use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction in project automatiko-engine by automatiko-io.
the class MappableNodeFactory method inMappingWithJqAssignment.
default MappableNodeFactory inMappingWithJqAssignment(String inputExpression, String... params) {
Assignment assignment = new Assignment("jq", null, null);
assignment.setMetaData("Action", new TaskInputJqAssignmentAction(inputExpression, params));
getMappableNode().addInAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(assignment), null));
return this;
}
use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction 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())));
}
}
}
Aggregations