diff options
Diffstat (limited to 'ms')
4 files changed, 99 insertions, 105 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index fb32aa78b..2a9218df3 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -1,6 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 IBM. + * Modifications Copyright © 2019 IBM, Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,5 @@ object ResourceResolutionConstants { const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence" const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id" const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type" - - + val DATA_DICTIONARY_SECRET_SOURCE_TYPES = arrayOf("vault-data") //Add more secret data dictionary source type here }
\ No newline at end of file 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 600de134e..f8193b7f9 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 @@ -1,6 +1,6 @@ /* * Copyright © 2018 IBM. - * Modifications Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2017-2018 AT&T Intellectual Property, Bell Canada. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor -import com.fasterxml.jackson.databind.node.JsonNodeFactory import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService @@ -152,50 +151,13 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert } logger.info("Response processing type($type)") - // Primitive Types - when (type) { - in BluePrintTypes.validPrimitiveTypes() -> { - val dbColumnValue = rows[0][outputKeyMapping[dName]] - logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue) - } - in BluePrintTypes.validCollectionTypes() -> { - val entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) { - "Entry schema is not defined for dictionary ($dName) info" - } - val arrayNode = JacksonUtils.objectMapper.createArrayNode() - rows.forEach { - if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) { - val dbColumnValue = it[outputKeyMapping[dName]] - // Add Array JSON - JacksonUtils.populatePrimitiveValues(dbColumnValue!!, entrySchemaType, arrayNode) - } else { - val arrayChildNode = JsonNodeFactory.instance.objectNode() - for (mapping in outputKeyMapping.entries) { - val dbColumnValue = checkNotNull(it[mapping.key]) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key) - JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode) - } - arrayNode.add(arrayChildNode) - } - } - logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) - } - else -> { - // Custom Simple Complex Types - val row = rows[0] - val objectNode = JacksonUtils.objectMapper.createObjectNode() - for (mapping in outputKeyMapping.entries) { - val dbColumnValue = checkNotNull(row[mapping.value]) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key) - JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode) - } - logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) - } + val responseNode = checkNotNull(JacksonUtils.getJsonNode(rows)) { + "Failed to get database query result into Json node." } + + val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(responseNode, resourceAssignment, + raRuntimeService, outputKeyMapping) + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, parsedResponseNode) } override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt index 57e028618..da156096e 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt @@ -137,64 +137,11 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS } logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)") + val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(responseNode, resourceAssignment, + raRuntimeService, outputKeyMapping) - when (type) { - in BluePrintTypes.validPrimitiveTypes() -> { - logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)") - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, responseNode) - } - in BluePrintTypes.validCollectionTypes() -> { - // Array Types - entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) { - "Entry schema is not defined for dictionary ($dName) info" - } - val arrayNode = JacksonUtils.objectMapper.createArrayNode() - - if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) { - - val responseArrayNode = responseNode.toList() - for (responseSingleJsonNode in responseArrayNode) { - - val arrayChildNode = JacksonUtils.objectMapper.createObjectNode() - - outputKeyMapping.map { - val responseKeyValue = responseSingleJsonNode.get(it.key) - val propertyTypeForDataType = ResourceAssignmentUtils - .getPropertyType(raRuntimeService, entrySchemaType, it.key) - - logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), " + - "type ({$propertyTypeForDataType})") - - JacksonUtils.populateJsonNodeValues(it.value, - responseKeyValue, propertyTypeForDataType, arrayChildNode) - } - arrayNode.add(arrayChildNode) - } - } - logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode) - } - else -> { - // Complex Types - entrySchemaType = checkNotEmpty(resourceAssignment.property?.type) { - "Entry schema is not defined for dictionary ($dName) info" - } - val objectNode = JacksonUtils.objectMapper.createObjectNode() - outputKeyMapping.map { - val responseKeyValue = responseNode.get(it.key) - val propertyTypeForDataType = ResourceAssignmentUtils - .getPropertyType(raRuntimeService, entrySchemaType, it.key) - - logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") - JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode) - } - - logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") - // Set the List of Complex Values - ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode) - } - } + // Set the List of Complex Values + ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, parsedResponseNode) } @Throws(BluePrintProcessorException::class) 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 f8024d92e..01cfd723b 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 @@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.uti import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ArrayNode import com.fasterxml.jackson.databind.node.ObjectNode import com.fasterxml.jackson.databind.node.TextNode import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService @@ -26,6 +27,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Reso import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.slf4j.LoggerFactory @@ -188,5 +190,89 @@ class ResourceAssignmentUtils { } return type } + + @Throws(BluePrintProcessorException::class) + fun parseResponseNode(responseNode: JsonNode, resourceAssignment: ResourceAssignment, + raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String>): JsonNode { + val dName = resourceAssignment.dictionaryName + val dSource = resourceAssignment.dictionarySource + val type = nullToEmpty(resourceAssignment.property?.type) + lateinit var entrySchemaType: String + when (type) { + in BluePrintTypes.validPrimitiveTypes() -> { + if (dSource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES) + logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)") + val result = if (responseNode is ArrayNode) + responseNode.get(0) + else + responseNode + return if (result.isComplexType()) { + check(result.has(outputKeyMapping[dName])) { + "Fail to find output key mapping ($dName) in result." + } + result[outputKeyMapping[dName]] + } else { + result + } + } + in BluePrintTypes.validCollectionTypes() -> { + // Array Types + entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) { + "Entry schema is not defined for dictionary ($dName) info" + } + val arrayNode = JacksonUtils.objectMapper.createArrayNode() + lateinit var responseValueNode: JsonNode + lateinit var propertyType: String + outputKeyMapping.map { + val arrayChildNode = JacksonUtils.objectMapper.createObjectNode() + val responseArrayNode = responseNode.rootFieldsToMap() + outer@ for ((key, responseSingleJsonNode) in responseArrayNode) { + if (key == it.key) { + if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) { + responseValueNode = responseSingleJsonNode + propertyType = entrySchemaType + + } else { + responseValueNode = responseSingleJsonNode.get(it.key) + propertyType = getPropertyType(raRuntimeService, entrySchemaType, it.key) + } + if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES) + logger.info("For List Type Resource: key (${it.key}), value ($responseValueNode), " + + "type ({$propertyType})") + JacksonUtils.populateJsonNodeValues(it.value, + responseValueNode, propertyType, arrayChildNode) + arrayNode.add(arrayChildNode) + break@outer + } + } + } + if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES) + logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)") + + return arrayNode + } + else -> { + // Complex Types + entrySchemaType = checkNotEmpty(resourceAssignment.property?.type) { + "Entry schema is not defined for dictionary ($dName) info" + } + val objectNode = JacksonUtils.objectMapper.createObjectNode() + outputKeyMapping.map { + val responseKeyValue = responseNode.get(it.key) + val propertyTypeForDataType = ResourceAssignmentUtils + .getPropertyType(raRuntimeService, entrySchemaType, it.key) + + if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES) + logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})") + JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode) + } + + if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES) + logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)") + + return objectNode + } + } + } } }
\ No newline at end of file |