Do not use ParserIdentifier for Point parsing 82/107082/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Jul 2023 12:45:40 +0000 (14:45 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Jul 2023 14:41:19 +0000 (16:41 +0200)
YangInstanceIdentifierDeserializer provides a much more direct access to
the path, use that to improve structure and eliminate nullness warnings.

Change-Id: I3e63be7870603d2a882ff36e5774cf7a00c71c2b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java

index a115719e6ece74fef8c2e004343ce0d9ef4f9fe6..5922287e93c79c88b5baad768d126469a7a5a7ff 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.net.URI;
-import java.util.Optional;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
@@ -18,14 +17,13 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.api.query.InsertParam;
 import org.opendaylight.restconf.api.query.PointParam;
-import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierDeserializer;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -146,12 +144,11 @@ public final class PostDataTransactionUtil {
                                             final RestconfTransaction transaction) {
         final YangInstanceIdentifier parent = path.getParent().getParent();
         transaction.remove(parent);
-        final InstanceIdentifierContext instanceIdentifier =
-            // FIXME: Point should be able to give us this method
-            ParserIdentifier.toInstanceIdentifier(point.value(), schemaContext, Optional.empty());
+        final var pointArg = YangInstanceIdentifierDeserializer.create(schemaContext, point.value()).path
+            .getLastPathArgument();
         int lastItemPosition = 0;
-        for (final NormalizedNode nodeChild : readList.body()) {
-            if (nodeChild.name().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+        for (var nodeChild : readList.body()) {
+            if (nodeChild.name().equals(pointArg)) {
                 break;
             }
             lastItemPosition++;
@@ -160,9 +157,9 @@ public final class PostDataTransactionUtil {
             lastItemPosition++;
         }
         int lastInsertedPosition = 0;
-        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, parent);
+        final var emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, parent);
         transaction.merge(YangInstanceIdentifier.of(emptySubtree.name()), emptySubtree);
-        for (final NormalizedNode nodeChild : readList.body()) {
+        for (var nodeChild : readList.body()) {
             if (lastInsertedPosition == lastItemPosition) {
                 transaction.replace(path, data, schemaContext);
             }
index a237bedc0e0aad5d831c16512ee45e5dfcece5b6..a1012e1c0be8b1983cd08af69e56d536098815ad 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
 import com.google.common.util.concurrent.FluentFuture;
-import java.util.Optional;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.opendaylight.mdsal.common.api.CommitInfo;
@@ -16,13 +15,12 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.api.query.InsertParam;
 import org.opendaylight.restconf.api.query.PointParam;
-import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.restconf.nb.rfc8040.utils.parser.YangInstanceIdentifierDeserializer;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -143,12 +141,11 @@ public final class PutDataTransactionUtil {
                                            final EffectiveModelContext schemaContext, final PointParam point,
                                            final NormalizedNodeContainer<?> readList, final boolean before) {
         transaction.remove(path.getParent());
-        final InstanceIdentifierContext instanceIdentifier =
-            // FIXME: Point should be able to give us this method
-            ParserIdentifier.toInstanceIdentifier(point.value(), schemaContext, Optional.empty());
+        final var pointArg = YangInstanceIdentifierDeserializer.create(schemaContext, point.value()).path
+            .getLastPathArgument();
         int lastItemPosition = 0;
-        for (final NormalizedNode nodeChild : readList.body()) {
-            if (nodeChild.name().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+        for (var nodeChild : readList.body()) {
+            if (nodeChild.name().equals(pointArg)) {
                 break;
             }
             lastItemPosition++;
@@ -157,9 +154,9 @@ public final class PutDataTransactionUtil {
             lastItemPosition++;
         }
         int lastInsertedPosition = 0;
-        final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+        final var emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
         transaction.merge(YangInstanceIdentifier.of(emptySubtree.name()), emptySubtree);
-        for (final NormalizedNode nodeChild : readList.body()) {
+        for (var nodeChild : readList.body()) {
             if (lastInsertedPosition == lastItemPosition) {
                 transaction.replace(path, data, schemaContext);
             }