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.DeleteMapping
38 import org.springframework.web.bind.annotation.GetMapping
39 import org.springframework.web.bind.annotation.PathVariable
40 import org.springframework.web.bind.annotation.PostMapping
41 import org.springframework.web.bind.annotation.RequestBody
42 import org.springframework.web.bind.annotation.RequestMapping
43 import org.springframework.web.bind.annotation.RequestParam
44 import org.springframework.web.bind.annotation.RequestPart
45 import org.springframework.web.bind.annotation.ResponseBody
46 import org.springframework.web.bind.annotation.RestController
47 import reactor.core.publisher.Mono
50 * BlueprintModelController Purpose: Handle controllerBlueprint API request
56 @RequestMapping("/api/v1/blueprint-model")
57 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
60 path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE),
61 consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)
64 @Throws(BluePrintException::class)
65 @PreAuthorize("hasRole('USER')")
66 fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Mono<Unit> = monoMdc {
67 bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest)
70 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
72 @Throws(BluePrintException::class)
73 @PreAuthorize("hasRole('USER')")
74 fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
75 bluePrintModelHandler.saveBlueprintModel(filePart)
78 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
80 @PreAuthorize("hasRole('USER')")
81 fun allBlueprintModel(): List<BlueprintModelSearch> {
82 return this.bluePrintModelHandler.allBlueprintModel()
85 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
87 @PreAuthorize("hasRole('USER')")
88 fun allBlueprintModel(
89 @RequestParam(defaultValue = "20") limit: Int,
90 @RequestParam(defaultValue = "0") offset: Int,
91 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption
92 ): Page<BlueprintModelSearch> {
93 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
94 return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
97 @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
99 @PreAuthorize("hasRole('USER')")
100 fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> {
101 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
104 @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
106 @PreAuthorize("hasRole('USER')")
107 fun allBlueprintModelMetaDataPaged(
108 @NotNull @PathVariable(value = "keyword") keyWord: String,
109 @RequestParam(defaultValue = "20") limit: Int,
110 @RequestParam(defaultValue = "0") offset: Int,
111 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption
112 ): Page<BlueprintModelSearch> {
113 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
114 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWordPaged(keyWord, pageRequest)
117 @DeleteMapping("/{id}")
118 @Throws(BluePrintException::class)
119 @PreAuthorize("hasRole('USER')")
120 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
121 this.bluePrintModelHandler.deleteBlueprintModel(id)
124 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
126 @Throws(BluePrintException::class)
127 @PreAuthorize("hasRole('USER')")
128 fun getBlueprintByNameAndVersion(
129 @PathVariable(value = "name") name: String,
130 @PathVariable(value = "version") version: String
132 Mono<BlueprintModelSearch> = monoMdc {
133 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
136 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
138 @Throws(BluePrintException::class)
139 @PreAuthorize("hasRole('USER')")
140 fun downloadBlueprintByNameAndVersion(
141 @PathVariable(value = "name") name: String,
142 @PathVariable(value = "version") version: String
144 Mono<ResponseEntity<Resource>> = monoMdc {
145 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
148 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
150 @Throws(BluePrintException::class)
151 @PreAuthorize("hasRole('USER')")
152 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
153 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
156 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
158 @Throws(BluePrintException::class)
159 @PreAuthorize("hasRole('USER')")
160 fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
161 bluePrintModelHandler.downloadBlueprintModelFile(id)
165 "/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
166 .MULTIPART_FORM_DATA_VALUE]
169 @Throws(BluePrintException::class)
170 @PreAuthorize("hasRole('USER')")
171 fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
172 bluePrintModelHandler.enrichBlueprint(file)
175 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
177 @Throws(BluePrintException::class)
178 @PreAuthorize("hasRole('USER')")
179 fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
180 bluePrintModelHandler.publishBlueprint(file)
183 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
185 @PreAuthorize("hasRole('USER')")
186 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
187 return this.bluePrintModelHandler.searchBlueprintModels(tags)
190 @DeleteMapping("/name/{name}/version/{version}")
192 value = "Delete a CBA",
193 notes = "Delete the CBA package identified by its name and version.",
194 produces = MediaType.APPLICATION_JSON_VALUE
196 @PreAuthorize("hasRole('USER')")
198 @ApiParam(value = "Name of the CBA.", required = true)
199 @PathVariable(value = "name") name: String,
200 @ApiParam(value = "Version of the CBA.", required = true)
201 @PathVariable(value = "version") version: String
203 bluePrintModelHandler.deleteBlueprintModel(name, version)