- @VisibleForTesting
- String prepareJson() {
- 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();
- }
-
- @VisibleForTesting
- void setNotification(final DOMNotification notification) {
- this.notification = Preconditions.checkNotNull(notification);
- }
-
- @VisibleForTesting
- void setSchemaContext(final SchemaContext schemaContext) {
- this.schemaContext = Preconditions.checkNotNull(schemaContext);
- }
-
- private String writeBodyToString() {
- final Writer writer = new StringWriter();
- final NormalizedNodeStreamWriter jsonStream =
- JSONNormalizedNodeStreamWriter.createExclusiveWriter(JSONCodecFactory.getShared(this.schemaContext),
- this.notification.getType(), null, JsonWriterFactory.createJsonWriter(writer));
- final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream);
- try {
- nodeWriter.write(this.notification.getBody());
- nodeWriter.close();
- } catch (final IOException e) {
- throw new RestconfDocumentedException("Problem while writing body of notification to JSON. ", e);
- }
- return writer.toString();
- }
-
- private String prepareXml() {
- final Document doc = createDocument();
- final Element notificationElement = basePartDoc(doc);
-
- 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);
- notificationElement.appendChild(notificationEventElement);
-
- return transformDoc(doc);