summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2019-09-23 16:11:17 -0400
committerSingal, Kapil (ks220y) <ks220y@att.com>2019-09-23 16:11:17 -0400
commit7acab9f8a2f0da70ecdbf8d7850134fcbbbf46c2 (patch)
tree57f6e274ff1fae3bf593b3a9b3b1a99558783a86 /ms
parenta869fe0dd29de8a4fb2c30336a9d5abdb7d1d476 (diff)
Refactoring ResourceAssignmentUtils
Refactoring ResourceAssignmentUtils parseResponseNodeForPrimitiveTypes API to remove cyclic value assignments Issue-ID: CCSDK-1748 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: I27b5a7d3ed2df38cf4e3e44686aec094ebdb5f25
Diffstat (limited to 'ms')
-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(