Eliminate DataPutPath 32/111232/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 3 Apr 2024 16:17:21 +0000 (18:17 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 3 Apr 2024 19:12:40 +0000 (21:12 +0200)
This interface has been useful, but now we have DatabindPath.Data, which
is a more powerful tool with equivalent semantics.

JIRA: NETCONF-1288
Change-Id: Ie135a1f7e6260bec0b6190fc331dc3ad559879f4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/RestconfStrategy.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DataPutPath.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/JsonResourceBody.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/ResourceBody.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/RestconfServer.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/XmlResourceBody.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/databind/AbstractResourceBodyTest.java

index 34b748f5cc024d5a2ccd6bbfc617d9a012a29dd7..ab67d22c84b5f9f6c85d1b5c85e222dd6edf83b8 100644 (file)
@@ -79,7 +79,6 @@ import org.opendaylight.restconf.server.api.DataPostPath;
 import org.opendaylight.restconf.server.api.DataPostResult;
 import org.opendaylight.restconf.server.api.DataPostResult.CreateResource;
 import org.opendaylight.restconf.server.api.DataPostResult.InvokeOperation;
-import org.opendaylight.restconf.server.api.DataPutPath;
 import org.opendaylight.restconf.server.api.DataPutResult;
 import org.opendaylight.restconf.server.api.DataYangPatchResult;
 import org.opendaylight.restconf.server.api.DatabindContext;
@@ -348,7 +347,7 @@ public abstract class RestconfStrategy {
         }
         final NormalizedNode data;
         try {
-            data = body.toNormalizedNode(new DataPutPath(databind, path.inference(), path.instance()));
+            data = body.toNormalizedNode(path);
         } catch (RestconfDocumentedException e) {
             return RestconfFuture.failed(e);
         }
@@ -587,7 +586,7 @@ public abstract class RestconfStrategy {
 
         final NormalizedNode data;
         try {
-            data = body.toNormalizedNode(new DataPutPath(databind, path.inference(), path.instance()));
+            data = body.toNormalizedNode(path);
         } catch (RestconfDocumentedException e) {
             return RestconfFuture.failed(e);
         }
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DataPutPath.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/api/DataPutPath.java
deleted file mode 100644 (file)
index 584dc9e..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.server.api;
-
-import static java.util.Objects.requireNonNull;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.restconf.api.ApiPath;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
-
-/**
- * An {@link ApiPath} subpath of {@code /data} {@code PUT} HTTP operation, as defined in
- * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.5">RFC8040 section 4.5</a>.
- *
- * @param databind Associated {@link DatabindContext}
- * @param inference Associated {@link Inference} pointing to the {@link EffectiveStatement} of the last ApiPath element.
- *                  This can be one of:
- *                  <ul>
- *                    <li>a datatore, inference being {@link Inference#isEmpty() empty}</li>
- *                    <li>a data resource, inference pointing to the the {@code data schema node} identified by
- *                        {@code instance}</li>
- *                  </ul>
- * @param instance Associated {@link YangInstanceIdentifier}
- * @see DataPostBody
- */
-@NonNullByDefault
-public record DataPutPath(DatabindContext databind, Inference inference, YangInstanceIdentifier instance)
-        implements DatabindAware {
-    public DataPutPath {
-        requireNonNull(databind);
-        requireNonNull(inference);
-        requireNonNull(instance);
-    }
-
-    public DataPutPath(final DatabindContext databind) {
-        this(databind, Inference.ofDataTreePath(databind.modelContext()), YangInstanceIdentifier.of());
-    }
-}
index 48a5bf456c1efb746004dcdea54a00f93ad93b48..99f20ebdf715d0548981ac3293bc54b7eb2509f8 100644 (file)
@@ -35,7 +35,7 @@ public final class JsonResourceBody extends ResourceBody {
     }
 
     @Override
-    void streamTo(final DataPutPath path, final PathArgument name, final InputStream inputStream,
+    void streamTo(final DatabindPath.Data path, final PathArgument name, final InputStream inputStream,
             final NormalizedNodeStreamWriter writer) throws IOException {
         try (var jsonParser = newParser(path, writer)) {
             try (var reader = new JsonReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
@@ -54,7 +54,7 @@ public final class JsonResourceBody extends ResourceBody {
             ErrorTag.MALFORMED_MESSAGE, cause);
     }
 
-    private static JsonParserStream newParser(final DataPutPath path, final NormalizedNodeStreamWriter writer) {
+    private static JsonParserStream newParser(final DatabindPath.Data path, final NormalizedNodeStreamWriter writer) {
         final var codecs = path.databind().jsonCodecs();
         final var inference = path.inference();
         if (inference.isEmpty()) {
index ac4bda4c486e1f40b0572f7b972936de08d534b1..bc9937999c8904e2599467b69c7dedd4a1f8d41b 100644 (file)
@@ -14,7 +14,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.restconf.restconf.Data;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
-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.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
@@ -40,11 +39,11 @@ public abstract sealed class ResourceBody extends AbstractBody permits JsonResou
     /**
      * Acquire the {@link NormalizedNode} representation of this body.
      *
-     * @param path A {@link YangInstanceIdentifier} corresponding to the body
+     * @param path A {@link DatabindPath.Data} corresponding to the body
      * @throws RestconfDocumentedException if the body cannot be decoded or it does not match {@code path}
      */
     @SuppressWarnings("checkstyle:illegalCatch")
-    public @NonNull NormalizedNode toNormalizedNode(final @NonNull DataPutPath path) {
+    public @NonNull NormalizedNode toNormalizedNode(final DatabindPath.@NonNull Data path) {
         final var instance = path.instance();
         final var expectedName = instance.isEmpty() ? DATA_NID : instance.getLastPathArgument();
         final var holder = new NormalizationResultHolder();
@@ -81,6 +80,6 @@ public abstract sealed class ResourceBody extends AbstractBody permits JsonResou
         return data;
     }
 
-    abstract void streamTo(@NonNull DataPutPath path, @NonNull PathArgument name, @NonNull InputStream inputStream,
-        @NonNull NormalizedNodeStreamWriter writer) throws IOException;
+    abstract void streamTo(DatabindPath.@NonNull Data path, @NonNull PathArgument name,
+        @NonNull InputStream inputStream, @NonNull NormalizedNodeStreamWriter writer) throws IOException;
 }
\ No newline at end of file
index f1ee961264a1b300d68338bc2c0af4b118e69e2a..0c7743ec8a94f7e6378da75d06ae9149ade7d501 100644 (file)
@@ -92,7 +92,8 @@ public interface RestconfServer {
         Map<String, String> queryParameters);
 
     /**
-     * Replace the data store.
+     * Replace the data store, as described in
+     * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.5">RFC8040 section 4.5</a>.
      *
      * @param body data node for put to config DS
      * @param queryParameters Query parameters
@@ -101,7 +102,8 @@ public interface RestconfServer {
     RestconfFuture<DataPutResult> dataPUT(ResourceBody body, Map<String, String> queryParameters);
 
     /**
-     * Create or replace a data store resource.
+     * Create or replace a data store resource, as described in
+     * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.5">RFC8040 section 4.5</a>.
      *
      * @param identifier resource identifier
      * @param body data node for put to config DS
index c49075beb3ae4babf97212a412607c3a5f4d89f7..288c446d89a2682d16986663fa4c4dfa7315308d 100644 (file)
@@ -33,7 +33,7 @@ public final class XmlResourceBody extends ResourceBody {
     }
 
     @Override
-    void streamTo(final DataPutPath path, final PathArgument name, final InputStream inputStream,
+    void streamTo(final DatabindPath.Data path, final PathArgument name, final InputStream inputStream,
             final NormalizedNodeStreamWriter writer) throws IOException {
         try (var xmlParser = XmlParserStream.create(writer, path.databind().xmlCodecs(), path.inference())) {
             final var doc = UntrustedXML.newDocumentBuilder().parse(inputStream);
index 6572f308052c21861808bb8bb7912a4c61534c73..d168b20055e74b21c2f1355cd573c0b842c8cdd4 100644 (file)
@@ -28,7 +28,6 @@ import org.opendaylight.restconf.api.ApiPath;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
-import org.opendaylight.restconf.server.api.DataPutPath;
 import org.opendaylight.restconf.server.api.DatabindContext;
 import org.opendaylight.restconf.server.api.ResourceBody;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -89,8 +88,7 @@ abstract class AbstractResourceBodyTest extends AbstractBodyTest {
         final var stratAndPath = strategy.resolveStrategyPath(apiPath);
 
         try (var body = bodyConstructor.apply(stringInputStream(patchBody))) {
-            return body.toNormalizedNode(new DataPutPath(stratAndPath.strategy().databind(),
-                stratAndPath.path().inference(), stratAndPath.path().instance()));
+            return body.toNormalizedNode(stratAndPath.path());
         }
     }