Fix: Run both sonar and clm scans in parallel
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / processor / DatabaseResourceAssignmentProcessor.kt
index 785f477..6072a92 100644 (file)
@@ -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<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
         }
@@ -159,7 +165,7 @@ open class DatabaseResourceAssignmentProcessor(
     }
 
     @Throws(BluePrintProcessorException::class)
-    private fun populateResource(
+    open fun populateResource(
         resourceAssignment: ResourceAssignment,
         sourceProperties: DatabaseResourceSource,
         rows: List<Map<String, Any>>