Search in sources :

Example 6 with DataAssociation

use of io.automatiko.engine.workflow.process.core.node.DataAssociation 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 7 with DataAssociation

use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.

the class ServiceTaskDescriptor method completeWorkItemViaHandler.

private MethodCallExpr completeWorkItemViaHandler() {
    ClassOrInterfaceType errorMapper = new ClassOrInterfaceType(null, implementation.equalsIgnoreCase("##webservice") ? "io.automatiko.engine.service.rest.WebErrorMapper" : "io.automatiko.engine.workflow.ErrorMapper");
    Expression name = null;
    Expression source = null;
    List<DataAssociation> outAssociations = workItemNode.getOutAssociations();
    if (hasReturn()) {
        if (outAssociations.isEmpty()) {
            name = new NullLiteralExpr();
        } else {
            name = new StringLiteralExpr(outAssociations.get(0).getSources().isEmpty() ? "workflowdata" : outAssociations.get(0).getSources().get(0));
        }
        source = new NameExpr("result");
    } else if (outAssociations.isEmpty()) {
        name = new NullLiteralExpr();
        source = new NullLiteralExpr();
    } else {
        name = new StringLiteralExpr(outAssociations.get(0).getSources().isEmpty() ? "workflowdata" : outAssociations.get(0).getSources().get(0));
        source = new NameExpr("result");
    }
    MethodCallExpr complitionHandlerCompleteMethod = new MethodCallExpr(new NameExpr("completionHandler"), "complete").addArgument(new MethodCallExpr(new NameExpr("workItem"), "getProcessId")).addArgument(name).addArgument(new NameExpr("workItem")).addArgument(new NameExpr("workItemManager")).addArgument(source).addArgument(new ObjectCreationExpr(null, errorMapper, NodeList.nodeList()));
    return complitionHandlerCompleteMethod;
}
Also used : NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 8 with DataAssociation

use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.

the class ActionNodeVisitor method visitNode.

@Override
public void visitNode(WorkflowProcess process, String factoryField, ActionNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, ActionNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Script"));
    // if there is trigger defined on end event create TriggerMetaData for it
    if (node.getMetaData(TRIGGER_REF) != null) {
        LambdaExpr lambda = TriggerMetaData.buildLambdaExpr(node, metadata);
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
    } else if (node.getMetaData(TRIGGER_TYPE) != null && node.getMetaData(TRIGGER_TYPE).equals("Compensation")) {
        // compensation
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, new ObjectCreationExpr(null, new ClassOrInterfaceType(null, "io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction"), NodeList.nodeList(new StringLiteralExpr((String) node.getMetaData("CompensationEvent"))))));
    } else if (node.getMetaData(TRIGGER_TYPE) != null && node.getMetaData(TRIGGER_TYPE).equals("Signal")) {
        // throw signal
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, new ObjectCreationExpr(null, new ClassOrInterfaceType(null, "io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction"), NodeList.nodeList(new StringLiteralExpr((String) node.getMetaData("Ref")), node.getMetaData("Variable") != null ? new StringLiteralExpr((String) node.getMetaData("Variable")) : new NullLiteralExpr()))));
    } else {
        String consequence = getActionConsequence(node.getAction());
        if (consequence == null || consequence.trim().isEmpty()) {
            throw new IllegalStateException("Action node " + node.getId() + " name '" + node.getName() + "' has no action defined");
        }
        BlockStmt actionBody = new BlockStmt();
        List<Variable> variables = variableScope.getVariables();
        variables.stream().filter(v -> consequence.contains(v.getName())).map(ActionNodeVisitor::makeAssignment).forEach(actionBody::addStatement);
        variables.stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(ActionNodeVisitor::makeAssignmentVersions).forEach(actionBody::addStatement);
        actionBody.addStatement(new NameExpr(consequence));
        LambdaExpr lambda = new // (kcontext) ->
        LambdaExpr(// (kcontext) ->
        new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
    }
    visitMetaData(node.getMetaData(), body, getNodeId(node));
    for (DataAssociation association : node.getInAssociations()) {
    }
    body.addStatement(getDoneMethod(getNodeId(node)));
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) UnknownType(com.github.javaparser.ast.type.UnknownType) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) Parameter(com.github.javaparser.ast.body.Parameter)

Example 9 with DataAssociation

use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method processInputMappings.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void processInputMappings() {
    VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
    for (DataAssociation association : getCompositeContextNode().getInAssociations()) {
        if (association.getTransformation() != null) {
            Transformation transformation = association.getTransformation();
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            if (transformer != null) {
                Object parameterValue = transformer.transform(transformation.getCompiledExpression(), getProcessInstance().getVariables());
                if (parameterValue != null) {
                    compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
                }
            }
        } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
            Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
                    logger.error("Continuing without setting parameter.");
                }
            }
            if (parameterValue != null) {
                compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
            }
        } else {
            association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
        }
    }
}
Also used : Context(io.automatiko.engine.workflow.base.core.Context) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) ContextInstanceFactoryRegistry(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactoryRegistry) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory) VARIABLE_SCOPE(io.automatiko.engine.workflow.base.core.context.variable.VariableScope.VARIABLE_SCOPE) Logger(org.slf4j.Logger) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Example 10 with DataAssociation

use of io.automatiko.engine.workflow.process.core.node.DataAssociation in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method triggerCompleted.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void triggerCompleted(String outType) {
    VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
    for (DataAssociation association : getCompositeContextNode().getOutAssociations()) {
        if (association.getTransformation() != null) {
            Transformation transformation = association.getTransformation();
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            if (transformer != null) {
                Object parameterValue = transformer.transform(transformation.getCompiledExpression(), compositeVariableScopeInstance.getVariables());
                if (parameterValue != null) {
                    getProcessInstance().setVariable(association.getTarget(), parameterValue);
                }
            }
        } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
            Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
                    logger.error("Continuing without setting parameter.");
                }
            }
            if (parameterValue != null) {
                getProcessInstance().setVariable(association.getTarget(), parameterValue);
            }
        } else {
            association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
        }
    }
    super.triggerCompleted(outType);
}
Also used : Context(io.automatiko.engine.workflow.base.core.Context) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) ContextInstanceFactoryRegistry(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactoryRegistry) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory) VARIABLE_SCOPE(io.automatiko.engine.workflow.base.core.context.variable.VariableScope.VARIABLE_SCOPE) Logger(org.slf4j.Logger) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Aggregations

DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)33 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)20 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)14 Transformation (io.automatiko.engine.workflow.process.core.node.Transformation)14 Map (java.util.Map)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)10 NodeInstanceResolverFactory (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory)9 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)7 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)7 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)7 Matcher (java.util.regex.Matcher)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Element (org.w3c.dom.Element)6 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)4 DataType (io.automatiko.engine.api.workflow.datatype.DataType)4 DataTransformerRegistry (io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry)4