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(path = arrayOf("/bootstrap"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE),
51 consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE))
53 @Throws(BluePrintException::class)
54 @PreAuthorize("hasRole('USER')")
55 fun bootstrap(@RequestBody bootstrapRequest: BootstrapRequest): Mono<Unit> = monoMdc {
56 bluePrintModelHandler.bootstrapBlueprint(bootstrapRequest)
59 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
61 @Throws(BluePrintException::class)
62 @PreAuthorize("hasRole('USER')")
63 fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
64 bluePrintModelHandler.saveBlueprintModel(filePart)
67 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
69 @PreAuthorize("hasRole('USER')")
70 fun allBlueprintModel(): List<BlueprintModelSearch> {
71 return this.bluePrintModelHandler.allBlueprintModel()
74 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
76 @PreAuthorize("hasRole('USER')")
77 fun allBlueprintModel(@RequestParam(defaultValue = "20") limit: Int,
78 @RequestParam(defaultValue = "0") offset: Int,
79 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption): Page<BlueprintModelSearch> {
80 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
81 return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
84 @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
86 @PreAuthorize("hasRole('USER')")
87 fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> {
88 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
92 @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
94 @PreAuthorize("hasRole('USER')")
95 fun allBlueprintModelMetaDataPaged(@NotNull @PathVariable(value = "keyword") keyWord: String,
96 @RequestParam(defaultValue = "20") limit: Int,
97 @RequestParam(defaultValue = "0") offset: Int,
98 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption
99 ): Page<BlueprintModelSearch> {
100 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
101 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWordPaged(keyWord, pageRequest)
105 @DeleteMapping("/{id}")
106 @Throws(BluePrintException::class)
107 @PreAuthorize("hasRole('USER')")
108 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
109 this.bluePrintModelHandler.deleteBlueprintModel(id)
112 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
114 @Throws(BluePrintException::class)
115 @PreAuthorize("hasRole('USER')")
116 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
117 @PathVariable(value = "version") version: String)
118 : Mono<BlueprintModelSearch> = monoMdc {
119 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
122 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
124 @Throws(BluePrintException::class)
125 @PreAuthorize("hasRole('USER')")
126 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
127 @PathVariable(value = "version") version: String)
128 : Mono<ResponseEntity<Resource>> = monoMdc {
129 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
132 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
134 @Throws(BluePrintException::class)
135 @PreAuthorize("hasRole('USER')")
136 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
137 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
140 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
142 @Throws(BluePrintException::class)
143 @PreAuthorize("hasRole('USER')")
144 fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
145 bluePrintModelHandler.downloadBlueprintModelFile(id)
148 @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
149 .MULTIPART_FORM_DATA_VALUE])
151 @Throws(BluePrintException::class)
152 @PreAuthorize("hasRole('USER')")
153 fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
154 bluePrintModelHandler.enrichBlueprint(file)
157 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
159 @Throws(BluePrintException::class)
160 @PreAuthorize("hasRole('USER')")
161 fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
162 bluePrintModelHandler.publishBlueprint(file)
165 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
167 @PreAuthorize("hasRole('USER')")
168 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
169 return this.bluePrintModelHandler.searchBlueprintModels(tags)
172 @DeleteMapping("/name/{name}/version/{version}")
173 @ApiOperation(value = "Delete a CBA",
174 notes = "Delete the CBA package identified by its name and version.",
175 produces = MediaType.APPLICATION_JSON_VALUE)
176 @PreAuthorize("hasRole('USER')")
177 fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true)
178 @PathVariable(value = "name") name: String,
179 @ApiParam(value = "Version of the CBA.", required = true)
180 @PathVariable(value = "version") version: String) = monoMdc {
181 bluePrintModelHandler.deleteBlueprintModel(name, version)