Search in sources :

Example 1 with TaskOutputJqAssignmentAction

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

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

the class ServerlessWorkflowFactory method consumeEventNode.

public EventNode consumeEventNode(long id, EventDefinition eventDefinition, EventDataFilter eventDataFilter, NodeContainer nodeContainer) {
    EventNode eventNode = new EventNode();
    eventNode.setId(id);
    eventNode.setName(eventDefinition.getName());
    EventTypeFilter eventFilter = new EventTypeFilter();
    eventFilter.setType("Message-" + eventDefinition.getName());
    eventNode.addEventFilter(eventFilter);
    eventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    eventNode.setMetaData(Metadata.TRIGGER_TYPE, "ConsumeMessage");
    eventNode.setMetaData(Metadata.TRIGGER_REF, eventDefinition.getName());
    eventNode.setMetaData(Metadata.EVENT_TYPE, "message");
    eventNode.setMetaData(Metadata.MESSAGE_TYPE, JSON_NODE);
    eventNode.setMetaData(Metadata.TRIGGER_FILTER_EXPR, "hasAttributeWithValue(eventData, \"type\", \"" + eventDefinition.getType() + "\")");
    eventNode.setVariableName(DEFAULT_WORKFLOW_VAR);
    if (eventDefinition.getMetadata() != null) {
        eventDefinition.getMetadata().forEach((k, v) -> eventNode.setMetaData(k, v));
    }
    if (eventDefinition.getCorrelation() != null && !eventDefinition.getCorrelation().isEmpty()) {
        eventNode.setMetaData("TriggerCorrelationExpr", "extensionAttribute(eventData, \"" + eventDefinition.getCorrelation().get(0).getContextAttributeName() + "\")");
    }
    // if (ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()) != null) {
    // eventNode.setMetaData(Metadata.TRIGGER_CORRELATION_EXPR,
    // ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()));
    // }
    boolean useData = true;
    String outputFilter = null;
    String scopeFilter = null;
    if (eventDataFilter != null) {
        useData = eventDataFilter.isUseData();
        outputFilter = unwrapExpression(eventDataFilter.getData());
        scopeFilter = unwrapExpression(eventDataFilter.getToStateData());
    }
    if (useData) {
        Assignment outAssignment = new Assignment("jq", null, null);
        outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter, true));
        eventNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
    }
    nodeContainer.addNode(eventNode);
    return eventNode;
}
Also used : Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)

Example 3 with TaskOutputJqAssignmentAction

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

the class ServerlessWorkflowFactory method messageStartNode.

public StartNode messageStartNode(long id, EventDefinition eventDefinition, OnEvents onEvents, NodeContainer nodeContainer) {
    StartNode startNode = new StartNode();
    startNode.setId(id);
    startNode.setName(eventDefinition.getName());
    startNode.setMetaData(Metadata.TRIGGER_MAPPING, DEFAULT_WORKFLOW_VAR);
    startNode.setMetaData(Metadata.TRIGGER_TYPE, "ConsumeMessage");
    // if (ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()) != null) {
    // startNode.setMetaData(Metadata.TRIGGER_CORRELATION_EXPR,
    // ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()));
    // }
    startNode.setMetaData(Metadata.TRIGGER_REF, eventDefinition.getName());
    startNode.setMetaData(Metadata.MESSAGE_TYPE, JSON_NODE);
    if (eventDefinition.getCorrelation() != null && !eventDefinition.getCorrelation().isEmpty()) {
        startNode.setMetaData("TriggerCorrelationExpr", "extensionAttribute(eventData, \"" + eventDefinition.getCorrelation().get(0).getContextAttributeName() + "\")");
        startNode.setMetaData("acceptStartSignal", "true");
    }
    startNode.setMetaData(Metadata.TRIGGER_FILTER_EXPR, "hasAttributeWithValue(eventData, \"type\", \"" + eventDefinition.getType() + "\")");
    EventTrigger trigger = new EventTrigger();
    EventTypeFilter eventFilter = new EventTypeFilter();
    eventFilter.setType("Message-" + eventDefinition.getName());
    trigger.addEventFilter(eventFilter);
    String mapping = (String) startNode.getMetaData(Metadata.TRIGGER_MAPPING);
    if (mapping != null) {
        trigger.addInMapping(mapping, startNode.getOutMapping(mapping));
    }
    startNode.addTrigger(trigger);
    startNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    if (eventDefinition.getMetadata() != null) {
        eventDefinition.getMetadata().forEach((k, v) -> startNode.setMetaData(k, v));
    }
    // if (ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()) != null) {
    // eventNode.setMetaData(Metadata.TRIGGER_CORRELATION_EXPR,
    // ServerlessWorkflowUtils.correlationExpressionFromSource(eventDefinition.getSource()));
    // }
    boolean useData = true;
    String outputFilter = null;
    String scopeFilter = null;
    if (onEvents.getEventDataFilter() != null) {
        useData = onEvents.getEventDataFilter().isUseData();
        outputFilter = unwrapExpression(onEvents.getEventDataFilter().getData());
        scopeFilter = unwrapExpression(onEvents.getEventDataFilter().getToStateData());
    }
    if (useData) {
        Assignment outAssignment = new Assignment("jq", null, null);
        outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter, true));
        startNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
    }
    nodeContainer.addNode(startNode);
    return startNode;
}
Also used : Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)

