Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / service / enhancer / BluePrintNodeTemplateEnhancerImpl.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.apps.controllerblueprints.service.enhancer
19
20 import com.att.eelf.configuration.EELFLogger
21 import com.att.eelf.configuration.EELFManager
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer
24 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
26 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
27 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
28 import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
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 BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
36                                              private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService)
37     : BluePrintNodeTemplateEnhancer {
38
39     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString())
40
41     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
42     lateinit var bluePrintContext: BluePrintContext
43
44
45     override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
46         log.info("***** Enhancing NodeTemplate($name)")
47         this.bluePrintRuntimeService = bluePrintRuntimeService
48         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
49
50
51         val nodeTypeName = nodeTemplate.type
52         // Get NodeType from Repo and Update Service Template
53         val nodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, nodeTypeName)
54
55         // Enrich NodeType
56         bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType)
57
58         //Enrich Node Template Artifacts
59         enhanceNodeTemplateArtifactDefinition(name, nodeTemplate)
60     }
61
62     open fun enhanceNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) {
63
64         nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition ->
65             // Enhance Artifacct Definitions
66             bluePrintTypeEnhancerService.enhanceArtifactDefinition(bluePrintRuntimeService, artifactDefinitionName, artifactDefinition)
67         }
68     }
69
70 }