Reset root array length when using setnode
authorSmokowski, Kevin (ks6305) <ks6305@att.com>
Tue, 12 Jun 2018 15:51:30 +0000 (15:51 +0000)
committerSmokowski, Kevin (ks6305) <ks6305@att.com>
Tue, 12 Jun 2018 15:52:10 +0000 (15:52 +0000)
Reset root array length when using setnode shortcut to support backwards compatibility

Change-Id: I0a51e396a9c75a632759cefd82ef4c6c6ca3a384
Issue-ID: CCSDK-302
Signed-off-by: Smokowski, Kevin (ks6305) <ks6305@att.com>
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java
sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java
sli/provider/src/test/resources/clearArrayValues.xml

index 758f203..5019b56 100644 (file)
@@ -131,6 +131,11 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor {
                         // If RHS is empty, unset attributes in LHS
                         LinkedList<String> parmsToRemove = new LinkedList<String>();
                         String prefix = lhsVarName + ".";
+                        //Clear length value in case an array exists with this prefix
+                        String lengthParamName = lhsVarName + "_length";
+                        parmsToRemove.add(lengthParamName);
+                        LOG.debug("Unsetting " + lengthParamName + " because prefix " + prefix + " is being cleared.");
+
                         for (String curCtxVarname : ctx.getAttributeKeySet()) {
                             String curCtxVarnameMatchingValue = curCtxVarname;
                             //Special handling for reseting array values, strips out brackets and any numbers between the brackets
index c400bf5..9ba2c05 100644 (file)
@@ -48,6 +48,11 @@ public class SetNodeExecutorTest {
         assertNull(ctx.getAttribute("si[0].field1"));
         assertNull(ctx.getAttribute("si[1].field2"));
         assertNull(ctx.getAttribute("si[2].field3"));
+        assertNull(ctx.getAttribute("si_length"));
+        assertNull(ctx.getAttribute("si[0].subarray[0]"));
+        assertNull(ctx.getAttribute("si[0].subarray[1]"));
+        assertNull(ctx.getAttribute("si[0].subarray[2]"));
+        assertNull(ctx.getAttribute("si[0].subarray_length"));
         assertEquals("6", ctx.getAttribute("search1"));
         assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
     }
index 629322d..8f40058 100644 (file)
@@ -7,6 +7,11 @@
                 <parameter name='si[0].field1' value='1' />\r
                 <parameter name='si[1].field2' value='2' />\r
                 <parameter name='si[2].field3' value='3' />\r
+                <parameter name='si_length' value='3' />\r
+                <parameter name='si[0].subarray[0]' value='a' />\r
+                <parameter name='si[0].subarray[1]' value='b' />\r
+                <parameter name='si[0].subarray[2]' value='c' />\r
+                <parameter name='si[0].subarray_length' value='3' />\r
                 <parameter name='search1' value='6' />\r
                 <parameter name='simonSays' value='KeepMe!' />\r
             </set>\r