Search in sources :

Example 6 with BoundaryEventNode

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

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

the class ServerlessWorkflowFactory method compensationBoundaryEventNode.

public BoundaryEventNode compensationBoundaryEventNode(long id, String name, ExecutableProcess process, Node attachToNode) {
    BoundaryEventNode boundaryEventNode = new BoundaryEventNode();
    boundaryEventNode.setId(id);
    boundaryEventNode.setName(name);
    EventTypeFilter filter = new EventTypeFilter();
    filter.setType("Compensation");
    boundaryEventNode.addEventFilter(filter);
    boundaryEventNode.setAttachedToNodeId(Long.toString(attachToNode.getId()));
    boundaryEventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    boundaryEventNode.setMetaData("EventType", "compensation");
    boundaryEventNode.setMetaData("AttachedTo", Long.toString(attachToNode.getId()));
    process.addNode(boundaryEventNode);
    return boundaryEventNode;
}
Also used : EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)

Example 8 with BoundaryEventNode

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

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

the class BoundaryEventNodeInstance method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    BoundaryEventNode boundaryNode = (BoundaryEventNode) getEventNode();
    String attachedTo = boundaryNode.getAttachedToNodeId();
    Collection<NodeInstance> nodeInstances = ((NodeInstanceContainer) getProcessInstance()).getNodeInstances(true);
    if (type != null && type.startsWith("Compensation")) {
        // if not active && completed, signal
        if (!isAttachedToNodeActive(nodeInstances, attachedTo, type, event) && isAttachedToNodeCompleted(attachedTo)) {
            super.signalEvent(type, event);
        } else {
            cancel();
        }
    } else {
        if (isAttachedToNodeActive(nodeInstances, attachedTo, type, event)) {
            super.signalEvent(type, event);
        } else {
            cancel();
        }
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance)

Example 10 with BoundaryEventNode

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

the class SvgBpmnProcessImageGenerator method buildNodeContainer.

/*
     * Build methods
     */
protected void buildNodeContainer(int x, int y, NodeContainer nodeContainer, SVGGraphics2D g2) {
    try {
        for (Node node : nodeContainer.getNodes()) {
            if (node instanceof StartNode) {
                buildStartEvent(x, y, (StartNode) node, g2);
            } else if (node instanceof EndNode) {
                buildEndEvent(x, y, (EndNode) node, g2);
            } else if (node instanceof FaultNode) {
                buildErrorEndEvent(x, y, (FaultNode) node, g2);
            } else if (node instanceof BoundaryEventNode) {
                buildBoundaryEvent(x, y, node, g2);
            } else if (node instanceof EventNode || node instanceof StateNode) {
                buildIntermediateEvent(x, y, node, g2);
            } else if (node instanceof HumanTaskNode) {
                buildHumanTaskNode(x, y, (HumanTaskNode) node, g2);
            } else if (node instanceof ActionNode) {
                buildScriptTaskNode(x, y, (ActionNode) node, g2);
            } else if (node instanceof WorkItemNode) {
                buildServiceTaskNode(x, y, (WorkItemNode) node, g2);
            } else if (node instanceof Split || node instanceof Join) {
                buildGateway(x, y, node, g2);
            } else if (node instanceof ForEachNode) {
                buildNodeContainer(x(node), y(node), ((ForEachNode) node).getCompositeNode(), g2);
            } else if (node instanceof CompositeNode) {
                buildSubprocessNode(x, y, (CompositeNode) node, g2);
                int sx = x(node);
                int sy = y(node);
                buildNodeContainer(sx, sy, (CompositeNode) node, g2);
            } else if (node instanceof RuleSetNode) {
                buildBusinessRuleTaskNode(x, y, (RuleSetNode) node, g2);
            } else if (node instanceof TimerNode) {
                buildTimerEvent(x, y, (TimerNode) node, g2);
            } else if (node instanceof SubProcessNode) {
                buildCallActivity(x, y, (SubProcessNode) node, g2);
            }
            buildSequenceFlow(x, y, node, g2);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) 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) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) 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) 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) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) Join(io.automatiko.engine.workflow.process.core.node.Join) UncheckedIOException(java.io.UncheckedIOException) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode) Split(io.automatiko.engine.workflow.process.core.node.Split) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode)

Aggregations

BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)21 ArrayList (java.util.ArrayList)16 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)14 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)12 List (java.util.List)11 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)10 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)9 Map (java.util.Map)9 Node (io.automatiko.engine.api.definition.process.Node)8 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)8 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)8 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)8 NonAcceptingEventTypeFilter (io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter)6 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)6 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)6 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)6 Split (io.automatiko.engine.workflow.process.core.node.Split)5 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)5 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)5