Controller Blueprints Microservice 79/63179/1
authorBrinda Santh <brindasanth@in.ibm.com>
Tue, 28 Aug 2018 03:16:39 +0000 (23:16 -0400)
committerBrinda Santh <brindasanth@in.ibm.com>
Tue, 28 Aug 2018 03:16:39 +0000 (23:16 -0400)
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>
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt
ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtilsTest.kt
ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json [new file with mode: 0644]
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java

index 9389a6f..ea8d491 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -21,6 +22,7 @@ import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.node.NullNode\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
+import org.onap.ccsdk.apps.controllerblueprints.core.format\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.ResourceResolverUtils\r
 import org.slf4j.Logger\r
@@ -45,7 +47,7 @@ If Property Assignment is Expression.
 \r
     fun resolveAssignmentExpression(nodeTemplateName: String, assignmentName: String,\r
                                             assignment: Any): JsonNode {\r
-        var valueNode: JsonNode = NullNode.getInstance()\r
+        val valueNode: JsonNode\r
         logger.trace("Assignment ({})", assignment)\r
         val expressionData = BluePrintExpressionService.getExpressionData(assignment)\r
 \r
@@ -96,7 +98,7 @@ If Property Assignment is Expression.
     <nested_property_name_or_index_1>, ..., <nested_property_name_or_index_n> ]\r
  */\r
     fun resolveAttributeExpression(nodeTemplateName: String, attributeExpression: AttributeExpression): JsonNode {\r
-        var valueNode: JsonNode = NullNode.getInstance()\r
+        val valueNode: JsonNode\r
 \r
         val attributeName = attributeExpression.attributeName\r
         val subAttributeName: String? = attributeExpression.subAttributeName\r
@@ -106,15 +108,15 @@ If Property Assignment is Expression.
             attributeNodeTemplateName = attributeExpression.modelableEntityName\r
         }\r
 \r
-        val attributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName)\r
+        val nodeTemplateAttributeExpression = bluePrintContext.nodeTemplateByName(attributeNodeTemplateName).attributes?.get(attributeName)\r
                 ?: throw BluePrintException(String.format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, attributeName))\r
 \r
         var propertyDefinition: AttributeDefinition = bluePrintContext.nodeTemplateNodeType(attributeNodeTemplateName).attributes?.get(attributeName)!!\r
 \r
-        logger.info("template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, attributeExpression)\r
+        logger.info("node template name ({}), property Name ({}) resolved value ({})", attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression)\r
 \r
         // Check it it is a nested expression\r
-        valueNode = resolveAssignmentExpression(attributeNodeTemplateName, attributeName, attributeExpression)\r
+        valueNode = resolveAssignmentExpression(attributeNodeTemplateName, attributeName, nodeTemplateAttributeExpression)\r
 \r
 //        subPropertyName?.let {\r
 //            valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName))\r
@@ -127,7 +129,7 @@ If Property Assignment is Expression.
         <nested_property_name_or_index_1>, ..., <nested_property_name_or_index_n> ]\r
      */\r
     fun resolvePropertyExpression(nodeTemplateName: String, propertyExpression: PropertyExpression): JsonNode {\r
-        var valueNode: JsonNode = NullNode.getInstance()\r
+        val valueNode: JsonNode\r
 \r
         val propertyName = propertyExpression.propertyName\r
         val subPropertyName: String? = propertyExpression.subPropertyName\r
@@ -137,15 +139,15 @@ If Property Assignment is Expression.
             propertyNodeTemplateName = propertyExpression.modelableEntityName\r
         }\r
 \r
