Revert removing buildOperationDetailsForPatchItem for patch item replace 20/142920/1
authorseanbeirne <sean.beirne@est.tech>
Tue, 13 Jan 2026 19:59:23 +0000 (19:59 +0000)
committerseanbeirne <sean.beirne@est.tech>
Tue, 13 Jan 2026 20:33:20 +0000 (20:33 +0000)
Issue-ID: CPS-3119
Change-Id: I84fc34aefbc19b30e3a825d444f4e1328218cbf7
Signed-off-by: seanbeirne <sean.beirne@est.tech>
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/ProvMnSControllerSpec.groovy
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/policyexecutor/OperationDetailsFactory.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/data/policyexecutor/OperationDetailsFactorySpec.groovy

index f4d2bcf..b628822 100644 (file)
@@ -100,7 +100,7 @@ class ProvMnSControllerSpec extends Specification {
 
     static def patchMediaType       = new MediaType('application', 'json-patch+json')
     static def patchMediaType3gpp   = new MediaType('application', '3gpp-json-patch+json')
-    static def patchJsonBody        = '[{"op":"replace","path":"/child=id2/attributes","value":{"id":"id1","attributes":{"attr1":"test"}}}]'
+    static def patchJsonBody        = '[{"op":"replace","path":"/child=id2/attributes","value":{"attr1":"test"}}]'
     static def patchJsonBody3gpp    = '[{"op":"replace","path":"/child=id2#/attributes/attr1","value":"test"}]'
 
     static def expectedDeleteChangeRequest = '{"":[]}'
index 5d5ef96..22b3097 100644 (file)
@@ -66,7 +66,7 @@ public class OperationDetailsFactory {
                 if (patchItem.getPath().contains("#/attributes")) {
                     operationDetails = buildOperationDetailsForPatchItemWithHash(requestParameters, patchItem);
                 } else {
-                    operationDetails = buildOperationDetails(UPDATE, requestParameters, patchItem.getValue());
+                    operationDetails = buildOperationDetailsForPatchItem(requestParameters, patchItem);
                 }
                 break;
             case REMOVE:
@@ -109,6 +109,21 @@ public class OperationDetailsFactory {
         return new OperationDetails(OperationType.DELETE, parentFdn, "", emptyList());
     }
 
+    /**
+     * Build OperationDetails for a specific patch item.
+     *
+     * @param requestParameters request parameters including uri-ldn-first-part, className and id
+     * @param patchItem         the patch item containing operation details
+     * @return OperationDetails object for the patch item
+     */
+    public OperationDetails buildOperationDetailsForPatchItem(final RequestParameters requestParameters,
+                                                              final PatchItem patchItem) {
+        final Map<String, Object> resourceAsObject = new HashMap<>(2);
+        resourceAsObject.put("id", requestParameters.id());
+        resourceAsObject.put("attributes", patchItem.getValue());
+        return buildOperationDetails(UPDATE, requestParameters, resourceAsObject);
+    }
+
     private OperationDetails buildOperationDetailsForPatchItemWithHash(final RequestParameters requestParameters,
                                                                        final PatchItem patchItem) {
         final Map<String, Object> attributeHierarchyAsMap = createNestedMap(patchItem);
index f9a9894..19b16ee 100644 (file)
@@ -80,7 +80,7 @@ class OperationDetailsFactorySpec extends Specification {
         where: 'attributes are set using # or resource'
             scenario                            | suffix               | value
             'set simple value using #'          | '#/attributes/attr1' | 456
-            'set complex value using resource'  | ''                   | [id:'id1', attributes:[attr1:456]]
+            'set complex value using resource'  | '/attributes'        | [attr1:456]
     }
 
     def 'Build an attribute map with different depths of hierarchy with #scenario.'() {