795738cb160096c4dc18c739c6b7fc83eb1c6966
[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.ResourceDictionaryService;\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\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/dictionary")\r
32 public class ResourceDictionaryRest {\r
33 \r
34 \r
35     private ResourceDictionaryService resourceDictionaryService;\r
36 \r
37     /**\r
38      * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database\r
39      *\r
40      * @param dataDictionaryService Data Dictionary Service\r
41      */\r
42     public ResourceDictionaryRest(ResourceDictionaryService dataDictionaryService) {\r
43         this.resourceDictionaryService = dataDictionaryService;\r
44     }\r
45 \r
46     @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)\r
47     public @ResponseBody\r
48     ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary)\r
49             throws BluePrintException {\r
50         try {\r
51             return resourceDictionaryService.saveResourceDictionary(dataDictionary);\r
52         } catch (Exception e) {\r
53             throw new BluePrintException(4100, e.getMessage(), e);\r
54         }\r
55     }\r
56 \r
57     @DeleteMapping(path = "/{name}")\r
58     public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException {\r
59         try {\r
60             resourceDictionaryService.deleteResourceDictionary(name);\r
61         } catch (Exception e) {\r
62             throw new BluePrintException(4400, e.getMessage(), e);\r
63         }\r
64     }\r
65 \r
66     @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE)\r
67     public @ResponseBody\r
68     ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException {\r
69         try {\r
70             return resourceDictionaryService.getResourceDictionaryByName(name);\r
71         } catch (Exception e) {\r
72             throw new BluePrintException(4001, e.getMessage(), e);\r
73         }\r
74     }\r
75 \r
76     @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)\r
77     public @ResponseBody\r
78     List<ResourceDictionary> searchResourceDictionaryByNames(@RequestBody List<String> names)\r
79             throws BluePrintException {\r
80         try {\r
81             return resourceDictionaryService.searchResourceDictionaryByNames(names);\r
82         } catch (Exception e) {\r
83             throw new BluePrintException(4002, e.getMessage(), e);\r
84         }\r
85     }\r
86 \r
87     @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)\r
88     public @ResponseBody\r
89     List<ResourceDictionary> searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException {\r
90         try {\r
91             return resourceDictionaryService.searchResourceDictionaryByTags(tags);\r
92         } catch (Exception e) {\r
93             throw new BluePrintException(4003, e.getMessage(), e);\r
94         }\r
95     }\r
96 \r
97 }\r