From 22f7a0c20eb189380411df2e99928f701cc8a53f Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Thu, 20 Feb 2020 09:06:41 +0200 Subject: Learn to inflate models by Customization uuids Issue-ID: VID-771 Change-Id: I3996639745e77b8754e8bfa82c153690df683925 Signed-off-by: Ittay Stern --- .../onap/vid/asdc/parser/ServiceModelInflator.kt | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'vid-app-common/src/main') diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt index cdd2550a8..1a625014b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt @@ -26,10 +26,21 @@ import org.springframework.stereotype.Component @Component class ServiceModelInflator { + private data class Ids (val modelCustomizationId: String?, val modelVersionId: String) data class Names (val modelCustomizationName: String?, val modelKey: String?) fun toNamesByVersionId(model: ServiceModel): Map { - return emptyMap() + return toNamesByIds(model).mapKeys { it.key.modelVersionId } + } + + fun toNamesByCustomizationId(model: ServiceModel): Map { + return toNamesByIds(model) + .filterKeys { it.modelCustomizationId != null } + .mapKeys { it.key.modelCustomizationId!! } + } + + private fun toNamesByIds(model: ServiceModel): Map { + return emptyMap() .plus(inflate(model.networks)) .plus(inflate(model.vnfs)) .plus(inflate(model.vnfGroups)) @@ -37,31 +48,31 @@ class ServiceModelInflator { .plus(inflate(model.collectionResources)) } - private fun inflate(instances: Map): Map { + private fun inflate(instances: Map): Map { return instances.entries.map { inflate(it.key, it.value) }.fold(emptyMap()) { acc, it -> acc.plus(it) } } - private fun inflate(modelKey: String, vnf: VNF): Map { - return mapOf(vnf.uuid to Names(vnf.modelCustomizationName, modelKey)) + private fun inflate(modelKey: String, vnf: VNF): Map { + return mapOf(Ids(vnf.customizationUuid, vnf.uuid) to Names(vnf.modelCustomizationName, modelKey)) .plus(inflate(vnf.vfModules)) .plus(inflate(vnf.volumeGroups)) } - private fun inflate(modelKey: String, cr: CR): Map { - return mapOf(cr.uuid to Names(null, modelKey)) + private fun inflate(modelKey: String, cr: CR): Map { + return mapOf(Ids(cr.customizationUuid, cr.uuid) to Names(null, modelKey)) .plus(inflate(cr.networksCollection)) } - private fun inflate(modelKey: String, instance: Any?): Map { + private fun inflate(modelKey: String, instance: Any?): Map { return when (instance) { - is Network -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) - is VfModule -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) - is VolumeGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) - is ResourceGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) + is Network -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey)) + is VfModule -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey)) + is VolumeGroup -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey)) + is ResourceGroup -> mapOf(Ids(null, instance.uuid) to Names(instance.modelCustomizationName, modelKey)) is VNF -> inflate(modelKey, instance) is CR -> inflate(modelKey, instance) - is NetworkCollection -> mapOf(instance.uuid to Names(null, modelKey)) - is Node -> mapOf(instance.uuid to Names(null, modelKey)) + is NetworkCollection -> mapOf(Ids(null, instance.uuid) to Names(null, modelKey)) + is Node -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(null, modelKey)) else -> { // sink -- cgit 1.2.3-korg