Search in sources :

Example 16 with CompositeNode

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

the class NodeImpl method getUniqueId.

public String getUniqueId() {
    String result = id + "";
    NodeContainer nodeContainer = getParentContainer();
    while (nodeContainer instanceof CompositeNode) {
        CompositeNode composite = (CompositeNode) nodeContainer;
        result = composite.getId() + ":" + result;
        nodeContainer = composite.getParentContainer();
    }
    return result;
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer)

Example 17 with CompositeNode

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

the class CompensationTest method createCompensationEventSubProcessProcess.

private ExecutableProcess createCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
    NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    // outer process
    StartNode startNode = startNodeCreator.createNode("start0");
    WorkItemNode workItemNode = workItemNodeCreator.createNode("work0-pre");
    workItemNode.getWork().setName(workItemNames[0]);
    connect(startNode, workItemNode);
    CompositeNode compositeNode = compNodeCreator.createNode("sub0");
    connect(workItemNode, compositeNode);
    workItemNode = workItemNodeCreator.createNode("work0-post");
    workItemNode.getWork().setName(workItemNames[2]);
    connect(compositeNode, workItemNode);
    EndNode endNode = endNodeCreator.createNode("end0");
    connect(workItemNode, endNode);
    // 1rst level nested subprocess
    startNodeCreator.setNodeContainer(compositeNode);
    workItemNodeCreator.setNodeContainer(compositeNode);
    endNodeCreator.setNodeContainer(compositeNode);
    startNode = startNodeCreator.createNode("start1");
    workItemNode = workItemNodeCreator.createNode("work1");
    workItemNode.getWork().setName(workItemNames[1]);
    connect(startNode, workItemNode);
    endNode = endNodeCreator.createNode("end1");
    connect(workItemNode, endNode);
    // 2nd level nested event subprocess in 1rst level subprocess
    NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
    EventSubProcessNode espNode = espNodeCreator.createNode("eventSub1");
    EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
    eventFilter.setType("Compensation");
    espNode.addEvent(eventFilter);
    addCompensationScope(espNode, process, (String) compositeNode.getMetaData("UniqueId"));
    startNodeCreator.setNodeContainer(espNode);
    endNodeCreator.setNodeContainer(espNode);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
    startNode = startNodeCreator.createNode("start1*");
    ActionNode actionNode = actionNodeCreator.createNode("action1*");
    actionNode.setName("Execute");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            eventList.add("Executed action");
        }
    });
    actionNode.setAction(action);
    connect(startNode, actionNode);
    endNode = endNodeCreator.createNode("end1*");
    connect(actionNode, endNode);
    return process;
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 18 with CompositeNode

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

the class CompensationTest method createNestedCompensationBoundaryEventProcess.

private ExecutableProcess createNestedCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType(java.lang.String.class);
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
    // process level
    CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
    {
        StartNode startNode = startNodeCreator.createNode("start0");
        connect(startNode, compositeNode);
        EndNode endNode = endNodeCreator.createNode("end0");
        connect(compositeNode, endNode);
    }
    // 1rst level nested subprocess (contains compensation visibility scope)
    {
        startNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start1");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
        connect(startNode, subCompNode);
        EndNode endNode = endNodeCreator.createNode("end1");
        connect(subCompNode, endNode);
        compositeNode = subCompNode;
    }
    // 2nd level nested subprocess (contains compensation visibility scope)
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
    {
        startNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start2");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub2");
        connect(startNode, subCompNode);
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
        workItemNode.getWork().setName(workItemNames[2]);
        connect(subCompNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end2");
        connect(workItemNode, endNode);
        createBoundaryEventCompensationHandler(compositeNode, workItemNode, eventList, "2");
        compositeNode = subCompNode;
    }
    // Fill 3rd level with process with compensation
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start");
        Node lastNode = startNode;
        WorkItemNode[] workItemNodes = new WorkItemNode[3];
        for (int i = 0; i < 2; ++i) {
            workItemNodes[i] = workItemNodeCreator.createNode("work-comp-" + (i + 1));
            workItemNodes[i].getWork().setName(workItemNames[i]);
            connect(lastNode, workItemNodes[i]);
            lastNode = workItemNodes[i];
        }
        EndNode endNode = endNodeCreator.createNode("end");
        connect(workItemNodes[1], endNode);
        // Compensation (boundary event) handlers
        for (int i = 0; i < 2; ++i) {
            createBoundaryEventCompensationHandler(compositeNode, workItemNodes[i], eventList, "" + i + 1);
        }
    }
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) 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) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 19 with CompositeNode

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

