7cddf27a523d6516e76d1057dd72f8d8862de031
[ccsdk/apps.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.core.validation
18
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
23 import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate
24 import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow
25 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateValidator
26 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
27 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
28
29 open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator {
30
31     var bluePrintContext: BluePrintContext? = null
32     var error: BluePrintValidationError? = null
33
34     override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) {
35         this.bluePrintContext = bluePrintContext
36         // Validate Inputs
37         topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) }
38         // Validate Node Templates
39         topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) }
40         // Validate Workflow
41         topologyTemplate.workflows?.let { validateWorkflows(topologyTemplate.workflows!!) }
42     }
43
44     @Throws(BluePrintException::class)
45     fun validateInputs(inputs: MutableMap<String, PropertyDefinition>) {
46         bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintContext!!, error!!, inputs)
47     }
48
49
50     @Throws(BluePrintException::class)
51     fun validateNodeTemplates(nodeTemplates: MutableMap<String, NodeTemplate>) {
52
53         nodeTemplates.forEach { nodeTemplateName, nodeTemplate ->
54             // Validate Single Node Template
55             bluePrintTypeValidatorService.validateNodeTemplate(bluePrintContext!!, error!!, nodeTemplateName, nodeTemplate)
56         }
57     }
58
59     @Throws(BluePrintException::class)
60     open fun validateWorkflows(workflows: MutableMap<String, Workflow>) {
61
62         workflows.forEach { workflowName, workflow ->
63             // Validate Single workflow
64             bluePrintTypeValidatorService.validateWorkflow(bluePrintContext!!, error!!, workflowName, workflow)
65         }
66     }
67
68 }