Search in sources :

Example 6 with Node

use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method connect.

public Connection connect(long fromId, long toId, String uniqueId, NodeContainer nodeContainer, boolean association) {
    Node from = nodeContainer.getNode(fromId);
    Node to = nodeContainer.getNode(toId);
    ConnectionImpl connection = new ConnectionImpl(from, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, to, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
    connection.setMetaData(UNIQUE_ID_PARAM, uniqueId);
    if (association) {
        connection.setMetaData("association", true);
    }
    return connection;
}
Also used : TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)

Example 7 with Node

use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method errorBoundaryEventNode.

public BoundaryEventNode errorBoundaryEventNode(long id, List<ErrorDefinition> defs, RetryDefinition retry, NodeContainer nodeContainer, Node attachedTo, Workflow workflow) {
    BoundaryEventNode boundaryEventNode = new BoundaryEventNode();
    boundaryEventNode.setId(id);
    boundaryEventNode.setName(defs.stream().map(def -> def.getName()).collect(Collectors.joining("|")));
    String errorCodes = defs.stream().map(def -> def.getCode()).collect(Collectors.joining(","));
    String attachedToId = (String) attachedTo.getMetaData().getOrDefault(UNIQUE_ID_PARAM, Long.toString(attachedTo.getId()));
    EventTypeFilter filter = new EventTypeFilter();
    filter.setType("Error-" + attachedToId + "-" + errorCodes);
    boundaryEventNode.addEventFilter(filter);
    boundaryEventNode.setAttachedToNodeId(attachedToId);
    boundaryEventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    boundaryEventNode.setMetaData("EventType", "error");
    boundaryEventNode.setMetaData("ErrorEvent", errorCodes);
    boundaryEventNode.setMetaData("AttachedTo", attachedToId);
    boundaryEventNode.setMetaData("HasErrorEvent", true);
    if (retry != null) {
        int delayAsInt = ((Long) DateTimeUtils.parseDuration(retry.getDelay())).intValue();
        boundaryEventNode.setMetaData("ErrorRetry", retry.getDelay() == null ? DEFAULT_RETRY_AFTER : delayAsInt);
        boundaryEventNode.setMetaData("ErrorRetryLimit", retry.getMaxAttempts() == null ? DEFAULT_RETRY_LIMIT : Integer.parseInt(retry.getMaxAttempts()));
        if (retry.getMultiplier() != null) {
            boundaryEventNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat(retry.getMultiplier()));
        }
    }
    nodeContainer.addNode(boundaryEventNode);
    return boundaryEventNode;
}
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) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)

Example 8 with Node

use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.

the class ServiceTaskDescriptor method collectHandledErrorCodes.

