From 341db21b2ac0a14a1ed2b8bf7930914dda054bfe Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 22 Nov 2019 18:06:08 -0500 Subject: Formatting Code base with ktlint No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331 --- .../api/ResourceConfigSnapshotController.kt | 82 +++++++++++++++------- .../api/ResourceConfigSnapshotExceptionHandler.kt | 17 +++-- .../api/ResourceConfigSnapshotControllerTest.kt | 48 +++++++------ 3 files changed, 90 insertions(+), 57 deletions(-) (limited to 'ms/blueprintsprocessor/modules/inbounds/configs-api/src') 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 eb7929509..0b18fb01f 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 @@ -27,7 +27,14 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController /** * Exposes Resource Configuration Snapshot API to store and retrieve stored resource configurations. @@ -37,52 +44,66 @@ import org.springframework.web.bind.annotation.* */ @RestController @RequestMapping("/api/v1/configs") -@Api(value = "/api/v1/configs", - description = "Interaction with stored configurations.") +@Api( + value = "/api/v1/configs", + description = "Interaction with stored configurations." +) open class ResourceConfigSnapshotController(private val resourceConfigSnapshotService: ResourceConfigSnapshotService) { - @RequestMapping(path = ["/health-check"], + @RequestMapping( + path = ["/health-check"], method = [RequestMethod.GET], - produces = [MediaType.APPLICATION_JSON_VALUE]) + produces = [MediaType.APPLICATION_JSON_VALUE] + ) @ResponseBody @ApiOperation(value = "Health Check", hidden = true) fun ressCfgSnapshotControllerHealthCheck(): JsonNode = runBlocking { "Success".asJsonPrimitive() } - @RequestMapping(path = [""], + @RequestMapping( + path = [""], method = [RequestMethod.GET], - produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE]) - @ApiOperation(value = "Retrieve a resource configuration snapshot.", + produces = [MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE] + ) + @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')") fun get( - @ApiParam(value = "Resource Type associated of the resource configuration snapshot.", required = false) + @ApiParam(value = "Resource Type associated of the resource configuration snapshot.", required = false) @RequestParam(value = "resourceType", required = true) resourceType: String, - @ApiParam(value = "Resource Id associated of the resource configuration snapshot.", required = false) + @ApiParam(value = "Resource Id associated of the resource configuration snapshot.", required = false) @RequestParam(value = "resourceId", required = true) resourceId: String, - @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "RUNNING", required = false) + @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "RUNNING", required = false) @RequestParam(value = "status", required = false, defaultValue = "RUNNING") status: String, - @ApiParam(value = "Expected format of the snapshot being retrieved.", defaultValue = MediaType.TEXT_PLAIN_VALUE, - required = false) - @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String) + @ApiParam( + value = "Expected format of the snapshot being retrieved.", defaultValue = MediaType.TEXT_PLAIN_VALUE, + required = false + ) + @RequestParam(value = "format", required = false, defaultValue = MediaType.TEXT_PLAIN_VALUE) format: String + ): - : ResponseEntity = runBlocking { + ResponseEntity = runBlocking { var configSnapshot = "" if (resourceType.isNotEmpty() && resourceId.isNotEmpty()) { try { - configSnapshot = resourceConfigSnapshotService.findByResourceIdAndResourceTypeAndStatus(resourceId, - resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) - } catch (ex : NoSuchElementException) { + configSnapshot = resourceConfigSnapshotService.findByResourceIdAndResourceTypeAndStatus( + resourceId, + resourceType, ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) + } catch (ex: NoSuchElementException) { throw ResourceConfigSnapshotException( - "Could not find configuration snapshot entry for type $resourceType and Id $resourceId") + "Could not find configuration snapshot entry for type $resourceType and Id $resourceId" + ) } } else { throw IllegalArgumentException("Missing param. You must specify resource-id and resource-type.") @@ -97,12 +118,16 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe ResponseEntity.ok().contentType(expectedMediaType).body(configSnapshot) } - @PostMapping("/{resourceType}/{resourceId}/{status}", - produces = [MediaType.APPLICATION_JSON_VALUE]) - @ApiOperation(value = "Store a resource configuration snapshot identified by resourceId, resourceType, status.", + @PostMapping( + "/{resourceType}/{resourceId}/{status}", + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @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.", - response = ResourceConfigSnapshot::class, produces = MediaType.APPLICATION_JSON_VALUE) + response = ResourceConfigSnapshot::class, produces = MediaType.APPLICATION_JSON_VALUE + ) @ResponseBody @PreAuthorize("hasRole('USER')") fun postWithResourceIdAndResourceType( @@ -113,11 +138,14 @@ open class ResourceConfigSnapshotController(private val resourceConfigSnapshotSe @ApiParam(value = "Status of the snapshot being retrieved.", defaultValue = "RUNNING", required = true) @PathVariable(value = "status", required = true) status: String, @ApiParam(value = "Config snapshot to store.", required = true) - @RequestBody snapshot: String): ResponseEntity = runBlocking { + @RequestBody snapshot: String + ): ResponseEntity = runBlocking { val resultStored = - resourceConfigSnapshotService.write(snapshot, resourceId, resourceType, - ResourceConfigSnapshot.Status.valueOf(status.toUpperCase())) + resourceConfigSnapshotService.write( + snapshot, resourceId, resourceType, + ResourceConfigSnapshot.Status.valueOf(status.toUpperCase()) + ) ResponseEntity.ok().body(resultStored) } 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 d21464ef5..d4c31e780 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 @@ -23,16 +23,16 @@ import com.fasterxml.jackson.annotation.JsonTypeName import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode import org.slf4j.LoggerFactory +import org.springframework.dao.EmptyResultDataAccessException +import org.springframework.dao.IncorrectResultSizeDataAccessException import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.orm.jpa.JpaObjectRetrievalFailureException -import org.springframework.dao.EmptyResultDataAccessException -import org.springframework.dao.IncorrectResultSizeDataAccessException -import org.springframework.web.server.ServerWebInputException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice +import org.springframework.web.server.ServerWebInputException import java.io.Serializable -import java.util.* +import java.util.Date /** * Handle exceptions in ResourceConfigSnapshot API and provide relevant HTTP status codes and messages @@ -102,9 +102,11 @@ open class ResourceConfigSnapshotExceptionHandler { log.error(e.message) } val errorMessage = - ErrorMessage(errorCode.message(e.message!!), + ErrorMessage( + errorCode.message(e.message!!), errorCode.value, - debugMsg) + debugMsg + ) return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode.httpCode)!!) } } @@ -113,6 +115,7 @@ open class ResourceConfigSnapshotExceptionHandler { @JsonTypeName("errorMessage") @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) class ErrorMessage(var message: String?, var code: Int?, var debugMessage: String?) : Serializable { + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") var timestamp = Date() -} \ No newline at end of file +} 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 89f62812e..34c7a7c7c 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 @@ -35,8 +35,10 @@ import org.springframework.web.reactive.function.BodyInserters @RunWith(SpringRunner::class) @WebFluxTest -@ContextConfiguration(classes = [BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, SecurityProperties::class]) +@ContextConfiguration( + classes = [BluePrintCoreConfiguration::class, + BluePrintCatalogService::class, SecurityProperties::class] +) @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) @TestPropertySource(locations = ["classpath:application-test.properties"]) class ResourceConfigSnapshotControllerTest { @@ -68,24 +70,24 @@ class ResourceConfigSnapshotControllerTest { runBlocking { webTestClient - .post() - .uri("/api/v1/configs/$resourceType/$resourceId/running") - .body(BodyInserters.fromObject(snapshotData)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.createdDate") - .value { println(it) } + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/running") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.createdDate") + .value { println(it) } webTestClient - .post() - .uri("/api/v1/configs/$resourceType/$resourceId/running") - .body(BodyInserters.fromObject(snapshotData)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .jsonPath("$.createdDate") - .value { println(it)} + .post() + .uri("/api/v1/configs/$resourceType/$resourceId/running") + .body(BodyInserters.fromObject(snapshotData)) + .exchange() + .expectStatus().is2xxSuccessful + .expectBody() + .jsonPath("$.createdDate") + .value { println(it) } } } @@ -93,7 +95,7 @@ class ResourceConfigSnapshotControllerTest { fun `get returns requested JSON content-type`() { runBlocking { post(resourceType, "22", "RUNNING") - get("json", resourceType,"22", "RUNNING") + get("json", resourceType, "22", "RUNNING") } } @@ -122,8 +124,8 @@ class ResourceConfigSnapshotControllerTest { val arguments = "resourceId=MISSING&resourceType=PNF&status=TOTALLY_WRONG" webTestClient.get().uri("/api/v1/configs?$arguments") - .exchange() - .expectStatus().isBadRequest + .exchange() + .expectStatus().isBadRequest } } @@ -140,7 +142,7 @@ class ResourceConfigSnapshotControllerTest { } } - private fun post( resourceType: String, resourceId: String, status: String) { + private fun post(resourceType: String, resourceId: String, status: String) { webTestClient .post() .uri("/api/v1/configs/$resourceType/$resourceId/$status") @@ -150,7 +152,7 @@ class ResourceConfigSnapshotControllerTest { .expectBody() } - private fun get(expectedType : String, resourceType: String, resourceId: String, status: String) { + private fun get(expectedType: String, resourceType: String, resourceId: String, status: String) { var requestArguments = "resourceId=$resourceId&resourceType=$resourceType&status=$status" if (expectedType.isNotEmpty()) { -- cgit 1.2.3-korg