2 * Copyright © 2019 Bell Canada Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
20 import io.swagger.annotations.ApiOperation
21 import io.swagger.annotations.ApiParam
22 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
23 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
24 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.utils.BlueprintSortByOption
25 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.monoMdc
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
27 import org.springframework.core.io.Resource
28 import org.springframework.data.domain.Page
29 import org.springframework.data.domain.PageRequest
30 import org.springframework.data.domain.Sort
31 import org.springframework.http.MediaType
32 import org.springframework.http.ResponseEntity
33 import org.springframework.http.codec.multipart.FilePart
34 import org.springframework.security.access.prepost.PreAuthorize
35 import org.springframework.web.bind.annotation.*
36 import reactor.core.publisher.Mono
39 * BlueprintModelController Purpose: Handle controllerBlueprint API request
45 @RequestMapping("/api/v1/blueprint-model")
46 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
48 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
50 @Throws(BluePrintException::class)
51 @PreAuthorize("hasRole('USER')")
52 fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
53 bluePrintModelHandler.saveBlueprintModel(filePart)
56 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
58 @PreAuthorize("hasRole('USER')")
59 fun allBlueprintModel(): List<BlueprintModelSearch> {
60 return this.bluePrintModelHandler.allBlueprintModel()
63 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
65 @PreAuthorize("hasRole('USER')")
66 fun allBlueprintModel(@RequestParam(defaultValue = "20") limit: Int,
67 @RequestParam(defaultValue = "0") offset: Int,
68 @RequestParam(defaultValue = "DATE") sort: BlueprintSortByOption): Page<BlueprintModelSearch> {
69 val pageRequest = PageRequest.of(offset, limit, Sort.Direction.ASC, sort.columnName)
70 return this.bluePrintModelHandler.allBlueprintModel(pageRequest)
73 @DeleteMapping("/{id}")
74 @Throws(BluePrintException::class)
75 @PreAuthorize("hasRole('USER')")
76 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
77 this.bluePrintModelHandler.deleteBlueprintModel(id)
80 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
82 @Throws(BluePrintException::class)
83 @PreAuthorize("hasRole('USER')")
84 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
85 @PathVariable(value = "version") version: String)
86 : Mono<BlueprintModelSearch> = monoMdc {
87 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
90 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
92 @Throws(BluePrintException::class)
93 @PreAuthorize("hasRole('USER')")
94 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
95 @PathVariable(value = "version") version: String)
96 : Mono<ResponseEntity<Resource>> = monoMdc {
97 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
100 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
102 @Throws(BluePrintException::class)
103 @PreAuthorize("hasRole('USER')")
104 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
105 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
108 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
110 @Throws(BluePrintException::class)
111 @PreAuthorize("hasRole('USER')")
112 fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
113 bluePrintModelHandler.downloadBlueprintModelFile(id)
116 @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
117 .MULTIPART_FORM_DATA_VALUE])
119 @Throws(BluePrintException::class)
120 @PreAuthorize("hasRole('USER')")
121 fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
122 bluePrintModelHandler.enrichBlueprint(file)
125 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
127 @Throws(BluePrintException::class)
128 @PreAuthorize("hasRole('USER')")
129 fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
130 bluePrintModelHandler.publishBlueprint(file)
133 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
135 @PreAuthorize("hasRole('USER')")
136 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
137 return this.bluePrintModelHandler.searchBlueprintModels(tags)
140 @DeleteMapping("/name/{name}/version/{version}")
141 @ApiOperation(value = "Delete a CBA",
142 notes = "Delete the CBA package identified by its name and version.",
143 produces = MediaType.APPLICATION_JSON_VALUE)
144 @PreAuthorize("hasRole('USER')")
145 fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true)
146 @PathVariable(value = "name") name: String,
147 @ApiParam(value = "Version of the CBA.", required = true)
148 @PathVariable(value = "version") version: String) = monoMdc {
149 bluePrintModelHandler.deleteBlueprintModel(name, version)