X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fblueprintsprocessor%2Fmodules%2Finbounds%2Fdesigner-api%2Fsrc%2Fmain%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Fdesigner%2Fapi%2FBlueprintModelController.kt;h=a6bff7051ab599dc30e122372abaa41b08d95360;hb=4433fa9514ed0a031b797367a0daa9aea611d138;hp=26420cc56433006ab6bc0c0deaa059ba05f9a4bc;hpb=a006efcfacc3499615e835dae212c854826cfe7c;p=ccsdk%2Fcds.git diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt index 26420cc56..a6bff7051 100644 --- a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/BlueprintModelController.kt @@ -17,14 +17,19 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import org.onap.ccsdk.cds.blueprintsprocessor.core.monoMdc import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch +import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.springframework.core.io.Resource import org.springframework.http.MediaType import org.springframework.http.ResponseEntity import org.springframework.http.codec.multipart.FilePart +import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* +import reactor.core.publisher.Mono /** * BlueprintModelController Purpose: Handle controllerBlueprint API request @@ -39,18 +44,21 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = runBlocking { + @PreAuthorize("hasRole('USER')") + fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono = monoMdc { bluePrintModelHandler.saveBlueprintModel(filePart) } @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody + @PreAuthorize("hasRole('USER')") fun allBlueprintModel(): List { return this.bluePrintModelHandler.allBlueprintModel() } @DeleteMapping("/{id}") @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") fun deleteBlueprint(@PathVariable(value = "id") id: String) { this.bluePrintModelHandler.deleteBlueprintModel(id) } @@ -58,22 +66,27 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String): BlueprintModelSearch { - return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) + @PathVariable(value = "version") version: String) + : Mono = monoMdc { + bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) } @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String): ResponseEntity { - return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) + @PathVariable(value = "version") version: String) + : Mono> = monoMdc { + bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) } @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { return this.bluePrintModelHandler.getBlueprintModelSearch(id) } @@ -81,28 +94,44 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity { - return this.bluePrintModelHandler.downloadBlueprintModelFile(id) + @PreAuthorize("hasRole('USER')") + fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono> = monoMdc { + bluePrintModelHandler.downloadBlueprintModelFile(id) } @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType .MULTIPART_FORM_DATA_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity = runBlocking { + @PreAuthorize("hasRole('USER')") + fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono> = monoMdc { bluePrintModelHandler.enrichBlueprint(file) } @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking { + @PreAuthorize("hasRole('USER')") + fun publishBlueprint(@RequestPart("file") file: FilePart): Mono = monoMdc { bluePrintModelHandler.publishBlueprint(file) } @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody + @PreAuthorize("hasRole('USER')") fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List { return this.bluePrintModelHandler.searchBlueprintModels(tags) } + + @DeleteMapping("/name/{name}/version/{version}") + @ApiOperation(value = "Delete a CBA", + notes = "Delete the CBA package identified by its name and version.", + produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize("hasRole('USER')") + fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true) + @PathVariable(value = "name") name: String, + @ApiParam(value = "Version of the CBA.", required = true) + @PathVariable(value = "version") version: String) = monoMdc { + bluePrintModelHandler.deleteBlueprintModel(name, version) + } }