62b6830328990296e944cf4bf5548abf0cfd3b7d
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
18 \r
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
20 import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService;\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
22 import org.springframework.http.MediaType;\r
23 import org.springframework.web.bind.annotation.*;\r
24 \r
25 import java.util.List;\r
26 \r
27 /**\r
28  * {@inheritDoc}\r
29  */\r
30 @RestController\r
31 @RequestMapping(value = "/api/v1/config-model")\r
32 public class ConfigModelRest {\r
33 \r
34     private ConfigModelService configModelService;\r
35 \r
36     /**\r
37      * This is a ConfigModelRest constructor.\r
38      *\r
39      * @param configModelService Config Model Service\r
40      */\r
41     public ConfigModelRest(ConfigModelService configModelService) {\r
42         this.configModelService = configModelService;\r
43 \r
44     }\r
45 \r
46     @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE)\r
47     public @ResponseBody\r
48     ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException {\r
49         try {\r
50             return this.configModelService.getInitialConfigModel(name);\r
51         } catch (Exception e) {\r
52             throw new BluePrintException(2000, e.getMessage(), e);\r
53         }\r
54     }\r
55 \r
56     @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)\r
57     public @ResponseBody\r
58     ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException {\r
59         try {\r
60             return this.configModelService.saveConfigModel(configModel);\r
61         } catch (Exception e) {\r
62             throw new BluePrintException(2200, e.getMessage(), e);\r
63         }\r
64     }\r
65 \r
66     @DeleteMapping(path = "/{id}")\r
67     public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
68         try {\r
69             this.configModelService.deleteConfigModel(id);\r
70         } catch (Exception e) {\r
71             throw new BluePrintException(2400, e.getMessage(), e);\r
72         }\r
73     }\r
74 \r
75     @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
76     public @ResponseBody\r
77     ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
78         try {\r
79             return this.configModelService.publishConfigModel(id);\r
80         } catch (Exception e) {\r
81             throw new BluePrintException(2500, e.getMessage(), e);\r
82         }\r
83     }\r
84 \r
85     @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
86     public @ResponseBody\r
87     ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
88         try {\r
89             return this.configModelService.getConfigModel(id);\r
90         } catch (Exception e) {\r
91             throw new BluePrintException(2001, e.getMessage(), e);\r
92         }\r
93     }\r
94 \r
95     @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE)\r
96     public @ResponseBody\r
97     ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name,\r
98                                                @PathVariable(value = "version") String version) throws BluePrintException {\r
99         try {\r
100             return this.configModelService.getConfigModelByNameAndVersion(name, version);\r
101         } catch (Exception e) {\r
102             throw new BluePrintException(2002, e.getMessage(), e);\r
103         }\r
104     }\r
105 \r
106     @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)\r
107     public @ResponseBody\r
108     List<ConfigModel> searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException {\r
109         try {\r
110             return this.configModelService.searchConfigModels(tags);\r
111         } catch (Exception e) {\r
112             throw new BluePrintException(2003, e.getMessage(), e);\r
113         }\r
114     }\r
115 \r
116     @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE)\r
117     public @ResponseBody\r
118     ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
119         try {\r
120             return this.configModelService.getCloneConfigModel(id);\r
121         } catch (Exception e) {\r
122             throw new BluePrintException(2004, e.getMessage(), e);\r
123         }\r
124     }\r
125 \r
126 }\r