Clean up minor things in policy-models
[policy/models.git] / models-interactions / model-impl / aai / src / main / java / org / onap / policy / aai / AaiCqResponse.java
index dea11d5..7024231 100644 (file)
@@ -55,7 +55,6 @@ public class AaiCqResponse {
     private static JAXBContext jaxbContext;
     private static Unmarshaller unmarshaller;
 
-
     // JABX initial stuff
     static {
         Map<String, Object> properties = new HashMap<>();
@@ -63,8 +62,17 @@ public class AaiCqResponse {
         properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);
         // Define JAXB context
         try {
-            jaxbContext = JAXBContextFactory.createContext(new Class[] {Vserver.class, GenericVnf.class, VfModule.class,
-                CloudRegion.class, ServiceInstance.class, Tenant.class, ModelVer.class}, properties);
+            // @formatter:off
+            jaxbContext = JAXBContextFactory.createContext(new Class[] {
+                Vserver.class,
+                GenericVnf.class,
+                VfModule.class,
+                CloudRegion.class,
+                ServiceInstance.class,
+                Tenant.class,
+                ModelVer.class
+            }, properties);
+            // @formatter:on
             unmarshaller = jaxbContext.createUnmarshaller();
         } catch (JAXBException e) {
             LOGGER.error("Could not initialize JAXBContext", e);
@@ -75,7 +83,6 @@ public class AaiCqResponse {
     @SerializedName("results")
     private List<Object> inventoryResponseItems = new LinkedList<>();
 
-
     /**
      * Constructor creates a custom query response from a valid json string.
      *
@@ -184,12 +191,8 @@ public class AaiCqResponse {
 
         }
 
-
-
     }
 
-
-
     private <T> T getAaiObject(StreamSource json, final Class<T> classOfResponse) {
         try {
             return unmarshaller.unmarshal(json, classOfResponse).getValue();
@@ -289,7 +292,6 @@ public class AaiCqResponse {
 
     }
 
-
     /**
      * Returns a generic Vnf matching vnf name.
      *
@@ -340,7 +342,6 @@ public class AaiCqResponse {
 
     }
 
-
     /**
      * Returns a generic Vnf of a given VF Module ID.
      *
@@ -362,8 +363,6 @@ public class AaiCqResponse {
         return null;
     }
 
-
-
     /**
      * Get the generic vnf associated with the vserver in the custom query.
      *
@@ -382,7 +381,8 @@ public class AaiCqResponse {
         String genericVnfId = "";
         List<RelationshipData> relationshipData = null;
 
-        // Iterate through the list of relationships and get generic vnf relationship data
+        // 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())) {
@@ -410,7 +410,6 @@ public class AaiCqResponse {
         return genericVnf;
     }
 
-
     /**
      * Get Vf Module associated with the vserver in the custom query.
      *
@@ -430,7 +429,8 @@ public class AaiCqResponse {
         String vfModuleId = "";
         List<RelationshipData> relationshipData = null;
 
-        // Iterate through the list of relationships and get vf module relationship data
+        // 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())) {
@@ -461,7 +461,6 @@ public class AaiCqResponse {
         return vfModule;
     }
 
-
     /**
      * Get vf modules in the custom query.
      *
@@ -494,7 +493,6 @@ public class AaiCqResponse {
         return vfModule;
     }
 
-
     /**
      * Get Vf Module matching a specific VF model invariant ID.
      *
@@ -543,8 +541,6 @@ public class AaiCqResponse {
         return modelVerList;
     }
 
-
-
     /**
      * Get ModelVer matching a specific version id.
      *
@@ -562,5 +558,29 @@ public class AaiCqResponse {
         return modelVer;
     }
 
-}
+    /**
+     * Get the count of vfModules matching customizationId, InvariantId and VersionId.
+     *
+     * @param custId ModelCustomizationId
+     * @param invId ModelInvariantId
+     * @param verId ModelVersionId
+     * @return Returns the count of vf modules
+     */
+    public int getVfModuleCount(String custId, String invId, String verId) {
+        List<VfModule> vfModuleList = this.getAllVfModules();
+        int count = 0;
+        for (VfModule vfModule : vfModuleList) {
+            if (vfModule.getModelCustomizationId() == null || vfModule.getModelInvariantId() == null
+                    || vfModule.getModelVersionId() == null) {
+                continue;
+            }
+
+            if (vfModule.getModelCustomizationId().equals(custId) && vfModule.getModelInvariantId().equals(invId)
+                    && vfModule.getModelVersionId().equals(verId)) {
+                count = count + 1;
+            }
+        }
+        return count;
+    }
 
+}