summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2022-08-18 23:06:29 +0200
committerKAPIL SINGAL <ks220y@att.com>2022-08-25 18:40:58 +0000
commitcae69646541ac0dfdd4cc7fb4178446b31efee50 (patch)
tree1b2b08a4ecfe6284ab5d920e48a99609400cfa61 /ms/blueprintsprocessor
parent9ab2a91f585864bf18fef788adeaf61f4f450b39 (diff)
Template headers, path and outputsmapping in the rest processor
Issue-ID: CCSDK-3716 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> Change-Id: I4abc2cdf3eeff1d982d2e96670df262cf16931b3
Diffstat (limited to 'ms/blueprintsprocessor')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt25
1 files changed, 16 insertions, 9 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
index b81455c83..b01707924 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
@@ -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)")