diff options
author | pramod.jamkhedkar <pramod@research.att.com> | 2019-05-06 00:00:24 -0400 |
---|---|---|
committer | pramod.jamkhedkar <pramod@research.att.com> | 2019-05-06 09:31:11 -0400 |
commit | 781ddc9f17cd3f7960ed2aa74bf02964026414f5 (patch) | |
tree | 1ecf0de077ce43015b5cf14eeb80b9f80bc29ce2 /models-interactions/model-impl/aai/src/main/java | |
parent | 23fc065efe1a2152b6bea3d522039784c3c29488 (diff) |
Supports new aai changes.
Made changes to support model and model version additions to Aai custom
query response.
Issue-ID: POLICY-1729
Change-Id: I84a202105d477548e9e8e060d983bf9cd47d3885
Signed-off-by: pramod.jamkhedkar <pramod@research.att.com>
Diffstat (limited to 'models-interactions/model-impl/aai/src/main/java')
-rw-r--r-- | models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java | 90 | ||||
-rw-r--r-- | models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java | 1 |
2 files changed, 90 insertions, 1 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 8e9c580f4..dea11d563 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 @@ -37,6 +37,7 @@ import org.json.JSONArray; import org.json.JSONObject; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.ModelVer; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.ServiceInstance; @@ -63,7 +64,7 @@ public class AaiCqResponse { // Define JAXB context try { jaxbContext = JAXBContextFactory.createContext(new Class[] {Vserver.class, GenericVnf.class, VfModule.class, - CloudRegion.class, ServiceInstance.class, Tenant.class}, properties); + CloudRegion.class, ServiceInstance.class, Tenant.class, ModelVer.class}, properties); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { LOGGER.error("Could not initialize JAXBContext", e); @@ -168,6 +169,19 @@ public class AaiCqResponse { this.inventoryResponseItems.add(tenant); } + // 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())); + + // Getting the ModelVer pojo again from the json + ModelVer modelVer = this.getAaiObject(json, ModelVer.class); + + this.inventoryResponseItems.add(modelVer); + } + } @@ -327,6 +341,28 @@ public class AaiCqResponse { } + /** + * Returns a generic Vnf of a given VF Module ID. + * + * @param vfModuleModelInvariantId of the vf module for which vnf is to be returned + * @return generic Vnf + */ + public GenericVnf getGenericVnfByVfModuleModelInvariantId(String vfModuleModelInvariantId) { + List<GenericVnf> genericVnfList = this.getGenericVnfs(); + + for (GenericVnf genVnf : genericVnfList) { + // Iterate through all the vfModules of that generic Vnf + for (VfModule vfMod : genVnf.getVfModules().getVfModule()) { + if (vfMod.getModelInvariantId() != null + && vfMod.getModelInvariantId().equals(vfModuleModelInvariantId)) { + return genVnf; + } + } + } + return null; + } + + /** * Get the generic vnf associated with the vserver in the custom query. @@ -458,6 +494,24 @@ public class AaiCqResponse { return vfModule; } + + /** + * Get Vf Module matching a specific VF model invariant ID. + * + * @return VfModule + */ + public VfModule getVfModuleByVfModelInvariantId(String vfModelInvariantId) { + VfModule vfModule = null; + + for (VfModule vfMod : this.getAllVfModules()) { + if (vfMod.getModelInvariantId() != null && vfModelInvariantId.equals(vfMod.getModelInvariantId())) { + vfModule = vfMod; + } + + } + return vfModule; + } + /** * Get verver in the custom query. * @@ -474,5 +528,39 @@ public class AaiCqResponse { } + /** + * Get Model Versions in the custom query. + * + * @return List of model Versions + */ + public List<ModelVer> getAllModelVer() { + List<ModelVer> modelVerList = new ArrayList<>(); + for (Object i : this.inventoryResponseItems) { + if (i.getClass() == ModelVer.class) { + modelVerList.add((ModelVer) i); + } + } + return modelVerList; + } + + + + /** + * Get ModelVer matching a specific version id. + * + * @return VfModule + */ + public ModelVer getModelVerByVersionId(String versionId) { + ModelVer modelVer = null; + + for (ModelVer modVersion : this.getAllModelVer()) { + if (versionId.equals(modVersion.getModelVersionId())) { + modelVer = modVersion; + } + + } + return modelVer; + } + } diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java index 891114aa1..2b51a7bde 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java @@ -365,6 +365,7 @@ public final class AaiManager { return headers; } + /** * This method uses Google's GSON to create a response object from a JSON string. * |