2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.asdc.parser
23 import org.onap.vid.model.*
24 import org.springframework.stereotype.Component
27 class ServiceModelInflator {
29 private data class Ids (val modelCustomizationId: String?, val modelVersionId: String)
30 data class Names (val modelCustomizationName: String?, val modelKey: String?)
32 fun toNamesByVersionId(model: ServiceModel): Map<String, Names> {
33 return toNamesByIds(model).mapKeys { it.key.modelVersionId }
36 fun toNamesByCustomizationId(model: ServiceModel): Map<String, Names> {
37 return toNamesByIds(model)
38 .filterKeys { it.modelCustomizationId != null }
39 .mapKeys { it.key.modelCustomizationId!! }
42 private fun toNamesByIds(model: ServiceModel): Map<Ids, Names> {
43 return emptyMap<Ids, Names>()
44 .plus(inflate(model.networks))
45 .plus(inflate(model.vnfs))
46 .plus(inflate(model.vnfGroups))
47 .plus(inflate(model.vrfs))
48 .plus(inflate(model.collectionResources))
51 private fun inflate(instances: Map<String, *>): Map<Ids, Names> {
52 return instances.entries.map { inflate(it.key, it.value) }.fold(emptyMap()) { acc, it -> acc.plus(it) }
55 private fun inflate(modelKey: String, vnf: VNF): Map<Ids, Names> {
56 return mapOf(Ids(vnf.customizationUuid, vnf.uuid) to Names(vnf.modelCustomizationName, modelKey))
57 .plus(inflate(vnf.vfModules))
58 .plus(inflate(vnf.volumeGroups))
61 private fun inflate(modelKey: String, cr: CR): Map<Ids, Names> {
62 return mapOf(Ids(cr.customizationUuid, cr.uuid) to Names(null, modelKey))
63 .plus(inflate(cr.networksCollection))
66 private fun inflate(modelKey: String, instance: Any?): Map<Ids, Names> {
67 return when (instance) {
68 is Network -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
69 is VfModule -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
70 is VolumeGroup -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
71 is ResourceGroup -> mapOf(Ids(null, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
72 is VNF -> inflate(modelKey, instance)
73 is CR -> inflate(modelKey, instance)
74 is NetworkCollection -> mapOf(Ids(null, instance.uuid) to Names(null, modelKey))
75 is Node -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(null, modelKey))