Purge AbstractNotificationsData 32/108832/4
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2023 06:29:29 +0000 (07:29 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 3 Nov 2023 10:43:09 +0000 (10:43 +0000)
Most of the methods here are completely unused, remove them and inline
the remainder into AbstractCommonSubscriber.

JIRA: NETCONF-1102
Change-Id: I1abdfaa522f4a215c9755de25e7d726f2177bb00
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/AbstractCommonSubscriber.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/AbstractNotificationsData.java [deleted file]

index 1ba3f0eeadbb7d8fd0520e2c8f7aaeb709b8810a..291a9baea6e8338d388e0f84b754f5ed0cb869fb 100644 (file)
@@ -13,6 +13,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -21,8 +22,11 @@ import javax.xml.xpath.XPathExpressionException;
 import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.checkerframework.checker.lock.qual.Holding;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -33,7 +37,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Features of subscribing part of both notifications.
  */
-abstract class AbstractCommonSubscriber<T> extends AbstractNotificationsData implements BaseListenerInterface {
+abstract class AbstractCommonSubscriber<T> implements BaseListenerInterface {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractCommonSubscriber.class);
 
     private final EventFormatterFactory<T> formatterFactory;
@@ -49,6 +53,10 @@ abstract class AbstractCommonSubscriber<T> extends AbstractNotificationsData imp
     // FIXME: NETCONF-1102: this should be tied to a subscriber
     private @NonNull EventFormatter<T> formatter;
 
+    // FIXME: these really should not live here
+    protected DatabindProvider databindProvider;
+    private DOMDataBroker dataBroker;
+
     AbstractCommonSubscriber(final String streamName, final NotificationOutputType outputType,
             final EventFormatterFactory<T> formatterFactory, final ListenersBroker listenersBroker) {
         this.streamName = requireNonNull(streamName);
@@ -86,7 +94,7 @@ abstract class AbstractCommonSubscriber<T> extends AbstractNotificationsData imp
             registration.close();
             registration = null;
         }
-        deleteDataInDS(streamName).get();
+        deleteDataInDS().get();
         subscribers.clear();
     }
 
@@ -194,6 +202,30 @@ abstract class AbstractCommonSubscriber<T> extends AbstractNotificationsData imp
         }
     }
 
+    /**
+     * Data broker for delete data in DS on close().
+     *
+     * @param dataBroker creating new write transaction for delete data on close
+     * @param databindProvider for formatting notifications
+     */
+    @SuppressWarnings("checkstyle:hiddenField")
+    // FIXME: this is pure lifecycle nightmare just because ...
+    public void setCloseVars(final DOMDataBroker dataBroker, final DatabindProvider databindProvider) {
+        this.dataBroker = dataBroker;
+        this.databindProvider = databindProvider;
+    }
+
+    /**
+     * Delete data in DS.
+     */
+    // FIXME: here we touch datastore, which probably should be done by whoever instantiated us or created the resource,
+    //        or they should be giving us the transaction
+    private ListenableFuture<?> deleteDataInDS() {
+        final var wTx = dataBroker.newWriteOnlyTransaction();
+        wTx.delete(LogicalDatastoreType.OPERATIONAL, RestconfStateStreams.restconfStateStreamPath(streamName));
+        return wTx.commit();
+    }
+
     @Override
     public final String toString() {
         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/AbstractNotificationsData.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/AbstractNotificationsData.java
deleted file mode 100644 (file)
index 22e5f79..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.streams;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import java.io.ByteArrayOutputStream;
-import java.nio.charset.StandardCharsets;
-import java.time.Instant;
-import java.time.OffsetDateTime;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.yangtools.util.xml.UntrustedXML;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * Abstract class for processing and preparing data.
- */
-abstract class AbstractNotificationsData {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractNotificationsData.class);
-    private static final TransformerFactory TF = TransformerFactory.newInstance();
-
-    protected DatabindProvider databindProvider;
-    private DOMDataBroker dataBroker;
-
-    /**
-     * Data broker for delete data in DS on close().
-     *
-     * @param dataBroker creating new write transaction for delete data on close
-     * @param databindProvider for formatting notifications
-     */
-    @SuppressWarnings("checkstyle:hiddenField")
-    // FIXME: this is pure lifecycle nightmare just because ...
-    public void setCloseVars(final DOMDataBroker dataBroker, final DatabindProvider databindProvider) {
-        this.dataBroker = dataBroker;
-        this.databindProvider = databindProvider;
-    }
-
-    /**
-     * Delete data in DS.
-     */
-    // FIXME: here we touch datastore, which probably should be done by whoever instantiated us or created the resource,
-    //        or they should be giving us the transaction
-    protected final ListenableFuture<?> deleteDataInDS(final String streamName) {
-        final DOMDataTreeWriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
-        wTx.delete(LogicalDatastoreType.OPERATIONAL, RestconfStateStreams.restconfStateStreamPath(streamName));
-        return wTx.commit();
-    }
-
-    /**
-     * Formats data specified by RFC3339.
-     *
-     * @param now time stamp
-     * @return Data specified by RFC3339.
-     */
-    protected static String toRFC3339(final Instant now) {
-        return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.ofInstant(now, ZoneId.systemDefault()));
-    }
-
-    /**
-     * Creates {@link Document} document.
-     *
-     * @return {@link Document} document.
-     */
-    protected static Document createDocument() {
-        return UntrustedXML.newDocumentBuilder().newDocument();
-    }
-
-    /**
-     * Generating base element of every notification.
-     *
-     * @param doc
-     *            base {@link Document}
-     * @return element of {@link Document}
-     */
-    protected Element basePartDoc(final Document doc) {
-        final var notificationElement = NotificationFormatter.createNotificationElement(doc);
-        doc.appendChild(notificationElement);
-        return notificationElement;
-    }
-
-    /**
-     * Generating of {@link Document} transforming to string.
-     *
-     * @param doc
-     *            {@link Document} with data
-     * @return - string from {@link Document}
-     */
-    protected String transformDoc(final Document doc) {
-        final ByteArrayOutputStream out = new ByteArrayOutputStream();
-
-        try {
-            final Transformer transformer = TF.newTransformer();
-            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
-            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
-            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
-            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
-            transformer.transform(new DOMSource(doc), new StreamResult(out));
-        } catch (final TransformerException e) {
-            // FIXME: this should raise an exception
-            final String msg = "Error during transformation of Document into String";
-            LOG.error(msg, e);
-            return msg;
-        }
-
-        return new String(out.toByteArray(), StandardCharsets.UTF_8);
-    }
-}