import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceDomains
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
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()
- inputKeyMapping?.mapValues { raRuntimeService.getDictionaryStore(it.value) }
- ?.map { KeyIdentifier(it.key, it.value) }
- ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+ resolvedInputKeyMapping.map { KeyIdentifier(it.key, it.value) }.let {
+ resourceAssignment.keyIdentifiers.addAll(it)
+ }
// 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)"
} catch (e: BluePrintProcessorException) {
val errorMsg = "Failed to process REST resource resolution in template key ($resourceAssignment) assignments."
ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, errorMsg)
- throw e.updateErrorMessage(ExecutionServiceDomains.RESOURCE_RESOLUTION, errorMsg,
- "Wrong resource definition or resolution failed.")
+ throw e.updateErrorMessage(
+ ExecutionServiceDomains.RESOURCE_RESOLUTION, errorMsg,
+ "Wrong resource definition or resolution failed."
+ )
} catch (e: Exception) {
ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
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)")
}
override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
- raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ addError(runtimeException.message!!)
}
}