Update AbstractQueryParams 30/98130/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Oct 2021 07:53:57 +0000 (09:53 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Oct 2021 11:04:10 +0000 (13:04 +0200)
We now have properly-encapsulated notification query parameters, make
sure we use them as a whole rather than breaking them apart in callers.

JIRA: NETCONF-773
Change-Id: I53bca1d2404e887de16f4e6c3f827c54db45945d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java

index b95059beb5e3efb4198361ffab02c8df0050fe72..2019aff332720709ecd41264b09e136b4e768b74 100644 (file)
@@ -130,13 +130,8 @@ abstract class SubscribeToStreamUtil {
 
         final EffectiveModelContext schemaContext = handlersHolder.getSchemaHandler().get();
         final URI uri = prepareUriByStreamName(uriInfo, streamName);
+        notificationListenerAdapter.setQueryParams(notificationQueryParams);
         notificationListenerAdapter.listen(handlersHolder.getNotificationServiceHandler());
-        notificationListenerAdapter.setQueryParams(
-                notificationQueryParams.startTime(),
-                notificationQueryParams.stopTime(),
-                notificationQueryParams.filter(),
-                notificationQueryParams.leafNodesOnly(),
-                notificationQueryParams.skipNotificationData());
         final DOMDataBroker dataBroker = handlersHolder.getDataBroker();
         notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getSchemaHandler());
         final MapEntryNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(
@@ -183,13 +178,7 @@ abstract class SubscribeToStreamUtil {
         final ListenerAdapter listener = ListenersBroker.getInstance().getDataChangeListenerFor(streamName)
             .orElseThrow(() -> new RestconfDocumentedException("No listener found for stream " + streamName,
                 ErrorType.APPLICATION, ErrorTag.DATA_MISSING));
-
-        listener.setQueryParams(
-                notificationQueryParams.startTime(),
-                notificationQueryParams.stopTime(),
-                notificationQueryParams.filter(),
-                notificationQueryParams.leafNodesOnly(),
-                notificationQueryParams.skipNotificationData());
+        listener.setQueryParams(notificationQueryParams);
 
         final DOMDataBroker dataBroker = handlersHolder.getDataBroker();
         final SchemaContextHandler schemaHandler = handlersHolder.getSchemaHandler();
index 25265cf80c69e3f3dcd49d62818f91bbea8e17d4..f31a72f376e5686bad65367f42535b1a459dfa7e 100644 (file)
@@ -17,11 +17,7 @@ import javax.xml.xpath.XPathExpressionException;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.FilterParam;
-import org.opendaylight.restconf.nb.rfc8040.LeafNodesOnlyParam;
-import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam;
-import org.opendaylight.restconf.nb.rfc8040.StartTimeParam;
-import org.opendaylight.restconf.nb.rfc8040.StopTimeParam;
+import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
 
 /**
@@ -51,20 +47,22 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
     /**
      * Set query parameters for listener.
      *
-     * @param startTime     Start-time of getting notification.
-     * @param stopTime      Stop-time of getting notification.
-     * @param filter        Indicates which subset of all possible events are of interest.
-     * @param leafNodesOnly If TRUE, notifications will contain changes of leaf nodes only.
+     * @param params     NotificationQueryParams to use.
      */
-    @SuppressWarnings("checkstyle:hiddenField")
-    public final void setQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
-            final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
-            final SkipNotificationDataParam skipNotificationData) {
+    public final void setQueryParams(final NotificationQueryParams params) {
+        final var startTime = params.startTime();
         start = startTime == null ? Instant.now() : parseDateAndTime(startTime.value());
+
+        final var stopTime = params.stopTime();
         stop = stopTime == null ? null : parseDateAndTime(stopTime.value());
-        this.leafNodesOnly = leafNodesOnly == null ? false : leafNodesOnly.value();
-        this.skipNotificationData = skipNotificationData == null ? false : skipNotificationData.value();
 
+        final var leafNodes = params.leafNodesOnly();
+        leafNodesOnly = leafNodes == null ? false : leafNodes.value();
+
+        final var skipData = params.skipNotificationData();
+        skipNotificationData = skipData == null ? false : skipData.value();
+
+        final var filter = params.filter();
         if (filter != null) {
             try {
                 setFilter(filter.paramValue());
index 7083a1a9a72102ebf6c5eabea5940c0d2775e61b..b616916c693803db06b52cd772a4d09d86175e7a 100644 (file)
@@ -35,6 +35,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.LeafNodesOnlyParam;
+import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.SkipNotificationDataParam;
 import org.opendaylight.restconf.nb.rfc8040.StartTimeParam;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
@@ -42,7 +43,7 @@ import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.P
 import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1;
 import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1Builder;
 import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.patch.cont.MyList1Key;
-import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping;
+import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -119,11 +120,11 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
         private CountDownLatch notificationLatch = new CountDownLatch(1);
 
         ListenerAdapterTester(final YangInstanceIdentifier path, final String streamName,
-                              final NotificationOutputTypeGrouping.NotificationOutputType outputType,
+                              final NotificationOutputType outputType,
                               final boolean leafNodesOnly, final boolean skipNotificationData) {
             super(path, streamName, outputType);
-            setQueryParams(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null,
-                LeafNodesOnlyParam.of(leafNodesOnly), SkipNotificationDataParam.of(skipNotificationData));
+            setQueryParams(NotificationQueryParams.of(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null,
+                LeafNodesOnlyParam.of(leafNodesOnly), SkipNotificationDataParam.of(skipNotificationData)));
         }
 
         @Override
@@ -201,8 +202,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     @Test
     public void testJsonNotifsLeaves() throws Exception {
-        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey",
-                NotificationOutputTypeGrouping.NotificationOutputType.JSON, true, false);
+        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON,
+            true, false);
         adapter.setCloseVars(domDataBroker, schemaContextHandler);
 
         final DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
@@ -233,8 +234,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     @Test
     public void testJsonNotifs() throws Exception {
-        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey",
-                NotificationOutputTypeGrouping.NotificationOutputType.JSON, false, false);
+        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON,
+            false, false);
         adapter.setCloseVars(domDataBroker, schemaContextHandler);
 
         final DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
@@ -265,8 +266,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     @Test
     public void testJsonNotifsWithoutData() throws Exception {
-        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey",
-                NotificationOutputTypeGrouping.NotificationOutputType.JSON, false, true);
+        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.JSON,
+            false, true);
         adapter.setCloseVars(domDataBroker, schemaContextHandler);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
@@ -295,8 +296,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     @Test
     public void testXmlNotifications() throws Exception {
-        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey",
-                NotificationOutputTypeGrouping.NotificationOutputType.XML, false, false);
+        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML,
+            false, false);
         adapter.setCloseVars(domDataBroker, schemaContextHandler);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
@@ -325,8 +326,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     @Test
     public void testXmlSkipData() throws Exception {
-        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey",
-                NotificationOutputTypeGrouping.NotificationOutputType.XML, false, true);
+        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML,
+            false, true);
         adapter.setCloseVars(domDataBroker, schemaContextHandler);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()
@@ -355,8 +356,8 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
 
     @Test
     public void testXmlLeavesOnly() throws Exception {
-        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey",
-                NotificationOutputTypeGrouping.NotificationOutputType.XML, true, false);
+        ListenerAdapterTester adapter = new ListenerAdapterTester(PATCH_CONT_YIID, "Casey", NotificationOutputType.XML,
+            true, false);
         adapter.setCloseVars(domDataBroker, schemaContextHandler);
 
         DOMDataTreeChangeService changeService = domDataBroker.getExtensions()