9d0b1e3e4b2abb19f0925f44c60be8b060c6ed22
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2019 Bell Canada.\r
4  *\r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  *\r
9  *     http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
19 \r
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.BlueprintModelService;\r
22 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch;\r
23 import org.springframework.beans.factory.annotation.Autowired;\r
24 import org.springframework.core.io.Resource;\r
25 import org.springframework.http.MediaType;\r
26 import org.springframework.http.ResponseEntity;\r
27 import org.springframework.http.codec.multipart.FilePart;\r
28 import org.springframework.web.bind.annotation.*;\r
29 import reactor.core.publisher.Mono;\r
30 \r
31 import java.util.List;\r
32 \r
33 /**\r
34  * {@inheritDoc}\r
35  */\r
36 @RestController\r
37 @RequestMapping(value = "/api/v1/blueprint-model")\r
38 public class BlueprintModelRest {\r
39 \r
40     @Autowired\r
41     private BlueprintModelService blueprintModelService;\r
42 \r
43     @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)\r
44     public @ResponseBody\r
45     Mono<BlueprintModelSearch> saveBluePrint(@RequestPart("file") FilePart file) throws BluePrintException{\r
46         return blueprintModelService.saveBlueprintModel(file);\r
47     }\r
48 \r
49     @DeleteMapping(path = "/{id}")\r
50     public void deleteBluePrint(@PathVariable(value = "id") String id) throws BluePrintException {\r
51         this.blueprintModelService.deleteBlueprintModel(id);\r
52     }\r
53 \r
54     @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
55     public @ResponseBody\r
56     BlueprintModelSearch getBluePrintByNameAndVersion(@PathVariable(value = "name") String name,\r
57                                                           @PathVariable(value = "version") String version) throws BluePrintException {\r
58         return this.blueprintModelService.getBlueprintModelByNameAndVersion(name, version);\r
59     }\r
60 \r
61     @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
62     public @ResponseBody\r
63     BlueprintModelSearch getCBA(@PathVariable(value = "id") String id) throws BluePrintException {\r
64         return this.blueprintModelService.getBlueprintModelSearch(id);\r
65     }\r
66 \r
67     @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)\r
68     public @ResponseBody\r
69     List<BlueprintModelSearch> getAllCBA() {\r
70         return this.blueprintModelService.getAllBlueprintModel();\r
71     }\r
72 \r
73     @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
74     public @ResponseBody\r
75     ResponseEntity<Resource> downloadBluePrint(@PathVariable(value = "id") String id) throws BluePrintException {\r
76         return this.blueprintModelService.downloadBlueprintModelFile(id);\r
77     }\r
78 \r
79     @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
80     public @ResponseBody\r
81     BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException {\r
82         return this.blueprintModelService.publishBlueprintModel(id);\r
83     }\r
84 \r
85     @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)\r
86     public @ResponseBody\r
87     List<BlueprintModelSearch> searchBlueprintModels(@PathVariable(value = "tags") String tags) {\r
88         return this.blueprintModelService.searchBlueprintModels(tags);\r
89     }\r
90 }\r