Move RestconfConstants.MOUNT 60/107060/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Jul 2023 16:09:09 +0000 (18:09 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 25 Jul 2023 20:46:24 +0000 (20:46 +0000)
This constant is only used in ParserIdentifier, move it there.

Change-Id: I8caba44e532168e34e640f231d2379c57f3b9a5e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/RestconfConstants.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifier.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/ParserIdentifierTest.java

index 12363a9bb511c579d899b51d2d32af317264d5e5..2979e028a9298d7bfd6446e2ba552789d432afbf 100644 (file)
@@ -17,12 +17,6 @@ public final class RestconfConstants {
     public static final String BASE_URI_PATTERN = "rests";
     public static final String NOTIF = "notif";
 
-    // FIXME: Remove this constant. All logic relying on this constant should instead rely on YangInstanceIdentifier
-    //        equivalent coming out of argument parsing. This may require keeping List<YangInstanceIdentifier> as the
-    //        nested path split on yang-ext:mount. This splitting needs to be based on consulting the
-    //        EffectiveModelContext and allowing it only where yang-ext:mount is actually used in models.
-    public static final String MOUNT = "yang-ext:mount";
-
     private RestconfConstants() {
         // Hidden on purpose
     }
index eeae15a48941e29676ce505a51d55999caab3693..1f30f97fbc46de46cd3f6552d5a6e0f231d585c7 100644 (file)
@@ -47,7 +47,13 @@ import org.slf4j.LoggerFactory;
  */
 public final class ParserIdentifier {
     private static final Logger LOG = LoggerFactory.getLogger(ParserIdentifier.class);
-    private static final Splitter MP_SPLITTER = Splitter.on("/" + RestconfConstants.MOUNT);
+
+    // FIXME: Remove this constant. All logic relying on this constant should instead rely on YangInstanceIdentifier
+    //        equivalent coming out of argument parsing. This may require keeping List<YangInstanceIdentifier> as the
+    //        nested path split on yang-ext:mount. This splitting needs to be based on consulting the
+    //        EffectiveModelContext and allowing it only where yang-ext:mount is actually used in models.
+    private static final String MOUNT = "yang-ext:mount";
+    private static final Splitter MP_SPLITTER = Splitter.on("/" + MOUNT);
 
     private ParserIdentifier() {
         // Hidden on purpose
@@ -78,7 +84,7 @@ public final class ParserIdentifier {
     //
     public static InstanceIdentifierContext toInstanceIdentifier(final String identifier,
             final EffectiveModelContext schemaContext, final Optional<DOMMountPointService> mountPointService) {
-        if (identifier == null || !identifier.contains(RestconfConstants.MOUNT)) {
+        if (identifier == null || !identifier.contains(MOUNT)) {
             return createIIdContext(schemaContext, identifier, null);
         }
         if (mountPointService.isEmpty()) {
@@ -136,11 +142,10 @@ public final class ParserIdentifier {
                     ErrorTag.INVALID_VALUE);
         }
 
-        final int mountIndex = identifier.indexOf(RestconfConstants.MOUNT);
+        final int mountIndex = identifier.indexOf(MOUNT);
         final String moduleNameAndRevision;
         if (mountIndex >= 0) {
-            moduleNameAndRevision = identifier.substring(mountIndex + RestconfConstants.MOUNT.length())
-                    .replaceFirst("/", "");
+            moduleNameAndRevision = identifier.substring(mountIndex + MOUNT.length()).replaceFirst("/", "");
         } else {
             moduleNameAndRevision = identifier;
         }
@@ -183,7 +188,7 @@ public final class ParserIdentifier {
             final DOMYangTextSourceProvider sourceProvider) {
         final Iterable<String> pathComponents = RestconfConstants.SLASH_SPLITTER.split(identifier);
         final Iterator<String> componentIter = pathComponents.iterator();
-        if (!Iterables.contains(pathComponents, RestconfConstants.MOUNT)) {
+        if (!Iterables.contains(pathComponents, MOUNT)) {
             final String moduleName = validateAndGetModulName(componentIter);
             final Revision revision = validateAndGetRevision(componentIter);
             final Module module = schemaContext.findModule(moduleName, revision).orElse(null);
@@ -193,8 +198,8 @@ public final class ParserIdentifier {
             while (componentIter.hasNext()) {
                 final String current = componentIter.next();
 
-                if (RestconfConstants.MOUNT.equals(current)) {
-                    pathBuilder.append('/').append(RestconfConstants.MOUNT);
+                if (MOUNT.equals(current)) {
+                    pathBuilder.append('/').append(MOUNT);
                     break;
                 }
 
index 62872fc9be46a89573172a05878a41aaf55db96e..828174350a8c742f26009b3aa1890ebabe0c2341 100644 (file)
@@ -36,7 +36,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -169,8 +168,7 @@ public class ParserIdentifierTest {
     }
 
     /**
-     * Positive test of creating <code>InstanceIdentifierContext</code> from identifier containing
-     * {@link RestconfConstants#MOUNT}.
+     * Positive test of creating {@code InstanceIdentifierContext} from identifier containing {@code yang-ext:mount}.
      */
     @Test
     public void toInstanceIdentifierMountPointTest() {
@@ -230,8 +228,8 @@ public class ParserIdentifierTest {
     }
 
     /**
-     * Negative test when identifier contains {@link RestconfConstants#MOUNT} but identifier part is not valid. Test
-     * should fail with <code>RestconfDocumentedException</code>.
+     * Negative test when identifier contains {@code yang-ext:mount} but identifier part is not valid. Test
+     * should fail with {@link RestconfDocumentedException}.
      */
     @Test
     public void toInstanceIdentifierMountPointInvalidIdentifierNegativeTest() {