From 1072867dfac0df993cbd3e44bcc11a5cac7465fd Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 22 Sep 2020 12:16:46 -0400 Subject: Enabling Code Formatter Code Formatter was turned off due to java 11 migation Issue-ID: CCSDK-2852 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I3d02ed3cc7a93d7551fe25356512cfe8db1517d8 --- .../resource/api/ErrorHandling.kt | 1 + .../resource/api/ResourceController.kt | 73 +++++++++++++--------- .../resource/api/ResourceExceptionHandler.kt | 2 +- .../resource/api/TemplateController.kt | 70 +++++++++++---------- 4 files changed, 82 insertions(+), 64 deletions(-) (limited to 'ms/blueprintsprocessor/modules/inbounds/resource-api/src/main') diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt index b37cd0eda..76e0346f4 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ErrorHandling.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.resource.api object ResourceApiDomains { + // Resource Api Domains Constants const val RESOURCE_API = "org.onap.ccsdk.cds.blueprintsprocessor.resource.api" } diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt index 1aae8aa1c..e7c11e306 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt @@ -61,7 +61,7 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR @ApiOperation( value = "Get all resolved resources using the resolution key. ", notes = "Retrieve all stored resolved resources using the blueprint name, blueprint version, " + - "artifact name and the resolution-key.", + "artifact name and the resolution-key.", response = ResourceResolution::class, responseContainer = "List", produces = MediaType.APPLICATION_JSON_VALUE @@ -82,37 +82,43 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR @ApiParam(value = "Resource Id associated with the resolution.", required = false) @RequestParam(value = "resourceId", required = false, defaultValue = "") resourceId: String ): - ResponseEntity> = runBlocking { + ResponseEntity> = runBlocking { - if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) { - throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, - "Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.") - } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) { - ResponseEntity.ok() - .body(resourceResolutionDBService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey)) - } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { - ResponseEntity.ok() - .body( - resourceResolutionDBService.readWithResourceIdAndResourceType( - bpName, - bpVersion, - resourceId, - resourceType + if ((resolutionKey.isNotEmpty() || artifactName.isNotEmpty()) && (resourceId.isNotEmpty() || resourceType.isNotEmpty())) { + throw httpProcessorException( + ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, + "Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type." + ) + } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) { + ResponseEntity.ok() + .body(resourceResolutionDBService.readWithResolutionKey(bpName, bpVersion, artifactName, resolutionKey)) + } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { + ResponseEntity.ok() + .body( + resourceResolutionDBService.readWithResourceIdAndResourceType( + bpName, + bpVersion, + resourceId, + resourceType + ) ) + } else { + throw httpProcessorException( + ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, + "Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type." ) - } else { - throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, - "Missing param. Either retrieve resolved value using artifact name and resolution-key OR using resource-id and resource-type.") + } } - } @RequestMapping( - path = [""], - method = [RequestMethod.DELETE], produces = [MediaType.APPLICATION_JSON_VALUE] + path = [""], + method = [RequestMethod.DELETE], produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Delete resources using resolution key", + notes = "Delete all the resources associated to a resolution-key using blueprint metadata, artifact name and the resolution-key.", + produces = MediaType.APPLICATION_JSON_VALUE ) - @ApiOperation(value = "Delete resources using resolution key", - notes = "Delete all the resources associated to a resolution-key using blueprint metadata, artifact name and the resolution-key.", - produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasRole('USER')") fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey( @ApiParam(value = "Name of the CBA.", required = true) @@ -125,7 +131,14 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR @RequestParam(value = "resolutionKey", required = true) resolutionKey: String ) = runBlocking { ResponseEntity.ok() - .body(resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(bpName, bpVersion, artifactName, resolutionKey)) + .body( + resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey( + bpName, + bpVersion, + artifactName, + resolutionKey + ) + ) } @RequestMapping( @@ -152,9 +165,9 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR @ApiParam(value = "Name of the resource to retrieve.", required = true) @RequestParam(value = "name", required = true) name: String ): - ResponseEntity = runBlocking { + ResponseEntity = runBlocking { - ResponseEntity.ok() - .body(resourceResolutionDBService.readValue(bpName, bpVersion, artifactName, resolutionKey, name)) - } + ResponseEntity.ok() + .body(resourceResolutionDBService.readValue(bpName, bpVersion, artifactName, resolutionKey, name)) + } } diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt index 9c09bd819..baaa858d1 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceExceptionHandler.kt @@ -27,4 +27,4 @@ import org.springframework.web.bind.annotation.RestControllerAdvice */ @RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.resource.api") open class ResourceExceptionHandler(private val errorCatalogService: ErrorCatalogService) : - ErrorCatalogExceptionHandler(errorCatalogService) + ErrorCatalogExceptionHandler(errorCatalogService) 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 bd52bfee6..b56a63b17 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 @@ -71,8 +71,8 @@ open class TemplateController(private val templateResolutionService: TemplateRes @ApiOperation( value = "Retrieve a resolved template.", notes = "Retrieve a config template for a given CBA's action, identified by its blueprint name, blueprint version, " + - "artifact name and resolution key. An extra 'format' parameter can be passed to tell what content-type" + - " to expect in return" + "artifact name and resolution key. An extra 'format' parameter can be passed to tell what content-type" + + " to expect in return" ) @ResponseBody @PreAuthorize("hasRole('USER')") @@ -98,50 +98,54 @@ open class TemplateController(private val templateResolutionService: TemplateRes @ApiParam(value = "Occurrence of the template resolution (1-n).", required = false) @RequestParam(value = "occurrence", required = false, defaultValue = "1") occurrence: Int = 1 ): - ResponseEntity = runBlocking { + ResponseEntity = runBlocking { - var result = "" + var result = "" - if ((resolutionKey.isNotEmpty() || artifactName.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.") - } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) { - result = templateResolutionService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( - bpName, - bpVersion, - artifactName, - resolutionKey, - occurrence - ) - } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { - result = - templateResolutionService.findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName( + if ((resolutionKey.isNotEmpty() || artifactName.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." + ) + } else if (resolutionKey.isNotEmpty() && artifactName.isNotEmpty()) { + result = templateResolutionService.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName( bpName, bpVersion, artifactName, - resourceId, - resourceType, + resolutionKey, occurrence ) - } else { - throw httpProcessorException(ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, - "Missing param. Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type.") - } + } else if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { + result = + templateResolutionService.findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName( + bpName, + bpVersion, + artifactName, + resourceId, + resourceType, + occurrence + ) + } else { + throw httpProcessorException( + ErrorCatalogCodes.REQUEST_NOT_FOUND, ResourceApiDomains.RESOURCE_API, + "Missing param. Either retrieve resolved template using artifact name and resolution-key OR using resource-id and resource-type." + ) + } - var expectedContentType = format - if (expectedContentType.indexOf('/') < 0) { - expectedContentType = "application/$expectedContentType" - } - val expectedMediaType: MediaType = MediaType.valueOf(expectedContentType) + var expectedContentType = format + if (expectedContentType.indexOf('/') < 0) { + expectedContentType = "application/$expectedContentType" + } + val expectedMediaType: MediaType = MediaType.valueOf(expectedContentType) - ResponseEntity.ok().contentType(expectedMediaType).body(result) - } + ResponseEntity.ok().contentType(expectedMediaType).body(result) + } @PostMapping("/{bpName}/{bpVersion}/{artifactName}/{resolutionKey}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ApiOperation( value = "Store a resolved template w/ resolution-key", notes = "Store a template for a given CBA's action, identified by its blueprint name, blueprint version, " + - "artifact name and resolution key.", + "artifact name and resolution key.", response = TemplateResolution::class, produces = MediaType.APPLICATION_JSON_VALUE ) @@ -173,7 +177,7 @@ open class TemplateController(private val templateResolutionService: TemplateRes @ApiOperation( value = "Store a resolved template w/ resourceId and resourceType", notes = "Store a template for a given CBA's action, identified by its blueprint name, blueprint version, " + - "artifact name, resourceId and resourceType.", + "artifact name, resourceId and resourceType.", response = TemplateResolution::class, produces = MediaType.APPLICATION_JSON_VALUE ) -- cgit 1.2.3-korg