From cc58683b528a670402e9f8b4a8c579605ce5f6da Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Thu, 15 Aug 2024 14:07:00 +0100 Subject: Fix constant missing in drools-applications Issue-ID: POLICY-5107 Change-Id: I63d71445de2c188916692d7f4136fdf9e4512948 Signed-off-by: adheli.tavares --- .../java/org/onap/policy/aai/AaiCqResponse.java | 69 +++++++++------------- 1 file changed, 28 insertions(+), 41 deletions(-) (limited to 'models-interactions/model-impl') 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 inventoryResponseItems = new LinkedList<>(); @@ -166,14 +174,6 @@ public class AaiCqResponse implements Serializable { } } - public List getInventoryResponseItems() { - return inventoryResponseItems; - } - - public void setInventoryResponseItems(List inventoryResponseItems) { - this.inventoryResponseItems = inventoryResponseItems; - } - /** * Get list of A&AI objects in the custom query. * @@ -360,14 +360,29 @@ public class AaiCqResponse implements Serializable { List 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 genericVnfList = this.getGenericVnfs(); + + for (GenericVnf genVnf : genericVnfList) { + if (genericVnfId.equals(genVnf.getVnfId())) { + genericVnf = genVnf; + } + } + + return genericVnf; + } + + private static String getGenericVnfId(List relations, String genericVnf, String x) { var genericVnfId = ""; - List relationshipData = null; + List 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 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 relations = vserver.getRelationshipList().getRelationship(); // Find the relationship of VfModule - var vfModuleId = ""; - List 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(); -- cgit 1.2.3-korg