2 * Copyright © 2019 Bell Canada Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.service.controller
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
20 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch
21 import org.onap.ccsdk.apps.controllerblueprints.service.handler.BluePrintModelHandler
22 import org.springframework.core.io.Resource
23 import org.springframework.http.MediaType
24 import org.springframework.http.ResponseEntity
25 import org.springframework.http.codec.multipart.FilePart
26 import org.springframework.web.bind.annotation.*
27 import reactor.core.publisher.Mono
30 * BlueprintModelRest Purpose: Handle controllerBlueprint API request
36 @RequestMapping("/api/v1/blueprint-model")
37 open class BlueprintModelRest(private val bluePrintModelHandler: BluePrintModelHandler) {
39 @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
41 @Throws(BluePrintException::class)
42 fun saveBlueprint(@RequestPart("file") file: FilePart): Mono<BlueprintModelSearch> {
43 return bluePrintModelHandler.saveBlueprintModel(file)
46 @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])
48 fun allBlueprintModel(): List<BlueprintModelSearch> {
49 return this.bluePrintModelHandler.allBlueprintModel()
52 @DeleteMapping("/{id}")
53 @Throws(BluePrintException::class)
54 fun deleteBlueprint(@PathVariable(value = "id") id: String) {
55 this.bluePrintModelHandler.deleteBlueprintModel(id)
58 @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
60 @Throws(BluePrintException::class)
61 fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
62 @PathVariable(value = "version") version: String): BlueprintModelSearch {
63 return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version)
66 @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE])
68 @Throws(BluePrintException::class)
69 fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String,
70 @PathVariable(value = "version") version: String): ResponseEntity<Resource> {
71 return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version)
74 @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
76 @Throws(BluePrintException::class)
77 fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
78 return this.bluePrintModelHandler.getBlueprintModelSearch(id)
81 @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
83 @Throws(BluePrintException::class)
84 fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity<Resource> {
85 return this.bluePrintModelHandler.downloadBlueprintModelFile(id)
88 @PutMapping("/publish/{id}", produces = [MediaType.APPLICATION_JSON_VALUE])
90 @Throws(BluePrintException::class)
91 fun publishBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch {
92 return this.bluePrintModelHandler.publishBlueprintModel(id)
95 @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE])
97 fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List<BlueprintModelSearch> {
98 return this.bluePrintModelHandler.searchBlueprintModels(tags)