989617bd37b947f2f6a6c2e2ea5211dea1fe0f7d
[ccsdk/cds.git] / components / core / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / core / interfaces / BluePrintEnhancer.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.core.interfaces
18
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintError
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
22 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
23
24 interface BluePrintEnhancer<T> {
25     fun enhance(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, type: T)
26 }
27
28 interface BluePrintServiceTemplateEnhancer : BluePrintEnhancer<ServiceTemplate>
29
30 interface BluePrintTopologyTemplateEnhancer : BluePrintEnhancer<TopologyTemplate>
31
32 interface BluePrintWorkflowEnhancer : BluePrintEnhancer<Workflow>
33
34 interface BluePrintNodeTemplateEnhancer : BluePrintEnhancer<NodeTemplate>
35
36 interface BluePrintNodeTypeEnhancer : BluePrintEnhancer<NodeType>
37
38 interface BluePrintPolicyTypeEnhancer : BluePrintEnhancer<PolicyType>
39
40 interface BluePrintPropertyDefinitionEnhancer : BluePrintEnhancer<PropertyDefinition>
41
42 interface BluePrintAttributeDefinitionEnhancer : BluePrintEnhancer<AttributeDefinition>
43
44
45 interface BluePrintEnhancerService {
46
47     @Throws(BluePrintException::class)
48     fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext
49
50     @Throws(BluePrintException::class)
51     fun enhance(basePath: String): BluePrintContext
52
53     @Throws(BluePrintException::class)
54     fun enhance(serviceTemplate: ServiceTemplate): ServiceTemplate
55 }
56
57 interface BluePrintTypeEnhancerService {
58
59     fun getServiceTemplateEnhancers(): List<BluePrintServiceTemplateEnhancer>
60
61     fun getTopologyTemplateEnhancers(): List<BluePrintTopologyTemplateEnhancer>
62
63     fun getWorkflowEnhancers(): List<BluePrintWorkflowEnhancer>
64
65     fun getNodeTemplateEnhancers(): List<BluePrintNodeTemplateEnhancer>
66
67     fun getNodeTypeEnhancers(): List<BluePrintNodeTypeEnhancer>
68
69     fun getPolicyTypeEnhancers(): List<BluePrintPolicyTypeEnhancer>
70
71     fun getPropertyDefinitionEnhancers(): List<BluePrintPropertyDefinitionEnhancer>
72
73     fun getAttributeDefinitionEnhancers(): List<BluePrintAttributeDefinitionEnhancer>
74
75     fun enhanceServiceTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, serviceTemplate: ServiceTemplate) {
76         val enhancers = getServiceTemplateEnhancers()
77         doEnhancement(bluePrintContext, error, name, serviceTemplate, enhancers)
78     }
79
80     fun enhanceTopologyTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, topologyTemplate: TopologyTemplate) {
81         val enhancers = getTopologyTemplateEnhancers()
82         doEnhancement(bluePrintContext, error, name, topologyTemplate, enhancers)
83     }
84
85     fun enhanceWorkflow(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, workflow: Workflow) {
86         val enhancers = getWorkflowEnhancers()
87         doEnhancement(bluePrintContext, error, name, workflow, enhancers)
88     }
89
90     fun enhanceNodeTemplate(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeTemplate: NodeTemplate) {
91         val enhancers = getNodeTemplateEnhancers()
92         doEnhancement(bluePrintContext, error, name, nodeTemplate, enhancers)
93     }
94
95     fun enhanceNodeType(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, nodeType: NodeType) {
96         val enhancers = getNodeTypeEnhancers()
97         doEnhancement(bluePrintContext, error, name, nodeType, enhancers)
98     }
99
100     fun enhancePolicyType(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, policyType: PolicyType) {
101         val enhancers = getPolicyTypeEnhancers()
102         doEnhancement(bluePrintContext, error, name, policyType, enhancers)
103     }
104
105     fun enhancePropertyDefinition(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, propertyDefinition: PropertyDefinition) {
106         val enhancers = getPropertyDefinitionEnhancers()
107         doEnhancement(bluePrintContext, error, name, propertyDefinition, enhancers)
108     }
109
110     fun enhanceAttributeDefinition(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, attributeDefinition: AttributeDefinition) {
111         val enhancers = getAttributeDefinitionEnhancers()
112         doEnhancement(bluePrintContext, error, name, attributeDefinition, enhancers)
113     }
114
115     private fun <T> doEnhancement(bluePrintContext: BluePrintContext, error: BluePrintError, name: String, definition: Any, enhancers: List<BluePrintEnhancer<T>>) {
116         if (enhancers.isNotEmpty()) {
117             enhancers.forEach {
118                 it.enhance(bluePrintContext, error, name, definition as T)
119             }
120         }
121     }
122 }