Refactor NotificationQueryParams 26/108826/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Nov 2023 18:50:55 +0000 (19:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Nov 2023 20:58:41 +0000 (21:58 +0100)
Add explicit documentation pointing to 'Subscribing to Receive
Notifications' chapter of RFC8040.

Turn this class into a record and rename it to ReceiveEventsParams to
mirror naming of ReadDataParams.

JIRA: NETCONF-1102
Change-Id: I7a033bad585aef1b2e6c628db9d8d5c95b9ac0ff
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ReceiveEventsParams.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParams.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
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/ListenersBroker.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/jaxrs/QueryParamsTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/ListenerAdapterTest.java

diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java
deleted file mode 100644 (file)
index 56bad1b..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- * Copyright (c) 2021 PANTHEON.tech, s.r.o.
- *
- * 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;
-
-import com.google.common.base.MoreObjects;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
-import org.opendaylight.restconf.api.query.ChildNodesOnlyParam;
-import org.opendaylight.restconf.api.query.FilterParam;
-import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
-import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
-import org.opendaylight.restconf.api.query.StartTimeParam;
-import org.opendaylight.restconf.api.query.StopTimeParam;
-import org.opendaylight.yangtools.concepts.Immutable;
-
-/**
- * Parser and holder of query parameters from uriInfo for notifications.
- */
-public final class NotificationQueryParams implements Immutable {
-    private final SkipNotificationDataParam skipNotificationData;
-    private final LeafNodesOnlyParam leafNodesOnly;
-    private final StartTimeParam startTime;
-    private final StopTimeParam stopTime;
-    private final FilterParam filter;
-    private final ChangedLeafNodesOnlyParam changedLeafNodesOnly;
-    private final ChildNodesOnlyParam childNodesOnly;
-
-    private NotificationQueryParams(final StartTimeParam startTime, final StopTimeParam stopTime,
-            final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
-            final SkipNotificationDataParam skipNotificationData, final ChangedLeafNodesOnlyParam changedLeafNodesOnly,
-            final ChildNodesOnlyParam childNodesOnly) {
-        this.startTime = startTime;
-        this.stopTime = stopTime;
-        this.filter = filter;
-        this.leafNodesOnly = leafNodesOnly;
-        this.skipNotificationData = skipNotificationData;
-        this.changedLeafNodesOnly = changedLeafNodesOnly;
-        this.childNodesOnly = childNodesOnly;
-    }
-
-    public static @NonNull NotificationQueryParams of(final StartTimeParam startTime, final StopTimeParam stopTime,
-            final FilterParam filter, final LeafNodesOnlyParam leafNodesOnly,
-            final SkipNotificationDataParam skipNotificationData, final ChangedLeafNodesOnlyParam changedLeafNodesOnly,
-            final ChildNodesOnlyParam childNodesOnly) {
-        if (stopTime != null && startTime == null) {
-            throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
-                + StartTimeParam.uriName + " parameter");
-        }
-        if (changedLeafNodesOnly != null) {
-            if (leafNodesOnly != null) {
-                throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
-                    + LeafNodesOnlyParam.uriName + " parameter");
-            }
-            if (childNodesOnly != null) {
-                throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
-                    + ChildNodesOnlyParam.uriName + " parameter");
-            }
-        }
-        return new NotificationQueryParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
-            changedLeafNodesOnly, childNodesOnly);
-    }
-
-    /**
-     * Get start-time query parameter.
-     *
-     * @return start-time
-     */
-    public @Nullable StartTimeParam startTime() {
-        return startTime;
-    }
-
-    /**
-     * Get stop-time query parameter.
-     *
-     * @return stop-time
-     */
-    public @Nullable StopTimeParam stopTime() {
-        return stopTime;
-    }
-
-    /**
-     * Get filter query parameter.
-     *
-     * @return filter
-     */
-    public @Nullable FilterParam filter() {
-        return filter;
-    }
-
-    /**
-     * Get odl-leaf-nodes-only query parameter.
-     *
-     * @return odl-leaf-nodes-only
-     */
-    public @Nullable LeafNodesOnlyParam leafNodesOnly() {
-        return leafNodesOnly;
-    }
-
-    /**
-     * Get odl-skip-notification-data query parameter.
-     *
-     * @return odl-skip-notification-data
-     */
-    public @Nullable SkipNotificationDataParam skipNotificationData() {
-        return skipNotificationData;
-    }
-
-    /**
-     * Get changed-leaf-nodes-only query parameter.
-     *
-     * @return changed-leaf-nodes-only
-     */
-    public @Nullable ChangedLeafNodesOnlyParam changedLeafNodesOnly() {
-        return changedLeafNodesOnly;
-    }
-
-    /**
-     * Get odl-child-nodes-only query parameter.
-     *
-     * @return odl-child-nodes-only
-     */
-    public @Nullable ChildNodesOnlyParam childNodesOnly() {
-        return childNodesOnly;
-    }
-
-    @Override
-    public String toString() {
-        final var helper = MoreObjects.toStringHelper(this);
-        if (startTime != null) {
-            helper.add("startTime", startTime.paramValue());
-        }
-        if (stopTime != null) {
-            helper.add("stopTime", stopTime.paramValue());
-        }
-        if (filter != null) {
-            helper.add("filter", filter.paramValue());
-        }
-        if (leafNodesOnly != null) {
-            helper.add("leafNodesOnly", leafNodesOnly.value());
-        }
-        if (skipNotificationData != null) {
-            helper.add("skipNotificationData", skipNotificationData.value());
-        }
-        if (changedLeafNodesOnly != null) {
-            helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
-        }
-        if (childNodesOnly != null) {
-            helper.add("childNodesOnly", childNodesOnly.value());
-        }
-        return helper.toString();
-    }
-}
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ReceiveEventsParams.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ReceiveEventsParams.java
new file mode 100644 (file)
index 0000000..c6f701a
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o.
+ *
+ * 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;
+
+import com.google.common.base.MoreObjects;
+import org.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
+import org.opendaylight.restconf.api.query.ChildNodesOnlyParam;
+import org.opendaylight.restconf.api.query.FilterParam;
+import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
+import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
+import org.opendaylight.restconf.api.query.StartTimeParam;
+import org.opendaylight.restconf.api.query.StopTimeParam;
+
+/**
+ * Query parameters valid in the scope of a GET request on an event stream resource, as outline in
+ * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-6.3">RFC8040 section 6.3</a>.
+ */
+public record ReceiveEventsParams(
+        StartTimeParam startTime,
+        StopTimeParam stopTime,
+        FilterParam filter,
+        LeafNodesOnlyParam leafNodesOnly,
+        SkipNotificationDataParam skipNotificationData,
+        ChangedLeafNodesOnlyParam changedLeafNodesOnly,
+        ChildNodesOnlyParam childNodesOnly) {
+    public ReceiveEventsParams {
+        if (stopTime != null && startTime == null) {
+            throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
+                + StartTimeParam.uriName + " parameter");
+        }
+        if (changedLeafNodesOnly != null) {
+            if (leafNodesOnly != null) {
+                throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
+                    + LeafNodesOnlyParam.uriName + " parameter");
+            }
+            if (childNodesOnly != null) {
+                throw new IllegalArgumentException(ChangedLeafNodesOnlyParam.uriName + " parameter cannot be used with "
+                    + ChildNodesOnlyParam.uriName + " parameter");
+            }
+        }
+    }
+
+    @Override
+    public String toString() {
+        final var helper = MoreObjects.toStringHelper(this);
+        if (startTime != null) {
+            helper.add("startTime", startTime.paramValue());
+        }
+        if (stopTime != null) {
+            helper.add("stopTime", stopTime.paramValue());
+        }
+        if (filter != null) {
+            helper.add("filter", filter.paramValue());
+        }
+        if (leafNodesOnly != null) {
+            helper.add("leafNodesOnly", leafNodesOnly.value());
+        }
+        if (skipNotificationData != null) {
+            helper.add("skipNotificationData", skipNotificationData.value());
+        }
+        if (changedLeafNodesOnly != null) {
+            helper.add("changedLeafNodesOnly", changedLeafNodesOnly.value());
+        }
+        if (childNodesOnly != null) {
+            helper.add("childNodesOnly", childNodesOnly.value());
+        }
+        return helper.toString();
+    }
+}
index 00d2c6b77821f07844ffe9bcd3f8344280133be3..b759f33a98d80a03fc906069ec57ee07651824c1 100644 (file)
@@ -35,8 +35,8 @@ import org.opendaylight.restconf.api.query.WithDefaultsParam;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.Insert;
-import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.ReadDataParams;
+import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
 import org.opendaylight.restconf.nb.rfc8040.legacy.InstanceIdentifierContext;
 import org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.NetconfFieldsTranslator;
