Search in sources :

Example 1 with JsonNodeDataType

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) JsonNodeDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType) TaskInputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl)

Example 2 with JsonNodeDataType

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;
}
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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Work (io.automatiko.engine.workflow.base.core.Work)2 JsonNodeDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType)2 ParameterDefinitionImpl (io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl)2 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)2 TaskInputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction)2 TaskOutputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)2 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)2 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)2 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 JsonVariableScope (io.automatiko.engine.workflow.base.core.context.variable.JsonVariableScope)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)1 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)1