use of io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType 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.core.datatype.impl.type.JsonNodeDataType in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method createProcess.
public ExecutableProcess createProcess(Workflow workflow) {
ExecutableProcess process = new ServerlessExecutableProcess();
if (workflow.getId() != null && !workflow.getId().isEmpty()) {
process.setId(workflow.getId());
} else {
LOGGER.info("setting default id {}", DEFAULT_WORKFLOW_ID);
process.setId(DEFAULT_WORKFLOW_ID);
}
if (workflow.getName() != null && !workflow.getName().isEmpty()) {
process.setName(workflow.getName());
} else {
LOGGER.info("setting default name {}", DEFAULT_WORKFLOW_NAME);
process.setName(DEFAULT_WORKFLOW_NAME);
}
if (workflow.getVersion() != null && !workflow.getVersion().isEmpty()) {
process.setVersion(workflow.getVersion());
} else {
LOGGER.info("no workflow version found.");
}
if (workflow.getMetadata() != null && workflow.getMetadata().get("package") != null) {
process.setPackageName(workflow.getMetadata().get("package"));
} else {
process.setPackageName(DEFAULT_PACKAGE_NAME);
}
if (workflow.isKeepActive()) {
process.setAutoComplete(false);
process.setDynamic(true);
} else {
process.setAutoComplete(true);
}
process.setVisibility(DEFAULT_VISIBILITY);
if (workflow.getMetadata() != null) {
process.getMetaData().putAll(workflow.getMetadata());
}
if (workflow.getDescription() != null) {
process.setMetaData("Documentation", workflow.getDescription());
}
if (workflow.getConstants() != null) {
Constants constants = workflow.getConstants();
String value = constants.getConstantsDef().toString();
Variable constantsVariable = new Variable("contantsVariable", "$CONST", new JsonNodeDataType());
constantsVariable.setMetaData("value", value.replaceAll("\"", "\\\""));
process.getVariableScope().addVariable(constantsVariable);
}
if (workflow.getAnnotations() != null) {
List<TagDefinition> tagDefinitions = new ArrayList<TagDefinition>();
int counter = 0;
for (String tag : workflow.getAnnotations()) {
if (tag.startsWith("${")) {
tagDefinitions.add(new FunctionTagDefinition(String.valueOf(++counter), unwrapExpression(tag), (exp, vars) -> {
Object result = ServerlessFunctions.expression(vars, exp);
if (result instanceof TextNode) {
return ((TextNode) result).asText();
}
return result.toString();
}));
} else {
tagDefinitions.add(new StaticTagDefinition(String.valueOf(++counter), tag));
}
}
((Process) process).setTagDefinitions(tagDefinitions);
}
return process;
}
Aggregations