Example 4 with TaskOutputJqAssignmentAction

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

the class StartNodeVisitor method visitNode.

@Override
public void visitNode(WorkflowProcess process, String factoryField, StartNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, StartNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Start")).addStatement(getFactoryMethod(getNodeId(node), METHOD_INTERRUPTING, new BooleanLiteralExpr(node.isInterrupting())));
    visitMetaData(node.getMetaData(), body, getNodeId(node));
    boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
    if (serverless) {
        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(getNodeId(node), 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 (DataAssociation entry : node.getOutAssociations()) {
            if (entry.getAssignments() != null && !entry.getAssignments().isEmpty()) {
                Assignment assignment = entry.getAssignments().get(0);
                body.addStatement(getFactoryMethod(getNodeId(node), "outMapping", new StringLiteralExpr(entry.getSources().get(0)), new NullLiteralExpr(), new StringLiteralExpr(assignment.getDialect()), new StringLiteralExpr(assignment.getFrom()), new StringLiteralExpr(assignment.getTo())));
            } else {
                body.addStatement(getFactoryMethod(getNodeId(node), "outMapping", new StringLiteralExpr(entry.getSources().get(0)), new StringLiteralExpr(entry.getTarget()), new NullLiteralExpr(), new NullLiteralExpr(), new NullLiteralExpr()));
            }
        }
    }
    body.addStatement(getDoneMethod(getNodeId(node)));
    if (node.getTimer() != null) {
        Timer timer = node.getTimer();
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TIMER, getOrNullExpr(timer.getDelay()), getOrNullExpr(timer.getPeriod()), getOrNullExpr(timer.getDate()), new IntegerLiteralExpr(node.getTimer().getTimeType())));
    } else if (node.getTriggers() != null && !node.getTriggers().isEmpty()) {
        Map<String, Object> nodeMetaData = node.getMetaData();
        TriggerMetaData trigger = new TriggerMetaData((String) nodeMetaData.get(TRIGGER_REF), (String) nodeMetaData.get(TRIGGER_TYPE), (String) nodeMetaData.get(MESSAGE_TYPE), (String) nodeMetaData.get(TRIGGER_MAPPING), String.valueOf(node.getId()), node.getName(), (String) nodeMetaData.get(TRIGGER_CORRELATION), (String) nodeMetaData.get(TRIGGER_CORRELATION_EXPR)).validate();
        trigger.addContext(node.getMetaData());
        trigger.addContext(Collections.singletonMap("_node_", node));
        // mark the trigger as capable of starting new instance only if this is top level start node
        if (node.getParentContainer() instanceof WorkflowProcess) {
            trigger.setStart(true);
        }
        metadata.addTrigger(trigger);
        handleTrigger(node, nodeMetaData, body, variableScope, metadata);
    } else {
        // since there is start node without trigger then make sure it is startable
        metadata.setStartable(true);
    }
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) StartNodeFactory(io.automatiko.engine.workflow.process.executable.core.factory.StartNodeFactory) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess)

Example 5 with TaskOutputJqAssignmentAction

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

TaskOutputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)6 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)6 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)5 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)2 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)2 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)2 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)2 TaskInputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Expression (com.github.javaparser.ast.expr.Expression)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 LongLiteralExpr (com.github.javaparser.ast.expr.LongLiteralExpr)1 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)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 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)1 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)1 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)1