summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/resource-dict
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2018-08-27 23:16:39 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2018-08-27 23:16:39 -0400
commit7c866aaefe19df34cb0c38e1f989179cf21dc497 (patch)
treeba61d9026f46b3467aad1f553e5f21acdb8cbd42 /ms/controllerblueprints/modules/resource-dict
parent90c3a2c421b262095ea9684811509fafb8bc9e17 (diff)
Controller Blueprints Microservice
Add resource dictionary node template property assignments validation for primitive and complex types. Change-Id: Ic6f3a521310c8e15ebb5b5b5d6ad3edb0ede9ecb Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/resource-dict')
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt35
1 files changed, 30 insertions, 5 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
index 5a1e38126..81bb37d02 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
@@ -20,12 +20,14 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.service
import com.fasterxml.jackson.databind.JsonNode
import com.google.common.base.Preconditions
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
import org.onap.ccsdk.apps.controllerblueprints.core.format
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintExpressionService
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
import org.slf4j.LoggerFactory
import java.io.Serializable
@@ -43,12 +45,13 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService:
override fun validate(resourceDefinition: ResourceDefinition) {
Preconditions.checkNotNull(resourceDefinition, "Failed to get Resource Definition")
+ log.trace("Validating Resource Dictionary Definition {}", resourceDefinition.name)
resourceDefinition.sources.forEach { (name, nodeTemplate) ->
val sourceType = nodeTemplate.type
val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block()
- ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType))
+ ?: throw BluePrintException(format("Failed to get source({}) node type definition({})", name, sourceType))
// Validate Property Name, expression, values and Data Type
validateNodeTemplateProperties(nodeTemplate, sourceNodeType)
@@ -62,7 +65,7 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService:
open fun validatePropertyAssignments(nodeTypeProperties: MutableMap<String, PropertyDefinition>,
- properties: MutableMap<String, JsonNode>) {
+ properties: MutableMap<String, JsonNode>) {
properties.forEach { propertyName, propertyAssignment ->
val propertyDefinition: PropertyDefinition = nodeTypeProperties[propertyName]
?: throw BluePrintException(format("failed to get definition for the property ({})", propertyName))
@@ -70,12 +73,34 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService:
val expressionData = BluePrintExpressionService.getExpressionData(propertyAssignment)
if (!expressionData.isExpression) {
checkPropertyValue(propertyDefinition, propertyName, propertyAssignment)
+ } else {
+ throw BluePrintException(format("property({}) of expression ({}) is not supported",
+ propertyName, propertyAssignment))
}
}
}
- open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, jsonNode: JsonNode) {
- //log.info("validating Property {}, name ({}) value ({})", propertyDefinition, propertyName, jsonNode)
- //TODO
+ open fun checkPropertyValue(propertyDefinition: PropertyDefinition, propertyName: String, propertyAssignment: JsonNode) {
+ val propertyType = propertyDefinition.type
+ var isValid = false
+
+ if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) {
+ isValid = JacksonUtils.checkJsonNodeValueOfPrimitiveType(propertyType, propertyAssignment)
+
+ } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) {
+
+ isValid = JacksonUtils.checkJsonNodeValueOfCollectionType(propertyType, propertyAssignment)
+ } else {
+ bluePrintRepoService.getDataType(propertyType)
+ ?: throw BluePrintException(format("property({}) defined of data type({}) is not in repository",
+ propertyName, propertyType))
+
+ isValid = true;
+ }
+
+ check(isValid) {
+ throw BluePrintException(format("property({}) defined of type({}) is not compatable with the value ({})",
+ propertyName, propertyType, propertyAssignment))
+ }
}
} \ No newline at end of file