package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
+import com.fasterxml.jackson.databind.JsonNode
import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDBLibGenericService
import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertyService
}
}
- private fun setValueFromDB(resourceAssignment: ResourceAssignment) {
+ open fun setValueFromDB(resourceAssignment: ResourceAssignment) {
val dName = resourceAssignment.dictionaryName!!
val dSource = resourceAssignment.dictionarySource!!
val resourceDefinition = resourceDefinition(dName)
"failed to get input-key-mappings for $dName under $dSource properties"
}
- sourceProperties.inputKeyMapping
- ?.mapValues { raRuntimeService.getResolutionStore(it.value) }
- ?.map { KeyIdentifier(it.key, it.value) }
- ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+ val resolvedInputKeyMapping = resolveInputKeyMappingVariables(
+ inputKeyMapping,
+ resourceAssignment.templatingConstants
+ ).toMutableMap()
+ logger.info("\nResolved Input Key mappings: \n$resolvedInputKeyMapping")
+
+ resolvedInputKeyMapping.map { KeyIdentifier(it.key, it.value) }.let {
+ resourceAssignment.keyIdentifiers.addAll(it)
+ }
logger.info(
"DatabaseResource ($dSource) dictionary information: " +
)
val jdbcTemplate = blueprintDBLibService(sourceProperties, dSource)
- val rows = jdbcTemplate.query(sql, populateNamedParameter(inputKeyMapping))
+ val rows = jdbcTemplate.query(sql, populateNamedParameter(resolvedInputKeyMapping))
if (rows.isEmpty()) {
logger.warn("Emptyset from dictionary-source($dSource) for dictionary name ($dName) the query ($sql).")
}
populateResource(resourceAssignment, sourceProperties, rows)
}
- private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource, selector: String): BluePrintDBLibGenericService {
+ open fun blueprintDBLibService(sourceProperties: DatabaseResourceSource, selector: String): BluePrintDBLibGenericService {
return if (isNotEmpty(sourceProperties.endpointSelector)) {
val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
bluePrintDBLibPropertyService.JdbcTemplate(dbPropertiesJson)
}
@Throws(BluePrintProcessorException::class)
- private fun validate(resourceAssignment: ResourceAssignment) {
+ open fun validate(resourceAssignment: ResourceAssignment) {
checkNotEmpty(resourceAssignment.name) { "resource assignment template key is not defined" }
checkNotEmpty(resourceAssignment.dictionaryName) {
"resource assignment dictionary name is not defined for template key (${resourceAssignment.name})"
}
// placeholder to get the list of DB sources.
- private fun getListOfDBSources(): Array<String> {
+ open fun getListOfDBSources(): Array<String> {
return ResourceSourceMappingFactory.getRegisterSourceMapping()
.resourceSourceMappings.filterValues { it == "source-db" }.keys.toTypedArray()
}
- private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
+ open fun populateNamedParameter(inputKeyMapping: Map<String, JsonNode>): Map<String, Any> {
val namedParameters = HashMap<String, Any>()
inputKeyMapping.forEach {
- val expressionValue = raRuntimeService.getResolutionStore(it.value).textValue()
+ val expressionValue = it.value.textValue()
logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)")
namedParameters[it.key] = expressionValue
}
}
@Throws(BluePrintProcessorException::class)
- private fun populateResource(
+ open fun populateResource(
resourceAssignment: ResourceAssignment,
sourceProperties: DatabaseResourceSource,
rows: List<Map<String, Any>>