From e0e2aa06217ea5299e720e97f4275197551b3e68 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Mon, 23 Sep 2019 18:47:29 -0400 Subject: Refactoring ResourceAssignmentUtils Changing isNull condition to isNullOrEmpty to make sure Empty value doesn't get assigned to resource Issue-ID: CCSDK-1748 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I0744537c7ddec80f20ffd7e6545b947439f63743 --- .../executor/ComponentRemoteAnsibleExecutor.kt | 8 ++-- .../DatabaseResourceAssignmentProcessor.kt | 6 ++- .../processor/ResourceAssignmentProcessor.kt | 2 +- .../processor/RestResourceResolutionProcessor.kt | 2 +- .../resolution/utils/ResourceAssignmentUtils.kt | 54 +++++++++++----------- 5 files changed, 36 insertions(+), 36 deletions(-) (limited to 'ms/blueprintsprocessor') diff --git a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt index 25bb3c938..3a655ded7 100644 --- a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt +++ b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt @@ -296,20 +296,20 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe val skipTagsProp = getOptionalOperationInput(INPUT_SKIP_TAGS) val askLimitOnLaunch = jtLaunchReqs.at("/ask_limit_on_launch").asBoolean() - if (askLimitOnLaunch && limitProp.isNotNull()) { + if (askLimitOnLaunch && !limitProp.isNullOrMissing()) { payload.set(INPUT_LIMIT_TO_HOST, limitProp) } val askTagsOnLaunch = jtLaunchReqs.at("/ask_tags_on_launch").asBoolean() - if (askTagsOnLaunch && tagsProp.isNotNull()) { + if (askTagsOnLaunch && !tagsProp.isNullOrMissing()) { payload.set(INPUT_TAGS, tagsProp) } - if (askTagsOnLaunch && skipTagsProp.isNotNull()) { + if (askTagsOnLaunch && !skipTagsProp.isNullOrMissing()) { payload.set("skip_tags", skipTagsProp) } } val askInventoryOnLaunch = jtLaunchReqs.at("/ask_inventory_on_launch").asBoolean() - if (askInventoryOnLaunch && inventoryProp.isNotNull()) { + if (askInventoryOnLaunch && !inventoryProp.isNullOrMissing()) { var inventoryKeyId = if (inventoryProp is TextNode) { resolveInventoryIdByName(awxClient, inventoryProp.textValue())?.asJsonPrimitive() } else { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt index 8d21e9a70..2120449ab 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt @@ -135,7 +135,9 @@ open class DatabaseResourceAssignmentProcessor( logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)") namedParameters[it.key] = expressionValue } - logger.info("Parameter information : ($namedParameters)") + if (namedParameters.isNotEmpty()) { + logger.info("Parameter information : ($namedParameters)") + } return namedParameters } @@ -152,7 +154,7 @@ open class DatabaseResourceAssignmentProcessor( val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } - logger.info("Response processing type($type)") + logger.info("Response processing type ($type)") val responseNode = checkNotNull(JacksonUtils.getJsonNode(rows)) { "Failed to get database query result into Json node." diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index af89bcef6..c4c308efb 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -51,7 +51,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode { + // Primitive Types parseResponseNodeForPrimitiveTypes(responseNode, outputKeyMapping) } in BluePrintTypes.validCollectionTypes() -> { @@ -268,34 +267,33 @@ class ResourceAssignmentUtils { responseNode: JsonNode, outputKeyMapping: MutableMap ): JsonNode { - if (responseNode.isComplexType()) { - val outputKey = outputKeyMapping.keys.firstOrNull() - var returnNode = if (responseNode is ArrayNode) { - val arrayNode = responseNode.toList() - if (outputKey.isNullOrEmpty()) { - arrayNode.first() - } else { - arrayNode.firstOrNull { element -> - element.isComplexType() && element.has(outputKeyMapping[outputKey]) - } - } - } else { - responseNode - } + // Return responseNode if is not a Complex Type + if (!responseNode.isComplexType()) { + return responseNode + } - if (returnNode.isNull() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) { - throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.") - } - return if (returnNode.isComplexType()) { - returnNode[outputKeyMapping[outputKey]] + val outputKey = outputKeyMapping.keys.firstOrNull() + var returnNode = if (responseNode is ArrayNode) { + val arrayNode = responseNode.toList() + if (outputKey.isNullOrEmpty()) { + arrayNode.first() } else { - returnNode + arrayNode.firstOrNull { element -> + element.isComplexType() && element.has(outputKeyMapping[outputKey]) + } } + } else { + responseNode } - if (outputKeyMapping.isNotEmpty()) { - throw BluePrintProcessorException("Fail to find key-value in response node to map output-key-mapping.") + + if (returnNode.isNullOrMissing() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) { + throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.") + } + return if (returnNode.isComplexType()) { + returnNode[outputKeyMapping[outputKey]] + } else { + returnNode } - return responseNode } private fun parseResponseNodeForCollection( @@ -566,7 +564,7 @@ class ResourceAssignmentUtils { fun getValueToLog(metadata: MutableMap?, value: Any): Any { return if (checkIfLogIsProtected(metadata)) { - "*************" + "******REDACTED******" } else { value } -- cgit 1.2.3-korg