Inline RestconfStreamsConstants 19/97519/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 18 Sep 2021 11:44:17 +0000 (13:44 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 18 Sep 2021 17:01:56 +0000 (19:01 +0200)
We have a number of single-use constants, make sure to inline them to
their users, making things a lot clearer.

Change-Id: Ifce07aa63086d90c47b3b6369c2bf7ef01589cf9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/CreateStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfStreamsConstants.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java

index b62e2ce67052c982bddd629390228b06423fc4ce..848aa328a0f5b8c4436419c100fcbdf7727b310d 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -58,7 +58,7 @@ final class CreateStreamUtil {
     private static final QName SCOPE_QNAME =
         QName.create(SAL_REMOTE_AUGMENT, RestconfStreamsConstants.SCOPE_PARAM_NAME).intern();
     private static final QName OUTPUT_TYPE_QNAME =
-        QName.create(SAL_REMOTE_AUGMENT, RestconfStreamsConstants.OUTPUT_TYPE_PARAM_NAME).intern();
+        QName.create(SAL_REMOTE_AUGMENT, "notification-output-type").intern();
     private static final NodeIdentifier DATASTORE_NODEID = NodeIdentifier.create(DATASTORE_QNAME);
     private static final NodeIdentifier SCOPE_NODEID = NodeIdentifier.create(SCOPE_QNAME);
     private static final NodeIdentifier OUTPUT_TYPE_NODEID = NodeIdentifier.create(OUTPUT_TYPE_QNAME);
@@ -156,13 +156,9 @@ final class CreateStreamUtil {
         final Scope scope = scopeName != null ? Scope.forName(scopeName).orElseThrow() : Scope.BASE;
 
         return RestconfStreamsConstants.DATA_SUBSCRIPTION
-                + "/"
-                + ListenersBroker.createStreamNameFromUri(
-                ParserIdentifier.stringFromYangInstanceIdentifier(path, schemaContext)
-                        + RestconfStreamsConstants.DS_URI
-                        + datastoreType
-                        + RestconfStreamsConstants.SCOPE_URI
-                        + scope);
+            + "/" + ListenersBroker.createStreamNameFromUri(IdentifierCodec.serialize(path, schemaContext)
+                + "/" + RestconfStreamsConstants.DATASTORE_PARAM_NAME + "=" + datastoreType
+                + "/" + RestconfStreamsConstants.SCOPE_PARAM_NAME + "=" + scope);
     }
 
     /**
@@ -174,12 +170,9 @@ final class CreateStreamUtil {
      *     are going to be generated.
      */
     private static YangInstanceIdentifier preparePath(final ContainerNode data, final QName qualifiedName) {
-        final Optional<DataContainerChild> path = data.findChildByArg(
-                new NodeIdentifier(QName.create(qualifiedName, RestconfStreamsConstants.STREAM_PATH_PARAM_NAME)));
-        Object pathValue = null;
-        if (path.isPresent()) {
-            pathValue = path.get().body();
-        }
+        final Object pathValue = data.findChildByArg(new NodeIdentifier(QName.create(qualifiedName, "path")))
+            .map(DataContainerChild::body)
+            .orElse(null);
         if (!(pathValue instanceof YangInstanceIdentifier)) {
             LOG.debug("Instance identifier {} was not normalized correctly", qualifiedName);
             throw new RestconfDocumentedException(
index 05333725a6d7edf5d078dcdbf9c4fb3f3580575b..cad9bee1db07be3ebe6c9cb09472e68e70dbe826 100644 (file)
@@ -34,7 +34,6 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -84,7 +83,7 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat
             schemaContextRef = schemaContextHandler.get();
             // FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS
             if (SAL_REMOTE_NAMESPACE.equals(namespace)) {
-                if (identifier.contains(RestconfStreamsConstants.CREATE_DATA_SUBSCRIPTION)) {
+                if (identifier.contains("create-data-change-event-subscription")) {
                     response = CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContextRef);
                 } else {
                     throw new RestconfDocumentedException("Not supported operation", ErrorType.RPC,
index 56110c4c2266512e7b29efe6d472544d639cafd5..1a08585272b623b2f9f373f0904ec765c25c54dd 100644 (file)
@@ -11,18 +11,11 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils;
  * Constants for streams.
  */
 public final class RestconfStreamsConstants {
-    public static final String STREAM_PATH_PARAM_NAME = "path";
     public static final String DATASTORE_PARAM_NAME = "datastore";
     public static final String SCOPE_PARAM_NAME = "scope";
-    public static final String OUTPUT_TYPE_PARAM_NAME = "notification-output-type";
-
-    public static final String DS_URI = '/' + DATASTORE_PARAM_NAME + '=';
-    public static final String SCOPE_URI = '/' + SCOPE_PARAM_NAME + '=';
 
     public static final String DATA_SUBSCRIPTION = "data-change-event-subscription";
-    public static final String CREATE_DATA_SUBSCRIPTION = "create-" + DATA_SUBSCRIPTION;
     public static final String NOTIFICATION_STREAM = "notification-stream";
-    public static final String CREATE_NOTIFICATION_STREAM = "create-" + NOTIFICATION_STREAM;
 
     public static final String STREAMS_PATH = "ietf-restconf-monitoring:restconf-state/streams";
     public static final String STREAM_PATH_PART = "/stream=";
@@ -30,9 +23,6 @@ public final class RestconfStreamsConstants {
     public static final String STREAM_ACCESS_PATH_PART = "/access=";
     public static final String STREAM_LOCATION_PATH_PART = "/location";
 
-    public static final String DATA_CHANGE_EVENT_STREAM_PATTERN = '/' + DATA_SUBSCRIPTION + "/*";
-    public static final String YANG_NOTIFICATION_STREAM_PATTERN = '/' + NOTIFICATION_STREAM + "/*";
-
     private RestconfStreamsConstants() {
         // Hidden on purpose
     }
index c7f32e3972ddc6641d59d01b86f4c8d47be47fd8..77a52811d24d223af26a649eb3a406ffe1603183 100644 (file)
@@ -59,8 +59,8 @@ public class WebInitializer {
                 .build())
             .addServlet(ServletDetails.builder()
                 .addAllUrlPatterns(List.of(
-                    RestconfConstants.BASE_URI_PATTERN + RestconfStreamsConstants.DATA_CHANGE_EVENT_STREAM_PATTERN,
-                    RestconfConstants.BASE_URI_PATTERN + RestconfStreamsConstants.YANG_NOTIFICATION_STREAM_PATTERN))
+                    RestconfConstants.BASE_URI_PATTERN + "/" + RestconfStreamsConstants.DATA_SUBSCRIPTION + "/*",
+                    RestconfConstants.BASE_URI_PATTERN + "/" + RestconfStreamsConstants.NOTIFICATION_STREAM + "/*"))
                 .servlet(webSocketServlet)
                 .build())
             .addServlet(ServletDetails.builder()