aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBenjamin, Max <max.benjamin@att.com>2019-08-09 08:53:50 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2019-08-09 08:53:52 -0400
commitfd42ba68518d781fbf1dd8407acfb28f55ae490e (patch)
tree920939356b3106cff5e9fdb0800552761a756da1 /common
parentc55a88d9e00399708cd6c5ea7b562ca579aabbfe (diff)
query builder now handles more than just strings
query builder now handles more than just strings Issue-ID: SO-2215 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: Ib138d96cf8578a0e3055120f9c3e036c690e7eae
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java14
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/__.java2
-rw-r--r--common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java10
3 files changed, 20 insertions, 6 deletions
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java
index f7f5d78604..e301edb0fd 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/DSLNodeKey.java
@@ -32,9 +32,9 @@ public class DSLNodeKey implements QueryStep {
private boolean not = false;
private final StringBuilder query = new StringBuilder();
private final String keyName;
- private final List<String> values;
+ private final List<Object> values;
- public DSLNodeKey(String keyName, String... value) {
+ public DSLNodeKey(String keyName, Object... value) {
this.keyName = keyName;
this.values = Arrays.asList(value);
@@ -54,14 +54,18 @@ public class DSLNodeKey implements QueryStep {
result.append(" !");
}
result.append("('").append(keyName).append("', ");
- List<String> temp = new ArrayList<>();
- for (String item : values) {
+ List<Object> temp = new ArrayList<>();
+ for (Object item : values) {
if ("null".equals(item)) {
temp.add(String.format("' %s '", item));
} else if ("".equals(item)) {
temp.add("' '");
} else {
- temp.add(String.format("'%s'", item));
+ if (item instanceof String) {
+ temp.add(String.format("'%s'", item));
+ } else {
+ temp.add(item);
+ }
}
}
result.append(Joiner.on(", ").join(temp)).append(")");
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java
index 2fdd6574e5..87d4d84cac 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/__.java
@@ -45,7 +45,7 @@ public class __ {
return __.<DSLNode>start(new DSLNode(name, key));
}
- public static DSLNodeKey key(String keyName, String... value) {
+ public static DSLNodeKey key(String keyName, Object... value) {
return new DSLNodeKey(keyName, value);
}
diff --git a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
index 6e55fe17fa..590e83827b 100644
--- a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
@@ -108,4 +108,14 @@ public class DSLQueryBuilderTest {
builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')"));
assertTrue(builder.equals(builder));
}
+
+
+ @Test
+ public void mixedTypeTest() {
+ DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION,
+ __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id")));
+ builder.to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output());
+ assertTrue(builder.equals(
+ "cloud-region('cloud-owner', 'owner')('cloud-region-id', 'id') > vlan-tag*('vlan-id-outer', 167)('my-boolean', true)"));
+ }
}