diff options
author | Steve Smokowski <ss835w@att.com> | 2020-01-08 14:02:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-01-08 14:02:59 +0000 |
commit | 1110790099fa6a019ab7e5fd530c623f88e10d59 (patch) | |
tree | 40852cb9ac957b47e1f572e46c33b4a35cea3970 /adapters/mso-catalog-db-adapter/src | |
parent | 23b9a7431972e68a84ac3b8e2ab2d418d9ca7a70 (diff) | |
parent | 6c7e376c12005118da96506d3f83c594b727750b (diff) |
Merge "Drop Resource Input Field if not valid JSON"
Diffstat (limited to 'adapters/mso-catalog-db-adapter/src')
6 files changed, 69 insertions, 6 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java index edec48dc95..a98778bf5d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/CatalogQuery.java @@ -21,6 +21,7 @@ package org.onap.so.adapters.catalogdb.catalogrest; +import java.io.IOException; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -95,4 +96,17 @@ public abstract class CatalogQuery { return smartToJSON(); } + + protected boolean isJSONValid(String jsonInString) { + try { + if (jsonInString == null) { + return false; + } + ObjectMapper mapper = new ObjectMapper(); + mapper.readValue(jsonInString, String.class); + return true; + } catch (IOException e) { + return false; + } + } } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java index c1acc319f7..afcb2d5761 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryAllottedResourceCustomization.java @@ -123,7 +123,10 @@ public class QueryAllottedResourceCustomization extends CatalogQuery { put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID()); put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID()); put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java index 5573b23a8d..129718241c 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceNetworks.java @@ -116,7 +116,10 @@ public class QueryServiceNetworks extends CatalogQuery { put(valueMap, "NETWORK_ROLE", o.getNetworkRole()); put(valueMap, "NETWORK_SCOPE", o.getNetworkScope()); put(valueMap, "NETWORK_TECHNOLOGY", o.getNetworkTechnology()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java index 0b8de60a81..d6e7415a77 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java @@ -23,6 +23,7 @@ package org.onap.so.adapters.catalogdb.catalogrest; /* should be called QueryVnfResource.java */ +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,6 +33,7 @@ import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.databind.ObjectMapper; @XmlRootElement(name = "serviceVnfs") public class QueryServiceVnfs extends CatalogQuery { @@ -120,7 +122,9 @@ public class QueryServiceVnfs extends CatalogQuery { put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode()); put(valueMap, "VNFC_INSTANCE_GROUP_ORDER", o.getVnfcInstanceGroupOrder()); put(valueMap, "MULTI_STEP_DESIGN", o.getMultiStageDesign()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t")); @@ -142,4 +146,5 @@ public class QueryServiceVnfs extends CatalogQuery { sb.append("}"); return sb.toString(); } + } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java index dc73fe904d..24c07d6d3e 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java @@ -20,12 +20,12 @@ package org.onap.so.adapters.catalogdb.catalogrest; -import org.onap.so.db.catalog.beans.VnfcCustomization; -import javax.xml.bind.annotation.XmlRootElement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.bind.annotation.XmlRootElement; +import org.onap.so.db.catalog.beans.VnfcCustomization; @XmlRootElement(name = "vnfcs") public class QueryVnfcs extends CatalogQuery { @@ -105,8 +105,10 @@ public class QueryVnfcs extends CatalogQuery { put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantUUID()); put(valueMap, "MODEL_VERSION", o.getModelVersion()); put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); - put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + if (isJSONValid(o.getResourceInput())) { + put(valueMap, "RESOURCE_INPUT", o.getResourceInput()); + } sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; } diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfTest.java new file mode 100644 index 0000000000..b71808b2c8 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfTest.java @@ -0,0 +1,36 @@ +package org.onap.so.adapters.catalogdb.catalogrest; + +import static org.junit.Assert.assertEquals; +import org.json.JSONException; +import org.junit.Test; + + +public class QueryServiceVnfTest extends QueryServiceVnfs { + + private QueryServiceVnfs queryServiceVnf = new QueryServiceVnfs(); + + private final String invalidJSON = + "\"{\\\\\\\"nf_function\\\\\\\":\\\\\\\"DO_STUFF\\\\\\\",\\\"_image_name\\\\\\\":\\\\\\\"test_image\\\""; + + private final String validJSON = "\"{\"nf_function\":\"DO_STUFF\",\"image_name\":\"test_image\"}"; + + @Test + public void test_IsValidJsonTrue() throws JSONException { + boolean isValidJson = queryServiceVnf.isJSONValid(validJSON); + assertEquals(true, isValidJson); + } + + @Test + public void test_IsValidJsonFalse() throws JSONException { + boolean isValidJson = queryServiceVnf.isJSONValid(invalidJSON); + assertEquals(false, isValidJson); + } + + @Test + public void test_IsValidJsonNull() throws JSONException { + boolean isValidJson = queryServiceVnf.isJSONValid(null); + assertEquals(false, isValidJson); + } + + +} |