aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt62
1 files changed, 30 insertions, 32 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
index 2a3820f07..05e7b6941 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
@@ -196,8 +196,10 @@ class ResourceAssignmentUtils {
}
}
- fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>,
- templateArtifactName: String): ResourceAssignmentRuntimeService {
+ fun transformToRARuntimeService(
+ blueprintRuntimeService: BluePrintRuntimeService<*>,
+ templateArtifactName: String
+ ): ResourceAssignmentRuntimeService {
val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService(
blueprintRuntimeService.id(),
@@ -210,8 +212,10 @@ class ResourceAssignmentUtils {
}
@Throws(BluePrintProcessorException::class)
- fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String,
- propertyName: String): String {
+ fun getPropertyType(
+ raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String,
+ propertyName: String
+ ): String {
lateinit var type: String
try {
val dataTypeProps =
@@ -228,8 +232,10 @@ class ResourceAssignmentUtils {
}
@Throws(BluePrintProcessorException::class)
- fun parseResponseNode(responseNode: JsonNode, resourceAssignment: ResourceAssignment,
- raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String>): JsonNode {
+ fun parseResponseNode(
+ responseNode: JsonNode, resourceAssignment: ResourceAssignment,
+ raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String>
+ ): JsonNode {
val metadata = resourceAssignment.property!!.metadata
try {
if ((resourceAssignment.property?.type).isNullOrEmpty()) {
@@ -258,46 +264,38 @@ class ResourceAssignmentUtils {
}
}
- //TODO: Need to Refactor
- private fun parseResponseNodeForPrimitiveTypes(responseNode: JsonNode,
- outputKeyMapping: MutableMap<String, String>): JsonNode {
- var result: JsonNode? = responseNode
-
+ private fun parseResponseNodeForPrimitiveTypes(
+ responseNode: JsonNode,
+ outputKeyMapping: MutableMap<String, String>
+ ): JsonNode {
if (responseNode.isComplexType()) {
- val key = outputKeyMapping.keys.firstOrNull()
- var returnNode: JsonNode?
- if (responseNode is ArrayNode) {
+ val outputKey = outputKeyMapping.keys.firstOrNull()
+ var returnNode = if (responseNode is ArrayNode) {
val arrayNode = responseNode.toList()
- val firstElement = if (key.isNullOrEmpty()) {
+ if (outputKey.isNullOrEmpty()) {
arrayNode.first()
} else {
arrayNode.firstOrNull { element ->
- element.isComplexType() && element.has(outputKeyMapping[key])
+ element.isComplexType() && element.has(outputKeyMapping[outputKey])
}
}
- returnNode = firstElement
} else {
- returnNode = responseNode
+ responseNode
}
- if (returnNode.isNull() || (returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[key]))) {
- if (key.isNullOrEmpty()) {
- throw BluePrintProcessorException("Fail to find mapping in the responseNode.")
- } else {
- throw BluePrintProcessorException("Fail to find response with output key mapping ($key) in result.")
- }
+ if (returnNode.isNull() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) {
+ throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.")
}
- result = if (returnNode.isComplexType()) {
- returnNode[outputKeyMapping[key]]
+ return if (returnNode.isComplexType()) {
+ returnNode[outputKeyMapping[outputKey]]
} else {
- responseNode
- }
- } else {
- if (outputKeyMapping.isNotEmpty()) {
- throw BluePrintProcessorException("Fail to find key-value in response node to map output-key-mapping.")
+ returnNode
}
}
- return result!!
+ if (outputKeyMapping.isNotEmpty()) {
+ throw BluePrintProcessorException("Fail to find key-value in response node to map output-key-mapping.")
+ }
+ return responseNode
}
private fun parseResponseNodeForCollection(