Fixed Template API (resourceId and resoourceType) input validation 77/129777/1
authorkuldipr <kuldip.rai@amdocs.com>
Fri, 17 Jun 2022 22:27:33 +0000 (18:27 -0400)
committerkuldipr <kuldip.rai@amdocs.com>
Mon, 4 Jul 2022 14:24:10 +0000 (10:24 -0400)
Validation was always checking for resolutionKey even when it is not
required when using resourceId and resourceType. Also artifactName
which is always required could not have been sent along with
resourceId and resourceType.

Issue-ID: CCSDK-3713
Signed-off-by: kuldipr <kuldip.rai@amdocs.com>
Change-Id: I4a2945397f10bf5c57a698894df09ee4fc5891d0

ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt

index 2840f80..03ba347 100644 (file)
@@ -84,7 +84,7 @@ open class TemplateController(private val templateResolutionService: TemplateRes
         @ApiParam(value = "Artifact name for which to retrieve a resolved resource", required = true)
         @RequestParam(value = "artifactName") artifactName: String,
         @ApiParam(value = "Resolution Key associated with the resolution", required = false)
-        @RequestParam(value = "resolutionKey") resolutionKey: String,
+        @RequestParam(value = "resolutionKey", required = false, defaultValue = "") resolutionKey: String,
         @ApiParam(value = "Resource Type associated with the resolution", required = false)
         @RequestParam(value = "resourceType", required = false, defaultValue = "") resourceType: String,
         @ApiParam(value = "Resource Id associated with the resolution", required = false)
@@ -102,10 +102,10 @@ open class TemplateController(private val templateResolutionService: TemplateRes
 
             var result = ""
 
-            if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) {
+            if (resolutionKey.isNotEmpty() && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) {
                 throw httpProcessorException(
                     ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API,
-                    "Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type."
+                    "Either retrieve resolved template using resolution-key OR using resource-id and resource-type."
                 )
             } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) {
                 result = templateResolutionService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
@@ -115,7 +115,7 @@ open class TemplateController(private val templateResolutionService: TemplateRes
                     resolutionKey,
                     occurrence
                 )
-            } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) {
+            } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty() && artifactName.isNotEmpty()) {
                 result =
                     templateResolutionService.findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName(
                         bpName,