Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / interfaces / BlueprintValidator.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 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.cds.controllerblueprints.core.interfaces
19
20 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactType
23 import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition
24 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
29 import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate
30 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
31 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
32
33 interface BlueprintValidator<T> {
34
35     fun validate(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, type: T)
36 }
37
38 interface BlueprintServiceTemplateValidator : BlueprintValidator<ServiceTemplate>
39
40 interface BlueprintTopologyTemplateValidator : BlueprintValidator<TopologyTemplate>
41
42 interface BlueprintArtifactTypeValidator : BlueprintValidator<ArtifactType>
43
44 interface BlueprintArtifactDefinitionValidator : BlueprintValidator<ArtifactDefinition>
45
46 interface BlueprintDataTypeValidator : BlueprintValidator<DataType>
47
48 interface BlueprintNodeTypeValidator : BlueprintValidator<NodeType>
49
50 interface BlueprintNodeTemplateValidator : BlueprintValidator<NodeTemplate>
51
52 interface BlueprintWorkflowValidator : BlueprintValidator<Workflow>
53
54 interface BlueprintPropertyDefinitionValidator : BlueprintValidator<PropertyDefinition>
55
56 interface BlueprintAttributeDefinitionValidator : BlueprintValidator<AttributeDefinition>
57
58 /**
59  * Blueprint Validation Interface.
60  */
61 interface BlueprintValidatorService {
62
63     @Throws(BlueprintException::class)
64     suspend fun validateBlueprints(basePath: String): Boolean
65
66     @Throws(BlueprintException::class)
67     suspend fun validateBlueprints(bluePrintRuntimeService: BlueprintRuntimeService<*>): Boolean
68 }
69
70 interface BlueprintTypeValidatorService {
71
72     fun <T : BlueprintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T?
73
74     fun <T : BlueprintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>?
75
76     fun <T : BlueprintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>?
77
78     fun getServiceTemplateValidators(): List<BlueprintServiceTemplateValidator>
79
80     fun getDataTypeValidators(): List<BlueprintDataTypeValidator>
81
82     fun getArtifactTypeValidators(): List<BlueprintArtifactTypeValidator>
83
84     fun getArtifactDefinitionsValidators(): List<BlueprintArtifactDefinitionValidator>
85
86     fun getNodeTypeValidators(): List<BlueprintNodeTypeValidator>
87
88     fun getTopologyTemplateValidators(): List<BlueprintTopologyTemplateValidator>
89
90     fun getNodeTemplateValidators(): List<BlueprintNodeTemplateValidator>
91
92     fun getWorkflowValidators(): List<BlueprintWorkflowValidator>
93
94     fun getPropertyDefinitionValidators(): List<BlueprintPropertyDefinitionValidator>
95
96     fun getAttributeDefinitionValidators(): List<BlueprintAttributeDefinitionValidator>
97
98     fun validateServiceTemplate(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, serviceTemplate: ServiceTemplate) {
99         val validators = getServiceTemplateValidators()
100         doValidation(bluePrintRuntimeService, name, serviceTemplate, validators)
101     }
102
103     fun validateArtifactType(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, artifactType: ArtifactType) {
104         val validators = getArtifactTypeValidators()
105         doValidation(bluePrintRuntimeService, name, artifactType, validators)
106     }
107
108     fun validateArtifactDefinition(
109         bluePrintRuntimeService: BlueprintRuntimeService<*>,
110         name: String,
111         artifactDefinition: ArtifactDefinition
112     ) {
113         val validators = getArtifactDefinitionsValidators()
114         doValidation(bluePrintRuntimeService, name, artifactDefinition, validators)
115     }
116
117     fun validateDataType(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, dataType: DataType) {
118         val validators = getDataTypeValidators()
119         doValidation(bluePrintRuntimeService, name, dataType, validators)
120     }
121
122     fun validateNodeType(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, nodeType: NodeType) {
123         val validators = getNodeTypeValidators()
124         doValidation(bluePrintRuntimeService, name, nodeType, validators)
125     }
126
127     fun validateTopologyTemplate(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, topologyTemplate: TopologyTemplate) {
128         val validators = getTopologyTemplateValidators()
129         doValidation(bluePrintRuntimeService, name, topologyTemplate, validators)
130     }
131
132     fun validateNodeTemplate(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) {
133         val validators = getNodeTemplateValidators()
134         doValidation(bluePrintRuntimeService, name, nodeTemplate, validators)
135     }
136
137     fun validateWorkflow(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, workflow: Workflow) {
138         val validators = getWorkflowValidators()
139         doValidation(bluePrintRuntimeService, name, workflow, validators)
140     }
141
142     fun validatePropertyDefinitions(bluePrintRuntimeService: BlueprintRuntimeService<*>, properties: MutableMap<String, PropertyDefinition>) {
143         properties.forEach { propertyName, propertyDefinition ->
144             validatePropertyDefinition(bluePrintRuntimeService, propertyName, propertyDefinition)
145         }
146     }
147
148     fun validatePropertyDefinition(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) {
149         val validators = getPropertyDefinitionValidators()
150         doValidation(bluePrintRuntimeService, name, propertyDefinition, validators)
151     }
152
153     fun validateAttributeDefinitions(bluePrintRuntimeService: BlueprintRuntimeService<*>, attributes: MutableMap<String, AttributeDefinition>) {
154         attributes.forEach { attributeName, attributeDefinition ->
155             validateAttributeDefinition(bluePrintRuntimeService, attributeName, attributeDefinition)
156         }
157     }
158
159     fun validateAttributeDefinition(bluePrintRuntimeService: BlueprintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) {
160         val validators = getAttributeDefinitionValidators()
161         doValidation(bluePrintRuntimeService, name, attributeDefinition, validators)
162     }
163
164     @Suppress("UNCHECKED_CAST")
165     private fun <T> doValidation(
166         bluePrintRuntimeService: BlueprintRuntimeService<*>,
167         name: String,
168         definition: Any,
169         validators: List<BlueprintValidator<T>>
170     ) {
171         validators.forEach {
172             it.validate(bluePrintRuntimeService, name, definition as T)
173         }
174     }
175 }