Removed redundant timeout handling for executeCommand
[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 }