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 kotlinx.coroutines.runBlocking
23 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModelSearch
24 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.BluePrintModelHandler
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.*
34 * BlueprintModelController Purpose: Handle controllerBlueprint API request
40 @RequestMapping("/api/v1/blueprint-model")
41 open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) {
43 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
45 @Throws(BluePrintException::class)
46 @PreAuthorize("hasRole('USER')")
47 fun saveBlueprint(@RequestPart("file") filePart: FilePart): BlueprintModelSearch = runBlocking {
48 bluePrintModelHandler.saveBlueprintModel(filePart)
51 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
53 @PreAuthorize("hasRole('USER')")
54 fun allBlueprintModel(): List<BlueprintModelSearch> {
55 return this.bluePrintModelHandler.allBlueprintModel()
58 @DeleteMapping("/{id}")
59 @Throws(BluePrintException::class)
60 @PreAuthorize("hasRole('USER')")
61 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
62 this.bluePrintModelHandler.deleteBlueprintModel(id)
65 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
67 @Throws(BluePrintException::class)
68 @PreAuthorize("hasRole('USER')")
69 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
70 @PathVariable(value = "version") version: String): BlueprintModelSearch {
71 return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
74 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
76 @Throws(BluePrintException::class)
77 @PreAuthorize("hasRole('USER')")
78 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
79 @PathVariable(value = "version") version: String): ResponseEntity<Resource> {
80 return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
83 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
85 @Throws(BluePrintException::class)
86 @PreAuthorize("hasRole('USER')")
87 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
88 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
91 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
93 @Throws(BluePrintException::class)
94 @PreAuthorize("hasRole('USER')")
95 fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> {
96 return this.bluePrintModelHandler.downloadBlueprintModelFile(id)
99 @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType
100 .MULTIPART_FORM_DATA_VALUE])
102 @Throws(BluePrintException::class)
103 @PreAuthorize("hasRole('USER')")
104 fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity<Resource> = runBlocking {
105 bluePrintModelHandler.enrichBlueprint(file)
108 @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE])
110 @Throws(BluePrintException::class)
111 @PreAuthorize("hasRole('USER')")
112 fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking {
113 bluePrintModelHandler.publishBlueprint(file)
116 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
118 @PreAuthorize("hasRole('USER')")
119 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
120 return this.bluePrintModelHandler.searchBlueprintModels(tags)
123 @DeleteMapping("/name/{name}/version/{version}")
124 @ApiOperation(value = "Delete a CBA",
125 notes = "Delete the CBA package identified by its name and version.",
126 produces = MediaType.APPLICATION_JSON_VALUE)
127 @PreAuthorize("hasRole('USER')")
128 fun deleteBlueprint(@ApiParam(value = "Name of the CBA.", required = true)
129 @PathVariable(value = "name") name: String,
130 @ApiParam(value = "Version of the CBA.", required = true)
131 @PathVariable(value = "version") version: String) = runBlocking {
132 bluePrintModelHandler.deleteBlueprintModel(name, version)