Search in sources :

Example 1 with ActionDataFilter

use of io.serverlessworkflow.api.filters.ActionDataFilter in project kogito-runtimes by kiegroup.

the class CompositeContextNodeHandler method getActionNode.

public MakeNodeResult getActionNode(RuleFlowNodeContainerFactory<?, ?> embeddedSubProcess, Action action, String collectVar, String... extraVariables) {
    ActionDataFilter actionFilter = action.getActionDataFilter();
    String fromExpr = null;
    String resultExpr = null;
    String toExpr = null;
    boolean useData = true;
    if (actionFilter != null) {
        fromExpr = actionFilter.getFromStateData();
        resultExpr = actionFilter.getResults();
        toExpr = actionFilter.getToStateData();
        useData = actionFilter.isUseResults();
    }
    if (action.getFunctionRef() != null) {
        return filterAndMergeNode(embeddedSubProcess, fromExpr, resultExpr, toExpr, useData, (factory, inputVar, outputVar) -> getActionNode(factory, action.getFunctionRef(), inputVar, outputVar, collectVar, extraVariables));
    } else if (action.getEventRef() != null) {
        return filterAndMergeNode(embeddedSubProcess, fromExpr, resultExpr, toExpr, useData, (factory, inputVar, outputVar) -> getActionNode(factory, action.getEventRef(), inputVar));
    } else if (action.getSubFlowRef() != null) {
        return filterAndMergeNode(embeddedSubProcess, fromExpr, resultExpr, toExpr, useData, (factory, inputVar, outputVar) -> getActionNode(factory, action.getSubFlowRef(), inputVar, outputVar));
    } else {
        throw new IllegalArgumentException("Action node " + action.getName() + " of state " + state.getName() + " does not have function or event defined");
    }
}
Also used : ServerlessWorkflowParser(org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser) RestBodyBuilderSupplier(org.kie.kogito.serverless.workflow.suppliers.RestBodyBuilderSupplier) SysoutActionSupplier(org.kie.kogito.serverless.workflow.suppliers.SysoutActionSupplier) ObjectResolver(org.kie.kogito.serverless.workflow.ObjectResolver) Action(io.serverlessworkflow.api.actions.Action) HashMap(java.util.HashMap) NodeFactory(org.jbpm.ruleflow.core.factory.NodeFactory) ExpressionActionSupplier(org.kie.kogito.serverless.workflow.suppliers.ExpressionActionSupplier) Workflow(io.serverlessworkflow.api.Workflow) JsonNodeResolver(org.kie.kogito.serverless.workflow.JsonNodeResolver) JsonObjectUtils(org.kie.kogito.jackson.utils.JsonObjectUtils) OpenApiTaskDescriptor(org.jbpm.compiler.canonical.descriptors.OpenApiTaskDescriptor) WorkItemNodeFactory(org.jbpm.ruleflow.core.factory.WorkItemNodeFactory) FunctionDefinition(io.serverlessworkflow.api.functions.FunctionDefinition) Map(java.util.Map) CompositeContextNodeFactory(org.jbpm.ruleflow.core.factory.CompositeContextNodeFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) FunctionRef(io.serverlessworkflow.api.functions.FunctionRef) ParserContext(org.kie.kogito.serverless.workflow.parser.ParserContext) ExpressionWorkItemResolver(org.kie.kogito.process.expr.ExpressionWorkItemResolver) ActionDataFilter(io.serverlessworkflow.api.filters.ActionDataFilter) AbstractServiceTaskDescriptor(org.jbpm.compiler.canonical.descriptors.AbstractServiceTaskDescriptor) Iterator(java.util.Iterator) EventRef(io.serverlessworkflow.api.events.EventRef) RuleFlowNodeContainerFactory(org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory) AbstractCompositeNodeFactory(org.jbpm.ruleflow.core.factory.AbstractCompositeNodeFactory) DataTypeResolver(org.jbpm.process.core.datatype.DataTypeResolver) JsonNodeVisitor(org.kie.kogito.jackson.utils.JsonNodeVisitor) ExpressionHandlerFactory(org.kie.kogito.process.expr.ExpressionHandlerFactory) List(java.util.List) State(io.serverlessworkflow.api.interfaces.State) RestWorkItemHandler(org.kogito.workitem.rest.RestWorkItemHandler) ExpressionHandlerUtils(org.kie.kogito.serverless.workflow.utils.ExpressionHandlerUtils) JavaDialect(org.drools.mvel.java.JavaDialect) Entry(java.util.Map.Entry) TaskDescriptor(org.jbpm.compiler.canonical.descriptors.TaskDescriptor) ServerlessWorkflowUtils(org.kie.kogito.serverless.workflow.utils.ServerlessWorkflowUtils) SubFlowRef(io.serverlessworkflow.api.functions.SubFlowRef) ActionDataFilter(io.serverlessworkflow.api.filters.ActionDataFilter)

Example 2 with ActionDataFilter

use of io.serverlessworkflow.api.filters.ActionDataFilter in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method expressionActionStateNode.

public ActionNode expressionActionStateNode(long id, String name, NodeContainer nodeContainer, String expression, Action action) {
    ActionNode actionNode = new ActionNode();
    actionNode.setId(id);
    actionNode.setName(name);
    ActionDataFilter actionDataFilter = action.getActionDataFilter();
    StringBuilder functionArguments = new StringBuilder();
    if (action.getFunctionRef().getArguments() != null) {
        functionArguments.append("(");
        for (JsonNode argument : action.getFunctionRef().getArguments()) {
            functionArguments.append(unwrapExpression(argument.toString())).append(",");
        }
        functionArguments.deleteCharAt(functionArguments.length() - 1);
        functionArguments.append(")");
    }
    String inputFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getFromStateData());
    String outputFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getResults());
    String scopeFilter = actionDataFilter == null ? null : unwrapExpression(actionDataFilter.getToStateData());
    ConsequenceAction processAction = new ConsequenceAction(null, "expression(context, " + escapeExpression(expression + functionArguments) + ", " + escapeExpression(inputFilter) + ");");
    if (actionDataFilter != null && actionDataFilter.isUseResults()) {
        processAction = new ConsequenceAction(null, "expression(context, " + escapeExpression(expression + functionArguments) + ", " + escapeExpression(inputFilter) + ", " + escapeExpression(outputFilter) + ", " + escapeExpression(scopeFilter) + ");");
    }
    io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
        if (actionDataFilter != null && actionDataFilter.isUseResults()) {
            io.automatiko.engine.workflow.sw.ServerlessFunctions.expression(context, expression, inputFilter, outputFilter, scopeFilter);
        } else {
            io.automatiko.engine.workflow.sw.ServerlessFunctions.expression(context, expression, inputFilter);
        }
    };
    processAction.setMetaData(ACTION, injectAction);
    actionNode.setAction(processAction);
    nodeContainer.addNode(actionNode);
    return actionNode;
}
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) ActionDataFilter(io.serverlessworkflow.api.filters.ActionDataFilter) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)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 Work (io.automatiko.engine.workflow.base.core.Work)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 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 ProcessValidationError (io.automatiko.engine.workflow.base.core.validation.ProcessValidationError)1