2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.enhancer
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
34 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
35 open class BlueprintPropertyDefinitionEnhancerImpl(
36 private val bluePrintRepoService: BlueprintRepoService,
37 private val bluePrintTypeEnhancerService: BlueprintTypeEnhancerService
39 BlueprintPropertyDefinitionEnhancer {
41 lateinit var bluePrintRuntimeService: BlueprintRuntimeService<*>
42 lateinit var bluePrintContext: BlueprintContext
44 override fun enhance(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
45 this.bluePrintRuntimeService = bluePrintRuntimeService
46 this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
48 val propertyType = propertyDefinition.type
49 if (BlueprintTypes.validPrimitiveTypes().contains(propertyType) ||
50 BlueprintTypes.validComplexTypes().contains(propertyType)
53 } else if (BlueprintTypes.validCollectionTypes().contains(propertyType)) {
54 val entrySchema = propertyDefinition.entrySchema
55 ?: throw BlueprintException("Entry Schema is missing for collection property($name)")
57 if (!BlueprintTypes.validPrimitiveTypes().contains(entrySchema.type)) {
58 BlueprintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type)
61 BlueprintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType)