Search in sources :

Example 1 with ActionNode

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

the class DefinitionsHandler method postProcessNodes.

protected void postProcessNodes(NodeContainer nodeContainer, List<Variable> parentVariables, ExtensibleXmlParser parser) throws SAXException {
    for (Node node : nodeContainer.getNodes()) {
        List<Variable> variables = new LinkedList<>(parentVariables);
        VariableScope variableScope = (VariableScope) ((ContextContainer) nodeContainer).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        if (variableScope != null) {
            variables.addAll(variableScope.getVariables());
        }
        if (node instanceof NodeContainer) {
            postProcessNodes((NodeContainer) node, variables, parser);
        } else {
            if (node instanceof ActionNode) {
                ActionNode actionNode = (ActionNode) node;
                ProcessAction action = actionNode.getAction();
                if (action instanceof ConsequenceAction) {
                    ConsequenceAction consequenceAction = (ConsequenceAction) action;
                    switch(consequenceAction.getDialect()) {
                        case "java":
                            if (actionNode.getAction().getMetaData("Action") == null) {
                                actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
                            }
                            break;
                        case "mvel":
                            if (actionNode.getAction().getMetaData("Action") == null) {
                                actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
                            }
                            break;
                        default:
                    }
                }
            }
        }
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Node(io.automatiko.engine.api.definition.process.Node) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) LinkedList(java.util.LinkedList) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 2 with ActionNode

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

the class IntermediateThrowEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String inputName = ((Element) xmlNode).getAttribute("name");
            dataInputs.put(id, inputName);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, actionNode, parser);
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new IllegalArgumentException("Could not find message " + messageRef);
            }
            String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
            Variable v = (Variable) ((ProcessBuildData) parser.getData()).getMetaData("Variable");
            if (v != null) {
                variable = (String) v.getMetaData(variable);
            }
            actionNode.setMetaData("MessageType", message.getType());
            actionNode.setMetaData("TriggerType", "ProduceMessage");
            actionNode.setMetaData("TriggerRef", message.getName());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                actionNode.setMetaData(entry.getKey(), entry.getValue());
            }
            ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable, (Transformation) actionNode.getMetaData().get(TRANSFORMATION_KEY)));
            actionNode.setAction(action);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Message(io.automatiko.engine.workflow.bpmn2.core.Message) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) HandleMessageAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleMessageAction) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 3 with ActionNode

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

the class IntermediateThrowEventHandler method handleEscalationNode.

@SuppressWarnings("unchecked")
public void handleEscalationNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    ActionNode actionNode = (ActionNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, actionNode, parser);
        } else if ("escalationEventDefinition".equals(nodeName)) {
            String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
            if (escalationRef != null && escalationRef.trim().length() > 0) {
                Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
                if (escalations == null) {
                    throw new IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                String faultName = escalation.getEscalationCode();
                String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
                ConsequenceAction action = createJavaAction(new HandleEscalationAction(faultName, variable));
                actionNode.setAction(action);
                actionNode.setMetaData("TriggerType", "Escalation");
            } else {
                throw new IllegalArgumentException("General escalation is not yet supported");
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) HandleEscalationAction(io.automatiko.engine.workflow.base.instance.impl.actions.HandleEscalationAction)

Example 4 with ActionNode

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

the class ServerlessWorkflowFactory method compensationEventNode.

public ActionNode compensationEventNode(long id, String name, NodeContainer nodeContainer, ExecutableProcess process) {
    ActionNode compensationEventNode = new ActionNode();
    compensationEventNode.setId(id);
    compensationEventNode.setName(name);
    compensationEventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    ProcessInstanceCompensationAction pic = new ProcessInstanceCompensationAction("implicit:" + process.getId());
    ProcessAction processAction = new ProcessAction();
    processAction.setMetaData(ACTION, pic);
    compensationEventNode.setAction(processAction);
    compensationEventNode.setMetaData(Metadata.TRIGGER_TYPE, "Compensation");
    compensationEventNode.setMetaData("NodeType", "IntermediateThrowEvent-None");
    compensationEventNode.setMetaData("CompensationEvent", "implicit:" + process.getId());
    nodeContainer.addNode(compensationEventNode);
    return compensationEventNode;
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction)

Example 5 with ActionNode

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

the class ServerlessWorkflowFactory method stateDataFilterActionNode.

public ActionNode stateDataFilterActionNode(long id, String name, NodeContainer nodeContainer, String outputFilterString) {
    ActionNode actionNode = new ActionNode();
    actionNode.setId(id);
    actionNode.setName(name);
    String outputFilter = unwrapExpression(outputFilterString);
    ConsequenceAction processAction = new ConsequenceAction(null, "new io.automatiko.engine.workflow.base.instance.impl.jq.OutputJqAssignmentAction(" + escapeExpression(outputFilter) + ").execute(null, context);");
    io.automatiko.engine.workflow.base.instance.impl.Action injectAction = context -> {
        new OutputJqAssignmentAction(outputFilter).execute(null, context);
    };
    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) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) OutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.OutputJqAssignmentAction) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)

Aggregations

ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)38 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)25 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)20 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)19 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)18 ArrayList (java.util.ArrayList)18 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)15 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)15 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)13 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)12 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)11 List (java.util.List)11 Node (io.automatiko.engine.api.definition.process.Node)10 Action (io.automatiko.engine.workflow.base.instance.impl.Action)10 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)10 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)10 Map (java.util.Map)10 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)9 NodeContainer (io.automatiko.engine.workflow.process.core.NodeContainer)9 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)9