summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/aai/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-07 13:58:09 -0400
committerJim Hahn <jrh3@att.com>2020-04-07 17:15:07 -0400
commit9b3ff5f270572a6760ff07dda9577cdadb53b088 (patch)
treeeacd325199fbb72fddaba94a057178a19e9c3360 /models-interactions/model-impl/aai/src/main
parent3000fdca611c32b7001c553621660b8ea0d2eb49 (diff)
Address sonar issues in models
Addressed the following sonar issues: - use RE2 instead of java.util Pattern for "+" and "*" - don't use deprecated methods - for Date(long), sonar appeared not to parse the argument's type correctly. Modified the code slightly to make sonar happy - duplicate blocks of code - either log or throw - missing assert in junit - for SDNR & VFC, eliminated threads, as they are unnecessary - duplicate code block in different branches - useless assignments - redeclaring abstract methods - cyclomatic complexity - used lombok in some cases (e.g., EqualsAndHashCode) - assert argument order - actually deleted ControlLoopTargetType, because it is not needed and sonar complains regardless of which order is used - add private constructor to utility classes - use StandardCharsets instead of literals Also: - added logback-test.xml to SO to eliminate the voluminous output from the junit test Issue-ID: POLICY-2305 Change-Id: I586c331781bedbd54a115a71847d04d293689445 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl/aai/src/main')
-rw-r--r--models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java157
1 files changed, 86 insertions, 71 deletions
diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java
index 92af217de..1e14e0704 100644
--- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java
+++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java
@@ -100,100 +100,115 @@ public class AaiCqResponse implements Serializable {
resultsArray = (JSONArray) responseObj.get("results");
}
for (int i = 0; i < resultsArray.length(); i++) {
- // Object is a vserver
- if (resultsArray.getJSONObject(i).has("vserver")) {
+ final JSONObject resultObject = resultsArray.getJSONObject(i);
+
+ extractVserver(resultObject);
+ extractGenericVnf(resultObject);
+ extractServiceInstance(resultObject);
+ extractVfModule(resultObject);
+ extractCloudRegion(resultObject);
+ extractTenant(resultObject);
+ extractModelVer(resultObject);
+ }
+ }
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("vserver").toString()));
+ private void extractVserver(final JSONObject resultObject) {
+ if (resultObject.has("vserver")) {
- // Getting the vserver pojo again from the json
- Vserver vserver = this.getAaiObject(json, Vserver.class);
- this.inventoryResponseItems.add(vserver);
- }
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("vserver").toString()));
- // Object is a Generic VNF
- if (resultsArray.getJSONObject(i).has(GENERIC_VNF)) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString()));
+ // Getting the vserver pojo again from the json
+ Vserver vserver = this.getAaiObject(json, Vserver.class);
+ this.inventoryResponseItems.add(vserver);
+ }
+ }
- // Getting the generic vnf pojo again from the json
- GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class);
+ private void extractGenericVnf(final JSONObject resultObject) {
+ if (resultObject.has(GENERIC_VNF)) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject(GENERIC_VNF).toString()));
- this.inventoryResponseItems.add(genericVnf);
- }
+ // Getting the generic vnf pojo again from the json
+ GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class);
- // Object is a Service Instance
- if (resultsArray.getJSONObject(i).has("service-instance")) {
+ this.inventoryResponseItems.add(genericVnf);
+ }
+ }
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("service-instance").toString()));
+ private void extractServiceInstance(final JSONObject resultObject) {
+ if (resultObject.has("service-instance")) {
- // Getting the employee pojo again from the json
- ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class);
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("service-instance").toString()));
- this.inventoryResponseItems.add(serviceInstance);
- }
+ // Getting the employee pojo again from the json
+ ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class);
- // Object is a VF Module
- if (resultsArray.getJSONObject(i).has(VF_MODULE)) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString()));
+ this.inventoryResponseItems.add(serviceInstance);
+ }
+ }
- // Getting the vf module pojo again from the json
- VfModule vfModule = this.getAaiObject(json, VfModule.class);
+ private void extractVfModule(final JSONObject resultObject) {
+ if (resultObject.has(VF_MODULE)) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject(VF_MODULE).toString()));
- this.inventoryResponseItems.add(vfModule);
- }
+ // Getting the vf module pojo again from the json
+ VfModule vfModule = this.getAaiObject(json, VfModule.class);
- // Object is a CloudRegion
- if (resultsArray.getJSONObject(i).has("cloud-region")) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString()));
+ this.inventoryResponseItems.add(vfModule);
+ }
+ }
- // Getting the cloud region pojo again from the json
- CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class);
+ private void extractCloudRegion(final JSONObject resultObject) {
+ if (resultObject.has("cloud-region")) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("cloud-region").toString()));
- this.inventoryResponseItems.add(cloudRegion);
- }
+ // Getting the cloud region pojo again from the json
+ CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class);
- // Object is a Tenant
- if (resultsArray.getJSONObject(i).has("tenant")) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("tenant").toString()));
+ this.inventoryResponseItems.add(cloudRegion);
+ }
+ }
- // Getting the tenant pojo again from the json
- Tenant tenant = this.getAaiObject(json, Tenant.class);
+ private void extractTenant(final JSONObject resultObject) {
+ if (resultObject.has("tenant")) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("tenant").toString()));
- this.inventoryResponseItems.add(tenant);
- }
+ // Getting the tenant pojo again from the json
+ Tenant tenant = this.getAaiObject(json, Tenant.class);
- // Object is a ModelVer
- if (resultsArray.getJSONObject(i).has("model-ver")) {
- // Create the StreamSource by creating StringReader using the
- // JSON input
- StreamSource json = new StreamSource(
- new StringReader(resultsArray.getJSONObject(i).getJSONObject("model-ver").toString()));
+ this.inventoryResponseItems.add(tenant);
+ }
+ }
- // Getting the ModelVer pojo again from the json
- ModelVer modelVer = this.getAaiObject(json, ModelVer.class);
+ private void extractModelVer(final JSONObject resultObject) {
+ if (resultObject.has("model-ver")) {
+ // Create the StreamSource by creating StringReader using the
+ // JSON input
+ StreamSource json = new StreamSource(
+ new StringReader(resultObject.getJSONObject("model-ver").toString()));
- this.inventoryResponseItems.add(modelVer);
- }
+ // Getting the ModelVer pojo again from the json
+ ModelVer modelVer = this.getAaiObject(json, ModelVer.class);
+ this.inventoryResponseItems.add(modelVer);
}
-
}
private <T> T getAaiObject(StreamSource json, final Class<T> classOfResponse) {