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