From c34a4b6b2e111462cde7f5663b8fbbc4ad86fc7e Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 8 Nov 2019 09:17:42 -0500 Subject: Fix sonar issue affecting in drools-applications Drools-applications has a serializable class that contains AaiCqResponse. Sonar complained that the latter class must also be serializable, so made the change in policy-models to fix that. In addition, the latter class contained a list of Object. To ensure that those are also serializable, the list was changed to a list of Serializable instead. The latter change can be reverted, if it causes compilation issues elsewhere. However, it seems safer to enforce serializability in the list rather than risk having a later change inject a non-serializable object into the list. Change-Id: Ia741a1a96ec4efcc63451e9af31c19b4fe99dd7d Issue-ID: POLICY-2225 Signed-off-by: Jim Hahn --- .../java/org/onap/policy/aai/AaiCqResponse.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 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 7024231e3..2010a5dff 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 @@ -21,6 +21,7 @@ package org.onap.policy.aai; import com.google.gson.annotations.SerializedName; +import java.io.Serializable; import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; @@ -47,8 +48,8 @@ import org.onap.aai.domain.yang.Vserver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AaiCqResponse { - +public class AaiCqResponse implements Serializable { + private static final long serialVersionUID = 1L; private static final String GENERIC_VNF = "generic-vnf"; private static final String VF_MODULE = "vf-module"; private static final Logger LOGGER = LoggerFactory.getLogger(AaiCqResponse.class); @@ -81,7 +82,7 @@ public class AaiCqResponse { } @SerializedName("results") - private List inventoryResponseItems = new LinkedList<>(); + private List inventoryResponseItems = new LinkedList<>(); /** * Constructor creates a custom query response from a valid json string. @@ -202,11 +203,11 @@ public class AaiCqResponse { } } - public List getInventoryResponseItems() { + public List getInventoryResponseItems() { return inventoryResponseItems; } - public void setInventoryResponseItems(List inventoryResponseItems) { + public void setInventoryResponseItems(List inventoryResponseItems) { this.inventoryResponseItems = inventoryResponseItems; } @@ -219,7 +220,7 @@ public class AaiCqResponse { @SuppressWarnings("unchecked") public List getItemListByType(Class classOfResponse) { List returnItemList = new ArrayList<>(); - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == classOfResponse) { returnItemList.add((T) i); } @@ -235,7 +236,7 @@ public class AaiCqResponse { */ public ServiceInstance getServiceInstance() { ServiceInstance serviceInstance = null; - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == ServiceInstance.class) { serviceInstance = (ServiceInstance) i; } @@ -251,7 +252,7 @@ public class AaiCqResponse { */ public Tenant getDefaultTenant() { Tenant tenant = null; - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == Tenant.class) { tenant = (Tenant) i; } @@ -267,7 +268,7 @@ public class AaiCqResponse { */ public CloudRegion getDefaultCloudRegion() { CloudRegion cloudRegion = null; - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == CloudRegion.class) { cloudRegion = (CloudRegion) i; } @@ -283,7 +284,7 @@ public class AaiCqResponse { */ public List getGenericVnfs() { List genericVnfList = new ArrayList<>(); - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == GenericVnf.class) { genericVnfList.add((GenericVnf) i); } @@ -301,7 +302,7 @@ public class AaiCqResponse { public GenericVnf getGenericVnfByVnfName(String vnfName) { List genericVnfList = new ArrayList<>(); GenericVnf genericVnf = null; - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == GenericVnf.class) { genericVnfList.add((GenericVnf) i); } @@ -326,7 +327,7 @@ public class AaiCqResponse { public GenericVnf getGenericVnfByModelInvariantId(String modelInvariantId) { List genericVnfList = new ArrayList<>(); GenericVnf genericVnf = null; - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == GenericVnf.class) { genericVnfList.add((GenericVnf) i); } @@ -533,7 +534,7 @@ public class AaiCqResponse { */ public List getAllModelVer() { List modelVerList = new ArrayList<>(); - for (Object i : this.inventoryResponseItems) { + for (Serializable i : this.inventoryResponseItems) { if (i.getClass() == ModelVer.class) { modelVerList.add((ModelVer) i); } -- cgit 1.2.3-korg