Hashmark support in 3gpp objects 59/139359/2
authoregernug <gerard.nugent@est.tech>
Fri, 8 Nov 2024 13:34:00 +0000 (13:34 +0000)
committeregernug <gerard.nugent@est.tech>
Tue, 12 Nov 2024 11:43:56 +0000 (11:43 +0000)
NCMP should cut off the part after the # of an alternateid
and use only the first part in CPS match check, but send the complete request to the DMI plugin.

Issue-ID: CPS-2485

Change-Id: Icc1442f2be9545036619043692c3559ffadecb0d
Signed-off-by: egernug <gerard.nugent@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy

index c526dfb..9facd63 100644 (file)
@@ -38,14 +38,15 @@ public class AlternateIdMatcher {
 
     /**
      * Get data node that matches longest alternate id by removing elements (as defined by the separator string)
-     * from right to left.
+     * from right to left. If alternate id contains a hash then all elements after that hash are ignored.
      *
      * @param alternateId alternate ID
      * @param separator   a string that separates each element from the next.
      * @return data node
      */
     public DataNode getCmHandleDataNodeByLongestMatchingAlternateId(final String alternateId, final String separator) {
-        String bestMatch = alternateId;
+        final String[] splitPath = alternateId.split("#", 2);
+        String bestMatch = splitPath[0];
         while (StringUtils.isNotEmpty(bestMatch)) {
             try {
                 return inventoryPersistence.getCmHandleDataNodeByAlternateId(bestMatch);
index a497b45..bd1faa2 100644 (file)
@@ -42,11 +42,15 @@ class AlternateIdMatcherSpec extends Specification {
         expect: 'querying for alternate id a matching result found'
             assert objectUnderTest.getCmHandleDataNodeByLongestMatchingAlternateId(targetAlternateId, '/') != null
         where: 'the following parameters are used'
-            scenario                   | targetAlternateId
-            'exact match'              | '/a/b'
-            'parent match'             | '/a/b/c'
-            'grand parent match'       | '/a/b/c/d'
-            'trailing separator match' | '/a/b/'
+            scenario                                | targetAlternateId
+            'exact match'                           | '/a/b'
+            'parent match'                          | '/a/b/c'
+            'grand parent match'                    | '/a/b/c/d'
+            'trailing separator match'              | '/a/b/'
+            'trailing hash'                         | '/a/b#q'
+            'trailing hash parent match'            | '/a/b/c#q'
+            'trailing hash grand parent match'      | '/a/b/c/d#q'
+            'trailing separator then hash match'    | '/a/b/#q'
     }
 
     def 'Attempt to find longest alternate id match without any matches.'() {