diff options
-rw-r--r-- | models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java | 69 |
1 files changed, 28 insertions, 41 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 ed77525be..e06f796ea 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 @@ -24,10 +24,13 @@ package org.onap.policy.aai; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.SerializedName; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import lombok.Getter; +import lombok.Setter; import org.json.JSONArray; import org.json.JSONObject; import org.onap.aai.domain.yang.CloudRegion; @@ -41,11 +44,16 @@ import org.onap.aai.domain.yang.VfModule; import org.onap.aai.domain.yang.Vserver; public class AaiCqResponse implements Serializable { + + @Serial private static final long serialVersionUID = 1L; + public static final String CONTEXT_KEY = AaiConstants.CONTEXT_PREFIX + "AaiCqResponse"; // NOSONAR used in pdps public static final String OPERATION = "CustomQuery"; private static final String GENERIC_VNF = "generic-vnf"; private static final String VF_MODULE = "vf-module"; + @Getter + @Setter @SerializedName("results") private List<Serializable> inventoryResponseItems = new LinkedList<>(); @@ -166,14 +174,6 @@ public class AaiCqResponse implements Serializable { } } - public List<Serializable> getInventoryResponseItems() { - return inventoryResponseItems; - } - - public void setInventoryResponseItems(List<Serializable> inventoryResponseItems) { - this.inventoryResponseItems = inventoryResponseItems; - } - /** * Get list of A&AI objects in the custom query. * @@ -360,14 +360,29 @@ public class AaiCqResponse implements Serializable { List<Relationship> relations = vserver.getRelationshipList().getRelationship(); // Find the relationship of the genericVNF + var genericVnfId = getGenericVnfId(relations, GENERIC_VNF, "generic-vnf.vnf-id"); + + // Get the list of generic vnfs + List<GenericVnf> genericVnfList = this.getGenericVnfs(); + + for (GenericVnf genVnf : genericVnfList) { + if (genericVnfId.equals(genVnf.getVnfId())) { + genericVnf = genVnf; + } + } + + return genericVnf; + } + + private static String getGenericVnfId(List<Relationship> relations, String genericVnf, String x) { var genericVnfId = ""; - List<RelationshipData> relationshipData = null; + List<RelationshipData> relationshipData = new ArrayList<>(); // Iterate through the list of relationships and get generic vnf // relationship data for (Relationship r : relations) { // Get the name of generic-vnf related to this server - if (GENERIC_VNF.equals(r.getRelatedTo())) { + if (genericVnf.equals(r.getRelatedTo())) { relationshipData = r.getRelationshipData(); } } @@ -375,21 +390,11 @@ public class AaiCqResponse implements Serializable { // Iterate through relationship data, and get vnf-id for (RelationshipData rd : relationshipData) { // Get the id of the generic-vnf - if ("generic-vnf.vnf-id".equals(rd.getRelationshipKey())) { + if (x.equals(rd.getRelationshipKey())) { genericVnfId = rd.getRelationshipValue(); } } - - // Get the list of generic vnfs - List<GenericVnf> genericVnfList = this.getGenericVnfs(); - - for (GenericVnf genVnf : genericVnfList) { - if (genericVnfId.equals(genVnf.getVnfId())) { - genericVnf = genVnf; - } - } - - return genericVnf; + return genericVnfId; } /** @@ -408,25 +413,7 @@ public class AaiCqResponse implements Serializable { List<Relationship> relations = vserver.getRelationshipList().getRelationship(); // Find the relationship of VfModule - var vfModuleId = ""; - List<RelationshipData> relationshipData = null; - - // Iterate through the list of relationships and get vf module - // relationship data - for (Relationship r : relations) { - // Get relationship data of vfmodule related to this server - if (VF_MODULE.equals(r.getRelatedTo())) { - relationshipData = r.getRelationshipData(); - } - } - - // Iterate through relationship data, and get vf-module-id - for (RelationshipData rd : relationshipData) { - // Get the id of the vf-module - if ("vf-module.vf-module-id".equals(rd.getRelationshipKey())) { - vfModuleId = rd.getRelationshipValue(); - } - } + var vfModuleId = getGenericVnfId(relations, VF_MODULE, "vf-module.vf-module-id"); // Get the generic VNF associated with this vserver query genericVnf = this.getDefaultGenericVnf(); |