Refactor constants relating to restconf-monitoring 68/96268/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 19 May 2021 13:30:48 +0000 (15:30 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 19 May 2021 19:17:10 +0000 (21:17 +0200)
We have a number of constants scattered around, some of which can
have better names and placement, or are duplicates of constants
generated for the ietf-restconf binding.

Reuse generated constants and construct native YangInstanceIdentifiers,
so we minimize duplication.

JIRA: NETCONF-773
Change-Id: I5a17cbdd863fcdbaf75db56d4a8b0daddfe5e7a9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/pom.xml
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
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/AbstractNotificationsData.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtil.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtilTest.java

index efd47e2c6968b8677a1e206618a8a48ff0a1400f..13458911866e0828a72d6beec59a45af7beb36ae 100644 (file)
       <groupId>org.opendaylight.netconf</groupId>
       <artifactId>restconf-common</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+      <artifactId>rfc6991-ietf-yang-types</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
       <artifactId>rfc8525</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.netconf</groupId>
+      <artifactId>ietf-restconf-monitoring</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.netconf</groupId>
       <artifactId>netconf-api</artifactId>
       <artifactId>yang-model-export</artifactId>
     </dependency>
 
-    <dependency>
-      <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
-      <artifactId>rfc6991-ietf-yang-types</artifactId>
-    </dependency>
-
     <dependency>
       <groupId>org.opendaylight.mdsal</groupId>
       <artifactId>mdsal-dom-spi</artifactId>
index ba02ed2d953c0556732c1d436debb184f95a2716..606d5f15d1fc39a1d6fba80d543fbd18d82f2ea4 100644 (file)
@@ -7,7 +7,11 @@
  */
 package org.opendaylight.restconf.nb.rfc8040;
 
+import com.google.common.annotations.Beta;
 import java.net.URI;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.RestconfState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.Streams;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.$YangModuleInfoImpl;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Deviation;
@@ -15,6 +19,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.librar
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 /**
  * Base Draft for Restconf project.
@@ -23,23 +30,66 @@ import org.opendaylight.yangtools.yang.common.Revision;
  * <li>Constants for modules
  * <ul>
  * <li>{@link RestconfModule}
- * <li>{@link MonitoringModule}
  * </ul>
  * </ul>
  */
 public final class Rfc8040 {
+    private static final YangInstanceIdentifier RESTCONF_STATE_STREAMS = YangInstanceIdentifier.create(
+        NodeIdentifier.create(RestconfState.QNAME), NodeIdentifier.create(Streams.QNAME));
+    private static final QName STREAM_QNAME = QName.create(Streams.QNAME, "stream").intern();
+
     private Rfc8040() {
         // Hidden on purpose
     }
 
+    @Beta
+    // FIXME: move this method somewhere else
+    public static @NonNull YangInstanceIdentifier restconfStateStreamPath(final String streamName) {
+        return restconfStateStreamPath(NodeIdentifierWithPredicates.of(Streams.QNAME, STREAM_QNAME, streamName));
+    }
+
+    @Beta
+    // FIXME: move this method somewhere else
+    public static @NonNull YangInstanceIdentifier restconfStateStreamPath(final NodeIdentifierWithPredicates arg) {
+        return RESTCONF_STATE_STREAMS.node(arg);
+    }
+
     /**
-     * Set of application specific media types to identify each of the available resource types.
+     * Constants for <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-11.4">RESTCONF Capability URNs</a>.
      */
-    public static final class MediaTypes {
-        private MediaTypes() {
+    public static final class Capabilities {
+        /**
+         * Support for <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.2">depth</a> Query Parameter.
+         */
+        public static final String DEPTH = "urn:ietf:params:restconf:capability:depth:1.0";
+        /**
+         * Support for <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.3">fields</a> Query Parameter.
+         */
+        public static final String FIELDS = "urn:ietf:params:restconf:capability:fields:1.0";
+        /**
+         * Support for <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.4">filter</a> Query Parameter.
+         */
+        public static final String FILTER = "urn:ietf:params:restconf:capability:filter:1.0";
+        /**
+         * Support for <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.7">start-time</a>
+         * and <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.7">stop-time</a> Query Parameters.
+         */
+        public static final String REPLAY = "urn:ietf:params:restconf:capability:replay:1.0";
+        /**
+         * Support for
+         * <a href="https://datatracker.ietf.org/doc/html/rfc8040#section-4.8.9">with-defaults</a> Query Parameter.
+         */
+        public static final String WITH_DEFAULTS = "urn:ietf:params:restconf:capability:with-defaults:1.0";
+
+        private Capabilities() {
             // Hidden on purpose
         }
+    }
 
+    /**
+     * Set of application specific media types to identify each of the available resource types.
+     */
+    public static final class MediaTypes {
         /**
          * See: <a href="https://tools.ietf.org/html/rfc6415">rfc6415</a>.
          */
@@ -48,16 +98,17 @@ public final class Rfc8040 {
         public static final String DATA = "application/yang-data";
         public static final String YANG_PATCH = "application/yang.patch";
         public static final String YANG_PATCH_STATUS = "application/yang.patch-status";
+
+        private MediaTypes() {
+            // Hidden on purpose
+        }
     }
 
     /**
      * Constants for restconf module.
      */
+    // FIXME: split this out
     public static final class RestconfModule {
-        private RestconfModule() {
-            throw new UnsupportedOperationException("Util class");
-        }
-
         public static final Revision REVISION = Revision.of("2017-01-26");
         public static final String NAME = "ietf-restconf";
         public static final String NAMESPACE = "urn:ietf:params:xml:ns:yang:ietf-restconf";
@@ -82,16 +133,17 @@ public final class Rfc8040 {
         public static final QName ERROR_MESSAGE_QNAME = QName.create(IETF_RESTCONF_QNAME, "error-message").intern();
         public static final QName ERROR_INFO_QNAME = QName.create(IETF_RESTCONF_QNAME, "error-info").intern();
         public static final QName ERROR_PATH_QNAME = QName.create(IETF_RESTCONF_QNAME, "error-path").intern();
+
+        private RestconfModule() {
+            // Hidden on purpose
+        }
     }
 
     /**
      * Constants for ietf-yang-library model.
      */
+    // FIXME: split this out
     public static final class IetfYangLibrary {
-        private IetfYangLibrary() {
-            // Hidden on purpose
-        }
-
         public static final QNameModule MODULE_QNAME = $YangModuleInfoImpl.getInstance().getName().getModule();
         public static final Revision REVISION = MODULE_QNAME.getRevision().orElseThrow();
 
@@ -121,66 +173,9 @@ public final class Rfc8040 {
                 QName.create(MODULE_QNAME, "conformance-type").intern();
 
         public static final QName SPECIFIC_MODULE_SUBMODULE_LIST_QNAME = Submodule.QNAME;
-    }
 
-    /**
-     * Constants for ietf-restconf-monitoring module.
-     */
-    public static final class MonitoringModule {
-        private MonitoringModule() {
+        private IetfYangLibrary() {
             // Hidden on purpose
         }
-
-        public static final String NAME = "ietf-restconf-monitoring";
-        public static final String NAMESPACE = "urn:ietf:params:xml:ns:yang:ietf-restconf-monitoring";
-        public static final Revision REVISION = Revision.of("2017-01-26");
-        public static final String PATH_TO_STREAM_WITHOUT_KEY =
-                "ietf-restconf-monitoring:restconf-state/streams/stream=";
-
-        public static final URI URI_MODULE = URI.create(NAMESPACE);
-
-        public static final QNameModule MODULE_QNAME = QNameModule.create(URI_MODULE, REVISION).intern();
-
-        public static final QName CONT_RESTCONF_STATE_QNAME = QName.create(MODULE_QNAME, "restconf-state").intern();
-
-        public static final QName CONT_CAPABILITES_QNAME = QName.create(MODULE_QNAME, "capabilities").intern();
-
-        public static final QName LEAF_LIST_CAPABILITY_QNAME = QName.create(MODULE_QNAME, "capability").intern();
-
-        public static final QName CONT_STREAMS_QNAME = QName.create(MODULE_QNAME, "streams").intern();
-
-        public static final QName LIST_STREAM_QNAME = QName.create(MODULE_QNAME, "stream").intern();
-
-        public static final QName LEAF_NAME_STREAM_QNAME = QName.create(MODULE_QNAME, "name").intern();
-
-        public static final QName LEAF_DESCR_STREAM_QNAME = QName.create(MODULE_QNAME, "description").intern();
-
-        public static final QName LEAF_REPLAY_SUPP_STREAM_QNAME = QName.create(MODULE_QNAME, "replay-support").intern();
-
-        public static final QName LEAF_START_TIME_STREAM_QNAME = QName.create(MODULE_QNAME, "replay-log-creation-time")
-            .intern();
-
-        public static final QName LIST_ACCESS_STREAM_QNAME = QName.create(MODULE_QNAME, "access").intern();
-
-        public static final QName LEAF_ENCODING_ACCESS_QNAME = QName.create(MODULE_QNAME, "encoding").intern();
-
-        public static final QName LEAF_LOCATION_ACCESS_QNAME = QName.create(MODULE_QNAME, "location").intern();
-
-        /**
-         * Constants for capabilities.
-         */
-        public static final class QueryParams {
-            private QueryParams() {
-                // Hidden on purpose
-            }
-
-            public static final String URI_BASE = "urn:ietf:params:restconf:capability:";
-
-            public static final String DEPTH = URI_BASE + "depth:1.0";
-            public static final String FIELDS = URI_BASE + "fields:1.0";
-            public static final String FILTER = URI_BASE + "filter:1.0";
-            public static final String REPLAY = URI_BASE + "replay:1.0";
-            public static final String WITH_DEFAULTS = URI_BASE + "with-defaults:1.0";
-        }
     }
 }
index f177962866ae7e580927f43c08135498205f77c5..a302e56d7f164e213ca335a596a9fa8de36935e9 100644 (file)
@@ -25,8 +25,8 @@ import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
 import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.RestconfState;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -92,7 +92,7 @@ public class SchemaContextHandler implements EffectiveModelContextListener, Auto
                 String.valueOf(this.moduleSetId.incrementAndGet())));
         }
 
-        final Module monitoringModule = schemaContext.findModule(MonitoringModule.MODULE_QNAME).orElse(null);
+        final Module monitoringModule = schemaContext.findModule(RestconfState.QNAME.getModule()).orElse(null);
         if (monitoringModule != null) {
             putData(RestconfMappingNodeUtil.mapCapabilites(monitoringModule));
         }
index cce8ebc8c1dafa8befe6399240399b6d4f84f2cb..5b12419e517580c033aced06f96d2cd295be0d57 100644 (file)
@@ -66,7 +66,6 @@ import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperations
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.Immutable;
@@ -221,10 +220,8 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                 listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null,
                 listener.getOutputType(), uri);
 
-        final String name = listener.getSchemaPath().lastNodeIdentifier().getLocalName();
         transaction.merge(LogicalDatastoreType.OPERATIONAL,
-            IdentifierCodec.deserialize(Rfc8040.MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name, schemaContext),
-            mapToStreams);
+            Rfc8040.restconfStateStreamPath(mapToStreams.getIdentifier()), mapToStreams);
     }
 
     @Override
index 553a59fe73c395e35f784b75ca937c73c8e0b001..ff06d5b24de99e422d92f8c350749812f8c0e591 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
@@ -29,7 +30,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.util.DataChangeScope;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 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.ResolveEnumUtil;
@@ -153,9 +154,7 @@ abstract class SubscribeToStreamUtil {
                     notificationListenerAdapter.getSchemaPath().lastNodeIdentifier(),
                     schemaContext.getNotifications(), notificationQueryParams.getStart(),
                     notificationListenerAdapter.getOutputType(), uri);
-        writeDataToDS(schemaContext,
-            notificationListenerAdapter.getSchemaPath().lastNodeIdentifier().getLocalName(), writeTransaction,
-            mapToStreams);
+        writeDataToDS(writeTransaction, mapToStreams);
         submitData(writeTransaction);
         transactionChain.close();
         return uri;
@@ -213,17 +212,16 @@ abstract class SubscribeToStreamUtil {
         final MapEntryNode mapToStreams =
             RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(listener.get().getPath(),
                 notificationQueryParams.getStart(), listener.get().getOutputType(), uri, schemaContext, serializedPath);
-        writeDataToDS(schemaContext, serializedPath, writeTransaction, mapToStreams);
+        writeDataToDS(writeTransaction, mapToStreams);
         submitData(writeTransaction);
         transactionChain.close();
         return uri;
     }
 
-    private static void writeDataToDS(final EffectiveModelContext schemaContext, final String name,
-            final DOMDataTreeReadWriteTransaction readWriteTransaction, final MapEntryNode mapToStreams) {
-        readWriteTransaction.merge(LogicalDatastoreType.OPERATIONAL,
-            // FIXME: do not use IdentifierCodec here
-            IdentifierCodec.deserialize(MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name, schemaContext),
+    // FIXME: callers are utter duplicates, refactor them
+    private static void writeDataToDS(final DOMDataTreeWriteOperations tx, final MapEntryNode mapToStreams) {
+        // FIXME: use put() here
+        tx.merge(LogicalDatastoreType.OPERATIONAL, Rfc8040.restconfStateStreamPath(mapToStreams.getIdentifier()),
             mapToStreams);
     }
 
index 45dde3f2da1fce45b8e7bf3ca191508e5d9f39a8..61b7b7a8700e80f0bbefc1c277c3daa73e23ddc7 100644 (file)
@@ -27,12 +27,10 @@ import javax.xml.transform.stream.StreamResult;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
@@ -60,12 +58,8 @@ abstract class AbstractNotificationsData {
     /**
      * Transaction chain for delete data in DS on close().
      *
-     * @param transactionChainHandler
-     *            creating new write transaction for delete data on close
-     * @param schemaHandler
-     *            for getting schema to deserialize
-     *            {@link MonitoringModule#PATH_TO_STREAM_WITHOUT_KEY} to
-     *            {@link YangInstanceIdentifier}
+     * @param transactionChainHandler creating new write transaction for delete data on close
+     * @param schemaHandler for formatting notifications
      */
     @SuppressWarnings("checkstyle:hiddenField")
     public void setCloseVars(final TransactionChainHandler transactionChainHandler,
@@ -80,8 +74,7 @@ abstract class AbstractNotificationsData {
     protected void deleteDataInDS() throws Exception {
         final DOMTransactionChain transactionChain = this.transactionChainHandler.get();
         final DOMDataTreeWriteTransaction wTx = transactionChain.newWriteOnlyTransaction();
-        wTx.delete(LogicalDatastoreType.OPERATIONAL, IdentifierCodec
-                .deserialize(MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + this.localName, this.schemaHandler.get()));
+        wTx.delete(LogicalDatastoreType.OPERATIONAL, Rfc8040.restconfStateStreamPath(this.localName));
         wTx.commit().get();
         transactionChain.close();
     }
index ad6a0edb19e09a058c59ce7db5d8b1781ca28855..38835e8d7e9d06b069fdf41cde767bbd6356b594 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.utils.mapping;
 
+import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.$YangModuleInfoImpl.qnameOf;
+
+import com.google.common.annotations.VisibleForTesting;
 import java.net.URI;
 import java.time.Instant;
 import java.time.OffsetDateTime;
@@ -17,10 +20,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule.QueryParams;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.RestconfState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.Capabilities;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.streams.Stream;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.streams.stream.Access;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module.ConformanceType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -51,9 +57,22 @@ import org.opendaylight.yangtools.yang.model.api.Submodule;
 
 /**
  * Util class for mapping nodes.
- *
  */
 public final class RestconfMappingNodeUtil {
+    private static final QName CAPABILITY_QNAME = qnameOf("capability");
+    @VisibleForTesting
+    static final QName DESCRIPTION_QNAME = qnameOf("description");
+    @VisibleForTesting
+    static final QName ENCODING_QNAME = qnameOf("encoding");
+    @VisibleForTesting
+    static final QName LOCATION_QNAME = qnameOf("location");
+    @VisibleForTesting
+    static final QName NAME_QNAME = qnameOf("name");
+    @VisibleForTesting
+    static final QName REPLAY_SUPPORT_QNAME = qnameOf("replay-support");
+    @VisibleForTesting
+    static final QName REPLAY_LOG_CREATION_TIME = qnameOf("replay-log-creation-time");
+
     private RestconfMappingNodeUtil() {
         // Hidden on purpose
     }
@@ -218,16 +237,16 @@ public final class RestconfMappingNodeUtil {
      */
     public static ContainerNode mapCapabilites(final Module monitoringModule) {
         return Builders.containerBuilder()
-            .withNodeIdentifier(new NodeIdentifier(MonitoringModule.CONT_RESTCONF_STATE_QNAME))
+            .withNodeIdentifier(new NodeIdentifier(RestconfState.QNAME))
             .withChild(Builders.containerBuilder()
-                .withNodeIdentifier(new NodeIdentifier(MonitoringModule.CONT_CAPABILITES_QNAME))
+                .withNodeIdentifier(new NodeIdentifier(Capabilities.QNAME))
                 .withChild(Builders.<String>orderedLeafSetBuilder()
-                    .withNodeIdentifier(new NodeIdentifier(MonitoringModule.LEAF_LIST_CAPABILITY_QNAME))
-                    .withChildValue(QueryParams.DEPTH)
-                    .withChildValue(QueryParams.FIELDS)
-                    .withChildValue(QueryParams.FILTER)
-                    .withChildValue(QueryParams.REPLAY)
-                    .withChildValue(QueryParams.WITH_DEFAULTS)
+                    .withNodeIdentifier(new NodeIdentifier(CAPABILITY_QNAME))
+                    .withChildValue(Rfc8040.Capabilities.DEPTH)
+                    .withChildValue(Rfc8040.Capabilities.FIELDS)
+                    .withChildValue(Rfc8040.Capabilities.FILTER)
+                    .withChildValue(Rfc8040.Capabilities.REPLAY)
+                    .withChildValue(Rfc8040.Capabilities.WITH_DEFAULTS)
                     .build())
                 .build())
             .build();
@@ -252,17 +271,14 @@ public final class RestconfMappingNodeUtil {
                 final String streamName = notifiQName.getLocalName();
                 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamEntry =
                     Builders.mapEntryBuilder()
-                        .withNodeIdentifier(NodeIdentifierWithPredicates.of(MonitoringModule.LIST_STREAM_QNAME,
-                            MonitoringModule.LEAF_NAME_STREAM_QNAME, streamName))
-                        .withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_NAME_STREAM_QNAME, streamName));
+                        .withNodeIdentifier(NodeIdentifierWithPredicates.of(Stream.QNAME, NAME_QNAME, streamName))
+                        .withChild(ImmutableNodes.leafNode(NAME_QNAME, streamName));
 
                 notificationDefinition.getDescription().ifPresent(
-                    desc -> streamEntry.withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_DESCR_STREAM_QNAME,
-                        desc)));
-                streamEntry.withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME,
-                    Boolean.TRUE));
+                    desc -> streamEntry.withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, desc)));
+                streamEntry.withChild(ImmutableNodes.leafNode(REPLAY_SUPPORT_QNAME, Boolean.TRUE));
                 if (start != null) {
-                    streamEntry.withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_START_TIME_STREAM_QNAME,
+                    streamEntry.withChild(ImmutableNodes.leafNode(REPLAY_LOG_CREATION_TIME,
                         DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.ofInstant(start,
                             ZoneId.systemDefault()))));
                 }
