Search in sources :

Example 1 with TaskInputJqAssignmentAction

use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction 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 TaskInputJqAssignmentAction

use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction in project automatiko-engine by automatiko-io.

the class MappableNodeFactory method inMappingWithJqAssignment.

default MappableNodeFactory inMappingWithJqAssignment(String inputExpression, String... params) {
    Assignment assignment = new Assignment("jq", null, null);
    assignment.setMetaData("Action", new TaskInputJqAssignmentAction(inputExpression, params));
    getMappableNode().addInAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(assignment), null));
    return this;
}
Also used : Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) TaskInputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction)

Example 3 with TaskInputJqAssignmentAction

use of io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction in project automatiko-engine by automatiko-io.

the class AbstractNodeVisitor method addNodeMappings.

protected void addNodeMappings(WorkflowProcess process, Mappable node, BlockStmt body, String variableName) {
    boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
    if (serverless) {
        for (DataAssociation association : node.getInAssociations()) {
            if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
                TaskInputJqAssignmentAction action = (TaskInputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
                String inputFilter = action.getInputFilterExpression();
                Set<String> params = action.getParamNames();
                List<Expression> expressions = new ArrayList<>();
                expressions.add(inputFilter != null ? new StringLiteralExpr().setString(inputFilter) : new NullLiteralExpr());
                for (String param : params) {
                    expressions.add(param != null ? new StringLiteralExpr().setString(param) : new NullLiteralExpr());
                }
                body.addStatement(getFactoryMethod(variableName, METHOD_IN_JQ_MAPPING, expressions.toArray(Expression[]::new)));
            }
        }
        for (DataAssociation association : node.getOutAssociations()) {
            if (association.getAssignments() != null && !association.getAssignments().isEmpty()) {
                TaskOutputJqAssignmentAction action = (TaskOutputJqAssignmentAction) association.getAssignments().get(0).getMetaData("Action");
                String outputFilter = action.getOutputFilterExpression();
                String scopeFilter = action.getScopeFilter();
                body.addStatement(getFactoryMethod(variableName, METHOD_OUT_JQ_MAPPING, (outputFilter != null ? new StringLiteralExpr().setString(outputFilter) : new NullLiteralExpr()), (scopeFilter != null ? new StringLiteralExpr().setString(scopeFilter) : new NullLiteralExpr()), new BooleanLiteralExpr(action.isIgnoreScopeFilter())));
            }
        }
    } else {
        for (Entry<String, String> entry : node.getInMappings().entrySet()) {
            body.addStatement(getFactoryMethod(variableName, METHOD_IN_MAPPING, new StringLiteralExpr(entry.getKey()), new StringLiteralExpr(entry.getValue())));
        }
        for (Entry<String, String> entry : node.getOutMappings().entrySet()) {
            body.addStatement(getFactoryMethod(variableName, METHOD_OUT_MAPPING, new StringLiteralExpr(entry.getKey()), new StringLiteralExpr(entry.getValue())));
        }
    }
}
Also used : DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) TaskInputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction) ArrayList(java.util.ArrayList) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr)

Aggregations

TaskInputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction)3 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)3 TaskOutputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)2 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1 Work (io.automatiko.engine.workflow.base.core.Work)1 JsonNodeDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType)1 ParameterDefinitionImpl (io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl)1 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)1 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1