Fixing Blueprint Typo's and docs
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / 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.cds.blueprintsprocessor.designer.api.enhancer
19
20 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintEnhancerUtils
21 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
22 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
24 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintPropertyDefinitionEnhancer
25 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintRepoService
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintTypeEnhancerService
27 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
28 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
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(
36     private val bluePrintRepoService: BlueprintRepoService,
37     private val bluePrintTypeEnhancerService: BlueprintTypeEnhancerService
38 ) :
39     BlueprintPropertyDefinitionEnhancer {
40
41     lateinit var bluePrintRuntimeService: BlueprintRuntimeService<*>
42     lateinit var bluePrintContext: BlueprintContext
43
44     override fun enhance(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
45         this.bluePrintRuntimeService = bluePrintRuntimeService
46         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
47
48         val propertyType = propertyDefinition.type
49         if (BlueprintTypes.validPrimitiveTypes().contains(propertyType) ||
50             BlueprintTypes.validComplexTypes().contains(propertyType)
51         ) {
52             // Do Nothing,
53         } else if (BlueprintTypes.validCollectionTypes().contains(propertyType)) {
54             val entrySchema = propertyDefinition.entrySchema
55                 ?: throw BlueprintException("Entry Schema is missing for collection property($name)")
56
57             if (!BlueprintTypes.validPrimitiveTypes().contains(entrySchema.type)) {
58                 BlueprintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type)
59             }
60         } else {
61             BlueprintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType)
62         }
63     }
64 }