-        val propertyExpression = bluePrintContext.nodeTemplateByName(propertyNodeTemplateName).properties?.get(propertyName)\r
-                ?: throw BluePrintException(String.format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, propertyName))\r
+        val nodeTemplatePropertyExpression = bluePrintContext.nodeTemplateByName(propertyNodeTemplateName).properties?.get(propertyName)\r
+                ?: throw BluePrintException(format("failed to get property definitions for node template ({})'s property name ({}) ", nodeTemplateName, propertyName))\r
 \r
         var propertyDefinition: PropertyDefinition = bluePrintContext.nodeTemplateNodeType(propertyNodeTemplateName).properties?.get(propertyName)!!\r
 \r
-        logger.info("template name ({}), property Name ({}) resolved value ({})", propertyNodeTemplateName, propertyName, propertyExpression)\r
+        logger.info("node template name ({}), property Name ({}) resolved value ({})", propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression)\r
 \r
         // Check it it is a nested expression\r
-        valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, propertyExpression)\r
+        valueNode = resolveAssignmentExpression(propertyNodeTemplateName, propertyName, nodeTemplatePropertyExpression)\r
 \r
 //        subPropertyName?.let {\r
 //            valueNode = valueNode.at(JsonPointer.valueOf(subPropertyName))\r
