aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2018-10-31 15:57:51 +0000
committerSingal, Kapil (ks220y) <ks220y@att.com>2018-11-01 09:47:55 -0400
commit28e2e1ca2a9c9d1df3e2b3ab69c0aecbb62918bd (patch)
treebd55c91dc6c971ca80586a6fc7eccd17a13f0b69
parent1537af8ec53887628f82b118b782a122046bc5ed (diff)
SetNode patch
Support nested array removal with setnode Change-Id: Ie70ef2ff7b84d35c9352c7597aef0f636128439b Issue-ID: CCSDK-643 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
-rwxr-xr-x[-rw-r--r--]sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutor.java29
-rwxr-xr-x[-rw-r--r--]sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java113
-rw-r--r--sli/provider/src/test/resources/clearMultipleArrayValues.xml (renamed from sli/provider/src/test/resources/clearArrayValues.xml)0
-rw-r--r--sli/provider/src/test/resources/clearNestedSubArrayValues.xml27
-rw-r--r--sli/provider/src/test/resources/clearSingleArrayValues.xml5
-rw-r--r--sli/provider/src/test/resources/clearSingleSubArrayValues.xml27
-rw-r--r--sli/provider/src/test/resources/clearSubArrayValues.xml24
-rw-r--r--sli/provider/src/test/resources/clearValues.xml4
8 files changed, 213 insertions, 16 deletions
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
index 5019b568..8275a8e4 100644..100755
--- 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<String, String> parmsToAdd = new HashMap<String, String>();
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<String> parmsToRemove = new LinkedList<String>();
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
index 9ba2c05e..7c6f4ce5 100644..100755
--- 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<SvcLogicGraph> graph = slp.parse("src/test/resources/clearArrayValues.xml");
+ LinkedList<SvcLogicGraph> 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<SvcLogicGraph> 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<SvcLogicGraph> 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<SvcLogicGraph> 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
index 8f40058f..8f40058f 100644
--- a/sli/provider/src/test/resources/clearArrayValues.xml
+++ b/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 00000000..a80b3e56
--- /dev/null
+++ b/sli/provider/src/test/resources/clearNestedSubArrayValues.xml
@@ -0,0 +1,27 @@
+<service-logic
+ xmlns='http://www.onap.org/sdnc/svclogic'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='TEST-DG' version='1.0.0'>
+ <method rpc='test-dg' mode='sync'>
+ <block>
+ <set>
+ <parameter name='tmp.si[0].field1' value='1' />
+ <parameter name='tmp.si[1].field2' value='2' />
+ <parameter name='tmp.si[2].field3' value='3' />
+ <parameter name='tmp.si_length' value='3' />
+ <parameter name='tmp.si[0].subarray[0]' value='a' />
+ <parameter name='tmp.si[0].subarray[1]' value='b' />
+ <parameter name='tmp.si[0].subarray[2]' value='c' />
+ <parameter name='tmp.si[0].subarray_length' value='3' />
+ <parameter name='tmp.si[1].subarray[0]' value='x' />
+ <parameter name='tmp.si[1].subarray[1]' value='y' />
+ <parameter name='tmp.si[1].subarray[2]' value='z' />
+ <parameter name='tmp.si[1].subarray_length' value='3' />
+ <parameter name='search1' value='6' />
+ <parameter name='simonSays' value='KeepMe!' />
+ </set>
+ <set>
+ <parameter name='tmp.si[0].subarray.' value='' />
+ </set>
+ </block>
+ </method>
+</service-logic> \ 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 3e4e5d98..56781a06 100644
--- a/sli/provider/src/test/resources/clearSingleArrayValues.xml
+++ b/sli/provider/src/test/resources/clearSingleArrayValues.xml
@@ -7,6 +7,11 @@
<parameter name='si[0].field1' value='1' />
<parameter name='si[1].field2' value='2' />
<parameter name='si[2].field3' value='3' />
+ <parameter name='si_length' value='3' />
+ <parameter name='si[0].subarray[0]' value='a' />
+ <parameter name='si[0].subarray[1]' value='b' />
+ <parameter name='si[0].subarray[2]' value='c' />
+ <parameter name='si[0].subarray_length' value='3' />
<parameter name='search1' value='6' />
<parameter name='simonSays' value='KeepMe!' />
</set>
diff --git a/sli/provider/src/test/resources/clearSingleSubArrayValues.xml b/sli/provider/src/test/resources/clearSingleSubArrayValues.xml
new file mode 100644
index 00000000..22f14f37
--- /dev/null
+++ b/sli/provider/src/test/resources/clearSingleSubArrayValues.xml
@@ -0,0 +1,27 @@
+<service-logic
+ xmlns='http://www.onap.org/sdnc/svclogic'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='TEST-DG' version='1.0.0'>
+ <method rpc='test-dg' mode='sync'>
+ <block>
+ <set>
+ <parameter name='tmp.si[0].field1' value='1' />
+ <parameter name='tmp.si[1].field2' value='2' />
+ <parameter name='tmp.si[2].field3' value='3' />
+ <parameter name='tmp.si_length' value='3' />
+ <parameter name='tmp.si[0].subarray[0]' value='a' />
+ <parameter name='tmp.si[0].subarray[1]' value='b' />
+ <parameter name='tmp.si[0].subarray[2]' value='c' />
+ <parameter name='tmp.si[0].subarray_length' value='3' />
+ <parameter name='tmp.si[1].subarray[0]' value='x' />
+ <parameter name='tmp.si[1].subarray[1]' value='y' />
+ <parameter name='tmp.si[1].subarray[2]' value='z' />
+ <parameter name='tmp.si[1].subarray_length' value='3' />
+ <parameter name='search1' value='6' />
+ <parameter name='simonSays' value='KeepMe!' />
+ </set>
+ <set>
+ <parameter name='tmp.si[0].subarray[1]' value='' />
+ </set>
+ </block>
+ </method>
+</service-logic> \ 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 00000000..cb25f38a
--- /dev/null
+++ b/sli/provider/src/test/resources/clearSubArrayValues.xml
@@ -0,0 +1,24 @@
+<service-logic
+ xmlns='http://www.onap.org/sdnc/svclogic'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='TEST-DG' version='1.0.0'>
+ <method rpc='test-dg' mode='sync'>
+ <block>
+ <set>
+ <parameter name='si[0].field1' value='1' />
+ <parameter name='si[1].field2' value='2' />
+ <parameter name='si[2].field3' value='3' />
+ <parameter name='si_length' value='3' />
+ <parameter name='si[0].subarray[0]' value='a' />
+ <parameter name='si[0].subarray[1]' value='b' />
+ <parameter name='si[0].subarray[2]' value='c' />
+ <parameter name='si[0].subarray_length' value='3' />
+ <parameter name='search1' value='6' />
+ <parameter name='simonSays' value='KeepMe!' />
+ </set>
+ <set>
+ <parameter name='si[0].subarray.' value='' />
+ <!-- <parameter name='si.subarray.' value='' /> -->
+ </set>
+ </block>
+ </method>
+</service-logic> \ 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 615c8566..dc7f5c8a 100644
--- a/sli/provider/src/test/resources/clearValues.xml
+++ b/sli/provider/src/test/resources/clearValues.xml
@@ -7,6 +7,10 @@
<parameter name='si.field1' value='1' />
<parameter name='si.field2' value='2' />
<parameter name='si.field3' value='3' />
+ <parameter name='si.subarray[0]' value='a' />
+ <parameter name='si.subarray[1]' value='b' />
+ <parameter name='si.subarray[2]' value='c' />
+ <parameter name='si.subarray_length' value='3' />
<parameter name='search1' value='6' />
<parameter name='simonSays' value='KeepMe!' />
</set>