private static final Logger LOG = LoggerFactory.getLogger(NotificationListenerAdapter.class);
+ private final ControllerContext controllerContext;
private final String streamName;
private final SchemaPath path;
private final String outputType;
* @param outputType
* type of output on notification (JSON, XML)
*/
- NotificationListenerAdapter(final SchemaPath path, final String streamName, final String outputType) {
- super();
+ NotificationListenerAdapter(final SchemaPath path, final String streamName, final String outputType,
+ final ControllerContext controllerContext) {
register(this);
- setLocalNameOfPath(path.getLastComponent().getLocalName());
-
this.outputType = Preconditions.checkNotNull(outputType);
this.path = Preconditions.checkNotNull(path);
Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
this.streamName = streamName;
+ this.controllerContext = controllerContext;
}
/**
}
@Override
+ @SuppressWarnings("checkstyle:hiddenField")
public void onNotification(final DOMNotification notification) {
- this.schemaContext = ControllerContext.getInstance().getGlobalSchema();
+ this.schemaContext = controllerContext.getGlobalSchema();
this.notification = notification;
final String xml = prepareXml();
*/
@VisibleForTesting
String prepareJson() {
- JsonParser jsonParser = new JsonParser();
- JsonObject json = new JsonObject();
+ final JsonParser jsonParser = new JsonParser();
+ final JsonObject json = new JsonObject();
json.add("ietf-restconf:notification", jsonParser.parse(writeBodyToString()));
json.addProperty("event-time", ListenerAdapter.toRFC3339(Instant.now()));
return json.toString();
final Element notificationEventElement = doc.createElementNS(
"urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote", "create-notification-stream");
- addValuesToNotificationEventElement(doc, notificationEventElement, this.notification, this.schemaContext);
+ addValuesToNotificationEventElement(doc, notificationEventElement);
notificationElement.appendChild(notificationEventElement);
return transformDoc(doc);
}
- private void addValuesToNotificationEventElement(final Document doc, final Element element,
- final DOMNotification notification, final SchemaContext schemaContext) {
- if (notification == null) {
- return;
- }
-
+ private void addValuesToNotificationEventElement(final Document doc, final Element element) {
final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> body =
notification.getBody();
try {