Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / service / enhancer / BluePrintServiceTemplateEnhancerImpl.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.enhancer
18
19 import com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
22 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
24 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
25 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
26 import org.springframework.beans.factory.config.ConfigurableBeanFactory
27 import org.springframework.context.annotation.Scope
28 import org.springframework.stereotype.Service
29
30 @Service
31 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
32 open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
33     : BluePrintServiceTemplateEnhancer {
34     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateEnhancerImpl::class.toString())
35
36
37     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
38     lateinit var bluePrintContext: BluePrintContext
39
40     override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: ServiceTemplate) {
41         this.bluePrintRuntimeService = bluePrintRuntimeService
42         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
43
44         initialCleanUp()
45         enhanceTopologyTemplate()
46     }
47
48     open fun initialCleanUp() {
49         bluePrintContext.serviceTemplate.artifactTypes?.clear()
50         bluePrintContext.serviceTemplate.nodeTypes?.clear()
51         bluePrintContext.serviceTemplate.dataTypes?.clear()
52         bluePrintContext.serviceTemplate.policyTypes?.clear()
53         bluePrintContext.serviceTemplate.relationshipTypes?.clear()
54
55         bluePrintContext.serviceTemplate.artifactTypes = mutableMapOf()
56         bluePrintContext.serviceTemplate.nodeTypes = mutableMapOf()
57         bluePrintContext.serviceTemplate.dataTypes = mutableMapOf()
58         bluePrintContext.serviceTemplate.policyTypes = mutableMapOf()
59         bluePrintContext.serviceTemplate.relationshipTypes = mutableMapOf()
60         log.info("reinitialized all type definitions")
61
62     }
63
64     open fun enhanceTopologyTemplate() {
65         bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate ->
66             bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "topology_template", topologyTemplate)
67         }
68     }
69 }