Propagate query parameters to YANG dataPATCH() 02/111302/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 6 Apr 2024 01:42:27 +0000 (03:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 6 Apr 2024 01:55:41 +0000 (03:55 +0200)
We should be honoring odl-pretty-print query parameter, this takes the
first step towards that.

JIRA: NETCONF-773
Change-Id: Id5a1d3445ef632f00d8d33539f76c8e5d420561c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java
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/RestconfServer.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfServer.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/RestconfDataPatchTest.java

index 670ffcf00bd9fb807f06b0fb6a82b694eb52adb5..ac8bf7459a899bf9dee216def68e1bb18c403bc8 100644 (file)
@@ -308,6 +308,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param body YANG Patch body
+     * @param uriInfo URI info
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
     @PATCH
@@ -317,9 +318,10 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_JSON,
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
-    public void dataYangJsonPATCH(final InputStream body, @Suspended final AsyncResponse ar) {
+    public void dataYangJsonPATCH(final InputStream body, @Context final UriInfo uriInfo,
+            @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(jsonBody), ar);
+            completeDataYangPATCH(server.dataPATCH(QueryParams.normalize(uriInfo), jsonBody), ar);
         }
     }
 
@@ -329,6 +331,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      *
      * @param identifier path to target
      * @param body YANG Patch body
+     * @param uriInfo URI info
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
     @PATCH
@@ -339,9 +342,9 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
     public void dataYangJsonPATCH(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
-            @Suspended final AsyncResponse ar) {
+            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(identifier, jsonBody), ar);
+            completeDataYangPATCH(server.dataPATCH(identifier, QueryParams.normalize(uriInfo), jsonBody), ar);
         }
     }
 
@@ -350,6 +353,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param body YANG Patch body
+     * @param uriInfo URI info
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
     @PATCH
@@ -359,9 +363,10 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_JSON,
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
-    public void dataYangXmlPATCH(final InputStream body, @Suspended final AsyncResponse ar) {
+    public void dataYangXmlPATCH(final InputStream body, @Context final UriInfo uriInfo,
+            @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(xmlBody), ar);
+            completeDataYangPATCH(server.dataPATCH(QueryParams.normalize(uriInfo), xmlBody), ar);
         }
     }
 
@@ -370,6 +375,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param identifier path to target
+     * @param uriInfo URI info
      * @param body YANG Patch body
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
@@ -381,9 +387,9 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
     public void dataYangXmlPATCH(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
-            @Suspended final AsyncResponse ar) {
+            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(identifier, xmlBody), ar);
+            completeDataYangPATCH(server.dataPATCH(identifier, QueryParams.normalize(uriInfo), xmlBody), ar);
         }
     }
 
index 1f1bf784d6c1722e792cb4ce38c9ddef6679b961..a0c28d31bad57e4d2b659d216ce28276af024604 100644 (file)
@@ -590,7 +590,8 @@ public abstract class RestconfStrategy {
         return merge(path.instance(), data);
     }
 
