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 data class Names (val modelCustomizationName: String?, val modelKey: String?)
31 fun toNamesByVersionId(model: ServiceModel): Map<String, Names> {
32 return emptyMap<String, Names>()
33 .plus(inflate(model.networks))
34 .plus(inflate(model.vnfs))
35 .plus(inflate(model.vnfGroups))
36 .plus(inflate(model.vrfs))
37 .plus(inflate(model.collectionResources))
40 private fun inflate(instances: Map<String, *>): Map<String, Names> {
41 return instances.entries.map { inflate(it.key, it.value) }.fold(emptyMap()) { acc, it -> acc.plus(it) }
44 private fun inflate(modelKey: String, vnf: VNF): Map<String, Names> {
45 return mapOf(vnf.uuid to Names(vnf.modelCustomizationName, modelKey))
46 .plus(inflate(vnf.vfModules))
47 .plus(inflate(vnf.volumeGroups))
50 private fun inflate(modelKey: String, cr: CR): Map<String, Names> {
51 return mapOf(cr.uuid to Names(null, modelKey))
52 .plus(inflate(cr.networksCollection))
55 private fun inflate(modelKey: String, instance: Any?): Map<String, Names> {
56 return when (instance) {
57 is Network -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
58 is VfModule -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
59 is VolumeGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
60 is ResourceGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
61 is VNF -> inflate(modelKey, instance)
62 is CR -> inflate(modelKey, instance)
63 is NetworkCollection -> mapOf(instance.uuid to Names(null, modelKey))
64 is Node -> mapOf(instance.uuid to Names(null, modelKey))