Search in sources :

Example 6 with Timer

use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.

the class TimerNodeFactory method date.

public TimerNodeFactory date(String date) {
    Timer timer = getTimerNode().getTimer();
    if (timer == null) {
        timer = new Timer();
        getTimerNode().setTimer(timer);
    }
    timer.setDate(date);
    return this;
}
Also used : Timer(io.automatiko.engine.workflow.base.core.timer.Timer)

Example 7 with Timer

use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.

the class TimerNodeFactory method delay.

public TimerNodeFactory delay(String delay) {
    Timer timer = getTimerNode().getTimer();
    if (timer == null) {
        timer = new Timer();
        getTimerNode().setTimer(timer);
    }
    timer.setDelay(delay);
    return this;
}
Also used : Timer(io.automatiko.engine.workflow.base.core.timer.Timer)

Example 8 with Timer

use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.

the class StateBasedNode method addTimer.

public void addTimer(Timer timer, ProcessAction action) {
    if (timers == null) {
        timers = new HashMap<Timer, ProcessAction>();
    }
    if (timer.getId() == 0) {
        long id = 0;
        for (Timer t : timers.keySet()) {
            if (t.getId() > id) {
                id = t.getId();
            }
        }
        timer.setId(++id);
    }
    timers.put(timer, action);
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Timer(io.automatiko.engine.workflow.base.core.timer.Timer)

Example 9 with Timer

use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.

the class StartEventHandler method writeNode.

@Override
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    StartNode startNode = (StartNode) node;
    writeNode("startEvent", startNode, xmlDump, metaDataType);
    xmlDump.append(" isInterrupting=\"");
    if (startNode.isInterrupting()) {
        xmlDump.append("true");
    } else {
        xmlDump.append("false");
    }
    xmlDump.append("\">" + EOL);
    writeExtensionElements(startNode, xmlDump);
    List<Trigger> triggers = startNode.getTriggers();
    if (triggers != null) {
        if (triggers.size() > 1) {
            throw new IllegalArgumentException("Multiple start triggers not supported");
        }
        Trigger trigger = triggers.get(0);
        if (trigger instanceof ConstraintTrigger) {
            ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
            if (constraintTrigger.getHeader() == null) {
                xmlDump.append("      <conditionalEventDefinition>" + EOL);
                xmlDump.append("        <condition xsi:type=\"tFormalExpression\" language=\"" + XmlBPMNProcessDumper.RULE_LANGUAGE + "\">" + constraintTrigger.getConstraint() + "</condition>" + EOL);
                xmlDump.append("      </conditionalEventDefinition>" + EOL);
            }
        } else if (trigger instanceof EventTrigger) {
            EventTrigger eventTrigger = (EventTrigger) trigger;
            String mapping = null;
            String nameMapping = "event";
            if (!trigger.getInMappings().isEmpty()) {
                mapping = eventTrigger.getInMappings().keySet().iterator().next();
                nameMapping = eventTrigger.getInMappings().values().iterator().next();
            } else {
                mapping = (String) startNode.getMetaData("TriggerMapping");
            }
            if (mapping != null) {
                xmlDump.append("      <dataOutput id=\"_" + startNode.getId() + "_Output\" name=\"" + nameMapping + "\" />" + EOL + "      <dataOutputAssociation>" + EOL + "        <sourceRef>_" + startNode.getId() + "_Output</sourceRef>" + EOL + "        <targetRef>" + mapping + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
            }
            String type = ((EventTypeFilter) eventTrigger.getEventFilters().get(0)).getType();
            if (type.startsWith("Message-")) {
                type = type.substring(8);
                xmlDump.append("      <messageEventDefinition messageRef=\"" + type + "\"/>" + EOL);
            } else if (type.startsWith("Error-")) {
                type = type.substring(6);
                String errorId = getErrorIdForErrorCode(type, startNode);
                xmlDump.append("      <errorEventDefinition errorRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(errorId) + "\"/>" + EOL);
            } else if (type.startsWith("Escalation-")) {
                type = type.substring(11);
                xmlDump.append("      <escalationEventDefinition escalationRef=\"" + type + "\"/>" + EOL);
            } else if (type.equals("Compensation")) {
                xmlDump.append("      <compensateEventDefinition/>" + EOL);
            } else {
                xmlDump.append("      <signalEventDefinition signalRef=\"" + type + "\" />" + EOL);
            }
        } else {
            throw new IllegalArgumentException("Unsupported trigger type " + trigger);
        }
        if (startNode.getTimer() != null) {
            Timer timer = startNode.getTimer();
            xmlDump.append("      <timerEventDefinition>" + EOL);
            if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
                if (timer.getTimeType() == Timer.TIME_DATE) {
                    xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
                } else if (timer.getTimeType() == Timer.TIME_DURATION) {
                    xmlDump.append("        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
                } else if (timer.getTimeType() == Timer.TIME_CYCLE) {
                    if (timer.getPeriod() != null) {
                        xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
                    } else {
                        xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
                    }
                }
            }
            xmlDump.append("      </timerEventDefinition>" + EOL);
        }
    } else if (startNode.getTimer() != null) {
        Timer timer = startNode.getTimer();
        xmlDump.append("      <timerEventDefinition>" + EOL);
        if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
            if (timer.getTimeType() == Timer.TIME_DATE) {
                xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
            } else if (timer.getTimeType() == Timer.TIME_DURATION) {
                xmlDump.append("        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
            } else if (timer.getTimeType() == Timer.TIME_CYCLE) {
                if (timer.getPeriod() != null) {
                    xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
                } else {
                    xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
                }
            }
        }
        xmlDump.append("      </timerEventDefinition>" + EOL);
    }
    endNode("startEvent", xmlDump);
}
Also used : ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) 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) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 10 with Timer

