4e226b2e2eb054963b2fbdd106707234ae2d355c
[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 com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.InterfaceDefinition
23 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationDefinition
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer
26 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
27 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService
28 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
29 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
30 import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils
31 import org.springframework.beans.factory.config.ConfigurableBeanFactory
32 import org.springframework.context.annotation.Scope
33 import org.springframework.stereotype.Service
34
35 @Service
36 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
37 open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService,
38                                          private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTypeEnhancer {
39
40     private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTypeEnhancerImpl::class.toString())
41
42     lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*>
43     lateinit var bluePrintContext: BluePrintContext
44
45
46     override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) {
47         this.bluePrintRuntimeService = bluePrintRuntimeService
48         this.bluePrintContext = bluePrintRuntimeService.bluePrintContext()
49
50
51         val derivedFrom = nodeType.derivedFrom
52
53         if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) {
54             val derivedFromNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, name)
55             // Enrich NodeType
56             enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType)
57         }
58
59         // NodeType Attribute Definitions
60         enrichNodeTypeAtributes(name, nodeType)
61
62         // NodeType Property Definitions
63         enrichNodeTypeProperties(name, nodeType)
64
65         //NodeType Requirement
66         enrichNodeTypeRequirements(name, nodeType)
67
68         //NodeType Capability
69         enrichNodeTypeCapabilityProperties(name, nodeType)
70
71         //NodeType Interface
72         enrichNodeTypeInterfaces(name, nodeType)
73
74     }
75
76     open fun enrichNodeTypeAtributes(nodeTypeName: String, nodeType: NodeType) {
77         nodeType.attributes?.let {
78             bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!)
79         }
80     }
81
82     open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) {
83         nodeType.properties?.let {
84             bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!)
85         }
86     }
87
88     open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) {
89
90         nodeType.requirements?.forEach { _, requirementDefinition ->
91             // Populate Requirement Node
92             requirementDefinition.node?.let { requirementNodeTypeName ->
93                 // Get Requirement NodeType from Repo and Update Service Template
94                 val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext,
95                         bluePrintRepoService, requirementNodeTypeName)
96                 // Enhanypece Node T
97                 enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType)
98             }
99         }
100     }
101
102     open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) {
103         nodeType.capabilities?.forEach { _, capabilityDefinition ->
104             capabilityDefinition.properties?.let { properties ->
105                 bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties)
106             }
107         }
108     }
109
110     open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) {
111         nodeType.interfaces?.forEach { interfaceName, interfaceObj ->
112             // Populate Node type Interface Operation
113             log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName)
114             populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj)
115
116         }
117     }
118
119     open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) {
120
121         interfaceObj.operations?.forEach { operationName, operation ->
122             enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation)
123             enrichNodeTypeInterfaceOperationOputputs(nodeTypeName, operationName, operation)
124         }
125     }
126
127     open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
128         operation.inputs?.let { inputs ->
129             bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
130         }
131     }
132
133     open fun enrichNodeTypeInterfaceOperationOputputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) {
134         operation.outputs?.let { inputs ->
135             bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs)
136         }
137     }
138
139 }