From fd42ba68518d781fbf1dd8407acfb28f55ae490e Mon Sep 17 00:00:00 2001 From: "Benjamin, Max" Date: Fri, 9 Aug 2019 08:53:50 -0400 Subject: 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) Change-Id: Ib138d96cf8578a0e3055120f9c3e036c690e7eae --- .../onap/so/client/graphinventory/entities/DSLNodeKey.java | 14 +++++++++----- .../org/onap/so/client/graphinventory/entities/__.java | 2 +- .../java/org/onap/so/client/aai/DSLQueryBuilderTest.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) (limited to 'common/src') 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 values; + private final List 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 temp = new ArrayList<>(); - for (String item : values) { + List 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 __.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 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)")); + } } -- cgit 1.2.3-korg