index 9621382..697a710 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -32,6 +33,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.format
 import org.slf4j.LoggerFactory\r
 import java.io.File\r
 import java.nio.charset.Charset\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 \r
 /**\r
  *\r
@@ -107,15 +109,61 @@ object JacksonUtils {
         return objectMapper.readValue(content, typeRef)\r
     }\r
 \r
+    @JvmStatic\r
+    fun checkJsonNodeValueOfType(type: String, jsonNode: JsonNode) : Boolean {\r
+        if (BluePrintTypes.validPrimitiveTypes().contains(type)) {\r
+            return checkJsonNodeValueOfPrimitiveType(type, jsonNode)\r
+        } else if (BluePrintTypes.validCollectionTypes().contains(type)) {\r
+            return checkJsonNodeValueOfCollectionType(type, jsonNode)\r
+        }\r
+        return false;\r
+    }\r
+\r
+    @JvmStatic\r
+    fun checkJsonNodeValueOfPrimitiveType(primitiveType: String, jsonNode: JsonNode): Boolean {\r
+        when (primitiveType) {\r
+            BluePrintConstants.DATA_TYPE_STRING -> {\r
+                return jsonNode.isTextual\r
+            }\r
+            BluePrintConstants.DATA_TYPE_BOOLEAN -> {\r
+                return jsonNode.isBoolean\r
+            }\r
+            BluePrintConstants.DATA_TYPE_INTEGER -> {\r
+                return jsonNode.isInt\r
+            }\r
+            BluePrintConstants.DATA_TYPE_FLOAT -> {\r
+                return jsonNode.isDouble\r
+            }\r
+            BluePrintConstants.DATA_TYPE_TIMESTAMP -> {\r
+                return jsonNode.isTextual\r
+            }\r
+            else ->\r
+                return false\r
+        }\r
+    }\r
+\r
+    @JvmStatic\r
+    fun checkJsonNodeValueOfCollectionType(type: String, jsonNode: JsonNode): Boolean {\r
+        when (type) {\r
+            BluePrintConstants.DATA_TYPE_LIST ->\r
+                return jsonNode.isArray\r
+            BluePrintConstants.DATA_TYPE_MAP ->\r
+                return jsonNode.isContainerNode\r
+            else ->\r
+                return false\r
+        }\r
+\r
+    }\r
+\r
     @JvmStatic\r
     fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) {\r
-        if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
+        if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
             objectNode.put(key, value as Boolean)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
             objectNode.put(key, value as Int)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
             objectNode.put(key, value as Float)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) {\r
             objectNode.put(key, value as String)\r
         } else {\r
             objectNode.put(key, value as String)\r
@@ -124,13 +172,13 @@ object JacksonUtils {
 \r
     @JvmStatic\r
     fun populatePrimitiveValues(value: Any, primitiveType: String, objectNode: ArrayNode) {\r
-        if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
+        if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
             objectNode.add(value as Boolean)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
             objectNode.add(value as Int)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
             objectNode.add(value as Float)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == primitiveType) {\r
             objectNode.add(value as String)\r
         } else {\r
             objectNode.add(value as String)\r
@@ -139,11 +187,11 @@ object JacksonUtils {
 \r
     @JvmStatic\r
     fun populatePrimitiveDefaultValues(key: String, primitiveType: String, objectNode: ObjectNode) {\r
-        if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
+        if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
             objectNode.put(key, false)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
             objectNode.put(key, 0)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
             objectNode.put(key, 0.0)\r
         } else {\r
             objectNode.put(key, "")\r
@@ -152,11 +200,11 @@ object JacksonUtils {
 \r
     @JvmStatic\r
     fun populatePrimitiveDefaultValuesForArrayNode(primitiveType: String, arrayNode: ArrayNode) {\r
-        if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
+        if (BluePrintConstants.DATA_TYPE_BOOLEAN == primitiveType) {\r
             arrayNode.add(false)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_INTEGER == primitiveType) {\r
             arrayNode.add(0)\r
-        } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
+        } else if (BluePrintConstants.DATA_TYPE_FLOAT == primitiveType) {\r
             arrayNode.add(0.0)\r
         } else {\r
             arrayNode.add("")\r
@@ -168,13 +216,13 @@ object JacksonUtils {
         if (nodeValue == null || nodeValue is NullNode) {\r
             objectNode.set(key, nodeValue)\r
         } else if (BluePrintTypes.validPrimitiveTypes().contains(type)) {\r
-            if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_BOOLEAN == type) {\r
+            if (BluePrintConstants.DATA_TYPE_BOOLEAN == type) {\r
                 objectNode.put(key, nodeValue.asBoolean())\r
-            } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_INTEGER == type) {\r
+            } else if (BluePrintConstants.DATA_TYPE_INTEGER == type) {\r
                 objectNode.put(key, nodeValue.asInt())\r
-            } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_FLOAT == type) {\r
+            } else if (BluePrintConstants.DATA_TYPE_FLOAT == type) {\r
                 objectNode.put(key, nodeValue.floatValue())\r
-            } else if (org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants.DATA_TYPE_TIMESTAMP == type) {\r
+            } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP == type) {\r
                 objectNode.put(key, nodeValue.asText())\r
             } else {\r
                 objectNode.put(key, nodeValue.asText())\r
index 28f3b39..8d0f968 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
 \r
 package org.onap.ccsdk.apps.controllerblueprints.core.utils\r
 \r
-import com.fasterxml.jackson.databind.JsonNode\r
 import org.junit.Test\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate\r
 import org.slf4j.Logger\r
 import org.slf4j.LoggerFactory\r
 import kotlin.test.assertEquals\r
 import kotlin.test.assertNotNull\r
+import kotlin.test.assertTrue\r
 \r
 /**\r
  * JacksonUtilsTest\r
@@ -31,7 +33,7 @@ import kotlin.test.assertNotNull
  */\r
 class JacksonUtilsTest {\r
 \r
-    private val logger: Logger = LoggerFactory.getLogger(this::class.toString())\r
+    private val log: Logger = LoggerFactory.getLogger(this::class.toString())\r
 \r
     val basePath = "load/blueprints"\r
 \r
@@ -49,17 +51,13 @@ class JacksonUtilsTest {
     @Test\r
     fun testJsonNodeFromClassPathFile() {\r
         val filePath = "data/default-context.json"\r
-        val jsonNode = JacksonUtils.jsonNodeFromClassPathFile(filePath)\r
-        assertNotNull(jsonNode, "Failed to get json node from file")\r
-        assertEquals(true, jsonNode is JsonNode, "failed to get JSON node instance")\r
+        JacksonUtils.jsonNodeFromClassPathFile(filePath)\r
     }\r
 \r
     @Test\r
     fun testJsonNodeFromFile() {\r
-        val filePath =  basePath + "/baseconfiguration/Definitions/activation-blueprint.json"\r
-        val jsonNode = JacksonUtils.jsonNodeFromFile(filePath)\r
-        assertNotNull(jsonNode, "Failed to get json node from file")\r
-        assertEquals(true, jsonNode is JsonNode, "failed to get JSON node instance")\r
+        val filePath = basePath + "/baseconfiguration/Definitions/activation-blueprint.json"\r
+        JacksonUtils.jsonNodeFromFile(filePath)\r
     }\r
 \r
     @Test\r
@@ -68,4 +66,28 @@ class JacksonUtilsTest {
         val nodeType = JacksonUtils.getListFromJson(content, String::class.java)\r
         assertNotNull(nodeType, "Failed to get String array from content")\r
     }\r
+\r
+\r
+    @Test\r
+    fun testJsonValue() {\r
+        val filePath = "data/alltype-data.json"\r
+        val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath);\r
+        assertNotNull(rootJson, "Failed to get all type data json node")\r
+        val intValue = rootJson.get("intValue")\r
+        assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value")\r
+        val floatValue = rootJson.get("floatValue")\r
+        assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value")\r
+        val stringValue = rootJson.get("stringValue")\r
+        assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value")\r
+        val booleanValue = rootJson.get("booleanValue")\r
+        assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value")\r
+        val arrayStringValue = rootJson.get("arrayStringValue")\r
+        assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value")\r
+        val mapValue = rootJson.get("mapValue")\r
+        assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value")\r
+\r
+        assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed")\r
+\r
+\r
+    }\r
 }
