From 28e2e1ca2a9c9d1df3e2b3ab69c0aecbb62918bd Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Wed, 31 Oct 2018 15:57:51 +0000 Subject: [PATCH] SetNode patch Support nested array removal with setnode Change-Id: Ie70ef2ff7b84d35c9352c7597aef0f636128439b Issue-ID: CCSDK-643 Signed-off-by: Smokowski, Kevin (ks6305) --- .../sli/core/sli/provider/SetNodeExecutor.java | 29 +++--- .../sli/core/sli/provider/SetNodeExecutorTest.java | 113 ++++++++++++++++++++- ...rrayValues.xml => clearMultipleArrayValues.xml} | 0 .../test/resources/clearNestedSubArrayValues.xml | 27 +++++ .../src/test/resources/clearSingleArrayValues.xml | 5 + .../test/resources/clearSingleSubArrayValues.xml | 27 +++++ .../src/test/resources/clearSubArrayValues.xml | 24 +++++ sli/provider/src/test/resources/clearValues.xml | 4 + 8 files changed, 213 insertions(+), 16 deletions(-) mode change 100644 => 100755 sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java mode change 100644 => 100755 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java rename sli/provider/src/test/resources/{clearArrayValues.xml => clearMultipleArrayValues.xml} (100%) create mode 100644 sli/provider/src/test/resources/clearNestedSubArrayValues.xml create mode 100644 sli/provider/src/test/resources/clearSingleSubArrayValues.xml create mode 100644 sli/provider/src/test/resources/clearSubArrayValues.xml diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java old mode 100644 new mode 100755 index 5019b5681..8275a8e40 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java @@ -110,17 +110,13 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor { if (lhsPrefix.endsWith(".")) { lhsPrefix = lhsPrefix.substring(0, lhsPrefix.length() - 1); } - int lhsPfxLength = lhsPrefix.length(); + HashMap parmsToAdd = new HashMap(); for (String sourceVarName : ctx.getAttributeKeySet()) { - if (sourceVarName.startsWith(rhsRoot)) { - String targetVar = lhsPrefix + "." + sourceVarName.substring(rhsRoot.length()); - - LOG.debug("Copying " + sourceVarName + " value to " + targetVar); - + LOG.debug("Copying {} value to {}", sourceVarName, targetVar); parmsToAdd.put(targetVar, ctx.getAttribute(sourceVarName)); } } @@ -131,20 +127,26 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor { // If RHS is empty, unset attributes in LHS LinkedList parmsToRemove = new LinkedList(); String prefix = lhsVarName + "."; + String arrayPrefix = 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."); + LOG.debug("Unsetting {} because prefix {} is being cleared.", lengthParamName, prefix); for (String curCtxVarname : ctx.getAttributeKeySet()) { String curCtxVarnameMatchingValue = curCtxVarname; //Special handling for reseting array values, strips out brackets and any numbers between the brackets //when testing if a context memory value starts with a prefix if(!prefix.contains("[") && curCtxVarnameMatchingValue.contains("[")) { - curCtxVarnameMatchingValue = curCtxVarname.replaceAll(arrayPattern, ""); + curCtxVarnameMatchingValue = curCtxVarname.replaceAll(arrayPattern, "") + "."; } if (curCtxVarnameMatchingValue.startsWith(prefix)) { - LOG.debug("Unsetting " + curCtxVarname + " because matching value " + curCtxVarnameMatchingValue + " starts with the prefix " + prefix); + LOG.debug("Unsetting {} because matching value {} starts with the prefix {}", curCtxVarname, curCtxVarnameMatchingValue, prefix); + parmsToRemove.add(curCtxVarname); + }else if (curCtxVarnameMatchingValue.startsWith(lengthParamName)) { + LOG.debug("Unsetting {} because matching value {} starts with the lengthParamName {}", curCtxVarname, curCtxVarnameMatchingValue, lengthParamName); + parmsToRemove.add(curCtxVarname); + }else if (curCtxVarnameMatchingValue.startsWith(arrayPrefix)) { + LOG.debug("Unsetting {} because matching value {} starts with the arrayPrefix {}", curCtxVarname, curCtxVarnameMatchingValue, arrayPrefix); parmsToRemove.add(curCtxVarname); } } @@ -158,16 +160,15 @@ public class SetNodeExecutor extends SvcLogicNodeExecutor { String ctxValue = ctx.getAttribute(lhsVarName); if ((ctxValue != null) && (ctxValue.length() > 0)) { setValue = false; - LOG.debug("Attribute " + lhsVarName - + " already set and only-if-unset is true, so not overriding"); + LOG.debug("Attribute {} already set and only-if-unset is true, so not overriding", lhsVarName); } } if (setValue) { String curValue = SvcLogicExpressionResolver.evaluate(curEnt.getValue(), node, ctx); if (LOG.isDebugEnabled()) { - LOG.trace("Parameter value " + curEnt.getValue().asParsedExpr() + " resolves to " + curValue); - LOG.debug("Setting context attribute " + lhsVarName + " to " + curValue); + LOG.trace("Parameter value {} resolves to {}", curEnt.getValue().asParsedExpr(), curValue); + LOG.debug("Setting context attribute {} to {}", lhsVarName, curValue); } ctx.setAttribute(lhsVarName, curValue); } diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java old mode 100644 new mode 100755 index 9ba2c05e6..7c6f4ce56 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java @@ -27,6 +27,10 @@ public class SetNodeExecutorTest { assertNull(ctx.getAttribute("si.field1")); assertNull(ctx.getAttribute("si.field2")); assertNull(ctx.getAttribute("si.field3")); + assertNull(ctx.getAttribute("si.subarray[0]")); + assertNull(ctx.getAttribute("si.subarray[1]")); + assertNull(ctx.getAttribute("si.subarray[2]")); + assertNull(ctx.getAttribute("si.subarray_length")); assertEquals("6", ctx.getAttribute("search1")); assertEquals("KeepMe!", ctx.getAttribute("simonSays")); } @@ -37,7 +41,7 @@ public class SetNodeExecutorTest { SvcLogicContext ctx = new SvcLogicContext(); SvcLogicParser slp = new SvcLogicParser(); - LinkedList graph = slp.parse("src/test/resources/clearArrayValues.xml"); + LinkedList graph = slp.parse("src/test/resources/clearMultipleArrayValues.xml"); SvcLogicNode root = graph.getFirst().getRootNode(); SvcLogicNode nodeOne = root.getOutcomeValue("1"); SvcLogicNode nodeTwo = root.getOutcomeValue("2"); @@ -56,7 +60,7 @@ public class SetNodeExecutorTest { assertEquals("6", ctx.getAttribute("search1")); assertEquals("KeepMe!", ctx.getAttribute("simonSays")); } - + @Test public void clearSingleArrayProperties() throws Exception { SetNodeExecutor sne = new SetNodeExecutor(); @@ -72,8 +76,80 @@ public class SetNodeExecutorTest { sne.execute(nodeTwo, ctx); assertNull(ctx.getAttribute("si[0].field1")); + 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")); + + // TODO: This is just setting up elements as null but note reducing the size of Array. + assertEquals("3",ctx.getAttribute("si_length")); + + assertEquals("2",ctx.getAttribute("si[1].field2")); + assertEquals("3", ctx.getAttribute("si[2].field3")); + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void clearSingleSubArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearSingleSubArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1",ctx.getAttribute("tmp.si[0].field1")); + assertEquals("2",ctx.getAttribute("tmp.si[1].field2")); + assertEquals("3", ctx.getAttribute("tmp.si[2].field3")); + assertEquals("3", ctx.getAttribute("tmp.si_length")); + + assertEquals("a",ctx.getAttribute("tmp.si[0].subarray[0]")); + + // TODO: This is setting up element as Empty instead null + //assertNull(ctx.getAttribute("tmp.si[0].subarray[1]")); + assertEquals("", ctx.getAttribute("tmp.si[0].subarray[1]")); + + assertEquals("c", ctx.getAttribute("tmp.si[0].subarray[2]")); + assertEquals("3", ctx.getAttribute("tmp.si[0].subarray_length")); + + assertEquals("x",ctx.getAttribute("tmp.si[1].subarray[0]")); + assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]")); + assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]")); + assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length")); + + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + + @Test + public void clearSubArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearSubArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1", ctx.getAttribute("si[0].field1")); assertEquals("2",ctx.getAttribute("si[1].field2")); assertEquals("3", ctx.getAttribute("si[2].field3")); + assertEquals("3", 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")); } @@ -107,4 +183,37 @@ public class SetNodeExecutorTest { assertEquals("3", ctx.getAttribute("rootTwo.field3")); } + @Test + public void clearNestedSubArrayProperties() throws Exception { + SetNodeExecutor sne = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/clearNestedSubArrayValues.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); + SvcLogicNode nodeOne = root.getOutcomeValue("1"); + SvcLogicNode nodeTwo = root.getOutcomeValue("2"); + + sne.execute(nodeOne, ctx); + sne.execute(nodeTwo, ctx); + + assertEquals("1", ctx.getAttribute("tmp.si[0].field1")); + assertEquals("2",ctx.getAttribute("tmp.si[1].field2")); + assertEquals("3", ctx.getAttribute("tmp.si[2].field3")); + assertEquals("3", ctx.getAttribute("tmp.si_length")); + + assertNull(ctx.getAttribute("tmp.si[0].subarray[0]")); + assertNull(ctx.getAttribute("tmp.si[0].subarray[1]")); + assertNull(ctx.getAttribute("tmp.si[0].subarray[2]")); + assertNull(ctx.getAttribute("tmp.si[0].subarray_length")); + + assertEquals("x", ctx.getAttribute("tmp.si[1].subarray[0]")); + assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]")); + assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]")); + assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length")); + + assertEquals("6", ctx.getAttribute("search1")); + assertEquals("KeepMe!", ctx.getAttribute("simonSays")); + } + } diff --git a/sli/provider/src/test/resources/clearArrayValues.xml b/sli/provider/src/test/resources/clearMultipleArrayValues.xml similarity index 100% rename from sli/provider/src/test/resources/clearArrayValues.xml rename to sli/provider/src/test/resources/clearMultipleArrayValues.xml diff --git a/sli/provider/src/test/resources/clearNestedSubArrayValues.xml b/sli/provider/src/test/resources/clearNestedSubArrayValues.xml new file mode 100644 index 000000000..a80b3e56c --- /dev/null +++ b/sli/provider/src/test/resources/clearNestedSubArrayValues.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearSingleArrayValues.xml b/sli/provider/src/test/resources/clearSingleArrayValues.xml index 3e4e5d98d..56781a066 100644 --- a/sli/provider/src/test/resources/clearSingleArrayValues.xml +++ b/sli/provider/src/test/resources/clearSingleArrayValues.xml @@ -7,6 +7,11 @@ + + + + + diff --git a/sli/provider/src/test/resources/clearSingleSubArrayValues.xml b/sli/provider/src/test/resources/clearSingleSubArrayValues.xml new file mode 100644 index 000000000..22f14f37b --- /dev/null +++ b/sli/provider/src/test/resources/clearSingleSubArrayValues.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearSubArrayValues.xml b/sli/provider/src/test/resources/clearSubArrayValues.xml new file mode 100644 index 000000000..cb25f38af --- /dev/null +++ b/sli/provider/src/test/resources/clearSubArrayValues.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sli/provider/src/test/resources/clearValues.xml b/sli/provider/src/test/resources/clearValues.xml index 615c8566a..dc7f5c8a2 100644 --- a/sli/provider/src/test/resources/clearValues.xml +++ b/sli/provider/src/test/resources/clearValues.xml @@ -7,6 +7,10 @@ + + + + -- 2.16.6