Search in sources :

Example 1 with ServerlessExecutableProcess

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;
}
Also used : Arrays(java.util.Arrays) TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode) Metadata(io.automatiko.engine.workflow.process.executable.core.Metadata) ExecutableProcessValidator(io.automatiko.engine.workflow.process.executable.core.validation.ExecutableProcessValidator) Constants(io.serverlessworkflow.api.workflow.Constants) LoggerFactory(org.slf4j.LoggerFactory) Workflow(io.serverlessworkflow.api.Workflow) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ConstraintImpl(io.automatiko.engine.workflow.process.core.impl.ConstraintImpl) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) OnEvents(io.serverlessworkflow.api.events.OnEvents) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) Set(java.util.Set) JsonVariableScope(io.automatiko.engine.workflow.base.core.context.variable.JsonVariableScope) ErrorDefinition(io.serverlessworkflow.api.error.ErrorDefinition) WorkflowExecTimeout(io.serverlessworkflow.api.timeouts.WorkflowExecTimeout) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) TextNode(com.fasterxml.jackson.databind.node.TextNode) List(java.util.List) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) Join(io.automatiko.engine.workflow.process.core.node.Join) StaticTagDefinition(io.automatiko.engine.workflow.base.core.StaticTagDefinition) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) WorkflowUtils(io.serverlessworkflow.utils.WorkflowUtils) Work(io.automatiko.engine.workflow.base.core.Work) ProcessValidationError(io.automatiko.engine.workflow.base.core.validation.ProcessValidationError) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) Action(io.serverlessworkflow.api.actions.Action) ServerlessExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) Split(io.automatiko.engine.workflow.process.core.node.Split) HashMap(java.util.HashMap) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) TaskInputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction) ProduceEvent(io.serverlessworkflow.api.produce.ProduceEvent) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) OutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.OutputJqAssignmentAction) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) FunctionDefinition(io.serverlessworkflow.api.functions.FunctionDefinition) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) ACTION(io.automatiko.engine.workflow.process.executable.core.Metadata.ACTION) Connection(io.automatiko.engine.api.definition.process.Connection) LinkedHashSet(java.util.LinkedHashSet) ActionDataFilter(io.serverlessworkflow.api.filters.ActionDataFilter) Logger(org.slf4j.Logger) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) Iterator(java.util.Iterator) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) DateTimeUtils(io.automatiko.engine.workflow.base.core.timer.DateTimeUtils) EventDefinition(io.serverlessworkflow.api.events.EventDefinition) RetryDefinition(io.serverlessworkflow.api.retry.RetryDefinition) End(io.serverlessworkflow.api.end.End) EventDataFilter(io.serverlessworkflow.api.filters.EventDataFilter) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ServerlessFunctions(io.automatiko.engine.workflow.sw.ServerlessFunctions) Process(io.automatiko.engine.workflow.base.core.Process) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) Collections(java.util.Collections) JsonNodeDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) StaticTagDefinition(io.automatiko.engine.workflow.base.core.StaticTagDefinition) StaticTagDefinition(io.automatiko.engine.workflow.base.core.StaticTagDefinition) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) JsonNodeDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType) ArrayList(java.util.ArrayList) Constants(io.serverlessworkflow.api.workflow.Constants) TextNode(com.fasterxml.jackson.databind.node.TextNode) ServerlessExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Process(io.automatiko.engine.workflow.base.core.Process) ServerlessExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ServerlessExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess)

Example 2 with ServerlessExecutableProcess

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);
    }
}
Also used : JsonVariableScope(io.automatiko.engine.workflow.base.core.context.variable.JsonVariableScope) ServerlessExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess)

Aggregations

JsonVariableScope (io.automatiko.engine.workflow.base.core.context.variable.JsonVariableScope)2 ServerlessExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ServerlessExecutableProcess)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 Connection (io.automatiko.engine.api.definition.process.Connection)1 Node (io.automatiko.engine.api.definition.process.Node)1 FunctionTagDefinition (io.automatiko.engine.workflow.base.core.FunctionTagDefinition)1 Process (io.automatiko.engine.workflow.base.core.Process)1 StaticTagDefinition (io.automatiko.engine.workflow.base.core.StaticTagDefinition)1 TagDefinition (io.automatiko.engine.workflow.base.core.TagDefinition)1 Work (io.automatiko.engine.workflow.base.core.Work)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)1 JsonNodeDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType)1 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)1 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)1 ParameterDefinitionImpl (io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl)1 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)1 DateTimeUtils (io.automatiko.engine.workflow.base.core.timer.DateTimeUtils)1 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)1