use of io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess 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;
}
use of io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess in project automatiko-engine by automatiko-io.
the class CompositeContextNodeFactory method setVariableScope.
protected void setVariableScope(NodeContainer nodeContainer, CompositeContextNode node) {
if (nodeContainer instanceof ServerlessExecutableProcess) {
JsonVariableScope variableScope = new JsonVariableScope();
node.addContext(variableScope);
node.setDefaultContext(variableScope);
}
}
Aggregations