aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-core
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-02-27 20:16:47 -0500
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-11 09:13:22 -0400
commita5130dcf4e70f394c1432baefffc198882f04dc1 (patch)
treed0eaa477c7795db5066726def23aa6bc2cd4e363 /ms/controllerblueprints/modules/blueprint-core
parentfc3e34836f7be8eda28a8f996d733e8dfca01450 (diff)
Add blueprint runtime validator
Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintTypes.kt20
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt3
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/JacksonUtils.kt16
3 files changed, 21 insertions, 18 deletions
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 b2f1b727c..cf400fa7a 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<String> {
val validTypes: MutableList<String> = 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
}
@@ -125,6 +118,13 @@ object BluePrintTypes {
}
@JvmStatic
+ fun validComplexTypes(): List<String> {
+ val validTypes: MutableList<String> = arrayListOf()
+ validTypes.add(BluePrintConstants.DATA_TYPE_JSON)
+ return validTypes
+ }
+
+ @JvmStatic
fun validCollectionTypes(): List<String> {
val validTypes: MutableList<String> = arrayListOf()
validTypes.add(BluePrintConstants.DATA_TYPE_LIST)
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 80ad3f2a8..c58280732 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<T> {
@@ -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 1bc250053..932f0edce 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 <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T>? {
+ fun <T> getMapFromJson(content: String, valueType: Class<T>): MutableMap<String, T> {
val objectMapper = jacksonObjectMapper()
val mapType = objectMapper.typeFactory.constructMapType(Map::class.java, String::class.java, valueType)
return objectMapper.readValue(content, mapType)
}
- fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T>? {
- val content: String = getContent(fileName)
+ fun <T> getMapFromFile(file: File, valueType: Class<T>): MutableMap<String, T> {
+ val content: String = getContent(file)
return getMapFromJson(content, valueType)
}
+ fun <T> getMapFromFile(fileName: String, valueType: Class<T>): MutableMap<String, T> = getMapFromFile(File(fileName), valueType)
+
fun <T> getInstanceFromMap(properties: MutableMap<String, JsonNode>, classType: Class<T>): T {
return readValue(getJson(properties), classType)
?: throw BluePrintProcessorException("failed to transform content ($properties) to type ($classType)")