/*
* 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.
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
/*
* 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.
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
}
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) {
}
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)
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
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
}
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