Template headers, path and outputsmapping in the rest processor 81/130381/9
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 18 Aug 2022 21:06:29 +0000 (23:06 +0200)
committerKAPIL SINGAL <ks220y@att.com>
Thu, 25 Aug 2022 18:40:58 +0000 (18:40 +0000)
Issue-ID: CCSDK-3716
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I4abc2cdf3eeff1d982d2e96670df262cf16931b3

ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt

index b81455c..b017079 100644 (file)
@@ -74,7 +74,6 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
                 val sourceProperties =
                     JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
 
-                val path = nullToEmpty(sourceProperties.path)
                 val inputKeyMapping =
                     checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
                 val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping).toMutableMap()
@@ -84,30 +83,37 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
                 }
 
                 // Resolving content Variables
+                val path = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.path), resolvedInputKeyMapping)
                 val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
                 resourceSourceProperties["resolved-payload"] = JacksonUtils.jsonNode(payload)
                 val urlPath =
                     resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
                 val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
-
+                var outputKeyMapping = sourceProperties.outputKeyMapping
+                if (!outputKeyMapping.isNullOrEmpty()) {
+                    outputKeyMapping = outputKeyMapping.mapValues { (_, value) ->
+                        resolveFromInputKeyMapping(value, resolvedInputKeyMapping)
+                    }.toMutableMap()
+                }
                 logger.info(
                     "RestResource ($dSource) dictionary information: " +
-                        "URL:($urlPath), input-key-mapping:($inputKeyMapping), output-key-mapping:(${sourceProperties.outputKeyMapping})"
+                        "URL:($urlPath), path:($path), input-key-mapping:($inputKeyMapping), output-key-mapping:($outputKeyMapping)"
                 )
-                val requestHeaders = sourceProperties.headers
-                logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
+                val requestHeaders = sourceProperties.headers.mapValues { (_, value) ->
+                    resolveFromInputKeyMapping(value, resolvedInputKeyMapping)
+                }
+                logger.info("$dSource dictionary information : ($urlPath), path:($path), ($inputKeyMapping), ($outputKeyMapping)")
                 // Get the Rest Client Service
                 val restClientService = blueprintWebClientService(resourceAssignment, sourceProperties)
 
                 val response = restClientService.exchangeResource(verb, urlPath, payload, requestHeaders.toMap())
                 val responseStatusCode = response.status
                 val responseBody = response.body
-                val outputKeyMapping = sourceProperties.outputKeyMapping
                 if (responseStatusCode in 200..299 && outputKeyMapping.isNullOrEmpty()) {
                     resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS
                     logger.info("AS>> outputKeyMapping==null, will not populateResource")
                 } else if (responseStatusCode in 200..299 && !responseBody.isBlank()) {
-                    populateResource(resourceAssignment, sourceProperties, responseBody, path)
+                    populateResource(resourceAssignment, sourceProperties, responseBody, path, outputKeyMapping)
                 } else {
                     val errMsg =
                         "Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath) response_code: ($responseStatusCode)"
@@ -147,14 +153,15 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
         resourceAssignment: ResourceAssignment,
         sourceProperties: RestResourceSource,
         restResponse: String,
-        path: String
+        path: String,
+        outputKeyMapping: MutableMap<String, String>?
     ) {
         val dName = resourceAssignment.dictionaryName
         val dSource = resourceAssignment.dictionarySource
         val type = nullToEmpty(resourceAssignment.property?.type)
         val metadata = resourceAssignment.property!!.metadata
 
-        val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) {
+        val outputKeyMapping = checkNotNull(outputKeyMapping) {
             "failed to get output-key-mappings for $dName under $dSource properties"
         }
         logger.info("Response processing type ($type)")