6bcbae96383b3b071302e42409a626c0fb03e8b2
[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.ModelTypeService;\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\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/model-type")\r
32 public class ModelTypeRest {\r
33 \r
34     private ModelTypeService modelTypeService;\r
35 \r
36     /**\r
37      * This is a ModelTypeResourceImpl, used to save and get the model types stored in database\r
38      *\r
39      * @param modelTypeService Model Type Service\r
40      */\r
41     public ModelTypeRest(ModelTypeService modelTypeService) {\r
42         this.modelTypeService = modelTypeService;\r
43     }\r
44 \r
45     @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE)\r
46     public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException {\r
47         try {\r
48             return modelTypeService.getModelTypeByName(name);\r
49         } catch (Exception e) {\r
50             throw new BluePrintException(1000, e.getMessage(), e);\r
51         }\r
52     }\r
53 \r
54     @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)\r
55     public List<ModelType> searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException {\r
56         try {\r
57             return modelTypeService.searchModelTypes(tags);\r
58         } catch (Exception e) {\r
59             throw new BluePrintException(1001, e.getMessage(), e);\r
60         }\r
61     }\r
62 \r
63     @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE)\r
64     public @ResponseBody\r
65     List<ModelType> getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException {\r
66         try {\r
67             return modelTypeService.getModelTypeByDefinitionType(definitionType);\r
68         } catch (Exception e) {\r
69             throw new BluePrintException(1002, e.getMessage(), e);\r
70         }\r
71     }\r
72 \r
73     @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)\r
74     public @ResponseBody\r
75     ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException {\r
76         try {\r
77             return modelTypeService.saveModel(modelType);\r
78         } catch (Exception e) {\r
79             throw new BluePrintException(1100, e.getMessage(), e);\r
80         }\r
81     }\r
82 \r
83     @DeleteMapping(path = "/{name}")\r
84     public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException {\r
85         try {\r
86             modelTypeService.deleteByModelName(name);\r
87         } catch (Exception e) {\r
88             throw new BluePrintException(1400, e.getMessage(), e);\r
89         }\r
90     }\r
91 }\r