the class WorkflowProcessInstanceImpl method getEventDescriptions.

@Override
public Set<EventDescription<?>> getEventDescriptions() {
    if (getState() == ProcessInstance.STATE_COMPLETED || getState() == ProcessInstance.STATE_ABORTED) {
        return Collections.emptySet();
    }
    VariableScope variableScope = (VariableScope) ((ContextContainer) getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<EventDescription<?>> eventDesciptions = new LinkedHashSet<>();
    List<EventListener> activeListeners = eventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList());
    activeListeners.addAll(externalEventListeners.values().stream().flatMap(List::stream).collect(Collectors.toList()));
    activeListeners.forEach(el -> eventDesciptions.addAll(el.getEventDescriptions()));
    ((io.automatiko.engine.workflow.process.core.WorkflowProcess) getProcess()).getNodesRecursively().stream().filter(n -> n instanceof EventNodeInterface).forEach(n -> {
        NamedDataType dataType = null;
        if (((EventNodeInterface) n).getVariableName() != null) {
            Map<String, Object> dataOutputs = (Map<String, Object>) n.getMetaData().get("DataOutputs");
            if (dataOutputs != null) {
                for (Entry<String, Object> dOut : dataOutputs.entrySet()) {
                    dataType = new NamedDataType(dOut.getKey(), dOut.getValue());
                }
            } else {
                Variable eventVar = variableScope.findVariable(((EventNodeInterface) n).getVariableName());
                if (eventVar != null) {
                    dataType = new NamedDataType(eventVar.getName(), eventVar.getType());
                }
            }
        }
        if (n instanceof BoundaryEventNode) {
            BoundaryEventNode boundaryEventNode = (BoundaryEventNode) n;
            StateBasedNodeInstance attachedToNodeInstance = (StateBasedNodeInstance) getNodeInstances(true).stream().filter(ni -> ni.getNode().getMetaData().get(UNIQUE_ID).equals(boundaryEventNode.getAttachedToNodeId())).findFirst().orElse(null);
            if (attachedToNodeInstance != null) {
                Map<String, String> properties = new HashMap<>();
                properties.put("AttachedToID", attachedToNodeInstance.getNodeDefinitionId());
                properties.put("AttachedToName", attachedToNodeInstance.getNodeName());
                String eventType = EVENT_TYPE_SIGNAL;
                String eventName = boundaryEventNode.getType();
                Map<String, String> timerProperties = attachedToNodeInstance.extractTimerEventInformation();
                if (timerProperties != null) {
                    properties.putAll(timerProperties);
                    eventType = "timer";
                    eventName = "timerTriggered";
                }
                eventDesciptions.add(new BaseEventDescription(eventName, (String) n.getMetaData().get(UNIQUE_ID), n.getName(), eventType, null, getId(), dataType, properties));
            }
        } else if (n instanceof EventSubProcessNode) {
            EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) n;
            boolean isContainerActive = false;
            if (eventSubProcessNode.getParentContainer() instanceof WorkflowProcess) {
                isContainerActive = true;
            } else if (eventSubProcessNode.getParentContainer() instanceof CompositeNode) {
                isContainerActive = !getNodeInstances(((CompositeNode) eventSubProcessNode.getParentContainer()).getId()).isEmpty();
            }
            if (isContainerActive) {
                Node startNode = eventSubProcessNode.findStartNode();
                Map<Timer, ProcessAction> timers = eventSubProcessNode.getTimers();
                if (timers != null && !timers.isEmpty()) {
                    getNodeInstances(eventSubProcessNode.getId()).forEach(ni -> {
                        Map<String, String> timerProperties = ((StateBasedNodeInstance) ni).extractTimerEventInformation();
                        if (timerProperties != null) {
                            eventDesciptions.add(new BaseEventDescription("timerTriggered", (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "timer", ni.getId(), getId(), null, timerProperties));
                        }
                    });
                } else {
                    for (String eventName : eventSubProcessNode.getEvents()) {
                        if ("variableChanged".equals(eventName)) {
                            continue;
                        }
                        eventDesciptions.add(new BaseEventDescription(eventName, (String) startNode.getMetaData().get("UniqueId"), startNode.getName(), "signal", null, getId(), dataType));
                    }
                }
            }
        } else if (n instanceof EventNode) {
            NamedDataType finalDataType = dataType;
            getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription(((EventNode) n).getType(), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getId(), getId(), finalDataType)));
        } else if (n instanceof StateNode) {
            getNodeInstances(n.getId()).forEach(ni -> eventDesciptions.add(new BaseEventDescription((String) n.getMetaData().get(CONDITION), (String) n.getMetaData().get(UNIQUE_ID), n.getName(), (String) n.getMetaData().getOrDefault(EVENT_TYPE, EVENT_TYPE_SIGNAL), ni.getId(), getId(), null)));
        }
    });
    return eventDesciptions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) Metadata(io.automatiko.engine.workflow.process.executable.core.Metadata) COMPLETED(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.COMPLETED) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Matcher(java.util.regex.Matcher) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) Map(java.util.Map) IS_FOR_COMPENSATION(io.automatiko.engine.workflow.process.executable.core.Metadata.IS_FOR_COMPENSATION) PrintWriter(java.io.PrintWriter) AdHocFragment(io.automatiko.engine.api.workflow.flexible.AdHocFragment) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) EventBasedNodeInstanceInterface(io.automatiko.engine.workflow.process.instance.node.EventBasedNodeInstanceInterface) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Set(java.util.Set) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) CORRELATION_KEY(io.automatiko.engine.workflow.process.executable.core.Metadata.CORRELATION_KEY) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) Stream(java.util.stream.Stream) CONDITION(io.automatiko.engine.workflow.process.executable.core.Metadata.CONDITION) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) CorrelationKey(io.automatiko.engine.services.correlation.CorrelationKey) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) CUSTOM_ASYNC(io.automatiko.engine.workflow.process.executable.core.Metadata.CUSTOM_ASYNC) EventListener(io.automatiko.engine.api.runtime.process.EventListener) LinkedHashSet(java.util.LinkedHashSet) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) StringWriter(java.io.StringWriter) TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) DateTimeUtils(io.automatiko.engine.workflow.base.core.timer.DateTimeUtils) CUSTOM_SLA_DUE_DATE(io.automatiko.engine.workflow.process.executable.core.Metadata.CUSTOM_SLA_DUE_DATE) NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) AVAILABLE(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.AVAILABLE) EventNodeInstanceInterface(io.automatiko.engine.workflow.process.instance.node.EventNodeInstanceInterface) EMPTY_EVENT_LISTENER(io.automatiko.engine.workflow.process.instance.impl.DummyEventListener.EMPTY_EVENT_LISTENER) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventDescription(io.automatiko.engine.api.workflow.EventDescription) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EVENT_TYPE(io.automatiko.engine.workflow.process.executable.core.Metadata.EVENT_TYPE) TagInstance(io.automatiko.engine.workflow.base.instance.TagInstance) NamedDataType(io.automatiko.engine.api.workflow.NamedDataType) FaultNodeInstance(io.automatiko.engine.workflow.process.instance.node.FaultNodeInstance) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) BaseEventDescription(io.automatiko.engine.api.workflow.BaseEventDescription) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) EventNodeInterface(io.automatiko.engine.workflow.process.core.node.EventNodeInterface) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) Collection(java.util.Collection) Tag(io.automatiko.engine.api.workflow.Tag) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Objects(java.util.Objects) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) List(java.util.List) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) EVENT_TYPE_SIGNAL(io.automatiko.engine.workflow.process.executable.core.Metadata.EVENT_TYPE_SIGNAL) ItemDescription(io.automatiko.engine.api.workflow.flexible.ItemDescription) Entry(java.util.Map.Entry) Optional(java.util.Optional) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) StartNodeInstance(io.automatiko.engine.workflow.process.instance.node.StartNodeInstance) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) UNIQUE_ID(io.automatiko.engine.workflow.process.executable.core.Metadata.UNIQUE_ID) HashMap(java.util.HashMap) Function(java.util.function.Function) DurationExpirationTime(io.automatiko.engine.api.jobs.DurationExpirationTime) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) EndNodeInstance(io.automatiko.engine.workflow.process.instance.node.EndNodeInstance) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) COMPENSATION(io.automatiko.engine.workflow.process.executable.core.Metadata.COMPENSATION) ACTIVE(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.ACTIVE) Logger(org.slf4j.Logger) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) TimerInstance(io.automatiko.engine.services.time.TimerInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) Process(io.automatiko.engine.workflow.base.core.Process) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) Collections(java.util.Collections) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) HashMap(java.util.HashMap) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) Node(io.automatiko.engine.api.definition.process.Node) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) 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) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EventListener(io.automatiko.engine.api.runtime.process.EventListener) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) EventNodeInterface(io.automatiko.engine.workflow.process.core.node.EventNodeInterface) BaseEventDescription(io.automatiko.engine.api.workflow.BaseEventDescription) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) NamedDataType(io.automatiko.engine.api.workflow.NamedDataType) EventDescription(io.automatiko.engine.api.workflow.EventDescription) BaseEventDescription(io.automatiko.engine.api.workflow.BaseEventDescription) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 20 with CompositeNode

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