use of io.automatiko.engine.workflow.base.core.timer.Timer in project automatiko-engine by automatiko-io.

the class StartEventHandler method handleTimerNode.

protected void handleTimerNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("timerEventDefinition".equals(nodeName)) {
            Timer timer = new Timer();
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode instanceof Element) {
                String subNodeName = subNode.getNodeName();
                if ("timeCycle".equals(subNodeName)) {
                    String delay = subNode.getTextContent();
                    int index = delay.indexOf("###");
                    if (index != -1) {
                        String period = delay.substring(index + 3);
                        delay = delay.substring(0, index);
                        timer.setPeriod(period);
                    }
                    timer.setTimeType(Timer.TIME_CYCLE);
                    timer.setDelay(delay);
                    break;
                } else if ("timeDuration".equals(subNodeName)) {
                    String delay = subNode.getTextContent();
                    timer.setTimeType(Timer.TIME_DURATION);
                    timer.setDelay(delay);
                    break;
                } else if ("timeDate".equals(subNodeName)) {
                    String date = subNode.getTextContent();
                    timer.setTimeType(Timer.TIME_DATE);
                    timer.setDate(date);
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            startNode.setTimer(timer);
            if (parser.getParent() instanceof EventSubProcessNode) {
                // handle timer on start events like normal (non rule) timers for event sub
                // process
                EventTrigger trigger = new EventTrigger();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Timer-" + ((EventSubProcessNode) parser.getParent()).getId());
                trigger.addEventFilter(eventFilter);
                String mapping = (String) startNode.getMetaData("TriggerMapping");
                if (mapping != null) {
                    trigger.addInMapping(mapping, "event");
                }
                startNode.addTrigger(trigger);
                ((EventSubProcessNode) parser.getParent()).addTimer(timer, new ConsequenceAction("java", ""));
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) Element(org.w3c.dom.Element) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Aggregations

Timer (io.automatiko.engine.workflow.base.core.timer.Timer)28 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)9 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)6 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)6 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)6 StateBasedNode (io.automatiko.engine.workflow.process.core.node.StateBasedNode)6 TimerNode (io.automatiko.engine.workflow.process.core.node.TimerNode)6 List (java.util.List)6 Node (io.automatiko.engine.api.definition.process.Node)5 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)5 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)5 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)5 ArrayList (java.util.ArrayList)5 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)4