@@ -64,7 +64,7 @@ public final class QueryParams {
         // Utility class
     }
 
-    public static @NonNull NotificationQueryParams newNotificationQueryParams(final UriInfo uriInfo) {
+    public static @NonNull ReceiveEventsParams newReceiveEventsParams(final UriInfo uriInfo) {
         StartTimeParam startTime = null;
         StopTimeParam stopTime = null;
         FilterParam filter = null;
@@ -112,7 +112,7 @@ public final class QueryParams {
         }
 
         try {
-            return NotificationQueryParams.of(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
+            return new ReceiveEventsParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
                 changedLeafNodesOnly, childNodesOnly);
         } catch (IllegalArgumentException e) {
             throw new RestconfDocumentedException("Invalid query parameters: " + e.getMessage(), e);
index 269bcf9f077d422c3ec923afa52f9679f8a40ade..1edd21fb383e82763463c8812a684ddf03daeb59 100644 (file)
@@ -60,7 +60,7 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
 
     @Override
     public Response subscribeToStream(final String identifier, final UriInfo uriInfo) {
-        final var params = QueryParams.newNotificationQueryParams(uriInfo);
+        final var params = QueryParams.newReceiveEventsParams(uriInfo);
 
         final URI location;
         if (identifier.contains(RestconfStreamsConstants.DATA_SUBSCRIPTION)) {
index 3f681574e9b58995c067317d9acefe9d3ccfc727..4599978cb7675de95f5c7d2701bb767e25c4bcb9 100644 (file)
@@ -28,7 +28,7 @@ import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.checkerframework.checker.lock.qual.Holding;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
+import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.Registration;
@@ -132,7 +132,7 @@ abstract class AbstractCommonSubscriber<T> extends AbstractNotificationsData imp
      *
      * @param params NotificationQueryParams to use.
      */
-    public final void setQueryParams(final NotificationQueryParams params) {
+    public final void setQueryParams(final ReceiveEventsParams params) {
         final var startTime = params.startTime();
         start = startTime == null ? Instant.now() : parseDateAndTime(startTime.value());
 
index 5a2e5d277e4b6ca7b189b3b9ab04d824553c0078..d6b325e05fcba179c16832e963655573c24c5cbb 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
+import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
 import org.opendaylight.restconf.nb.rfc8040.URLConstants;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
@@ -480,7 +480,7 @@ public abstract sealed class ListenersBroker {
      * @return Stream location for listening.
      */
     public final @NonNull URI subscribeToYangStream(final String identifier, final UriInfo uriInfo,
-            final NotificationQueryParams notificationQueryParams, final HandlersHolder handlersHolder) {
+            final ReceiveEventsParams notificationQueryParams, final HandlersHolder handlersHolder) {
         final String streamName = createStreamNameFromUri(identifier);
         if (isNullOrEmpty(streamName)) {
             throw new RestconfDocumentedException("Stream name is empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
@@ -519,7 +519,7 @@ public abstract sealed class ListenersBroker {
      * @return Location for listening.
      */
     public final URI subscribeToDataStream(final String identifier, final UriInfo uriInfo,
-            final NotificationQueryParams notificationQueryParams, final HandlersHolder handlersHolder) {
+            final ReceiveEventsParams notificationQueryParams, final HandlersHolder handlersHolder) {
         final var streamName = createStreamNameFromUri(identifier);
         final var listener = dataChangeListenerFor(streamName);
         if (listener == null) {
index a16c1d630073a98c4bb660c6d74a5e175fd2be8c..2a4b81ab04af775bc5b9c44c5042ba8da08d031d 100644 (file)
@@ -74,11 +74,11 @@ public class QueryParamsTest {
      */
     @Test
     public void checkParametersTypesNegativeTest() {
-        assertUnknownParam(QueryParams::newNotificationQueryParams);
+        assertUnknownParam(QueryParams::newReceiveEventsParams);
         assertUnknownParam(QueryParams::newReadDataParams);
         assertUnknownParam(uriInfo -> QueryParams.parseInsert(mock(EffectiveModelContext.class), uriInfo));
 
-        assertInvalidParam(QueryParams::newNotificationQueryParams, ContentParam.ALL);
+        assertInvalidParam(QueryParams::newReceiveEventsParams, ContentParam.ALL);
         assertInvalidParam(QueryParams::newReadDataParams, InsertParam.LAST);
         assertInvalidParam(
             uriInfo -> QueryParams.parseInsert(mock(EffectiveModelContext.class), uriInfo),
index 693eb90411003486eb92ec7a0cce2ff2c2d24ac3..b12c65cd22ff13ff1f0a28ecbc087a29595fd308 100644 (file)
@@ -37,7 +37,7 @@ import org.opendaylight.restconf.api.query.ChildNodesOnlyParam;
 import org.opendaylight.restconf.api.query.LeafNodesOnlyParam;
 import org.opendaylight.restconf.api.query.SkipNotificationDataParam;
 import org.opendaylight.restconf.api.query.StartTimeParam;
-import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
+import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.yang.gen.v1.augment.instance.identifier.patch.module.rev220218.PatchCont1Builder;
@@ -181,7 +181,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
                 final boolean skipNotificationData, final boolean changedLeafNodesOnly, final boolean childNodesOnly,
                 final ListenersBroker listenersBroker) {
             super(streamName, outputType, listenersBroker, LogicalDatastoreType.CONFIGURATION, path);
-            setQueryParams(NotificationQueryParams.of(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null,
+            setQueryParams(new ReceiveEventsParams(StartTimeParam.forUriValue("1970-01-01T00:00:00Z"), null, null,
                 leafNodesOnly ? LeafNodesOnlyParam.of(true) : null,
                 skipNotificationData ? SkipNotificationDataParam.of(true) : null,
                 changedLeafNodesOnly ? ChangedLeafNodesOnlyParam.of(true) : null,