2 * Copyright © 2017-2018 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.apps.controllerblueprints.core.validation
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
29 open class BluePrintTopologyTemplateValidatorImpl(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService) : BluePrintTopologyTemplateValidator {
31 var bluePrintContext: BluePrintContext? = null
32 var error: BluePrintValidationError? = null
34 override fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) {
35 this.bluePrintContext = bluePrintContext
37 topologyTemplate.inputs?.let { validateInputs(topologyTemplate.inputs!!) }
38 // Validate Node Templates
39 topologyTemplate.nodeTemplates?.let { validateNodeTemplates(topologyTemplate.nodeTemplates!!) }
41 topologyTemplate.workflows?.let { validateWorkflows(topologyTemplate.workflows!!) }
44 @Throws(BluePrintException::class)
45 fun validateInputs(inputs: MutableMap<String, PropertyDefinition>) {
46 bluePrintTypeValidatorService.validatePropertyDefinitions(bluePrintContext!!, error!!, inputs)
50 @Throws(BluePrintException::class)
51 fun validateNodeTemplates(nodeTemplates: MutableMap<String, NodeTemplate>) {
53 nodeTemplates.forEach { nodeTemplateName, nodeTemplate ->
54 // Validate Single Node Template
55 bluePrintTypeValidatorService.validateNodeTemplate(bluePrintContext!!, error!!, nodeTemplateName, nodeTemplate)
59 @Throws(BluePrintException::class)
60 open fun validateWorkflows(workflows: MutableMap<String, Workflow>) {
62 workflows.forEach { workflowName, workflow ->
63 // Validate Single workflow
64 bluePrintTypeValidatorService.validateWorkflow(bluePrintContext!!, error!!, workflowName, workflow)