Refactor ReceiveEventsParams 07/109107/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Nov 2023 17:08:01 +0000 (18:08 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Nov 2023 17:13:37 +0000 (18:13 +0100)
This is a simple request DTO. Move it to restconf.server.api, where it
really belongs. Also rename it to EventStreamGetParams in keeping with
package naming.

JIRA: NETCONF-773
Change-Id: I06ca58bcf5dde64b9e8787b4d467a384a960596e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/Insert.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/SSESender.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/SSEStreamService.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/WebSocketSender.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/EventStreamGetParams.java [moved from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ReceiveEventsParams.java with 90% similarity]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/spi/RestconfStream.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/DataTreeChangeStreamTest.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/SSESessionHandlerTest.java

index 985fad114f5e6609de6a3b0d56dc48979c2653e8..3959a74867c1c071b64763bdde83a4cbffa630c0 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.restconf.nb.rfc8040;
 
 import static java.util.Objects.requireNonNull;
-import static org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams.optionalParam;
+import static org.opendaylight.restconf.server.api.EventStreamGetParams.optionalParam;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
index 3aed886699fd361c107c4743fa94b819a15044b0..e2972e782cc20d2153f8cabcb013c5fccbaf7f50 100644 (file)
@@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
 import javax.ws.rs.sse.Sse;
 import javax.ws.rs.sse.SseEventSink;
 import javax.xml.xpath.XPathExpressionException;
-import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RestconfStream.EncodingName;
 import org.opendaylight.restconf.server.spi.RestconfStream.Sender;
@@ -36,7 +36,7 @@ final class SSESender implements Sender {
     private final PingExecutor pingExecutor;
     private final RestconfStream<?> stream;
     private final EncodingName encoding;
-    private final ReceiveEventsParams params;
+    private final EventStreamGetParams params;
     private final SseEventSink sink;
     private final Sse sse;
     private final int maximumFragmentLength;
@@ -61,7 +61,7 @@ final class SSESender implements Sender {
      *            session up. Ping control frames are disabled if this parameter is set to 0.
      */
     SSESender(final PingExecutor pingExecutor, final SseEventSink sink, final Sse sse, final RestconfStream<?> stream,
-            final EncodingName encoding, final ReceiveEventsParams params, final int maximumFragmentLength,
+            final EncodingName encoding, final EventStreamGetParams params, final int maximumFragmentLength,
             final long heartbeatMillis) {
         this.pingExecutor = requireNonNull(pingExecutor);
         this.sse = requireNonNull(sse);
index 839491a3d01abd1857fba9388d6970c7b4943d75..a3fd811756dce9930558ee4316854194a24fde03 100644 (file)
@@ -23,8 +23,8 @@ import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.sse.Sse;
 import javax.ws.rs.sse.SseEventSink;
 import javax.xml.xpath.XPathExpressionException;
-import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
 import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RestconfStream.EncodingName;
 import org.slf4j.Logger;
@@ -74,9 +74,9 @@ final class SSEStreamService {
             throw new BadRequestException(e.getMessage(), e);
         }
 
-        final ReceiveEventsParams params;
+        final EventStreamGetParams params;
         try {
-            params = ReceiveEventsParams.ofQueryParameters(queryParameters);
+            params = EventStreamGetParams.ofQueryParameters(queryParameters);
         } catch (IllegalArgumentException e) {
             throw new BadRequestException(e.getMessage(), e);
         }
index ff7075bb01a34f38bd85abda991ab742d94a747c..ce47ee7021f391f63244f7d5ca0b8187fe960936 100644 (file)
@@ -28,7 +28,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
 import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
 import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
 import org.eclipse.jetty.websocket.api.annotations.WebSocket;
-import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RestconfStream.EncodingName;
 import org.opendaylight.restconf.server.spi.RestconfStream.Sender;
@@ -48,7 +48,7 @@ final class WebSocketSender implements Sender {
     private final PingExecutor pingExecutor;
     private final RestconfStream<?> stream;
     private final EncodingName encodingName;
-    private final ReceiveEventsParams params;
+    private final EventStreamGetParams params;
     private final int maximumFragmentLength;
     private final long heartbeatInterval;
 
@@ -73,7 +73,8 @@ final class WebSocketSender implements Sender {
      *                              to keep session up. Ping control frames are disabled if this parameter is set to 0.
      */
     WebSocketSender(final PingExecutor pingExecutor, final RestconfStream<?> stream, final EncodingName encodingName,
-            final @Nullable ReceiveEventsParams params, final int maximumFragmentLength, final long heartbeatInterval) {
+            final @Nullable EventStreamGetParams params, final int maximumFragmentLength,
+            final long heartbeatInterval) {
         this.pingExecutor = requireNonNull(pingExecutor);
         this.stream = requireNonNull(stream);
         this.encodingName = requireNonNull(encodingName);
similarity index 90%
rename from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ReceiveEventsParams.java
rename to restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/EventStreamGetParams.java
index fca7f705c06ff073e4e5cb121cbbe50477feb566..79f1ac3ad1facd0a8b3c30aca961c542eeeaa5ef 100644 (file)
@@ -6,7 +6,7 @@
  * 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;
+package org.opendaylight.restconf.server.api;
 
 import static java.util.Objects.requireNonNull;
 
@@ -27,7 +27,7 @@ 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(
+public record EventStreamGetParams(
         StartTimeParam startTime,
         StopTimeParam stopTime,
         FilterParam filter,
@@ -35,7 +35,7 @@ public record ReceiveEventsParams(
         SkipNotificationDataParam skipNotificationData,
         ChangedLeafNodesOnlyParam changedLeafNodesOnly,
         ChildNodesOnlyParam childNodesOnly) {
-    public ReceiveEventsParams {
+    public EventStreamGetParams {
         if (stopTime != null && startTime == null) {
             throw new IllegalArgumentException(StopTimeParam.uriName + " parameter has to be used with "
                 + StartTimeParam.uriName + " parameter");
@@ -53,14 +53,14 @@ public record ReceiveEventsParams(
     }
 
     /**
-     * Return {@link ReceiveEventsParams} for specified query parameters.
+     * Return {@link EventStreamGetParams} for specified query parameters.
      *
      * @param queryParameters Parameters and their values
-     * @return A {@link ReceiveEventsParams}
+     * @return A {@link EventStreamGetParams}
      * @throws NullPointerException if {@code queryParameters} is {@code null}
      * @throws IllegalArgumentException if the parameters are invalid
      */
-    public static @NonNull ReceiveEventsParams ofQueryParameters(final Map<String, String> queryParameters) {
+    public static @NonNull EventStreamGetParams ofQueryParameters(final Map<String, String> queryParameters) {
         StartTimeParam startTime = null;
         StopTimeParam stopTime = null;
         FilterParam filter = null;
@@ -102,7 +102,7 @@ public record ReceiveEventsParams(
             }
         }
 
-        return new ReceiveEventsParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
+        return new EventStreamGetParams(startTime, stopTime, filter, leafNodesOnly, skipNotificationData,
             changedLeafNodesOnly, childNodesOnly);
     }
 
@@ -133,7 +133,8 @@ public record ReceiveEventsParams(
         return helper.toString();
     }
 
-    static <T> @Nullable T optionalParam(final Function<String, @NonNull T> factory, final String name,
+    // FIXME: find a better place for this method
+    public static <T> @Nullable T optionalParam(final Function<String, @NonNull T> factory, final String name,
             final String value) {
         try {
             return factory.apply(requireNonNull(value));
index fc01ab7880755cef6f5e3246db06942966bfe1a6..2ead3acab84d1449c858dad826943e231d6b4ad6 100644 (file)
@@ -24,7 +24,7 @@ import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.common.errors.RestconfFuture;
-import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.streams.stream.Access;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -235,7 +235,7 @@ public final class RestconfStream<T> {
      * @throws XPathExpressionException if requested filter is not valid
      */
     public @Nullable Registration addSubscriber(final Sender handler, final EncodingName encoding,
-            final ReceiveEventsParams params) throws UnsupportedEncodingException, XPathExpressionException {
+            final EventStreamGetParams params) throws UnsupportedEncodingException, XPathExpressionException {
         final var factory = source.encodings.get(requireNonNull(encoding));
         if (factory == null) {
             throw new UnsupportedEncodingException("Stream '" + name + "' does not support " + encoding);
index e612e0e4dd21317cd62c954bec6058a5ebdbd19a..8cfd79b3e1b3f238dd5604ca28d39856280f07fc 100644 (file)
@@ -33,11 +33,11 @@ import org.opendaylight.restconf.api.query.RestconfQueryParam;
 import org.opendaylight.restconf.api.query.WithDefaultsParam;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.Insert;
-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.WriterFieldsTranslator;
 import org.opendaylight.restconf.server.api.DatabindContext;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -80,11 +80,11 @@ public class QueryParamsTest {
     @Test
     public void checkParametersTypesNegativeTest() {
         final var mockDatabind = DatabindContext.ofModel(mock(EffectiveModelContext.class));
-        assertInvalidIAE(ReceiveEventsParams::ofQueryParameters);
+        assertInvalidIAE(EventStreamGetParams::ofQueryParameters);
         assertUnknownParam(QueryParams::newDataGetParams);
         assertInvalidIAE(queryParams -> Insert.ofQueryParameters(mockDatabind, queryParams));
 
-        assertInvalidIAE(ReceiveEventsParams::ofQueryParameters, ContentParam.ALL);
+        assertInvalidIAE(EventStreamGetParams::ofQueryParameters, ContentParam.ALL);
         assertInvalidParam(QueryParams::newDataGetParams, InsertParam.LAST);
         assertInvalidIAE(queryParams -> Insert.ofQueryParameters(mockDatabind, queryParams), ContentParam.ALL);
     }
index dbe7e0c4190e1f07730f663781242e0ed989cbd0..398f0cf73f482093a41f4e2973e5debf1adea8c2 100644 (file)
@@ -35,8 +35,8 @@ import org.opendaylight.restconf.api.query.ChangedLeafNodesOnlyParam;
 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.nb.rfc8040.ReceiveEventsParams;
 import org.opendaylight.restconf.server.api.DatabindContext;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.restconf.server.mdsal.MdsalRestconfStreamRegistry;
 import org.opendaylight.restconf.server.mdsal.streams.dtcl.DataTreeChangeSource;
 import org.opendaylight.restconf.server.spi.DatabindProvider;
@@ -240,7 +240,7 @@ public class DataTreeChangeStreamTest extends AbstractConcurrentDataBrokerTest {
                 case JSON -> EncodingName.RFC8040_JSON;
                 case XML -> EncodingName.RFC8040_XML;
             },
-            new ReceiveEventsParams(null, null, null,
+            new EventStreamGetParams(null, null, null,
                 leafNodesOnly ? LeafNodesOnlyParam.of(true) : null,
                 skipNotificationData ? SkipNotificationDataParam.of(true) : null,
                 changedLeafNodesOnly ? ChangedLeafNodesOnlyParam.of(true) : null,
index dbda937232720db76884a0e6d088e83077061b43..feca29166938d88b4aee48042dfbcc8219696d31 100644 (file)
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
-import org.opendaylight.restconf.nb.rfc8040.ReceiveEventsParams;
+import org.opendaylight.restconf.server.api.EventStreamGetParams;
 import org.opendaylight.restconf.server.spi.RestconfStream;
 import org.opendaylight.restconf.server.spi.RestconfStream.EncodingName;
 import org.opendaylight.yangtools.concepts.Registration;
@@ -49,7 +49,7 @@ class SSESessionHandlerTest {
 
     private SSESender setup(final int maxFragmentSize, final long heartbeatInterval) throws Exception {
         final var sseSessionHandler = new SSESender(pingExecutor, eventSink, sse, stream,
-            EncodingName.RFC8040_XML, new ReceiveEventsParams(null, null, null, null, null, null, null),
+            EncodingName.RFC8040_XML, new EventStreamGetParams(null, null, null, null, null, null, null),
             maxFragmentSize, heartbeatInterval);
         doReturn(reg).when(stream).addSubscriber(eq(sseSessionHandler), any(), any());
         return sseSessionHandler;