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