the class WorkflowProcessInstanceImpl method signalEvent.

@Override
@SuppressWarnings("unchecked")
public void signalEvent(String type, Object event) {
    logger.debug("Signal {} received with data {} in process instance {}", type, event, getId());
    synchronized (this) {
        if (getState() != ProcessInstance.STATE_ACTIVE) {
            return;
        }
        InternalProcessRuntime processRuntime = getProcessRuntime();
        processRuntime.getProcessEventSupport().fireBeforeProcessSignaled(type, event, this, processRuntime);
        if ("timerTriggered".equals(type)) {
            TimerInstance timer = (TimerInstance) event;
            if (timer.getId().equals(slaTimerId)) {
                handleSLAViolation();
                // no need to pass the event along as it was purely for SLA tracking
                return;
            }
        }
        if ("slaViolation".equals(type)) {
            handleSLAViolation();
            // no need to pass the event along as it was purely for SLA tracking
            return;
        }
        List<NodeInstance> currentView = new ArrayList<>(this.nodeInstances);
        try {
            this.activatingNodeIds = new ArrayList<>();
            List<EventListener> listeners = eventListeners.get(type);
            if (listeners != null) {
                for (EventListener listener : listeners) {
                    listener.signalEvent(type, event);
                }
            }
            listeners = externalEventListeners.get(type);
            if (listeners != null) {
                for (EventListener listener : listeners) {
                    listener.signalEvent(type, event);
                }
            }
            if (!type.startsWith("Compensation")) {
                for (Node node : getWorkflowProcess().getNodes()) {
                    if (node instanceof EventNodeInterface && ((EventNodeInterface) node).acceptsEvent(type, event, getResolver(node, currentView))) {
                        if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
                            EventNodeInstance eventNodeInstance = (EventNodeInstance) getNodeInstance(node);
                            eventNodeInstance.signalEvent(type, event);
                        } else {
                            if (node instanceof EventSubProcessNode && (resolveVariables(((EventSubProcessNode) node).getEvents()).contains(type))) {
                                EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) 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);
                                    }
                                }
                            }
                        }
                    } else if (node instanceof StartNode && ((StartNode) node).getTriggers() != null) {
                        boolean accepted = ((StartNode) node).getTriggers().stream().filter(EventTrigger.class::isInstance).anyMatch(t -> ((EventTrigger) t).getEventFilters().stream().anyMatch(e -> e.acceptsEvent(type, event)));
                        if (accepted && node.getMetaData().get("acceptStartSignal") != null) {
                            StartNodeInstance startNodeInstance = (StartNodeInstance) getNodeInstance(node);
                            startNodeInstance.signalEvent(type, event);
                        }
                    }
                }
                if (((io.automatiko.engine.workflow.process.core.WorkflowProcess) getWorkflowProcess()).isDynamic()) {
                    for (Node node : getWorkflowProcess().getNodes()) {
                        if (node.hasMatchingEventListner(type) && node.getIncomingConnections().isEmpty()) {
                            NodeInstance nodeInstance = getNodeInstance(node);
                            if (nodeInstance != null) {
                                if (event != null) {
                                    Map<String, Object> dynamicParams = new HashMap<>(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, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
                            }
                        } else if (this instanceof ExecutableProcessInstance && node instanceof CompositeNode) {
                            Optional<NodeInstance> instance = this.nodeInstances.stream().filter(ni -> ni.getNodeId() == node.getId()).findFirst();
                            instance.ifPresent(n -> ((CompositeNodeInstance) n).signalEvent(type, event));
                        }
                    }
                }
            }
        } finally {
            processRuntime.getProcessEventSupport().fireAfterProcessSignaled(type, event, this, processRuntime);
            if (this.activatingNodeIds != null) {
                this.activatingNodeIds.clear();
                this.activatingNodeIds = null;
            }
        }
    }
}
Also used : StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) Metadata(io.automatiko.engine.workflow.process.executable.core.Metadata) COMPLETED(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.COMPLETED) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Matcher(java.util.regex.Matcher) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) Map(java.util.Map) IS_FOR_COMPENSATION(io.automatiko.engine.workflow.process.executable.core.Metadata.IS_FOR_COMPENSATION) PrintWriter(java.io.PrintWriter) AdHocFragment(io.automatiko.engine.api.workflow.flexible.AdHocFragment) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) EventBasedNodeInstanceInterface(io.automatiko.engine.workflow.process.instance.node.EventBasedNodeInstanceInterface) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Set(java.util.Set) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) CORRELATION_KEY(io.automatiko.engine.workflow.process.executable.core.Metadata.CORRELATION_KEY) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) Stream(java.util.stream.Stream) CONDITION(io.automatiko.engine.workflow.process.executable.core.Metadata.CONDITION) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) CorrelationKey(io.automatiko.engine.services.correlation.CorrelationKey) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) CUSTOM_ASYNC(io.automatiko.engine.workflow.process.executable.core.Metadata.CUSTOM_ASYNC) EventListener(io.automatiko.engine.api.runtime.process.EventListener) LinkedHashSet(java.util.LinkedHashSet) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) StringWriter(java.io.StringWriter) TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) DateTimeUtils(io.automatiko.engine.workflow.base.core.timer.DateTimeUtils) CUSTOM_SLA_DUE_DATE(io.automatiko.engine.workflow.process.executable.core.Metadata.CUSTOM_SLA_DUE_DATE) NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) AVAILABLE(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.AVAILABLE) EventNodeInstanceInterface(io.automatiko.engine.workflow.process.instance.node.EventNodeInstanceInterface) EMPTY_EVENT_LISTENER(io.automatiko.engine.workflow.process.instance.impl.DummyEventListener.EMPTY_EVENT_LISTENER) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventDescription(io.automatiko.engine.api.workflow.EventDescription) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) EVENT_TYPE(io.automatiko.engine.workflow.process.executable.core.Metadata.EVENT_TYPE) TagInstance(io.automatiko.engine.workflow.base.instance.TagInstance) NamedDataType(io.automatiko.engine.api.workflow.NamedDataType) FaultNodeInstance(io.automatiko.engine.workflow.process.instance.node.FaultNodeInstance) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) BaseEventDescription(io.automatiko.engine.api.workflow.BaseEventDescription) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) EventNodeInterface(io.automatiko.engine.workflow.process.core.node.EventNodeInterface) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) Collection(java.util.Collection) Tag(io.automatiko.engine.api.workflow.Tag) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Objects(java.util.Objects) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) List(java.util.List) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) EVENT_TYPE_SIGNAL(io.automatiko.engine.workflow.process.executable.core.Metadata.EVENT_TYPE_SIGNAL) ItemDescription(io.automatiko.engine.api.workflow.flexible.ItemDescription) Entry(java.util.Map.Entry) Optional(java.util.Optional) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) StartNodeInstance(io.automatiko.engine.workflow.process.instance.node.StartNodeInstance) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) UNIQUE_ID(io.automatiko.engine.workflow.process.executable.core.Metadata.UNIQUE_ID) HashMap(java.util.HashMap) Function(java.util.function.Function) DurationExpirationTime(io.automatiko.engine.api.jobs.DurationExpirationTime) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) EndNodeInstance(io.automatiko.engine.workflow.process.instance.node.EndNodeInstance) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) COMPENSATION(io.automatiko.engine.workflow.process.executable.core.Metadata.COMPENSATION) ACTIVE(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.ACTIVE) Logger(org.slf4j.Logger) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) TimerInstance(io.automatiko.engine.services.time.TimerInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) Process(io.automatiko.engine.workflow.base.core.Process) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) Collections(java.util.Collections) TimerInstance(io.automatiko.engine.services.time.TimerInstance) StartNodeInstance(io.automatiko.engine.workflow.process.instance.node.StartNodeInstance) HashMap(java.util.HashMap) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) Node(io.automatiko.engine.api.definition.process.Node) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) 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) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNodeInstanceInterface(io.automatiko.engine.workflow.process.instance.node.EventNodeInstanceInterface) EventListener(io.automatiko.engine.api.runtime.process.EventListener) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Optional(java.util.Optional) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) EventNodeInterface(io.automatiko.engine.workflow.process.core.node.EventNodeInterface) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) FaultNodeInstance(io.automatiko.engine.workflow.process.instance.node.FaultNodeInstance) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) StateBasedNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateBasedNodeInstance) StartNodeInstance(io.automatiko.engine.workflow.process.instance.node.StartNodeInstance) EndNodeInstance(io.automatiko.engine.workflow.process.instance.node.EndNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) Map(java.util.Map) HashMap(java.util.HashMap) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Aggregations

CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)27 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)16 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)16 ArrayList (java.util.ArrayList)15 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)14 Node (io.automatiko.engine.api.definition.process.Node)13 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)13 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)12 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)12 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)11 List (java.util.List)11 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)10 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)9 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)8 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)8 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)8 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)8 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)7 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)7 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)6