Promote NotificationQueryParams 03/98103/4
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Oct 2021 13:06:35 +0000 (15:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 24 Oct 2021 13:14:40 +0000 (15:14 +0200)
This is now a properly-aligned DTO containing possible request parameters,
make sure it is widely available.

JIRA: NETCONF-773
Change-Id: Ifb7a26777919ac8d97608c8fc975c6a565be3ac8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractReplayParameter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java

index d0ebee9ed9e295168242774b92874a001d6e998b..a413ea91292ffa194db66a1816c3b4a297b25ac3 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.restconf.nb.rfc8040;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
 import java.net.URI;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
@@ -37,6 +38,11 @@ public abstract class AbstractReplayParameter implements Immutable {
         return value.getValue();
     }
 
+    @Override
+    public final String toString() {
+        return MoreObjects.toStringHelper(this).add("value", uriValue()).toString();
+    }
+
     public static final URI capabilityUri() {
         return CAPABILITY;
     }
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/NotificationQueryParams.java
new file mode 100644 (file)
index 0000000..45e2c82
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * 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 java.util.List;
+import java.util.Map.Entry;
+import javax.ws.rs.core.UriInfo;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.yangtools.concepts.Immutable;
+
+/**
+ * Parser and holder of query paramteres from uriInfo for notifications.
+ */
+public final class NotificationQueryParams implements Immutable {
+    private final StartTimeParameter startTime;
+    private final StopTimeParameter stopTime;
+    private final FilterParameter filter;
+    private final boolean skipNotificationData;
+
+    private NotificationQueryParams(final StartTimeParameter startTime, final StopTimeParameter stopTime,
+            final FilterParameter filter, final boolean skipNotificationData) {
+        this.startTime = startTime;
+        this.stopTime = stopTime;
+        this.filter = filter;
+        this.skipNotificationData = skipNotificationData;
+    }
+
+    // FIXME: this is JAX-RS specific
+    public static @NonNull NotificationQueryParams fromUriInfo(final UriInfo uriInfo) {
+        StartTimeParameter startTime = null;
+        StopTimeParameter stopTime = null;
+        FilterParameter filter = null;
+        boolean skipNotificationData = false;
+
+        for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
+            final String paramName = entry.getKey();
+            final List<String> paramValues = entry.getValue();
+            if (paramName.equals(StartTimeParameter.uriName())) {
+                switch (paramValues.size()) {
+                    case 0:
+                        break;
+                    case 1:
+                        final String str = paramValues.get(0);
+                        try {
+                            startTime = StartTimeParameter.forUriValue(str);
+                        } catch (IllegalArgumentException e) {
+                            throw new RestconfDocumentedException("Invalid start-time date: " + str, e);
+                        }
+                        break;
+                    default:
+                        throw new RestconfDocumentedException("Start-time parameter can be used only once.");
+                }
+            } else if (paramName.equals(StopTimeParameter.uriName())) {
+                switch (paramValues.size()) {
+                    case 0:
+                        break;
+                    case 1:
+                        final String str = paramValues.get(0);
+                        try {
+                            stopTime = StopTimeParameter.forUriValue(str);
+                        } catch (IllegalArgumentException e) {
+                            throw new RestconfDocumentedException("Invalid stop-time date: " + str, e);
+                        }
+                        break;
+                    default:
+                        throw new RestconfDocumentedException("Stop-time parameter can be used only once.");
+                }
+            } else if (paramName.equals(FilterParameter.uriName())) {
+                if (!paramValues.isEmpty()) {
+                    filter = FilterParameter.forUriValue(paramValues.get(0));
+                }
+            } else if (paramName.equals("odl-skip-notification-data")) {
+                switch (paramValues.size()) {
+                    case 0:
+                        break;
+                    case 1:
+                        skipNotificationData = Boolean.parseBoolean(paramValues.get(0));
+                        break;
+                    default:
+                        throw new RestconfDocumentedException(
+                            "Odl-skip-notification-data parameter can be used only once.");
+                }
+            } else {
+                throw new RestconfDocumentedException("Bad parameter used with notifications: " + paramName);
+            }
+        }
+        if (startTime == null && stopTime != null) {
+            throw new RestconfDocumentedException("Stop-time parameter has to be used with start-time parameter.");
+        }
+
+        return new NotificationQueryParams(startTime, stopTime, filter, skipNotificationData);
+    }
+
+    /**
+     * Get start-time query parameter.
+     *
+     * @return start-time
+     */
+    public @Nullable StartTimeParameter startTime() {
+        return startTime;
+    }
+
+    /**
+     * Get stop-time query parameter.
+     *
+     * @return stop-time
+     */
+    public @Nullable StopTimeParameter stopTime() {
+        return stopTime;
+    }
+
+    /**
+     * Get filter query parameter.
+     *
+     * @return filter
+     */
+    public @Nullable FilterParameter filter() {
+        return filter;
+    }
+
+    /**
+     * Check whether this query should notify changes without data.
+     *
+     * @return true if this query should notify about changes with  data
+     */
+    public boolean isSkipNotificationData() {
+        return skipNotificationData;
+    }
+
+    @Override
+    public String toString() {
+        final var helper = MoreObjects.toStringHelper(this);
+        if (startTime != null) {
+            helper.add("startTime", startTime.uriValue());
+        }
+        if (stopTime != null) {
+            helper.add("stopTime", stopTime.uriValue());
+        }
+        if (filter != null) {
+            helper.add("filter", filter.uriValue());
+        }
+        return helper.add("skipNotificationData", skipNotificationData).toString();
+    }
+}
index 35cdea9e8792007fc006950f3a98b3988d40bcb6..a6d5dca51d09ceceaffef65adf3059fe72324103 100644 (file)
@@ -10,19 +10,14 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 import static com.google.common.base.Preconditions.checkState;
 
 import java.net.URI;
