From 977287b586e27e2f835a5d24950abf1f2adae8be Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 5 Aug 2019 09:50:15 -0400 Subject: Add resource definition resolution service. Change-Id: Ife75d290540e3ed0e0dfd0a82785a498607a2d25 Issue-ID: CCSDK-1577 Signed-off-by: Brinda Santh --- .../ccsdk/cds/controllerblueprints/core/CustomFunctions.kt | 7 ++++++- .../core/service/BluePrintDependencyService.kt | 6 ++++++ .../cds/controllerblueprints/core/utils/JacksonUtils.kt | 13 ++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) (limited to 'ms/controllerblueprints/modules/blueprint-core') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt index 2717c3be9..d148745df 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt @@ -21,8 +21,8 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.node.* import org.apache.commons.lang3.ObjectUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.slf4j.LoggerFactory import org.onap.ccsdk.cds.controllerblueprints.core.utils.JsonParserUtils +import org.slf4j.LoggerFactory import org.slf4j.helpers.MessageFormatter import kotlin.reflect.KClass @@ -156,6 +156,11 @@ fun ArrayNode.asListOfString(): List { return JacksonUtils.getListFromJsonNode(this, String::class.java) } +fun JsonNode.asListOfString(): List { + check(this is ArrayNode) { "JsonNode is not of type ArrayNode" } + return this.asListOfString() +} + fun JsonNode.returnNullIfMissing(): JsonNode? { return if (this is NullNode || this is MissingNode) { null diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt index fdaf25c15..776e0411e 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintDependencyService.kt @@ -18,6 +18,7 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.springframework.context.ApplicationContext +import kotlin.reflect.KClass /** * Generic Bluepring Dependency Service, which will be used mainly in scripts. @@ -44,4 +45,9 @@ object BluePrintDependencyService { return applicationContext.getBean(type) ?: throw BluePrintProcessorException("failed to get instance($type)") } + + inline fun instance(type: KClass<*>): T { + return applicationContext.getBean(type.java) as? T + ?: throw BluePrintProcessorException("failed to get instance($type)") + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt index 9b1b66b5b..768f8753f 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/JacksonUtils.kt @@ -238,11 +238,14 @@ class JacksonUtils { fun populatePrimitiveValues(key: String, value: Any, primitiveType: String, objectNode: ObjectNode) { when (primitiveType.toLowerCase()) { - BluePrintConstants.DATA_TYPE_BOOLEAN -> objectNode.put(key, (value as BooleanNode).booleanValue()) - BluePrintConstants.DATA_TYPE_INTEGER -> objectNode.put(key, (value as IntNode).intValue()) - BluePrintConstants.DATA_TYPE_FLOAT -> objectNode.put(key, (value as FloatNode).floatValue()) - BluePrintConstants.DATA_TYPE_DOUBLE -> objectNode.put(key, (value as DoubleNode).doubleValue()) - else -> objectNode.put(key, (value as TextNode).textValue()) + BluePrintConstants.DATA_TYPE_STRING, + BluePrintConstants.DATA_TYPE_BOOLEAN, + BluePrintConstants.DATA_TYPE_INTEGER, + BluePrintConstants.DATA_TYPE_FLOAT, + BluePrintConstants.DATA_TYPE_DOUBLE, + BluePrintConstants.DATA_TYPE_TIMESTAMP -> + objectNode.set(key, value.asJsonPrimitive()) + else -> objectNode.set(key, value.asJsonType()) } } -- cgit 1.2.3-korg