Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / service / enhancer / BluePrintPropertyDefinitionEnhancerImpl.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
19
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionEnhancer
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
26 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
27 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
28 import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
29 import org.springframework.beans.factory.config.ConfigurableBeanFactory
30 import org.springframework.context.annotation.Scope
31 import org.springframework.stereotype.Service
32
33 @Service
34 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
35 open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
36                                                    private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
37     : BluePrintPropertyDefinitionEnhancer {
38
39     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
40     lateinit var bluePrintContext: BluePrintContext
41
42     override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
43         this.bluePrintRuntimeService = bluePrintRuntimeService
44         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
45
46         val propertyType = propertyDefinition.type
47         if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)
48                 || BluePrintTypes.validComplexTypes().contains(propertyType)) {
49             // Do Nothing,
50         } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) {
51             val entrySchema = propertyDefinition.entrySchema
52                     ?: throw BluePrintException("Entry Schema is missing for collection property($name)")
53
54             if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) {
55                 BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type)
56             }
57         } else {
58             BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType)
59         }
60     }
61
62 }