Search in sources :

Example 11 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class StartEventHandler method handleCompensationNode.

protected void handleCompensationNode(final StartNode startNode, final org.w3c.dom.Node xmlNode) {
    if (startNode.isInterrupting()) {
        logger.warn("Compensation Event Sub-Processes [" + startNode.getMetaData("UniqueId") + "] may not be specified as interrupting:" + " overriding attribute and setting to not-interrupting.");
    }
    startNode.setInterrupting(false);
    /**
     * From the BPMN2 spec, P.264: "For a Start Event: This Event "catches" the
     * compensation for an Event Sub-Process. No further information is required.
     * The Event Sub-Process will provide the id necessary to match the Compensation
     * Event with the Event that threw the compensation"
     *
     * In other words, the id of the Sub-Process containing this Event Sub-Process
     * is what should be used as the activityRef value in any Intermediate (throw)
     * or End compensation event that targets this particular Event Sub-Process.
     *
     * This is similar to the logic used for a Compensation Boundary Event: it's
     * signaled using the id of the activity to which the CBE is attached to.
     */
    String activityRef = ((Element) xmlNode).getAttribute("activityRef");
    if (activityRef != null && activityRef.length() > 0) {
        logger.warn("activityRef value [" + activityRef + "] on Start Event '" + startNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
    }
    // so that this node will get processed in ProcessHandler.postProcessNodes(...)
    EventTrigger startTrigger = new EventTrigger();
    EventFilter eventFilter = new NonAcceptingEventTypeFilter();
    ((NonAcceptingEventTypeFilter) eventFilter).setType("Compensation");
    startTrigger.addEventFilter(eventFilter);
    List<Trigger> startTriggers = new ArrayList<>();
    startTriggers.add(startTrigger);
    startNode.setTriggers(startTriggers);
    String mapping = (String) startNode.getMetaData("TriggerMapping");
    if (mapping != null) {
        startTrigger.addInMapping(mapping, startNode.getOutMapping(mapping));
    }
}
Also used : Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 12 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class ProcessEventSupportTest method testProcessEventListenerWithEvent.

@Test
public void testProcessEventListenerWithEvent() throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.core.process.event");
    process.setName("Event Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            logger.info("Executed action");
        }
    });
    actionNode.setAction(action);
    actionNode.setId(2);
    process.addNode(actionNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    EventNode eventNode = new EventNode();
    eventNode.setName("Event");
    eventNode.setId(3);
    List<EventFilter> filters = new ArrayList<EventFilter>();
    EventTypeFilter filter = new EventTypeFilter();
    filter.setType("signal");
    filters.add(filter);
    eventNode.setEventFilters(filters);
    process.addNode(eventNode);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, eventNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(4);
    process.addNode(endNode);
    new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
    final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
    final ProcessEventListener processEventListener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }
    };
    processRuntime.addEventListener(processEventListener);
    // execute the process
    ProcessInstance pi = processRuntime.startProcess("org.company.core.process.event");
    pi.signalEvent("signal", null);
    assertEquals(20, processEventList.size());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
    assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
    assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(6)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(7)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(8)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(11)).getProcessInstance().getProcessId());
    assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(12)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(13)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(14)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(16)).getProcessInstance().getProcessId());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(17)).getNodeInstance().getNodeName());
    assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(19)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(18)).getNodeInstance().getNodeName());
}
Also used : ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) 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) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ArrayList(java.util.ArrayList) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ProcessRuntimeImpl(io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 13 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class BoundaryEventHandler method handleConditionNode.

protected void handleConditionNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setMetaData("CancelActivity", cancelActivity);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String outputName = ((Element) xmlNode).getAttribute("name");
            dataOutputs.put(id, outputName);
            populateDataOutputs(xmlNode, outputName, parser);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode, parser);
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    eventNode.setMetaData("Condition", xmlNode.getTextContent());
                    List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                    EventTypeFilter eventFilter = new EventTypeFilter();
                    eventFilter.setType("Condition-" + attachedTo);
                    eventFilters.add(eventFilter);
                    eventNode.setScope("external");
                    eventNode.setEventFilters(eventFilters);
                    break;
                }
                subNode = subNode.getNextSibling();
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Example 14 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class BoundaryEventHandler method handleTimerNode.

protected void handleTimerNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setMetaData("CancelActivity", cancelActivity);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("timerEventDefinition".equals(nodeName)) {
            String timeDuration = null;
            String timeCycle = null;
            String timeDate = null;
            String language = "";
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode instanceof Element) {
                String subNodeName = subNode.getNodeName();
                if ("timeDuration".equals(subNodeName)) {
                    timeDuration = subNode.getTextContent();
                    break;
                } else if ("timeCycle".equals(subNodeName)) {
                    timeCycle = subNode.getTextContent();
                    language = ((Element) subNode).getAttribute("language");
                    break;
                } else if ("timeDate".equals(subNodeName)) {
                    timeDate = subNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            if (timeDuration != null && timeDuration.trim().length() > 0) {
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Timer-" + attachedTo + "-" + timeDuration + "-" + eventNode.getId());
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("TimeDuration", timeDuration);
            } else if (timeCycle != null && timeCycle.trim().length() > 0) {
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Timer-" + attachedTo + "-" + timeCycle + "-" + eventNode.getId());
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("TimeCycle", timeCycle);
                eventNode.setMetaData("Language", language);
            } else if (timeDate != null && timeDate.trim().length() > 0) {
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Timer-" + attachedTo + "-" + timeDate + "-" + eventNode.getId());
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("TimeDate", timeDate);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter)

Example 15 with EventFilter

use of io.automatiko.engine.workflow.base.core.event.EventFilter in project automatiko-engine by automatiko-io.

the class CompensationTest method createBoundaryEventCompensationHandler.

private void createBoundaryEventCompensationHandler(io.automatiko.engine.workflow.process.core.NodeContainer nodeContainer, Node attachedToNode, final List<String> eventList, final String id) throws Exception {
    NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(nodeContainer, BoundaryEventNode.class);
    BoundaryEventNode boundaryNode = boundaryNodeCreator.createNode("boundary" + id);
    String attachedTo = (String) attachedToNode.getMetaData().get("UniqueId");
    boundaryNode.setMetaData("AttachedTo", attachedTo);
    boundaryNode.setAttachedToNodeId(attachedTo);
    EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
    eventFilter.setType("Compensation");
    List<EventFilter> eventFilters = new ArrayList<EventFilter>();
    boundaryNode.setEventFilters(eventFilters);
    eventFilters.add(eventFilter);
    addCompensationScope(boundaryNode, nodeContainer, attachedTo);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(nodeContainer, ActionNode.class);
    ActionNode actionNode = actionNodeCreator.createNode("handlerAction" + id);
    actionNode.setMetaData("isForCompensation", true);
    actionNode.setName("Execute");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            eventList.add("action" + id);
        }
    });
    actionNode.setAction(action);
    connect(boundaryNode, actionNode);
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) 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) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ArrayList(java.util.ArrayList) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator)

Aggregations

EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)25 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)24 ArrayList (java.util.ArrayList)16 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)14 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)11 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)10 Element (org.w3c.dom.Element)10 Node (io.automatiko.engine.api.definition.process.Node)9 NonAcceptingEventTypeFilter (io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter)9 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)8 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)8 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)8 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)8 Trigger (io.automatiko.engine.workflow.process.core.node.Trigger)8 List (java.util.List)7 Map (java.util.Map)7 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)6 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)6 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)6 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)5