private Set<String> collectHandledErrorCodes() {
    Set<String> errorCodes = new HashSet<>();
    NodeContainer container = workItemNode.getParentContainer();
    String thisNodeId = (String) workItemNode.getMetaData("UniqueId");
    for (Node node : container.getNodes()) {
        if (node instanceof BoundaryEventNode) {
            String errorCode = (String) node.getMetaData().get("ErrorEvent");
            if (errorCode != null && ((BoundaryEventNode) node).getAttachedToNodeId().equals(thisNodeId)) {
                errorCodes.add(errorCode);
            }
        }
    }
    // next collect event subprocess node with error start event from this level and to all parents
    String replaceRegExp = "Error-|Escalation-";
    for (Node node : container.getNodes()) {
        if (node instanceof EventSubProcessNode) {
            EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
            Node[] nodes = eventSubProcessNode.getNodes();
            for (Node subNode : nodes) {
                // avoids cyclomatic complexity
                if (subNode == null || !(subNode instanceof StartNode)) {
                    continue;
                }
                List<Trigger> triggers = ((StartNode) subNode).getTriggers();
                if (triggers == null) {
                    continue;
                }
                for (Trigger trigger : triggers) {
                    if (trigger instanceof EventTrigger) {
                        final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                        for (EventFilter filter : filters) {
                            if (filter instanceof EventTypeFilter) {
                                eventSubProcessNode.addEvent((EventTypeFilter) filter);
                                String type = ((EventTypeFilter) filter).getType();
                                if (type.startsWith("Error-")) {
                                    String trimmedType = type.replaceFirst(replaceRegExp, "");
                                    for (String error : trimmedType.split(",")) {
                                        errorCodes.add(error);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return errorCodes;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Node(io.automatiko.engine.api.definition.process.Node) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) HashSet(java.util.HashSet) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 9 with Node

use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.

the class CompositeNodeInstance method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    List<NodeInstance> currentView = new ArrayList<>(this.nodeInstances);
    super.signalEvent(type, event);
    for (Node node : getCompositeNode().internalGetNodes()) {
        if (node instanceof EventNodeInterface && ((EventNodeInterface) node).acceptsEvent(type, event)) {
            if (node instanceof EventNode && ((EventNode) node).getFrom() == null || node instanceof EventSubProcessNode) {
                EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
                eventNodeInstance.signalEvent(type, event);
            } else {
                List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
                if (nodeInstances != null && !nodeInstances.isEmpty()) {
                    for (NodeInstance nodeInstance : nodeInstances) {
                        ((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
                    }
                }
            }
        }
        if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) {
            NodeInstance nodeInstance = getNodeInstance(node);
            if (nodeInstance != null) {
                if (event != null) {
                    Map<String, Object> dynamicParams = new HashMap<>(getProcessInstance().getVariables());
                    if (event instanceof Map) {
                        dynamicParams.putAll((Map<String, Object>) event);
                    } else if (event instanceof WorkflowProcessInstance) {
                    // ignore variables of process instance type
                    } else {
                        dynamicParams.put("Data", event);
                    }
                    nodeInstance.setDynamicParameters(dynamicParams);
                }
                nodeInstance.trigger(null, null);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EventNodeInterface(io.automatiko.engine.workflow.process.core.node.EventNodeInterface) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ArrayList(java.util.ArrayList) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 10 with Node

use of io.automatiko.engine.api.definition.process.Node in project automatiko-engine by automatiko-io.

the class ExecutableProcessValidator method validateCompensationIntermediateOrEndEvent.

protected void validateCompensationIntermediateOrEndEvent(Node node, ExecutableProcess process, List<ProcessValidationError> errors) {
    if (node.getMetaData().containsKey("Compensation")) {
        // Validate that activityRef in throw/end compensation event refers to "visible"
        // compensation
        String activityRef = (String) node.getMetaData().get("Compensation");
        Node refNode = null;
        if (activityRef != null) {
            Queue<Node> nodeQueue = new LinkedList<>();
            nodeQueue.addAll(Arrays.asList(process.getNodes()));
            while (!nodeQueue.isEmpty()) {
                Node polledNode = nodeQueue.poll();
                if (activityRef.equals(polledNode.getMetaData().get("UniqueId"))) {
                    refNode = polledNode;
                    break;
                }
                if (node instanceof NodeContainer) {
                    nodeQueue.addAll(Arrays.asList(((NodeContainer) node).getNodes()));
                }
            }
        }
        if (refNode == null) {
            addErrorMessage(process, node, errors, "Does not reference an activity that exists (" + activityRef + ") in its compensation event definition.");
        }
        CompensationScope compensationScope = (CompensationScope) ((NodeImpl) node).resolveContext(CompensationScope.COMPENSATION_SCOPE, activityRef);
        if (compensationScope == null) {
            addErrorMessage(process, node, errors, "References an activity (" + activityRef + ") in its compensation event definition that is not visible to it.");
        }
    }
}
Also used : TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) ForEachSplitNode(io.automatiko.engine.workflow.process.core.node.ForEachNode.ForEachSplitNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ForEachJoinNode(io.automatiko.engine.workflow.process.core.node.ForEachNode.ForEachJoinNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ThrowLinkNode(io.automatiko.engine.workflow.process.core.node.ThrowLinkNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CatchLinkNode(io.automatiko.engine.workflow.process.core.node.CatchLinkNode) Node(io.automatiko.engine.api.definition.process.Node) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) CompensationScope(io.automatiko.engine.workflow.base.core.context.exception.CompensationScope) LinkedList(java.util.LinkedList)

Aggregations

Node (io.automatiko.engine.api.definition.process.Node)67 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)37 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)33 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)33 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)32 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)28 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)28 ArrayList (java.util.ArrayList)26 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)24 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)24 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)23 HumanTaskNode (io.automatiko.engine.workflow.process.core.node.HumanTaskNode)20 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)19 StateBasedNode (io.automatiko.engine.workflow.process.core.node.StateBasedNode)17 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)16 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)16 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)14 RuleSetNode (io.automatiko.engine.workflow.process.core.node.RuleSetNode)14 List (java.util.List)14 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)13