2cd9e3288ec0d83534e5773834c86addd1d6d231
[ccsdk/cds.git] /
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 org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
20 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
21 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
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.springframework.beans.factory.config.ConfigurableBeanFactory
26 import org.springframework.context.annotation.Scope
27 import org.springframework.stereotype.Service
28
29 @Service
30 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
31 open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
32                                                 private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
33     : BluePrintServiceTemplateEnhancer {
34
35     lateinit var bluePrintContext: BluePrintContext
36     lateinit var error: BluePrintError
37
38     override fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: ServiceTemplate) {
39         this.bluePrintContext = bluePrintContext
40         this.error = error
41         initialCleanUp()
42         enhanceTopologyTemplate()
43     }
44
45     open fun initialCleanUp() {
46         bluePrintContext.serviceTemplate.artifactTypes?.clear()
47         bluePrintContext.serviceTemplate.nodeTypes?.clear()
48         bluePrintContext.serviceTemplate.dataTypes?.clear()
49         bluePrintContext.serviceTemplate.policyTypes?.clear()
50
51         bluePrintContext.serviceTemplate.artifactTypes = mutableMapOf()
52         bluePrintContext.serviceTemplate.nodeTypes = mutableMapOf()
53         bluePrintContext.serviceTemplate.dataTypes = mutableMapOf()
54         bluePrintContext.serviceTemplate.policyTypes = mutableMapOf()
55
56     }
57
58     open fun enhanceTopologyTemplate() {
59         bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate ->
60             bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintContext, error, "default", topologyTemplate)
61         }
62     }
63 }