@@ -278,13 +294,11 @@ public final class RestconfMappingNodeUtil {
 
     private static MapNode createAccessList(final String outputType, final URI uriToWebsocketServer) {
         return Builders.mapBuilder()
-            .withNodeIdentifier(new NodeIdentifier(MonitoringModule.LIST_ACCESS_STREAM_QNAME))
+            .withNodeIdentifier(new NodeIdentifier(Access.QNAME))
             .withChild(Builders.mapEntryBuilder()
-                .withNodeIdentifier(NodeIdentifierWithPredicates.of(MonitoringModule.LIST_ACCESS_STREAM_QNAME,
-                    MonitoringModule.LEAF_ENCODING_ACCESS_QNAME, outputType))
-                .withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_ENCODING_ACCESS_QNAME, outputType))
-                .withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_LOCATION_ACCESS_QNAME,
-                    uriToWebsocketServer.toString()))
+                .withNodeIdentifier(NodeIdentifierWithPredicates.of(Access.QNAME, ENCODING_QNAME, outputType))
+                .withChild(ImmutableNodes.leafNode(ENCODING_QNAME, outputType))
+                .withChild(ImmutableNodes.leafNode(LOCATION_QNAME, uriToWebsocketServer.toString()))
                 .build())
             .build();
     }
@@ -309,16 +323,15 @@ public final class RestconfMappingNodeUtil {
                 .getSchemaNode();
         final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamEntry =
             Builders.mapEntryBuilder()
-                .withNodeIdentifier(NodeIdentifierWithPredicates.of(MonitoringModule.LIST_STREAM_QNAME,
-                    MonitoringModule.LEAF_NAME_STREAM_QNAME, streamName))
-                .withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_NAME_STREAM_QNAME, streamName));
+                .withNodeIdentifier(NodeIdentifierWithPredicates.of(Stream.QNAME, NAME_QNAME, streamName))
+                .withChild(ImmutableNodes.leafNode(NAME_QNAME, streamName));
 
         schemaNode.getDescription().ifPresent(desc ->
-            streamEntry.withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_DESCR_STREAM_QNAME, desc)));
+            streamEntry.withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, desc)));
 
         return streamEntry
