94324a808be83be5d6db70dd3296a8a0cd4f721b
[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.stereotype.Component;\r
23 import org.springframework.stereotype.Service;\r
24 import org.springframework.web.bind.annotation.*;\r
25 \r
26 import java.util.List;\r
27 \r
28 /**\r
29  * {@inheritDoc}\r
30  */\r
31 @RestController\r
32 @RequestMapping("/api/v1/config-model")\r
33 public class ConfigModelRest {\r
34 \r
35     private ConfigModelService configModelService;\r
36 \r
37     /**\r
38      * This is a ConfigModelRest constructor.\r
39      *\r
40      * @param configModelService Config Model Service\r
41      */\r
42     public ConfigModelRest(ConfigModelService configModelService) {\r
43         this.configModelService = configModelService;\r
44 \r
45     }\r
46 \r
47     @GetMapping(path = "/initial/{name}")\r
48     public @ResponseBody\r
49     ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException {\r
50         try {\r
51             return this.configModelService.getInitialConfigModel(name);\r
52         } catch (Exception e) {\r
53             throw new BluePrintException(2000, e.getMessage(), e);\r
54         }\r
55     }\r
56 \r
57     @PostMapping(path = "/")\r
58     public @ResponseBody\r
59     ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException {\r
60         try {\r
61             return this.configModelService.saveConfigModel(configModel);\r
62         } catch (Exception e) {\r
63             throw new BluePrintException(2200, e.getMessage(), e);\r
64         }\r
65     }\r
66 \r
67     @DeleteMapping(path = "/{id}")\r
68     public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
69         try {\r
70             this.configModelService.deleteConfigModel(id);\r
71         } catch (Exception e) {\r
72             throw new BluePrintException(4000, e.getMessage(), e);\r
73         }\r
74     }\r
75 \r
76     @GetMapping(path = "/publish/{id}")\r
77     public @ResponseBody\r
78     ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
79         try {\r
80             return this.configModelService.publishConfigModel(id);\r
81         } catch (Exception e) {\r
82             throw new BluePrintException(2500, e.getMessage(), e);\r
83         }\r
84     }\r
85 \r
86     @GetMapping(path = "/{id}")\r
87     public @ResponseBody\r
88     ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
89         try {\r
90             return this.configModelService.getConfigModel(id);\r
91         } catch (Exception e) {\r
92             throw new BluePrintException(2001, e.getMessage(), e);\r
93         }\r
94     }\r
95 \r
96     @GetMapping(path = "/by-name/{name}/version/{version}")\r
97     public @ResponseBody\r
98     ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name,\r
99                                                @PathVariable(value = "version") String version) throws BluePrintException {\r
100         try {\r
101             return this.configModelService.getConfigModelByNameAndVersion(name, version);\r
102         } catch (Exception e) {\r
103             throw new BluePrintException(2002, e.getMessage(), e);\r
104         }\r
105     }\r
106 \r
107     @GetMapping(path = "/search/{tags}")\r
108     public @ResponseBody\r
109     List<ConfigModel> searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException {\r
110         try {\r
111             return this.configModelService.searchConfigModels(tags);\r
112         } catch (Exception e) {\r
113             throw new BluePrintException(2003, e.getMessage(), e);\r
114         }\r
115     }\r
116 \r
117     @GetMapping(path = "/clone/{id}")\r
118     public @ResponseBody\r
119     ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException {\r
120         try {\r
121             return this.configModelService.getCloneConfigModel(id);\r
122         } catch (Exception e) {\r
123             throw new BluePrintException(2004, e.getMessage(), e);\r
124         }\r
125     }\r
126 \r
127 }\r