\ No newline at end of file
diff --git a/ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json b/ms/controllerblueprints/modules/core/src/test/resources/data/alltype-data.json
new file mode 100644 (file)
index 0000000..055b096
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "intValue" : 1,
+  "floatValue" : 1.34,
+  "booleanValue" : true,
+  "stringValue" : "sample-String",
+  "timeValue" : "2018-09-29",
+  "arrayStringValue" : ["one", "two"],
+  "mapValue" : {"profile_name1":"profile_name1",
+                "profile_name2":"profile_name2"}
+}
\ No newline at end of file
index 5a1e381..81bb37d 100644 (file)
@@ -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
index 4c11d8c..ae4fed9 100644 (file)
@@ -82,7 +82,7 @@ public class BluePrintRepoDBService implements BluePrintRepoService {
     }\r
 \r
     private Mono<String> getModelDefinitions(String modelName) throws BluePrintException {\r
-        String modelDefinition = null;\r
+        String modelDefinition;\r
         Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);\r
         if (modelTypeDb.isPresent()) {\r
             modelDefinition = modelTypeDb.get().getDefinition();\r
index 7e96f2f..e40c2cf 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -138,7 +139,7 @@ public class ConfigModelCreateService {
             if (StringUtils.isBlank(artifactVersion)) {\r
                 throw new BluePrintException("Artifact Version is missing in the Service Template");\r
             }\r
-            ConfigModel updateConfigModel = null;\r
+            ConfigModel updateConfigModel;\r
 \r
             Optional<ConfigModel> dbConfigModelOptional = Optional.empty();\r
 \r
index feee3a3..b729e3e 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -144,7 +145,7 @@ public class ConfigModelService {
      */\r
     public ConfigModel getConfigModelByNameAndVersion(String name, String version) {\r
         ConfigModel configModel = null;\r
-        Optional<ConfigModel> dbConfigModel = null;\r
+        Optional<ConfigModel> dbConfigModel;\r
         if (StringUtils.isNotBlank(version)) {\r
             dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version);\r
         } else {\r
@@ -182,7 +183,7 @@ public class ConfigModelService {
 \r
     public ConfigModel getCloneConfigModel(Long id) {\r
 \r
-        ConfigModel configModel = null;\r
+        ConfigModel configModel;\r
         ConfigModel cloneConfigModel = null;\r
         if (id != null) {\r
             Optional<ConfigModel> dbConfigModel = configModelRepository.findById(id);\r
index 3a5c4fd..4b732cc 100644 (file)
@@ -115,31 +115,28 @@ public class DataBaseInitService {
         try {\r
             Resource[] dataTypefiles = getPathResources(dataTypePath, ".json");\r
             StrBuilder errorBuilder = new StrBuilder();\r
-            if (dataTypefiles != null) {\r
                 for (Resource file : dataTypefiles) {\r
                     if (file != null) {\r
                         loadDataType(file, errorBuilder);\r
                     }\r
                 }\r
-            }\r
 \r
             Resource[] nodeTypefiles = getPathResources(nodeTypePath, ".json");\r
-            if (nodeTypefiles != null) {\r
-                for (Resource file : nodeTypefiles) {\r
+                       for (Resource file : nodeTypefiles) {\r
                     if (file != null) {\r
                         loadNodeType(file, errorBuilder);\r
                     }\r
                 }\r
-            }\r
+\r
 \r
             Resource[] artifactTypefiles = getPathResources(artifactTypePath, ".json");\r
-            if (artifactTypefiles != null) {\r
+\r
                 for (Resource file : artifactTypefiles) {\r
                     if (file != null) {\r
                         loadArtifactType(file, errorBuilder);\r
                     }\r
                 }\r
-            }\r
+\r
 \r
             if (!errorBuilder.isEmpty()) {\r
                 log.error(errorBuilder.toString());\r
@@ -154,9 +151,9 @@ public class DataBaseInitService {
                 " *************************** loadResourceDictionary **********************");\r
         try {\r
             Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, ".json");\r
-            if (dataTypefiles != null) {\r
+\r
                 StrBuilder errorBuilder = new StrBuilder();\r
-                String fileName = null;\r
+                String fileName;\r
                 for (Resource file : dataTypefiles) {\r
                     try {\r
                         fileName = file.getFilename();\r
@@ -201,7 +198,7 @@ public class DataBaseInitService {
                     log.error(errorBuilder.toString());\r
                 }\r
 \r
-            }\r
+\r
         } catch (Exception e) {\r
             log.error(\r
                     "Failed in Resource dictionary loading", e);\r
@@ -248,6 +245,7 @@ public class DataBaseInitService {
             String nodeKey = file.getFilename().replace(".json", "");\r
             String definitionContent = getResourceContent(file);\r
             NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class);\r
+            Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename()));\r
             ModelType modelType = new ModelType();\r
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE);\r
             modelType.setDerivedFrom(nodeType.getDerivedFrom());\r
@@ -271,6 +269,7 @@ public class DataBaseInitService {
             String dataKey = file.getFilename().replace(".json", "");\r
             String definitionContent = getResourceContent(file);\r
             DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class);\r
+            Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename()));\r
             ModelType modelType = new ModelType();\r
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
             modelType.setDerivedFrom(dataType.getDerivedFrom());\r
@@ -294,6 +293,7 @@ public class DataBaseInitService {
             String dataKey = file.getFilename().replace(".json", "");\r
             String definitionContent = getResourceContent(file);\r
             ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class);\r
+            Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename()));\r
             ModelType modelType = new ModelType();\r
             modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);\r
             modelType.setDerivedFrom(artifactType.getDerivedFrom());\r
index 629b94c..85e701b 100644 (file)
@@ -20,7 +20,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service;
 import com.google.common.base.Preconditions;\r
 import org.apache.commons.lang3.StringUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
@@ -119,6 +118,7 @@ public class ResourceDictionaryService {
 \r
         ResourceDefinition resourceDefinition =\r
                 JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
+        Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content");\r
         // Validate the Resource Definitions\r
         resourceDictionaryValidationService.validate(resourceDefinition);\r
 \r