use of io.automatiko.engine.workflow.process.core.node.EventTrigger in project automatiko-engine by automatiko-io.
the class LightProcessRuntime method initProcessEventListener.
private void initProcessEventListener(Process process) {
if (process instanceof ExecutableProcess) {
for (Node node : ((ExecutableProcess) process).getNodes()) {
if (node instanceof StartNode) {
StartNode startNode = (StartNode) node;
if (startNode != null) {
List<Trigger> triggers = startNode.getTriggers();
if (triggers != null) {
for (Trigger trigger : triggers) {
if (trigger instanceof EventTrigger) {
final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
String type = null;
for (EventFilter filter : filters) {
if (filter instanceof EventTypeFilter) {
type = ((EventTypeFilter) filter).getType();
}
}
StartProcessEventListener listener = new StartProcessEventListener(process.getId(), filters, trigger.getInMappings(), startNode.getEventTransformer());
signalManager.addEventListener(type, listener);
((ExecutableProcess) process).getRuntimeMetaData().put("StartProcessEventType", type);
((ExecutableProcess) process).getRuntimeMetaData().put("StartProcessEventListener", listener);
}
}
}
}
}
}
}
}
use of io.automatiko.engine.workflow.process.core.node.EventTrigger in project automatiko-engine by automatiko-io.
the class ServerlessWorkflowFactory method addTriggerToStartNode.
public void addTriggerToStartNode(StartNode startNode, String triggerEventType) {
EventTrigger trigger = new EventTrigger();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType(triggerEventType);
trigger.addEventFilter(eventFilter);
String mapping = (String) startNode.getMetaData(Metadata.TRIGGER_MAPPING);
if (mapping != null) {
trigger.addInMapping(mapping, startNode.getOutMapping(mapping));
}
startNode.addTrigger(trigger);
}
use of io.automatiko.engine.workflow.process.core.node.EventTrigger in project automatiko-engine by automatiko-io.
the class ServiceTaskDescriptor method collectHandledErrorCodes.
private Set<String> collectHandledErrorCodes() {
Set<String> errorCodes = new HashSet<>();
NodeContainer container = workItemNode.getParentContainer();
String thisNodeId = (String) workItemNode.getMetaData("UniqueId");
for (Node node : container.getNodes()) {
if (node instanceof BoundaryEventNode) {
String errorCode = (String) node.getMetaData().get("ErrorEvent");
if (errorCode != null && ((BoundaryEventNode) node).getAttachedToNodeId().equals(thisNodeId)) {
errorCodes.add(errorCode);
}
}
}
// next collect event subprocess node with error start event from this level and to all parents
String replaceRegExp = "Error-|Escalation-";
for (Node node : container.getNodes()) {
if (node instanceof EventSubProcessNode) {
EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
Node[] nodes = eventSubProcessNode.getNodes();
for (Node subNode : nodes) {
// avoids cyclomatic complexity
if (subNode == null || !(subNode instanceof StartNode)) {
continue;
}
List<Trigger> triggers = ((StartNode) subNode).getTriggers();
if (triggers == null) {
continue;
}
for (Trigger trigger : triggers) {
if (trigger instanceof EventTrigger) {
final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
for (EventFilter filter : filters) {
if (filter instanceof EventTypeFilter) {
eventSubProcessNode.addEvent((EventTypeFilter) filter);
String type = ((EventTypeFilter) filter).getType();
if (type.startsWith("Error-")) {
String trimmedType = type.replaceFirst(replaceRegExp, "");
for (String error : trimmedType.split(",")) {
errorCodes.add(error);
}
}
}
}
}
}
}
}
}
return errorCodes;
}
use of io.automatiko.engine.workflow.process.core.node.EventTrigger in project automatiko-engine by automatiko-io.
the class StartNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
StartNode startNode = (StartNode) node;
writeNode("start", startNode, xmlDump, includeMeta);
List<Trigger> triggers = startNode.getTriggers();
if ((triggers == null || triggers.isEmpty()) && (!includeMeta || !containsMetaData(startNode))) {
endNode(xmlDump);
} else {
xmlDump.append(">" + EOL);
if (includeMeta) {
writeMetaData(startNode, xmlDump);
}
if (triggers != null) {
xmlDump.append(" <triggers>" + EOL);
for (Trigger trigger : triggers) {
if (trigger instanceof ConstraintTrigger) {
xmlDump.append(" <trigger type=\"constraint\" >" + EOL);
xmlDump.append(" <constraint type=\"rule\" dialect=\"mvel\" >" + ((ConstraintTrigger) trigger).getConstraint() + "</constraint>" + EOL);
Map<String, String> inMappings = trigger.getInMappings();
if (inMappings != null && !inMappings.isEmpty()) {
for (Map.Entry<String, String> entry : inMappings.entrySet()) {
xmlDump.append(" <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
}
}
xmlDump.append(" </trigger>" + EOL);
} else if (trigger instanceof EventTrigger) {
xmlDump.append(" <trigger type=\"event\" >" + EOL);
xmlDump.append(" <eventFilters>" + EOL);
for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
if (filter instanceof EventTypeFilter) {
xmlDump.append(" <eventFilter " + "type=\"eventType\" " + "eventType=\"" + ((EventTypeFilter) filter).getType() + "\" />" + EOL);
} else {
throw new IllegalArgumentException("Unknown filter type: " + filter);
}
}
xmlDump.append(" </eventFilters>" + EOL);
Map<String, String> inMappings = trigger.getInMappings();
if (inMappings != null && !inMappings.isEmpty()) {
for (Map.Entry<String, String> entry : inMappings.entrySet()) {
xmlDump.append(" <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
}
}
xmlDump.append(" </trigger>" + EOL);
} else {
throw new IllegalArgumentException("Unknown trigger type " + trigger);
}
}
xmlDump.append(" </triggers>" + EOL);
}
endNode("start", xmlDump);
}
}
use of io.automatiko.engine.workflow.process.core.node.EventTrigger in project automatiko-engine by automatiko-io.
the class TriggerHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
StartNode startNode = (StartNode) parser.getParent();
String type = attrs.getValue("type");
emptyAttributeCheck(localName, "type", type, parser);
Trigger trigger = null;
if ("constraint".equals(type)) {
trigger = new ConstraintTrigger();
} else if ("event".equals(type)) {
trigger = new EventTrigger();
} else {
throw new SAXException("Unknown trigger type " + type);
}
startNode.addTrigger(trigger);
return trigger;
}
Aggregations