use of io.automatiko.engine.workflow.base.core.StaticTagDefinition 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.base.core.StaticTagDefinition in project automatiko-engine by automatiko-io.
the class ProcessHandler method processTags.
protected void processTags(WorkflowProcess process) {
String tags = (String) process.getMetaData().get("tags");
List<TagDefinition> tagDefinitions = new ArrayList<TagDefinition>();
if (tags != null) {
String[] tagList = tags.split(",");
int counter = 0;
for (String tag : tagList) {
boolean isExpression = PatternConstants.PARAMETER_MATCHER.matcher(tag).matches();
if (isExpression) {
tagDefinitions.add(new FunctionTagDefinition(String.valueOf(++counter), tag, (exp, vars) -> {
Map<String, Object> replacements = new HashMap<>();
Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(exp);
while (matcher.find()) {
String paramName = matcher.group(1);
Object value = MVEL.executeExpression(exp, vars.getVariables());
replacements.put(paramName, value);
}
for (Map.Entry<String, Object> replacement : replacements.entrySet()) {
exp = exp.replace("#{" + replacement.getKey() + "}", replacement.getValue().toString());
}
return exp;
}));
} else {
tagDefinitions.add(new StaticTagDefinition(String.valueOf(++counter), tag));
}
}
}
((Process) process).setTagDefinitions(tagDefinitions);
}
Aggregations