Fixing Blueprint Typo's and docs
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / blueprints / blueprint-validation / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / validation / BluePrintTypeValidatorServiceImpl.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.validation
19
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
21 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionValidator
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintArtifactTypeValidator
23 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionValidator
24 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintDataTypeValidator
25 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTemplateValidator
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTypeValidator
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionValidator
28 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintServiceTemplateValidator
29 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTopologyTemplateValidator
30 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
31 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidator
32 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowValidator
33 import org.springframework.beans.factory.annotation.Autowired
34 import org.springframework.context.ApplicationContext
35 import org.springframework.stereotype.Service
36
37 @Service
38 class BluePrintTypeValidatorServiceImpl : BluePrintTypeValidatorService {
39
40     companion object {
41
42         const val PREFIX_DEFAULT = "default"
43     }
44
45     @Autowired
46     private lateinit var context: ApplicationContext
47
48     override fun <T : BluePrintValidator<*>> bluePrintValidator(referenceName: String, classType: Class<T>): T? {
49         return if (context.containsBean(referenceName)) {
50             context.getBean(referenceName, classType)
51         } else {
52             null
53         }
54     }
55
56     override fun <T : BluePrintValidator<*>> bluePrintValidators(referenceNamePrefix: String, classType: Class<T>): List<T>? {
57         return context.getBeansOfType(classType)
58             .filter { it.key.startsWith(referenceNamePrefix) }
59             .mapNotNull { it.value }
60     }
61
62     override fun <T : BluePrintValidator<*>> bluePrintValidators(classType: Class<T>): List<T>? {
63         return context.getBeansOfType(classType).mapNotNull { it.value }
64     }
65
66     override fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator> {
67         return bluePrintValidators(PREFIX_DEFAULT, BluePrintServiceTemplateValidator::class.java)
68             ?: throw BluePrintProcessorException("failed to get default ServiceTemplate validators")
69     }
70
71     override fun getDataTypeValidators(): List<BluePrintDataTypeValidator> {
72         return bluePrintValidators(PREFIX_DEFAULT, BluePrintDataTypeValidator::class.java)
73             ?: throw BluePrintProcessorException("failed to get default DataType validators")
74     }
75
76     override fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator> {
77         return bluePrintValidators(PREFIX_DEFAULT, BluePrintArtifactTypeValidator::class.java)
78             ?: throw BluePrintProcessorException("failed to get default ArtifactType validators")
79     }
80
81     override fun getArtifactDefinitionsValidators(): List<BluePrintArtifactDefinitionValidator> {
82         return bluePrintValidators(PREFIX_DEFAULT, BluePrintArtifactDefinitionValidator::class.java)
83             ?: throw BluePrintProcessorException("failed to get default ArtifactDefinition validators")
84     }
85
86     override fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator> {
87         return bluePrintValidators(PREFIX_DEFAULT, BluePrintNodeTypeValidator::class.java)
88             ?: throw BluePrintProcessorException("failed to get default NodeType validators")
89     }
90
91     override fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator> {
92         return bluePrintValidators(PREFIX_DEFAULT, BluePrintTopologyTemplateValidator::class.java)
93             ?: throw BluePrintProcessorException("failed to get default TopologyTemplate validators")
94     }
95
96     override fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator> {
97         return bluePrintValidators(PREFIX_DEFAULT, BluePrintNodeTemplateValidator::class.java)
98             ?: throw BluePrintProcessorException("failed to get default NodeTemplate validators")
99     }
100
101     override fun getWorkflowValidators(): List<BluePrintWorkflowValidator> {
102         return bluePrintValidators(PREFIX_DEFAULT, BluePrintWorkflowValidator::class.java)
103             ?: throw BluePrintProcessorException("failed to get default Workflow validators")
104     }
105
106     override fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator> {
107         return bluePrintValidators(PREFIX_DEFAULT, BluePrintPropertyDefinitionValidator::class.java)
108             ?: throw BluePrintProcessorException("failed to get default PropertyDefinition validators")
109     }
110
111     override fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator> {
112         return bluePrintValidators(PREFIX_DEFAULT, BluePrintAttributeDefinitionValidator::class.java)
113             ?: throw BluePrintProcessorException("failed to get default AttributeDefinition validators")
114     }
115 }