2 * Copyright © 2019 Bell Canada Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
4 * Modifications Copyright © 2019 Orange.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
21 import io.swagger.annotations.ApiOperation
22 import io.swagger.annotations.ApiParam
23 import org.jetbrains.annotations.NotNull
24 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
25 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
26 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
27 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.monoMdc
28 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
29 import org.springframework.core.io.Resource
30 import org.springframework.data.domain.Page
31 import org.springframework.data.domain.PageRequest
32 import org.springframework.data.domain.Sort
33 import org.springframework.http.MediaType
34 import org.springframework.http.ResponseEntity
35 import org.springframework.http.codec.multipart.FilePart
36 import org.springframework.security.access.prepost.PreAuthorize
37 import org.springframework.web.bind.annotation.*
38 import reactor.core.publisher.Mono
41 * BlueprintModelController Purpose: Handle controllerBlueprint API request
47 @RequestMapping("/api/v1/blueprint-model")
48 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
50 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
52 @Throws(BluePrintException::class)
53 @PreAuthorize("hasRole('USER')")
54 fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
55 bluePrintModelHandler.saveBlueprintModel(filePart)
58 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
60 @PreAuthorize("hasRole('USER')")
61 fun allBlueprintModel(): List<BlueprintModelSearch> {
62 return this.bluePrintModelHandler.allBlueprintModel()
65 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
67 @PreAuthorize("hasRole('USER')")
68 fun allBlueprintModel(@RequestParam(defaultValue = "20") limit: Int,
69 @RequestParam(defaultValue = "0") offset: Int,
70 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption): Page<BlueprintModelSearch> {
71 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
72 return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
75 @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
77 @PreAuthorize("hasRole('USER')")
78 fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> {
79 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
83 @DeleteMapping("/{id}")
84 @Throws(BluePrintException::class)
85 @PreAuthorize("hasRole('USER')")
86 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
87 this.bluePrintModelHandler.deleteBlueprintModel(id)
90 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
92 @Throws(BluePrintException::class)
93 @PreAuthorize("hasRole('USER')")
94 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
95 @PathVariable(value = "version") version: String)
96 : Mono<BlueprintModelSearch> = monoMdc {
97 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
100 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
102 @Throws(BluePrintException::class)
103 @PreAuthorize("hasRole('USER')")
104 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
105 @PathVariable(value = "version") version: String)
106 : Mono<ResponseEntity<Resource>> = monoMdc {
107 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
110 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
112 @Throws(BluePrintException::class)
113 @PreAuthorize("hasRole('USER')")
114 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
115 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
118 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
120 @Throws(BluePrintException::class)
121 @PreAuthorize("hasRole('USER')")
122 fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
123 bluePrintModelHandler.downloadBlueprintModelFile(id)
126 @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
127 .MULTIPART_FORM_DATA_VALUE])
129 @Throws(BluePrintException::class)
130 @PreAuthorize("hasRole('USER')")
131 fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
132 bluePrintModelHandler.enrichBlueprint(file)
135 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
137 @Throws(BluePrintException::class)
138 @PreAuthorize("hasRole('USER')")
139 fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
140 bluePrintModelHandler.publishBlueprint(file)
143 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
145 @PreAuthorize("hasRole('USER')")
146 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
147 return this.bluePrintModelHandler.searchBlueprintModels(tags)
150 @DeleteMapping("/name/{name}/version/{version}")
151 @ApiOperation(value = "Delete a CBA",
152 notes = "Delete the CBA package identified by its name and version.",
153 produces = MediaType.APPLICATION_JSON_VALUE)
154 @PreAuthorize("hasRole('USER')")
155 fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true)
156 @PathVariable(value = "name") name: String,
157 @ApiParam(value = "Version of the CBA.", required = true)
158 @PathVariable(value = "version") version: String) = monoMdc {
159 bluePrintModelHandler.deleteBlueprintModel(name, version)