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.rest.service.monoMdc
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
26 import org.springframework.core.io.Resource
27 import org.springframework.http.MediaType
28 import org.springframework.http.ResponseEntity
29 import org.springframework.http.codec.multipart.FilePart
30 import org.springframework.security.access.prepost.PreAuthorize
31 import org.springframework.web.bind.annotation.*
32 import reactor.core.publisher.Mono
35 * BlueprintModelController Purpose: Handle controllerBlueprint API request
41 @RequestMapping("/api/v1/blueprint-model")
42 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
44 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
46 @Throws(BluePrintException::class)
47 @PreAuthorize("hasRole('USER')")
48 fun saveBlueprint(@RequestPart("file") filePart: FilePart): Mono<BlueprintModelSearch> = monoMdc {
49 bluePrintModelHandler.saveBlueprintModel(filePart)
52 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
54 @PreAuthorize("hasRole('USER')")
55 fun allBlueprintModel(): List<BlueprintModelSearch> {
56 return this.bluePrintModelHandler.allBlueprintModel()
59 @DeleteMapping("/{id}")
60 @Throws(BluePrintException::class)
61 @PreAuthorize("hasRole('USER')")
62 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
63 this.bluePrintModelHandler.deleteBlueprintModel(id)
66 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
68 @Throws(BluePrintException::class)
69 @PreAuthorize("hasRole('USER')")
70 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
71 @PathVariable(value = "version") version: String)
72 : Mono<BlueprintModelSearch> = monoMdc {
73 bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
76 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
78 @Throws(BluePrintException::class)
79 @PreAuthorize("hasRole('USER')")
80 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
81 @PathVariable(value = "version") version: String)
82 : Mono<ResponseEntity<Resource>> = monoMdc {
83 bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
86 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
88 @Throws(BluePrintException::class)
89 @PreAuthorize("hasRole('USER')")
90 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
91 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
94 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
96 @Throws(BluePrintException::class)
97 @PreAuthorize("hasRole('USER')")
98 fun downloadBluePrint(@PathVariable(value = "id") id: String): Mono<ResponseEntity<Resource>> = monoMdc {
99 bluePrintModelHandler.downloadBlueprintModelFile(id)
102 @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
103 .MULTIPART_FORM_DATA_VALUE])
105 @Throws(BluePrintException::class)
106 @PreAuthorize("hasRole('USER')")
107 fun enrichBlueprint(@RequestPart("file") file: FilePart): Mono<ResponseEntity<Resource>> = monoMdc {
108 bluePrintModelHandler.enrichBlueprint(file)
111 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
113 @Throws(BluePrintException::class)
114 @PreAuthorize("hasRole('USER')")
115 fun publishBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> = monoMdc {
116 bluePrintModelHandler.publishBlueprint(file)
119 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
121 @PreAuthorize("hasRole('USER')")
122 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
123 return this.bluePrintModelHandler.searchBlueprintModels(tags)
126 @DeleteMapping("/name/{name}/version/{version}")
127 @ApiOperation(value = "Delete a CBA",
128 notes = "Delete the CBA package identified by its name and version.",
129 produces = MediaType.APPLICATION_JSON_VALUE)
130 @PreAuthorize("hasRole('USER')")
131 fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true)
132 @PathVariable(value = "name") name: String,
133 @ApiParam(value = "Version of the CBA.", required = true)
134 @PathVariable(value = "version") version: String) = monoMdc {
135 bluePrintModelHandler.deleteBlueprintModel(name, version)