use of io.automatiko.engine.workflow.process.core.node.StateBasedNode in project automatiko-engine by automatiko-io.
the class ProcessHandler method linkBoundaryEvents.
public void linkBoundaryEvents(NodeContainer nodeContainer) {
for (Node node : nodeContainer.getNodes()) {
if (node instanceof EventNode) {
final String attachedTo = (String) node.getMetaData().get("AttachedTo");
if (attachedTo != null) {
for (EventFilter filter : ((EventNode) node).getEventFilters()) {
String type = ((EventTypeFilter) filter).getType();
Node attachedNode = findNodeByIdOrUniqueIdInMetadata(nodeContainer, attachedTo, "Could not find node to attach to: " + attachedTo);
//
if (!(attachedNode instanceof StateBasedNode) && !type.equals("Compensation")) {
throw new IllegalArgumentException("Boundary events are supported only on StateBasedNode, found node: " + attachedNode.getClass().getName() + " [" + attachedNode.getMetaData().get("UniqueId") + "]");
}
if (type.startsWith("Escalation")) {
linkBoundaryEscalationEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.startsWith("Error-")) {
linkBoundaryErrorEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.startsWith("Timer-")) {
linkBoundaryTimerEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.equals("Compensation")) {
linkBoundaryCompensationEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (node.getMetaData().get("SignalName") != null || type.startsWith("Message-")) {
linkBoundarySignalEvent(nodeContainer, node, attachedTo, attachedNode);
} else if (type.startsWith("Condition-")) {
linkBoundaryConditionEvent(nodeContainer, node, attachedTo, attachedNode);
}
}
}
}
}
}
use of io.automatiko.engine.workflow.process.core.node.StateBasedNode in project automatiko-engine by automatiko-io.
the class TimerHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
Element element = parser.endElementBuilder();
StateBasedNode parent = (StateBasedNode) parser.getParent();
String id = element.getAttribute("id");
emptyAttributeCheck(localName, "id", id, parser);
String delay = element.getAttribute("delay");
String period = element.getAttribute("period");
Timer timer = new Timer();
timer.setId(new Long(id));
if (delay != null && delay.length() != 0) {
timer.setDelay(delay);
}
if (period != null && period.length() != 0) {
timer.setPeriod(period);
}
org.w3c.dom.Node xmlNode = element.getFirstChild();
ProcessAction action = null;
if (xmlNode instanceof Element) {
Element actionXml = (Element) xmlNode;
action = AbstractNodeHandler.extractAction(actionXml);
}
parent.addTimer(timer, action);
return null;
}
use of io.automatiko.engine.workflow.process.core.node.StateBasedNode in project automatiko-engine by automatiko-io.
the class ProcessHandler method linkBoundaryTimerEvent.
protected void linkBoundaryTimerEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
StateBasedNode compositeNode = (StateBasedNode) attachedNode;
String timeDuration = (String) node.getMetaData().get("TimeDuration");
String timeCycle = (String) node.getMetaData().get("TimeCycle");
String timeDate = (String) node.getMetaData().get("TimeDate");
Timer timer = new Timer();
if (timeDuration != null) {
timer.setDelay(timeDuration);
timer.setTimeType(Timer.TIME_DURATION);
ConsequenceAction consequenceAction = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
compositeNode.addTimer(timer, consequenceAction);
} else if (timeCycle != null) {
int index = timeCycle.indexOf("###");
if (index != -1) {
String period = timeCycle.substring(index + 3);
timeCycle = timeCycle.substring(0, index);
timer.setPeriod(period);
}
timer.setDelay(timeCycle);
timer.setTimeType(Timer.TIME_CYCLE);
String finalTimeCycle = timeCycle;
ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + finalTimeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
compositeNode.addTimer(timer, action);
} else if (timeDate != null) {
timer.setDate(timeDate);
timer.setTimeType(Timer.TIME_DATE);
ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Timer-" + attachedTo + "-" + timeDate + "-" + node.getId(), kcontext -> kcontext.getNodeInstance().getId(), SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
compositeNode.addTimer(timer, action);
}
if (cancelActivity) {
List<ProcessAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
if (actions == null) {
actions = new ArrayList<ProcessAction>();
}
ConsequenceAction action = createJavaAction(new CancelNodeInstanceAction(attachedTo));
actions.add(action);
((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
}
}
use of io.automatiko.engine.workflow.process.core.node.StateBasedNode in project automatiko-engine by automatiko-io.
the class ExecutableProcessFactory method linkBoundaryTimerEvent.
protected void linkBoundaryTimerEvent(Node node, String attachedTo, Node attachedNode) {
boolean cancelActivity = (Boolean) node.getMetaData().get(CANCEL_ACTIVITY);
StateBasedNode compositeNode = (StateBasedNode) attachedNode;
String timeDuration = (String) node.getMetaData().get(TIME_DURATION);
String timeCycle = (String) node.getMetaData().get(TIME_CYCLE);
String timeDate = (String) node.getMetaData().get(TIME_DATE);
Timer timer = new Timer();
if (timeDuration != null) {
timer.setDelay(timeDuration);
timer.setTimeType(Timer.TIME_DURATION);
compositeNode.addTimer(timer, timerAction("Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId()));
} else if (timeCycle != null) {
int index = timeCycle.indexOf("###");
if (index != -1) {
String period = timeCycle.substring(index + 3);
timeCycle = timeCycle.substring(0, index);
timer.setPeriod(period);
}
timer.setDelay(timeCycle);
timer.setTimeType(Timer.TIME_CYCLE);
compositeNode.addTimer(timer, timerAction("Timer-" + attachedTo + "-" + timeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId()));
} else if (timeDate != null) {
timer.setDate(timeDate);
timer.setTimeType(Timer.TIME_DATE);
compositeNode.addTimer(timer, timerAction("Timer-" + attachedTo + "-" + timeDate + "-" + node.getId()));
}
if (cancelActivity) {
List<ProcessAction> actions = ((EventNode) node).getActions(EVENT_NODE_EXIT);
if (actions == null) {
actions = new ArrayList<>();
}
ConsequenceAction cancelAction = new ConsequenceAction("java", null);
cancelAction.setMetaData(ACTION, new CancelNodeInstanceAction(attachedTo));
actions.add(cancelAction);
((EventNode) node).setActions(EVENT_NODE_EXIT, actions);
}
}
Aggregations