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;
}
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;
}
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);
}
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);
}
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();
}
}
Aggregations