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.Flux
39 import reactor.core.publisher.Mono
40 import java.time.Duration
43 * BlueprintModelController Purpose: Handle controllerBlueprint API request
49 @RequestMapping("/api/v1/blueprint-model")
50 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
52 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
54 @Throws(BluePrintException::class)
55 @PreAuthorize("hasRole('USER')")
56 fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
57 bluePrintModelHandler.saveBlueprintModel(filePart)
60 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
62 @PreAuthorize("hasRole('USER')")
63 fun allBlueprintModel(): List<BlueprintModelSearch> {
64 return this.bluePrintModelHandler.allBlueprintModel()
67 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
69 @PreAuthorize("hasRole('USER')")
70 fun allBlueprintModel(@RequestParam(defaultValue = "20") limit: Int,
71 @RequestParam(defaultValue = "0") offset: Int,
72 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption): Page<BlueprintModelSearch> {
73 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
74 return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
77 @GetMapping("meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
79 @PreAuthorize("hasRole('USER')")
80 fun allBlueprintModelMetaData(@NotNull @PathVariable(value = "keyword") keyWord: String): List<BlueprintModelSearch> {
81 return this.bluePrintModelHandler.searchBluePrintModelsByKeyWord(keyWord)
85 @GetMapping("/paged/meta-data/{keyword}", produces = [MediaType.APPLICATION_JSON_VALUE])
87 @PreAuthorize("hasRole('USER')")
88 fun allBlueprintModelMetaDataPaged(@NotNull @PathVariable(value = "keyword") keyWord: String,
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.searchBluePrintModelsByKeyWordPaged(keyWord,pageRequest)
98 @DeleteMapping("/{id}")
99 @Throws(BluePrintException::class)
100 @PreAuthorize("hasRole('USER')")
101 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
102 this.bluePrintModelHandler.deleteBlueprintModel(id)
105 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
107 @Throws(BluePrintException::class)
108 @PreAuthorize("hasRole('USER')")
109 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
110 @PathVariable(value = "version") version: String)
111 : Mono<BlueprintModelSearch> = monoMdc {
112 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
115 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
117 @Throws(BluePrintException::class)
118 @PreAuthorize("hasRole('USER')")
119 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
120 @PathVariable(value = "version") version: String)
121 : Mono<ResponseEntity<Resource>> = monoMdc {
122 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
125 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
127 @Throws(BluePrintException::class)
128 @PreAuthorize("hasRole('USER')")
129 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
130 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
133 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
135 @Throws(BluePrintException::class)
136 @PreAuthorize("hasRole('USER')")
137 fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
138 bluePrintModelHandler.downloadBlueprintModelFile(id)
141 @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
142 .MULTIPART_FORM_DATA_VALUE])
144 @Throws(BluePrintException::class)
145 @PreAuthorize("hasRole('USER')")
146 fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
147 bluePrintModelHandler.enrichBlueprint(file)
150 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
152 @Throws(BluePrintException::class)
153 @PreAuthorize("hasRole('USER')")
154 fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
155 bluePrintModelHandler.publishBlueprint(file)
158 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
160 @PreAuthorize("hasRole('USER')")
161 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
162 return this.bluePrintModelHandler.searchBlueprintModels(tags)
165 @DeleteMapping("/name/{name}/version/{version}")
166 @ApiOperation(value = "Delete a CBA",
167 notes = "Delete the CBA package identified by its name and version.",
168 produces = MediaType.APPLICATION_JSON_VALUE)
169 @PreAuthorize("hasRole('USER')")
170 fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true)
171 @PathVariable(value = "name") name: String,
172 @ApiParam(value = "Version of the CBA.", required = true)
173 @PathVariable(value = "version") version: String) = monoMdc {
174 bluePrintModelHandler.deleteBlueprintModel(name, version)