Peel DataSchemaNode-only users of InstanceIdentifierContext 59/100259/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Mar 2022 14:50:57 +0000 (15:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 25 Mar 2022 14:55:06 +0000 (15:55 +0100)
A number of callers are not providing a YangInstanceIdentifier, peel
them off into a separate instantiation method.

JIRA: NETCONF-818
Change-Id: Ic92cbc469d66e3e8ad957bde73c2f858b0daa8f2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/context/InstanceIdentifierContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfDocumentedExceptionMapper.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/input/to/cnsn/test/RestPutListDataTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnInstanceIdentifierToXmlTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlTest.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlWithChoiceTest.java

index ff290ce001162f99cbb2f248bab935435df4b5b0..3c7ed16a9c8c05e51d8c32506f3e96bd4127a4ac 100644 (file)
@@ -12,10 +12,12 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.collect.Iterables;
 import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.ContainerLike;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
@@ -69,6 +71,18 @@ public final class InstanceIdentifierContext {
         return new InstanceIdentifierContext(context, rpc, null);
     }
 
+    // Invocations of various identifier-less details
+    public static @NonNull InstanceIdentifierContext ofDataSchemaNode(final EffectiveModelContext context,
+            final DataSchemaNode schemaNode) {
+        return new InstanceIdentifierContext(null, requireNonNull(schemaNode), null, requireNonNull(context));
+    }
+
+    // Invocations of various identifier-less details, potentially having a mount point
+    public static @NonNull InstanceIdentifierContext ofDataSchemaNode(final EffectiveModelContext context,
+            final DataSchemaNode schemaNode, final @Nullable DOMMountPoint mountPoint) {
+        return new InstanceIdentifierContext(null, requireNonNull(schemaNode), mountPoint, requireNonNull(context));
+    }
+
     public static @NonNull InstanceIdentifierContext ofLocalRpcInput(final EffectiveModelContext context,
             // FIXME: this this method really needed?
             final RpcDefinition rpc) {
index e0545519c9e21a2f003d4e94b1673dd80d134c90..1803a4b3ba20bedb649d3e1c6e5f6ac016db1309 100644 (file)
@@ -143,8 +143,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         }
         errContBuild.withChild(listErorsBuilder.build());
 
-        final NormalizedNodeContext errContext =  new NormalizedNodeContext(new InstanceIdentifierContext(null,
-                (DataSchemaNode) errorsSchemaNode, null, controllerContext.getGlobalSchema()), errContBuild.build());
+        final NormalizedNodeContext errContext = new NormalizedNodeContext(InstanceIdentifierContext.ofDataSchemaNode(
+            controllerContext.getGlobalSchema(), (DataSchemaNode) errorsSchemaNode), errContBuild.build());
 
         Object responseBody;
         if (mediaType.getSubtype().endsWith("json")) {
index f08f37bf4108fc4838befc1b65d90b8c87ffeb76..01931e9798be039d8d32d478b90a93c49f42d332 100644 (file)
@@ -222,7 +222,7 @@ public final class RestconfImpl implements RestconfService {
                 SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) modulesSchemaNode);
         moduleContainerBuilder.withChild(allModuleMap);
 
-        return new NormalizedNodeContext(new InstanceIdentifierContext(null, modulesSchemaNode, null, schemaContext),
+        return new NormalizedNodeContext(InstanceIdentifierContext.ofDataSchemaNode(schemaContext, modulesSchemaNode),
                 moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
     }
 
@@ -293,7 +293,7 @@ public final class RestconfImpl implements RestconfService {
         checkState(moduleSchemaNode instanceof ListSchemaNode);
 
         return new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, moduleSchemaNode, mountPoint, schemaContext), moduleMap,
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContext, moduleSchemaNode, mountPoint), moduleMap,
                 QueryParametersParser.parseWriterParameters(uriInfo));
     }
 
@@ -323,7 +323,7 @@ public final class RestconfImpl implements RestconfService {
         streamsContainerBuilder.withChild(listStreamsBuilder.build());
 
         return new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, streamsContainerSchemaNode, null, schemaContext),
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContext, streamsContainerSchemaNode),
                 streamsContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
     }
 
