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=bb824ce4df9544a757981a3307671a4fe37bd6b7;hb=c6da9f5aaa7c29644ead22d5ba5fc8ef3ec5811a;hp=a6bff7051ab599dc30e122372abaa41b08d95360;hpb=626cce5c6921376fa0ad3d927cec391b19c45b3a;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 a6bff7051..bb824ce4d 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 @@ -1,6 +1,7 @@ /* * Copyright © 2019 Bell Canada Intellectual Property. * Modifications Copyright © 2019 IBM. + * Modifications Copyright © 2019 Orange. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +20,31 @@ package org.onap.ccsdk.cds.blueprintsprocessor.designer.api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam -import org.onap.ccsdk.cds.blueprintsprocessor.core.monoMdc +import org.jetbrains.annotations.NotNull 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.blueprintsprocessor.designer.api.utils.BlueprintSortByOption +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.springframework.core.io.Resource +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageRequest +import org.springframework.data.domain.Sort +import org.springframework.http.HttpStatus 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 +import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.GetMapping +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.RequestParam +import org.springframework.web.bind.annotation.RequestPart +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController /** * BlueprintModelController Purpose: Handle controllerBlueprint API request @@ -41,11 +56,22 @@ import reactor.core.publisher.Mono @RequestMapping("/api/v1/blueprint-model") open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) { + @PostMapping( + path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), + consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE) + ) + @ResponseBody + @Throws(BluePrintException::class) + @PreAuthorize("hasRole('USER')") + suspend fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Unit = mdcWebCoroutineScope { + bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest) + } + @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono = monoMdc { + suspend fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = mdcWebCoroutineScope { bluePrintModelHandler.saveBlueprintModel(filePart) } @@ -56,30 +82,70 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint return this.bluePrintModelHandler.allBlueprintModel() } + @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @PreAuthorize("hasRole('USER')") + fun allBlueprintModel( + @RequestParam(defaultValue = "20") limit: Int, + @RequestParam(defaultValue = "0") offset: Int, + @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption + ): Page { + val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName) + return this.bluePrintModelHandler.allBlueprintModel(pageRequest) + } + + @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @PreAuthorize("hasRole('USER')") + suspend fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List = + mdcWebCoroutineScope { + bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord) + } + + @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @PreAuthorize("hasRole('USER')") + fun allBlueprintModelMetaDataPaged( + @NotNull @PathVariable(value = "keyword") keyWord: String, + @RequestParam(defaultValue = "20") limit: Int, + @RequestParam(defaultValue = "0") offset: Int, + @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption + ): Page { + val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName) + return this.bluePrintModelHandler.searchBluePrintModelsByKeyWordPaged(keyWord, pageRequest) + } + @DeleteMapping("/{id}") @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun deleteBlueprint(@PathVariable(value = "id") id: String) { - this.bluePrintModelHandler.deleteBlueprintModel(id) + suspend fun deleteBlueprint(@PathVariable(value = "id") id: String) = mdcWebCoroutineScope { + bluePrintModelHandler.deleteBlueprintModel(id) } @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) - : Mono = monoMdc { - bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) + suspend fun getBlueprintByNameAndVersion( + @PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String + ): ResponseEntity = mdcWebCoroutineScope { + val bluePrintModel: BlueprintModelSearch? = + bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) + if (bluePrintModel != null) + ResponseEntity(bluePrintModel, HttpStatus.OK) + else + ResponseEntity(HttpStatus.NO_CONTENT) } @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) - : Mono> = monoMdc { + suspend fun downloadBlueprintByNameAndVersion( + @PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String + ): ResponseEntity = mdcWebCoroutineScope { bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) } @@ -87,24 +153,27 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { - return this.bluePrintModelHandler.getBlueprintModelSearch(id) + suspend fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch = mdcWebCoroutineScope { + bluePrintModelHandler.getBlueprintModelSearch(id) } @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono> = monoMdc { - bluePrintModelHandler.downloadBlueprintModelFile(id) - } + suspend fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity = + mdcWebCoroutineScope { + bluePrintModelHandler.downloadBlueprintModelFile(id) + } - @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType - .MULTIPART_FORM_DATA_VALUE]) + @PostMapping( + "/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType + .MULTIPART_FORM_DATA_VALUE] + ) @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono> = monoMdc { + suspend fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity = mdcWebCoroutineScope { bluePrintModelHandler.enrichBlueprint(file) } @@ -112,26 +181,31 @@ open class BlueprintModelController(private val bluePrintModelHandler: BluePrint @ResponseBody @Throws(BluePrintException::class) @PreAuthorize("hasRole('USER')") - fun publishBlueprint(@RequestPart("file") file: FilePart): Mono = monoMdc { + suspend fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = mdcWebCoroutineScope { 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) - } + suspend fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List = + mdcWebCoroutineScope { + 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) + @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 { + suspend 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 + ) = mdcWebCoroutineScope { bluePrintModelHandler.deleteBlueprintModel(name, version) } }