-    public final @NonNull RestconfFuture<DataYangPatchResult> dataPATCH(final ApiPath apiPath, final PatchBody body) {
+    public final @NonNull RestconfFuture<DataYangPatchResult> dataPATCH(final ApiPath apiPath,
+            final Map<String, String> queryParameters, final PatchBody body) {
         final Data path;
         try {
             path = pathNormalizer.normalizeDataPath(apiPath);
index dc4cd820929e86121c42b4f2cc3601afe48ce541..67bcdc67202a7235e4644c1a29a1ffb30bd55187 100644 (file)
@@ -72,20 +72,23 @@ public interface RestconfServer {
      * Ordered list of edits that are applied to the datastore by the server, as defined in
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
+     * @param queryParameters query parameters
      * @param body YANG Patch body
      * @return A {@link RestconfFuture} of the {@link DataYangPatchResult} content
      */
-    RestconfFuture<DataYangPatchResult> dataPATCH(PatchBody body);
+    RestconfFuture<DataYangPatchResult> dataPATCH(Map<String, String> queryParameters, PatchBody body);
 
     /**
      * Ordered list of edits that are applied to the datastore by the server, as defined in
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param identifier path to target
+     * @param queryParameters query parameters
      * @param body YANG Patch body
      * @return A {@link RestconfFuture} of the {@link DataYangPatchResult} content
      */
-    RestconfFuture<DataYangPatchResult> dataPATCH(ApiPath identifier, PatchBody body);
+    RestconfFuture<DataYangPatchResult> dataPATCH(ApiPath identifier, Map<String, String> queryParameters,
+        PatchBody body);
 
     RestconfFuture<CreateResourceResult> dataPOST(ChildBody body, Map<String, String> queryParameters);
 
index be62873bafd7a36e4f61170b92426f8d2558d354..b990b148edc9ae24e4edc0aa57aabd197a3be2ba 100644 (file)
@@ -193,19 +193,21 @@ public final class MdsalRestconfServer implements RestconfServer, AutoCloseable
     }
 
     @Override
-    public RestconfFuture<DataYangPatchResult> dataPATCH(final PatchBody body) {
-        return localStrategy().dataPATCH(ApiPath.empty(), body);
+    public RestconfFuture<DataYangPatchResult> dataPATCH(final Map<String, String> queryParameters,
+            final PatchBody body) {
+        return localStrategy().dataPATCH(ApiPath.empty(), queryParameters, body);
     }
 
     @Override
-    public RestconfFuture<DataYangPatchResult> dataPATCH(final ApiPath identifier, final PatchBody body) {
+    public RestconfFuture<DataYangPatchResult> dataPATCH(final ApiPath identifier,
+            final Map<String, String> queryParameters, final PatchBody body) {
         final StrategyAndTail strategyAndTail;
         try {
             strategyAndTail = localStrategy().resolveStrategy(identifier);
         } catch (RestconfDocumentedException e) {
             return RestconfFuture.failed(e);
         }
-        return strategyAndTail.strategy().dataPATCH(strategyAndTail.tail(), body);
+        return strategyAndTail.strategy().dataPATCH(strategyAndTail.tail(), queryParameters, body);
     }
 
     @Override
index 2f9070b8a2391e53982980f7ccaa97facf619b72..b09575c21a356f174588483915d810ebc315079f 100644 (file)
@@ -12,6 +12,8 @@ import static org.mockito.Mockito.doReturn;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFalseFluentFuture;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateTrueFluentFuture;
 
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.UriInfo;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -26,10 +28,13 @@ import org.opendaylight.restconf.server.spi.YangPatchStatusBody;
 class RestconfDataPatchTest extends AbstractRestconfTest {
     @Mock
     private DOMDataTreeReadWriteTransaction tx;
+    @Mock
+    private UriInfo uriInfo;
 
     @BeforeEach
     void beforeEach() {
         doReturn(tx).when(dataBroker).newReadWriteTransaction();
+        doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
     }
 
     @Test
@@ -76,7 +81,7 @@ class RestconfDataPatchTest extends AbstractRestconfTest {
                       }
                     ]
                   }
-                }"""), ar));
+                }"""), uriInfo, ar));
 
         assertFormat("""
             {"ietf-yang-patch:yang-patch-status":{"patch-id":"test patch id","ok":[null]}}""", body::formatToJSON);
@@ -119,7 +124,7 @@ class RestconfDataPatchTest extends AbstractRestconfTest {
                       }
                     ]
                   }
-                }"""), ar));
+                }"""), uriInfo, ar));
 
         assertFormat("""
             {"ietf-yang-patch:yang-patch-status":{"patch-id":"test patch id","edit-status":{"edit":[\
@@ -170,7 +175,7 @@ class RestconfDataPatchTest extends AbstractRestconfTest {
                     <operation>delete</operation>
                     <target>/example-jukebox:jukebox/player/gap</target>
                   </edit>
-                </yang-patch>"""), ar));
+                </yang-patch>"""), uriInfo, ar));
 
         assertFormat("""
             <yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">\