Add Blueprint Validation Interfaces.
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Tue, 27 Nov 2018 15:03:04 +0000 (10:03 -0500)
committerBrinda Santh Muthuramalingam <bs2796@att.com>
Fri, 30 Nov 2018 20:55:37 +0000 (20:55 +0000)
Change-Id: Idbda09fc8be7878814e782990ab8d6e9a5d8b047
Issue-ID: CCSDK-757
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt [new file with mode: 0644]
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt [new file with mode: 0644]
components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintContext.kt

diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintValidationError.kt
new file mode 100644 (file)
index 0000000..3ec0691
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core
+
+class BluePrintValidationError {
+    var errors: MutableList<String> = arrayListOf()
+
+    fun addError(type: String, name: String, error: String) {
+        this.errors.add("$type : $name : $error")
+    }
+
+    fun addError(error: String) {
+        this.errors.add(error)
+    }
+}
\ No newline at end of file
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/interfaces/BlueprintValidator.kt
new file mode 100644 (file)
index 0000000..9407cfa
--- /dev/null
@@ -0,0 +1,129 @@
+package org.onap.ccsdk.apps.controllerblueprints.core.interfaces
+
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintValidationError
+import org.onap.ccsdk.apps.controllerblueprints.core.data.*
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
+
+
+interface BluePrintValidator<T> {
+
+    fun validate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, type: T)
+
+}
+
+
+interface BluePrintServiceTemplateValidator : BluePrintValidator<ServiceTemplate>
+
+interface BluePrintTopologyTemplateValidator : BluePrintValidator<TopologyTemplate>
+
+interface BluePrintArtifactTypeValidator : BluePrintValidator<ArtifactType>
+
+interface BluePrintDataTypeValidator : BluePrintValidator<DataType>
+
+interface BluePrintNodeTypeValidator : BluePrintValidator<NodeType>
+
+interface BluePrintNodeTemplateValidator : BluePrintValidator<NodeTemplate>
+
+interface BluePrintWorkflowValidator : BluePrintValidator<Workflow>
+
+interface BluePrintPropertyDefinitionValidator : BluePrintValidator<PropertyDefinition>
+
+interface BluePrintAttributeDefinitionValidator : BluePrintValidator<AttributeDefinition>
+
+/**
+ * Blueprint Validation Interface.
+ */
+interface BluePrintValidatorService {
+
+    @Throws(BluePrintException::class)
+    fun validateBluePrints(bluePrintContext: BluePrintContext, properties: MutableMap<String, Any>)
+}
+
+
+interface BluePrintTypeValidatorService {
+
+    fun getServiceTemplateValidators(): List<BluePrintServiceTemplateValidator>
+
+    fun getDataTypeValidators(): List<BluePrintDataTypeValidator>
+
+    fun getArtifactTypeValidators(): List<BluePrintArtifactTypeValidator>
+
+    fun getNodeTypeValidators(): List<BluePrintNodeTypeValidator>
+
+    fun getTopologyTemplateValidators(): List<BluePrintTopologyTemplateValidator>
+
+    fun getNodeTemplateValidators(): List<BluePrintNodeTemplateValidator>
+
+    fun getWorkflowValidators(): List<BluePrintWorkflowValidator>
+
+    fun getPropertyDefinitionValidators(): List<BluePrintPropertyDefinitionValidator>
+
+    fun getAttributeDefinitionValidators(): List<BluePrintAttributeDefinitionValidator>
+
+    fun validateServiceTemplate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, serviceTemplate: ServiceTemplate) {
+        val validators = getServiceTemplateValidators()
+        doValidation(bluePrintContext, error, name, serviceTemplate, validators)
+    }
+
+    fun validateArtifactType(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, artifactType: ArtifactType) {
+        val validators = getArtifactTypeValidators()
+        doValidation(bluePrintContext, error, name, artifactType, validators)
+    }
+
+    fun validateDataType(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, dataType: DataType) {
+        val validators = getDataTypeValidators()
+        doValidation(bluePrintContext, error, name, dataType, validators)
+    }
+
+    fun validateNodeType(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, nodeType: NodeType) {
+        val validators = getNodeTypeValidators()
+        doValidation(bluePrintContext, error, name, nodeType, validators)
+    }
+
+    fun validateTopologyTemplate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, topologyTemplate: TopologyTemplate) {
+        val validators = getTopologyTemplateValidators()
+        doValidation(bluePrintContext, error, name, topologyTemplate, validators)
+    }
+
+    fun validateNodeTemplate(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, nodeTemplate: NodeTemplate) {
+        val validators = getNodeTemplateValidators()
+        doValidation(bluePrintContext, error, name, nodeTemplate, validators)
+    }
+
+    fun validateWorkflow(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, workflow: Workflow) {
+        val validators = getWorkflowValidators()
+        doValidation(bluePrintContext, error, name, workflow, validators)
+    }
+
+    fun validatePropertyDefinitions(bluePrintContext: BluePrintContext, error: BluePrintValidationError, properties: MutableMap<String, PropertyDefinition>) {
+        properties.forEach { propertyName, propertyDefinition ->
+            validatePropertyDefinition(bluePrintContext, error, propertyName, propertyDefinition)
+        }
+    }
+
+    fun validatePropertyDefinition(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, propertyDefinition: PropertyDefinition) {
+        val validators = getPropertyDefinitionValidators()
+        doValidation(bluePrintContext, error, name, propertyDefinition, validators)
+    }
+
+    fun validateAttributeDefinitions(bluePrintContext: BluePrintContext, error: BluePrintValidationError, attributes: MutableMap<String, AttributeDefinition>) {
+        attributes.forEach { attributeName, attributeDefinition ->
+            validateAttributeDefinition(bluePrintContext, error, attributeName, attributeDefinition)
+        }
+    }
+
+    fun validateAttributeDefinition(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, attributeDefinition: AttributeDefinition) {
+        val validators = getAttributeDefinitionValidators()
+        doValidation(bluePrintContext, error, name, attributeDefinition, validators)
+    }
+
+    private fun <T> doValidation(bluePrintContext: BluePrintContext, error: BluePrintValidationError, name: String, definition: Any, validators: List<BluePrintValidator<T>>) {
+        validators.forEach {
+            it.validate(bluePrintContext, error, name, definition as T)
+        }
+    }
+}
+
+
+
index f73fb72..cce6d90 100644 (file)
@@ -32,6 +32,11 @@ class BluePrintContext(val serviceTemplate: ServiceTemplate) {
 \r
     private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())\r
 \r
+    /**\r
+     * Blueprint CBA extracted file location\r
+     */\r
+    var rootPath = "."\r
+\r
     val imports: List<ImportDefinition>? = serviceTemplate.imports\r
 \r
     val metadata: MutableMap<String, String>? = serviceTemplate.metadata\r