aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules
diff options
context:
space:
mode:
authorjuhi arora <j.arora@cgi.com>2022-05-19 14:14:17 -0400
committerJUHI ARORA <juhi.arora1@bell.ca>2022-05-24 18:27:15 +0000
commit9500d29a3edceee521d16bb1256974222cf37214 (patch)
tree43bd0151df680c86b631d1cb3d4049704df8fdb4 /ms/blueprintsprocessor/modules
parentc3943fbc70105c4ce38d66c7cbe227ddec35d535 (diff)
Extend Template API to retrieve resolutions by occurrence
Add new endpoints - template to get firstN, lastN and by Range (begin, end) of 'occurrence' to get the templates Issue-ID: CCSDK-3666 Change-Id: I242626e826022ed8b70a0abc287560ea634121b7 Signed-off-by: juhi arora <juhi.arora1@bell.ca>
Diffstat (limited to 'ms/blueprintsprocessor/modules')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt54
1 files changed, 54 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt
index 2d32d0e1d..2840f8016 100644
--- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/TemplateController.kt
@@ -169,6 +169,60 @@ open class TemplateController(private val templateResolutionService: TemplateRes
ResponseEntity.ok().body(resultStored)
}
+ @RequestMapping(
+ path = ["/occurrences"],
+ method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE]
+ )
+ @ApiOperation(
+ value = "Get the map of resolved templates with 'occurrence' as the keys to the resolved templates ",
+ notes = "With optional 'occurrence' options, subset of stored resolved templates can be retrieved " +
+ "using the blueprint name, blueprint version, artifact name and the resolution-key.",
+ response = TemplateResolution::class,
+ responseContainer = "List",
+ produces = MediaType.APPLICATION_JSON_VALUE
+ )
+ @ResponseBody
+ @PreAuthorize("hasRole('USER')")
+ fun getOccurrences(
+ @ApiParam(value = "Name of the CBA.", required = true)
+ @RequestParam(value = "bpName", required = true) bpName: String,
+ @ApiParam(value = "Version of the CBA.", required = true)
+ @RequestParam(value = "bpVersion", required = true) bpVersion: String,
+ @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true)
+ @RequestParam(value = "artifactName", required = true, defaultValue = "") artifactName: String,
+ @ApiParam(value = "Resolution Key associated with the resolution.", required = true)
+ @RequestParam(value = "resolutionKey", required = true, defaultValue = "") resolutionKey: String,
+ @ApiParam(value = "Number of earlier N occurrences of the templates.", required = false)
+ @RequestParam(value = "firstN", required = false) firstN: Int?,
+ @ApiParam(value = "Number of latest N occurrences of the templates.", required = false)
+ @RequestParam(value = "lastN", required = false) lastN: Int?,
+ @ApiParam(value = "For Range option - 'begin' is the start occurrence of range of the templates.", required = false)
+ @RequestParam(value = "begin", required = false) begin: Int?,
+ @ApiParam(value = "For Range option - 'end' is the end occurrence of the range of the templates.", required = false)
+ @RequestParam(value = "end", required = false) end: Int?
+ ): ResponseEntity<Map<Int, List<TemplateResolution>>> = runBlocking {
+ when {
+ artifactName.isEmpty() -> "'artifactName' must not be empty"
+ resolutionKey.isEmpty() -> "'resolutionKey' must not be empty"
+ // Optional options - validate if provided
+ (firstN != null && lastN != null) -> "Retrieve occurrences using either 'firstN' OR 'lastN' option"
+ ((firstN != null || lastN != null) && (begin != null || end != null)) -> "Retrieve occurrences using either 'firstN' OR 'lastN' OR 'begin' and 'end' option."
+ ((begin != null && end == null) || (begin == null && end != null)) -> " Retrieving occurrences within range - please provide both 'begin' and 'end' option"
+ else -> null
+ }?.let { throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, it) }
+
+ when {
+ firstN != null ->
+ templateResolutionService.findFirstNOccurrences(bpName, bpVersion, artifactName, resolutionKey, firstN)
+ lastN != null ->
+ templateResolutionService.findLastNOccurrences(bpName, bpVersion, artifactName, resolutionKey, lastN)
+ begin != null && end != null ->
+ templateResolutionService.findOccurrencesWithinRange(bpName, bpVersion, artifactName, resolutionKey, begin, end)
+ else ->
+ templateResolutionService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey).groupBy(TemplateResolution::occurrence).toSortedMap(reverseOrder())
+ }.let { result -> ResponseEntity.ok().body(result) }
+ }
+
@PostMapping(
"/{bpName}/{bpVersion}/{artifactName}/{resourceType}/{resourceId}",
produces = [MediaType.APPLICATION_JSON_VALUE]