X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fblueprintsprocessor%2Ffunctions%2Fresource-resolution%2Fsrc%2Fmain%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Ffunctions%2Fresource%2Fresolution%2Fprocessor%2FDatabaseResourceAssignmentProcessor.kt;h=98df3f1cfd7a453a1893c22371f502b3845751c2;hb=refs%2Fheads%2Fmaster;hp=785f47772a57e1b365e36c21b4f3b664cecea071;hpb=3395dfa1f31111bb4dd03e89a7e493a2850901f2;p=ccsdk%2Fcds.git 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 785f47772..6072a9233 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 @@ -17,6 +17,7 @@ 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 @@ -78,7 +79,7 @@ open class DatabaseResourceAssignmentProcessor( } } - private fun setValueFromDB(resourceAssignment: ResourceAssignment) { + open fun setValueFromDB(resourceAssignment: ResourceAssignment) { val dName = resourceAssignment.dictionaryName!! val dSource = resourceAssignment.dictionarySource!! val resourceDefinition = resourceDefinition(dName) @@ -100,10 +101,15 @@ open class DatabaseResourceAssignmentProcessor( "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: " + @@ -111,7 +117,7 @@ open class DatabaseResourceAssignmentProcessor( ) 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).") } @@ -119,7 +125,7 @@ open class DatabaseResourceAssignmentProcessor( 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) @@ -129,7 +135,7 @@ open class DatabaseResourceAssignmentProcessor( } @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})" @@ -140,15 +146,15 @@ open class DatabaseResourceAssignmentProcessor( } // placeholder to get the list of DB sources. - private fun getListOfDBSources(): Array { + open fun getListOfDBSources(): Array { return ResourceSourceMappingFactory.getRegisterSourceMapping() .resourceSourceMappings.filterValues { it == "source-db" }.keys.toTypedArray() } - private fun populateNamedParameter(inputKeyMapping: Map): Map { + open fun populateNamedParameter(inputKeyMapping: Map): Map { val namedParameters = HashMap() 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 } @@ -159,7 +165,7 @@ open class DatabaseResourceAssignmentProcessor( } @Throws(BluePrintProcessorException::class) - private fun populateResource( + open fun populateResource( resourceAssignment: ResourceAssignment, sourceProperties: DatabaseResourceSource, rows: List>