use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.
the class IntermediateCatchEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
EventNode eventNode = (EventNode) node;
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);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, eventNode);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
eventNode.setMetaData("MessageType", message.getType());
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Message-" + messageRef);
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.
the class IntermediateCatchEventHandler method handleSignalNode.
@SuppressWarnings("unchecked")
protected void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
EventNode eventNode = (EventNode) node;
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);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, eventNode);
} else if ("signalEventDefinition".equals(nodeName)) {
String type = ((Element) xmlNode).getAttribute("signalRef");
if (type != null && type.trim().length() > 0) {
type = checkSignalAndConvertToRealSignalNam(parser, type);
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType(type);
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
}
}
xmlNode = xmlNode.getNextSibling();
}
}
use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.
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 org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.
the class ProcessRuntimeImpl method initProcessEventListener.
private void initProcessEventListener(Process process) {
if (process instanceof RuleFlowProcess) {
for (Node node : ((RuleFlowProcess) 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);
((RuleFlowProcess) process).getRuntimeMetaData().put("StartProcessEventType", type);
((RuleFlowProcess) process).getRuntimeMetaData().put("StartProcessEventListener", listener);
}
}
}
}
}
}
}
}
use of org.jbpm.process.core.event.EventFilter in project jbpm by kiegroup.
the class ProcessHandler method postProcessNodes.
private void postProcessNodes(RuleFlowProcess process, NodeContainer container) {
List<String> eventSubProcessHandlers = new ArrayList<String>();
for (Node node : container.getNodes()) {
if (node instanceof StateNode) {
StateNode stateNode = (StateNode) node;
String condition = (String) stateNode.getMetaData("Condition");
Constraint constraint = new ConstraintImpl();
constraint.setConstraint(condition);
constraint.setType("rule");
for (org.kie.api.definition.process.Connection connection : stateNode.getDefaultOutgoingConnections()) {
stateNode.setConstraint(connection, constraint);
}
} else if (node instanceof NodeContainer) {
// prepare event sub process
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-") || type.startsWith("Escalation")) {
String faultCode = (String) subNode.getMetaData().get("FaultCode");
String replaceRegExp = "Error-|Escalation-";
final String signalType = type;
ExceptionScope exceptionScope = (ExceptionScope) ((ContextContainer) eventSubProcessNode.getNodeContainer()).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScope == null) {
exceptionScope = new ExceptionScope();
((ContextContainer) eventSubProcessNode.getNodeContainer()).addContext(exceptionScope);
((ContextContainer) eventSubProcessNode.getNodeContainer()).setDefaultContext(exceptionScope);
}
String faultVariable = null;
if (trigger.getInAssociations() != null && !trigger.getInAssociations().isEmpty()) {
faultVariable = trigger.getInAssociations().get(0).getTarget();
}
ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
DroolsConsequenceAction action = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + signalType + "\", " + (faultVariable == null ? "null" : "kcontext.getVariable(\"" + faultVariable + "\")") + ");");
exceptionHandler.setAction(action);
exceptionHandler.setFaultVariable(faultVariable);
if (faultCode != null) {
String trimmedType = type.replaceFirst(replaceRegExp, "");
exceptionScope.setExceptionHandler(trimmedType, exceptionHandler);
eventSubProcessHandlers.add(trimmedType);
} else {
exceptionScope.setExceptionHandler(faultCode, exceptionHandler);
}
} else if (type.equals("Compensation")) {
// 1. Find the parent sub-process to this event sub-process
NodeContainer parentSubProcess;
NodeContainer subProcess = eventSubProcessNode.getNodeContainer();
Object isForCompensationObj = eventSubProcessNode.getMetaData("isForCompensation");
if (isForCompensationObj == null) {
eventSubProcessNode.setMetaData("isForCompensation", true);
logger.warn("Overriding empty or false value of \"isForCompensation\" attribute on Event Sub-Process [" + eventSubProcessNode.getMetaData("UniqueId") + "] and setting it to true.");
}
if (subProcess instanceof RuleFlowProcess) {
// ..how do you expect to signal compensation on the completed process (instance)?!?
throw new IllegalArgumentException("Compensation Event Sub-Processes at the process level are not supported.");
}
parentSubProcess = ((Node) subProcess).getNodeContainer();
// 2. The event filter (never fires, purely for dumping purposes) has already been added
// 3. Add compensation scope
String compensationHandlerId = (String) ((CompositeNode) subProcess).getMetaData("UniqueId");
addCompensationScope(process, eventSubProcessNode, parentSubProcess, compensationHandlerId);
}
}
}
} else if (trigger instanceof ConstraintTrigger) {
ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
if (constraintTrigger.getConstraint() != null) {
String processId = ((RuleFlowProcess) container).getId();
String type = "RuleFlowStateEventSubProcess-Event-" + processId + "-" + eventSubProcessNode.getUniqueId();
EventTypeFilter eventTypeFilter = new EventTypeFilter();
eventTypeFilter.setType(type);
eventSubProcessNode.addEvent(eventTypeFilter);
}
}
}
}
// for( Node subNode : nodes)
}
postProcessNodes(process, (NodeContainer) node);
} else if (node instanceof EndNode) {
handleIntermediateOrEndThrowCompensationEvent((EndNode) node);
} else if (node instanceof ActionNode) {
handleIntermediateOrEndThrowCompensationEvent((ActionNode) node);
} else if (node instanceof EventNode) {
final EventNode eventNode = (EventNode) node;
if (!(eventNode instanceof BoundaryEventNode) && eventNode.getDefaultIncomingConnections().size() == 0) {
throw new IllegalArgumentException("Event node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection");
}
}
}
// process fault node to disable termnate parent if there is event subprocess handler
for (Node node : container.getNodes()) {
if (node instanceof FaultNode) {
FaultNode faultNode = (FaultNode) node;
if (eventSubProcessHandlers.contains(faultNode.getFaultName())) {
faultNode.setTerminateParent(false);
}
}
}
}
Aggregations