index c4455df65814af620181d743833ce0c385d5adeb..d886dc3c0dc7b0f52784621e8320cdd4b6ec52ea 100644 (file)
@@ -201,8 +201,9 @@ public class RestPutListDataTest {
             testNodeContainer.withChild(leafKey2.build());
         }
 
-        final NormalizedNodeContext testCompositeContext = new NormalizedNodeContext(new InstanceIdentifierContext(
-                null, testNodeSchemaNode, null, schemaContextTestModule), testNodeContainer.build());
+        final NormalizedNodeContext testCompositeContext = new NormalizedNodeContext(
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContextTestModule, testNodeSchemaNode),
+                testNodeContainer.build());
 
         final UriInfo uriInfo = Mockito.mock(UriInfo.class);
         restconfImpl.updateConfigurationData(toUri(uriKey1, uriKey2), testCompositeContext, uriInfo);
index 19cf4cf1252f9a42caf7dcc4540d55cd6aea1576..19fd58f23032c97fa7f5ac2d4ee17464073d5491 100644 (file)
@@ -137,11 +137,8 @@ public class NnInstanceIdentifierToXmlTest extends AbstractBodyReaderTest {
                 .withValue("/instanceidentifier/").build());
         dataCont.withChild(dataCont1.build());
 
-        final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, schemaCont,
-                        null, schemaContext), dataCont.build());
-
-        return testNormalizedNodeContext;
+        return new NormalizedNodeContext(InstanceIdentifierContext.ofDataSchemaNode(schemaContext, schemaCont),
+                dataCont.build());
     }
 
     @Test
@@ -236,7 +233,7 @@ public class NnInstanceIdentifierToXmlTest extends AbstractBodyReaderTest {
         dataCont1.withChild(dataLst11.build());
         dataCont.withChild(dataCont1.build());
 
-        return new NormalizedNodeContext(new InstanceIdentifierContext(null, schemaCont, null, schemaContext),
+        return new NormalizedNodeContext(InstanceIdentifierContext.ofDataSchemaNode(schemaContext, schemaCont),
             dataCont.build());
     }
 
index ac52922dc14242fdf8468580198b48fd294c78d1..dc56907b15b59212b367a0497c7f8f6d08944a24 100644 (file)
@@ -304,10 +304,8 @@ public class NnToXmlTest extends AbstractBodyReaderTest {
 
         contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue(object).build());
 
-        final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, contSchema, null, schemaContext), contData.build());
-
-        return testNormalizedNodeContext;
+        return new NormalizedNodeContext(InstanceIdentifierContext.ofDataSchemaNode(schemaContext, contSchema),
+                contData.build());
     }
 
     private void nnToXml(final NormalizedNodeContext normalizedNodeContext, final String... xmlRepresentation)
@@ -343,7 +341,7 @@ public class NnToXmlTest extends AbstractBodyReaderTest {
         contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue("true").build());
 
         final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, contSchema, null, schemaContext), contData.build());
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContext, contSchema), contData.build());
 
         return testNormalizedNodeContext;
     }
@@ -363,7 +361,7 @@ public class NnToXmlTest extends AbstractBodyReaderTest {
         contData.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) schemaLf).withValue("value").build());
 
         return new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, contSchema, null, schemaContext), contData.build());
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContext, contSchema), contData.build());
     }
 
     private static NormalizedNodeContext prepareIdrefData(final String prefix, final boolean valueAsQName) {
@@ -397,7 +395,7 @@ public class NnToXmlTest extends AbstractBodyReaderTest {
         contData.withChild(cont1Data.build());
 
         final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, contSchema, null, schemaContext), contData.build());
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContext, contSchema), contData.build());
         return testNormalizedNodeContext;
     }
 
index b0282126f5b0cdcb08fd6435e85cd059a20317a6..484b9f80f290416d4e61e17e063fa6ffbbecf1ff 100644 (file)
@@ -96,7 +96,7 @@ public class NnToXmlWithChoiceTest extends AbstractBodyReaderTest {
         dataContainerNodeAttrBuilder.withChild(dataChoice.build());
 
         final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
-                new InstanceIdentifierContext(null, contSchemaNode, null, schemaContext),
+                InstanceIdentifierContext.ofDataSchemaNode(schemaContext, contSchemaNode),
                 dataContainerNodeAttrBuilder.build());
 
         return testNormalizedNodeContext;