-import java.util.List;
-import java.util.Map.Entry;
 import java.util.Optional;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.UriInfo;
-import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.FilterParameter;
-import org.opendaylight.restconf.nb.rfc8040.StartTimeParameter;
-import org.opendaylight.restconf.nb.rfc8040.StopTimeParameter;
+import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
@@ -153,123 +148,4 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
             return schemaHandler;
         }
     }
-
-    /**
-     * Parser and holder of query paramteres from uriInfo for notifications.
-     */
-    public static final class NotificationQueryParams {
-        private final StartTimeParameter startTime;
-        private final StopTimeParameter stopTime;
-        private final FilterParameter filter;
-        private final boolean skipNotificationData;
-
-        private NotificationQueryParams(final StartTimeParameter startTime, final StopTimeParameter stopTime,
-                final FilterParameter filter, final boolean skipNotificationData) {
-            this.startTime = startTime;
-            this.stopTime = stopTime;
-            this.filter = filter;
-            this.skipNotificationData = skipNotificationData;
-        }
-
-        static NotificationQueryParams fromUriInfo(final UriInfo uriInfo) {
-            StartTimeParameter startTime = null;
-            StopTimeParameter stopTime = null;
-            FilterParameter filter = null;
-            boolean skipNotificationData = false;
-
-            for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
-                final String paramName = entry.getKey();
-                final List<String> paramValues = entry.getValue();
-                if (paramName.equals(StartTimeParameter.uriName())) {
-                    switch (paramValues.size()) {
-                        case 0:
-                            break;
-                        case 1:
-                            final String str = paramValues.get(0);
-                            try {
-                                startTime = StartTimeParameter.forUriValue(str);
-                            } catch (IllegalArgumentException e) {
-                                throw new RestconfDocumentedException("Invalid start-time date: " + str, e);
-                            }
-                            break;
-                        default:
-                            throw new RestconfDocumentedException("Start-time parameter can be used only once.");
-                    }
-                } else if (paramName.equals(StopTimeParameter.uriName())) {
-                    switch (paramValues.size()) {
-                        case 0:
-                            break;
-                        case 1:
-                            final String str = paramValues.get(0);
-                            try {
-                                stopTime = StopTimeParameter.forUriValue(str);
-                            } catch (IllegalArgumentException e) {
-                                throw new RestconfDocumentedException("Invalid stop-time date: " + str, e);
-                            }
-                            break;
-                        default:
-                            throw new RestconfDocumentedException("Stop-time parameter can be used only once.");
-                    }
-                } else if (paramName.equals(FilterParameter.uriName())) {
-                    if (!paramValues.isEmpty()) {
-                        filter = FilterParameter.forUriValue(paramValues.get(0));
-                    }
-                } else if (paramName.equals("odl-skip-notification-data")) {
-                    switch (paramValues.size()) {
-                        case 0:
-                            break;
-                        case 1:
-                            skipNotificationData = Boolean.parseBoolean(paramValues.get(0));
-                            break;
-                        default:
-                            throw new RestconfDocumentedException(
-                                "Odl-skip-notification-data parameter can be used only once.");
-                    }
-                } else {
-                    throw new RestconfDocumentedException("Bad parameter used with notifications: " + paramName);
-                }
-            }
-            if (startTime == null && stopTime != null) {
-                throw new RestconfDocumentedException("Stop-time parameter has to be used with start-time parameter.");
-            }
-
-            return new NotificationQueryParams(startTime, stopTime, filter, skipNotificationData);
-        }
-
-        /**
-         * Get start-time query parameter.
-         *
-         * @return start-time
-         */
-        public @Nullable StartTimeParameter startTime() {
-            return startTime;
-        }
-
-        /**
-         * Get stop-time query parameter.
-         *
-         * @return stop-time
-         */
-        public @Nullable StopTimeParameter stopTime() {
-            return stopTime;
-        }
-
-        /**
-         * Get filter query parameter.
-         *
-         * @return filter
-         */
-        public @Nullable FilterParameter filter() {
-            return filter;
-        }
-
-        /**
-         * Check whether this query should notify changes without data.
-         *
-         * @return true if this query should notify about changes with  data
-         */
-        public boolean isSkipNotificationData() {
-            return skipNotificationData;
-        }
-    }
 }
index 6d872c8227b60e93adc20e2d26967db4c3383fd9..4c7dc29bb8d56fdf2c5f98a9314c8d5722229f9c 100644 (file)
@@ -21,10 +21,10 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;