From 948114a77bcf55433191e31de8f0612f55b01612 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 27 Feb 2019 20:16:47 -0500 Subject: Add blueprint runtime validator Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh --- .../apps/controllerblueprints/core/BluePrintTypes.kt | 20 ++++++++++---------- .../core/service/BluePrintRuntimeService.kt | 3 +-- .../controllerblueprints/core/utils/JacksonUtils.kt | 16 ++++++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) (limited to 'ms/controllerblueprints/modules/blueprint-core') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt index b2f1b727..cf400fa7 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt @@ -98,16 +98,9 @@ object BluePrintTypes { @JvmStatic fun validPropertyTypes(): List { val validTypes: MutableList = arrayListOf() - validTypes.add(BluePrintConstants.DATA_TYPE_STRING) - validTypes.add(BluePrintConstants.DATA_TYPE_INTEGER) - validTypes.add(BluePrintConstants.DATA_TYPE_FLOAT) - validTypes.add(BluePrintConstants.DATA_TYPE_DOUBLE) - validTypes.add(BluePrintConstants.DATA_TYPE_BOOLEAN) - validTypes.add(BluePrintConstants.DATA_TYPE_TIMESTAMP) - validTypes.add(BluePrintConstants.DATA_TYPE_NULL) - validTypes.add(BluePrintConstants.DATA_TYPE_LIST) - validTypes.add(BluePrintConstants.DATA_TYPE_MAP) - validTypes.add(BluePrintConstants.DATA_TYPE_JSON) + validTypes.addAll(validPrimitiveTypes()) + validTypes.addAll(validComplexTypes()) + validTypes.addAll(validCollectionTypes()) return validTypes } @@ -124,6 +117,13 @@ object BluePrintTypes { return validTypes } + @JvmStatic + fun validComplexTypes(): List { + val validTypes: MutableList = arrayListOf() + validTypes.add(BluePrintConstants.DATA_TYPE_JSON) + return validTypes + } + @JvmStatic fun validCollectionTypes(): List { val validTypes: MutableList = arrayListOf() diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt index 80ad3f2a..c5828073 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt @@ -29,7 +29,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import java.io.File interface BluePrintRuntimeService { @@ -234,7 +233,7 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl } else { // Assign default value to the Operation nodeTypeProperty.defaultValue?.let { - resolvedValue = JacksonUtils.jsonNodeFromObject(nodeTypeProperty.defaultValue!!) + resolvedValue = nodeTypeProperty.defaultValue!! } } // Set for Return of method diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt index 1bc25005..932f0edc 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt @@ -68,12 +68,14 @@ class JacksonUtils { } } - fun getContent(fileName: String): String = runBlocking { + fun getContent(fileName: String): String = getContent(File(fileName)) + + fun getContent(file: File): String = runBlocking { async { try { - File(fileName).readText(Charsets.UTF_8) + file.readText(Charsets.UTF_8) } catch (e: Exception) { - throw BluePrintException("couldn't get file ($fileName) content : ${e.message}") + throw BluePrintException("couldn't get file (${file.absolutePath}) content : ${e.message}") } }.await() } @@ -167,17 +169,19 @@ class JacksonUtils { return getListFromJson(content, valueType) } - fun getMapFromJson(content: String, valueType: Class): MutableMap? { + fun getMapFromJson(content: String, valueType: Class): MutableMap { val objectMapper = jacksonObjectMapper() val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType) return objectMapper.readValue(content, mapType) } - fun getMapFromFile(fileName: String, valueType: Class): MutableMap? { - val content: String = getContent(fileName) + fun getMapFromFile(file: File, valueType: Class): MutableMap { + val content: String = getContent(file) return getMapFromJson(content, valueType) } + fun getMapFromFile(fileName: String, valueType: Class): MutableMap = getMapFromFile(File(fileName), valueType) + fun getInstanceFromMap(properties: MutableMap, classType: Class): T { return readValue(getJson(properties), classType) ?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)") -- cgit 1.2.3-korg