-            .withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME, Boolean.TRUE))
-            .withChild(ImmutableNodes.leafNode(MonitoringModule.LEAF_START_TIME_STREAM_QNAME,
+            .withChild(ImmutableNodes.leafNode(REPLAY_SUPPORT_QNAME, Boolean.TRUE))
+            .withChild(ImmutableNodes.leafNode(REPLAY_LOG_CREATION_TIME,
                 DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(OffsetDateTime.ofInstant(start, ZoneId.systemDefault()))))
             .withChild(createAccessList(outputType, uri))
             .build();
index 5f93049d52ff537ba2d9e91ca9d312810180e6a9..7a04f6de1ce335b557bc62d3e16f22d3ae7e9a23 100644 (file)
@@ -23,12 +23,13 @@ import java.util.List;
 import java.util.Map;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
-import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule.QueryParams;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.RestconfModule;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.RestconfState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.monitoring.rev170126.restconf.state.Capabilities;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -86,13 +87,13 @@ public class RestconfMappingNodeUtilTest {
 
     @Test
     public void restconfStateCapabilitesTest() {
-        final Module monitoringModule = schemaContextMonitoring.findModule(MonitoringModule.MODULE_QNAME).get();
+        final Module monitoringModule = schemaContextMonitoring.findModule(RestconfState.QNAME.getModule()).get();
         final ContainerNode normNode = RestconfMappingNodeUtil.mapCapabilites(monitoringModule);
         assertNotNull(normNode);
         final List<Object> listOfValues = new ArrayList<>();
 
         for (final DataContainerChild<?, ?> child : normNode.getValue()) {
-            if (child.getNodeType().equals(MonitoringModule.CONT_CAPABILITES_QNAME)) {
+            if (child.getNodeType().equals(Capabilities.QNAME)) {
                 for (final DataContainerChild<?, ?> dataContainerChild : ((ContainerNode) child).getValue()) {
                     for (final Object entry : ((LeafSetNode<?>) dataContainerChild).getValue()) {
                         listOfValues.add(((LeafSetEntryNode<?>) entry).getValue());
@@ -100,11 +101,11 @@ public class RestconfMappingNodeUtilTest {
                 }
             }
         }
-        assertTrue(listOfValues.contains(QueryParams.DEPTH));
-        assertTrue(listOfValues.contains(QueryParams.FIELDS));
-        assertTrue(listOfValues.contains(QueryParams.FILTER));
-        assertTrue(listOfValues.contains(QueryParams.REPLAY));
-        assertTrue(listOfValues.contains(QueryParams.WITH_DEFAULTS));
+        assertTrue(listOfValues.contains(Rfc8040.Capabilities.DEPTH));
+        assertTrue(listOfValues.contains(Rfc8040.Capabilities.FIELDS));
+        assertTrue(listOfValues.contains(Rfc8040.Capabilities.FILTER));
+        assertTrue(listOfValues.contains(Rfc8040.Capabilities.REPLAY));
+        assertTrue(listOfValues.contains(Rfc8040.Capabilities.WITH_DEFAULTS));
     }
 
     @Test
@@ -129,7 +130,7 @@ public class RestconfMappingNodeUtilTest {
         final URI uri = new URI("uri");
 
         final Map<QName, Object> map = prepareMap("notifi", uri, start, outputType);
-        map.put(MonitoringModule.LEAF_DESCR_STREAM_QNAME, "Notifi");
+        map.put(RestconfMappingNodeUtil.DESCRIPTION_QNAME, "Notifi");
 
         final QName notifiQName = QName.create("urn:nested:module", "2014-06-03", "notifi");
         final MapEntryNode mappedData = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(
@@ -140,12 +141,12 @@ public class RestconfMappingNodeUtilTest {
     private static Map<QName, Object> prepareMap(final String name, final URI uri, final Instant start,
             final String outputType) {
         final Map<QName, Object> map = new HashMap<>();
-        map.put(MonitoringModule.LEAF_NAME_STREAM_QNAME, name);
-        map.put(MonitoringModule.LEAF_LOCATION_ACCESS_QNAME, uri.toString());
-        map.put(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME, Boolean.TRUE);
-        map.put(MonitoringModule.LEAF_START_TIME_STREAM_QNAME, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
+        map.put(RestconfMappingNodeUtil.NAME_QNAME, name);
+        map.put(RestconfMappingNodeUtil.LOCATION_QNAME, uri.toString());
+        map.put(RestconfMappingNodeUtil.REPLAY_SUPPORT_QNAME, Boolean.TRUE);
+        map.put(RestconfMappingNodeUtil.REPLAY_LOG_CREATION_TIME, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
             OffsetDateTime.ofInstant(start, ZoneId.systemDefault())));
-        map.put(MonitoringModule.LEAF_ENCODING_ACCESS_QNAME, outputType);
+        map.put(RestconfMappingNodeUtil.ENCODING_QNAME, outputType);
         return map;
     }