diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/configs-api/src')
6 files changed, 115 insertions, 96 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorHandling.kt index e742e6375..1103a1b5b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorHandling.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorHandling.kt @@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.configs.api object ConfigsApiDomains { + // ConfigsApi Domains Constants const val CONFIGS_API = "org.onap.ccsdk.cds.blueprintsprocessor.configs.api" } diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt index 05f43c151..d285fe52d 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotController.kt @@ -74,7 +74,7 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe @ApiOperation( value = "Retrieve a resource configuration snapshot.", notes = "Retrieve a config snapshot, identified by its Resource Id and Type. " + - "An extra 'format' parameter can be passed to tell what content-type is expected." + "An extra 'format' parameter can be passed to tell what content-type is expected." ) @ResponseBody @PreAuthorize("hasRole('USER')") @@ -95,38 +95,44 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String ): - ResponseEntity<String> = runBlocking { + ResponseEntity<String> = runBlocking { - var configSnapshot = "" + var configSnapshot = "" - if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { - try { - configSnapshot = resourceConfigSnapshotService.findByResourceIdAndResourceTypeAndStatus( - resourceId, - resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) - ) - } catch (ex: NoSuchElementException) { - throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, + if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { + try { + configSnapshot = resourceConfigSnapshotService.findByResourceIdAndResourceTypeAndStatus( + resourceId, + resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) + } catch (ex: NoSuchElementException) { + throw httpProcessorException( + ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, "Could not find configuration snapshot entry for type $resourceType and Id $resourceId", - ex.errorCauseOrDefault()) - } catch (ex: Exception) { - throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, + ex.errorCauseOrDefault() + ) + } catch (ex: Exception) { + throw httpProcessorException( + ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, "Could not find configuration snapshot entry for type $resourceType and Id $resourceId", - ex.errorCauseOrDefault()) + ex.errorCauseOrDefault() + ) + } + } else { + throw httpProcessorException( + ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, + "Missing param. You must specify resource-id and resource-type." + ) } - } else { - throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, - "Missing param. You must specify 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(configSnapshot) - } + ResponseEntity.ok().contentType(expectedMediaType).body(configSnapshot) + } @PostMapping( "/{resourceType}/{resourceId}/{status}", @@ -135,7 +141,7 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe @ApiOperation( value = "Store a resource configuration snapshot identified by resourceId, resourceType, status.", notes = "Store a resource configuration snapshot, identified by its resourceId and resourceType, " + - "and optionally its status, either RUNNING or CANDIDATE.", + "and optionally its status, either RUNNING or CANDIDATE.", response = ResourceConfigSnapshot::class, produces = MediaType.APPLICATION_JSON_VALUE ) @ResponseBody @@ -161,13 +167,13 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe } @RequestMapping( - path = ["/allByID"], - method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE] + path = ["/allByID"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] ) @ApiOperation( - value = "Retrieve all resource configuration snapshots identified by a given resource_id", - notes = "Retrieve all config snapshots, identified by its Resource Id, ordered by most recently created/modified date. " + value = "Retrieve all resource configuration snapshots identified by a given resource_id", + notes = "Retrieve all config snapshots, identified by its Resource Id, ordered by most recently created/modified date. " ) @ResponseBody @PreAuthorize("hasRole('USER')") @@ -184,16 +190,21 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe configSnapshots = resourceConfigSnapshotService.findAllByResourceId(resourceId) } else { configSnapshots = resourceConfigSnapshotService.findAllByResourceIdForStatus( - resourceId, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) + resourceId, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) } } catch (ex: NoSuchElementException) { - throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, - "Could not find configuration snapshot entry for ID $resourceId", - ex.errorCauseOrDefault()) + throw httpProcessorException( + ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, + "Could not find configuration snapshot entry for ID $resourceId", + ex.errorCauseOrDefault() + ) } catch (ex: Exception) { - throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, - "Unexpected error while finding configuration snapshot entries for ID $resourceId", - ex.errorCauseOrDefault()) + throw httpProcessorException( + ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, + "Unexpected error while finding configuration snapshot entries for ID $resourceId", + ex.errorCauseOrDefault() + ) } val expectedMediaType: MediaType = MediaType.valueOf(JSON_MIME_TYPE) @@ -201,13 +212,13 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe } @RequestMapping( - path = ["allByType"], - method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE] + path = ["allByType"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] ) @ApiOperation( - value = "Retrieve all resource configuration snapshots for a given resource type.", - notes = "Retrieve all config snapshots matching a specified Resource Type, ordered by most recently created/modified date. " + value = "Retrieve all resource configuration snapshots for a given resource type.", + notes = "Retrieve all config snapshots matching a specified Resource Type, ordered by most recently created/modified date. " ) @ResponseBody @PreAuthorize("hasRole('USER')") @@ -224,16 +235,21 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe configSnapshots = resourceConfigSnapshotService.findAllByResourceType(resourceType) } else { configSnapshots = resourceConfigSnapshotService.findAllByResourceTypeForStatus( - resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) + resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) } } catch (ex: NoSuchElementException) { - throw httpProcessorException(ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, - "Could not find configuration snapshot entry for ID $resourceType", - ex.errorCauseOrDefault()) + throw httpProcessorException( + ErrorCatalogCodes.RESOURCE_NOT_FOUND, ConfigsApiDomains.CONFIGS_API, + "Could not find configuration snapshot entry for ID $resourceType", + ex.errorCauseOrDefault() + ) } catch (ex: Exception) { - throw httpProcessorException(ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, - "Unexpected error while finding configuration snapshot entries for type $resourceType", - ex.errorCauseOrDefault()) + throw httpProcessorException( + ErrorCatalogCodes.INVALID_REQUEST_FORMAT, ConfigsApiDomains.CONFIGS_API, + "Unexpected error while finding configuration snapshot entries for type $resourceType", + ex.errorCauseOrDefault() + ) } val expectedMediaType: MediaType = MediaType.valueOf(JSON_MIME_TYPE) diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt index 2b9bb31f6..8cd8dbd9a 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotExceptionHandler.kt @@ -28,4 +28,4 @@ import org.springframework.web.bind.annotation.RestControllerAdvice */ @RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.configs.api") open class ResourceConfigSnapshotExceptionHandler(private val errorCatalogService: ErrorCatalogService) : - ErrorCatalogExceptionHandler(errorCatalogService) + ErrorCatalogExceptionHandler(errorCatalogService) diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt index 66fc3b2ed..5a000d157 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ErrorCatalogTestConfiguration.kt @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration @Configuration @ComponentScan( - basePackages = ["org.onap.ccsdk.cds.error.catalog"] + basePackages = ["org.onap.ccsdk.cds.error.catalog"] ) @EnableAutoConfiguration open class ErrorCatalogTestConfiguration diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt index e2fa5ca44..634c3368b 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/ResourceConfigSnapshotControllerTest.kt @@ -148,13 +148,13 @@ class ResourceConfigSnapshotControllerTest { post(resourceType, resourceId, "RUNNING") webTestClient - .get() - .uri("/api/v1/configs/allByID?resourceId=$resourceId") - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.length()") - .isEqualTo(1) + .get() + .uri("/api/v1/configs/allByID?resourceId=$resourceId") + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.length()") + .isEqualTo(1) } } @@ -166,13 +166,13 @@ class ResourceConfigSnapshotControllerTest { post(resourceType, resourceId, "CANDIDATE") webTestClient - .get() - .uri("/api/v1/configs/allByID?resourceId=$resourceId&status=CANDIDATE") - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.length()") - .isEqualTo(1) + .get() + .uri("/api/v1/configs/allByID?resourceId=$resourceId&status=CANDIDATE") + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.length()") + .isEqualTo(1) } } @@ -181,11 +181,11 @@ class ResourceConfigSnapshotControllerTest { runBlocking { webTestClient - .get() - .uri("/api/v1/configs/allByID") - .exchange() - .expectStatus().is4xxClientError - .expectBody() + .get() + .uri("/api/v1/configs/allByID") + .exchange() + .expectStatus().is4xxClientError + .expectBody() } } @@ -194,11 +194,11 @@ class ResourceConfigSnapshotControllerTest { runBlocking { webTestClient - .get() - .uri("/api/v1/configs/allByID?resourceId=$resourceId&status=NOTGOOD") - .exchange() - .expectStatus().is4xxClientError - .expectBody() + .get() + .uri("/api/v1/configs/allByID?resourceId=$resourceId&status=NOTGOOD") + .exchange() + .expectStatus().is4xxClientError + .expectBody() } } @@ -210,13 +210,13 @@ class ResourceConfigSnapshotControllerTest { post(resourceType, "1", "RUNNING") webTestClient - .get() - .uri("/api/v1/configs/allByType?resourceType=$resourceType") - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.length()") - .isEqualTo(3) + .get() + .uri("/api/v1/configs/allByType?resourceType=$resourceType") + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.length()") + .isEqualTo(3) } } @@ -225,11 +225,11 @@ class ResourceConfigSnapshotControllerTest { runBlocking { webTestClient - .get() - .uri("/api/v1/configs/allByType") - .exchange() - .expectStatus().is4xxClientError - .expectBody() + .get() + .uri("/api/v1/configs/allByType") + .exchange() + .expectStatus().is4xxClientError + .expectBody() } } @@ -238,11 +238,11 @@ class ResourceConfigSnapshotControllerTest { runBlocking { webTestClient - .get() - .uri("/api/v1/configs/allByType?resourceType=$resourceType&status=NOTGOOD") - .exchange() - .expectStatus().is4xxClientError - .expectBody() + .get() + .uri("/api/v1/configs/allByType?resourceType=$resourceType&status=NOTGOOD") + .exchange() + .expectStatus().is4xxClientError + .expectBody() } } diff --git a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/TestDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/TestDatabaseConfiguration.kt index 661e28def..ee4c0a544 100644 --- a/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/TestDatabaseConfiguration.kt +++ b/ms/blueprintsprocessor/modules/inbounds/configs-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/configs/api/TestDatabaseConfiguration.kt @@ -31,9 +31,11 @@ import javax.sql.DataSource @Configuration @Import(BluePrintDBLibConfiguration::class) @EnableJpaRepositories( - basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution", + basePackages = [ + "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution", "org.onap.ccsdk.cds.blueprintsprocessor.functions.config.snapshots", - "org.onap.ccsdk.cds.blueprintsprocessor.db.primary"], + "org.onap.ccsdk.cds.blueprintsprocessor.db.primary" + ], entityManagerFactoryRef = "primaryEntityManager", transactionManagerRef = "primaryTransactionManager" ) |