6a4f6232cf0d2762f556f9031273bc4bd20dba5a
[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.BluePrintRepoService
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
25 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
26 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
27 import org.springframework.beans.factory.config.ConfigurableBeanFactory
28 import org.springframework.context.annotation.Scope
29 import org.springframework.stereotype.Service
30
31 @Service
32 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
33 open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
34                                                 private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
35     : BluePrintServiceTemplateEnhancer {
36     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString())
37
38
39     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
40     lateinit var bluePrintContext: BluePrintContext
41
42     override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: ServiceTemplate) {
43         this.bluePrintRuntimeService = bluePrintRuntimeService
44         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
45
46         initialCleanUp()
47         enhanceTopologyTemplate()
48     }
49
50     open fun initialCleanUp() {
51         bluePrintContext.serviceTemplate.artifactTypes?.clear()
52         bluePrintContext.serviceTemplate.nodeTypes?.clear()
53         bluePrintContext.serviceTemplate.dataTypes?.clear()
54         bluePrintContext.serviceTemplate.policyTypes?.clear()
55
56         bluePrintContext.serviceTemplate.artifactTypes = mutableMapOf()
57         bluePrintContext.serviceTemplate.nodeTypes = mutableMapOf()
58         bluePrintContext.serviceTemplate.dataTypes = mutableMapOf()
59         bluePrintContext.serviceTemplate.policyTypes = mutableMapOf()
60
61     }
62
63     open fun enhanceTopologyTemplate() {
64         bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate ->
65             bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "default", topologyTemplate)
66         }
67     }
68 }