124d29c275d84822fd1d1a30d0f3beb69df631d2
[clamp.git] / ui-react / src / api / TemplateService.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END============================================
19  * ===================================================================
20  *
21  */
22
23 export default class TemplateService {
24         static getTemplateNames() {
25                 return fetch('/restservices/clds/v2/templates/names', { method: 'GET', credentials: 'same-origin' })
26                         .then(function (response) {
27                                 console.debug("GetTemplateNames response received: ", response.status);
28                                 if (response.ok) {
29                                         return response.json();
30                                 } else {
31                                         console.error("GetTemplateNames query failed");
32                                         return {};
33                                 }
34                         })
35                         .catch(function (error) {
36                                 console.error("GetTemplateNames error received", error);
37                                 return {};
38                         });
39         }
40
41         static getBlueprintMicroServiceTemplates() {
42             return fetch('restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', })
43                 .then(function (response) {
44                     console.debug("getBlueprintMicroServiceTemplates response received: ", response.status);
45                     if (response.ok) {
46                         return response.json();
47                     } else {
48                         console.error("getBlueprintMicroServiceTemplates query failed");
49                         return {};
50                     }
51                 })
52                 .catch(function (error) {
53                     console.error("getBlueprintMicroServiceTemplates error received", error);
54                     return {};
55                 });
56             }
57         
58         static getDictionary() {
59             return fetch('restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', })
60               .then(function (response) {
61                 console.debug("getDictionary response received: ", response.status);
62                 if (response.ok) {
63                   return response.json();
64                 } else {
65                   console.error("getDictionary query failed");
66                   return {};
67                 }
68               })
69               .catch(function (error) {
70                 console.error("getDictionary error received", error);
71                 return {};
72               });
73           }
74
75           static getDictionaryElements(dictionaryName) {
76             return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
77               method: 'GET',
78               headers: {
79                 "Content-Type": "application/json",
80               },
81               credentials: 'same-origin',
82             })
83               .then(function (response) {
84                 console.debug("getDictionaryElements response received: ", response.status);
85                 if (response.ok) {
86                   return response.json();
87                 } else {
88                   console.error("getDictionaryElements query failed");
89                   return {};
90                 }
91               })
92               .catch(function (error) {
93                 console.error("getDictionaryElements error received", error);
94                 return {};
95               });
96           }
97
98           static insDictionary(jsonData) {
99             console.log("dictionaryName is", jsonData.name)
100             return fetch('/restservices/clds/v2/dictionary/', {
101               method: 'PUT',
102               credentials: 'same-origin',
103               headers: {
104                 "Content-Type": "application/json",
105               },
106               body: JSON.stringify(jsonData)
107             })
108               .then(function (response) {
109                 console.debug("insDictionary response received: ", response.status);
110                 if (response.ok) {
111                   return response.status;
112                 } else {
113                   var errorMessage = response.status;
114                   console.error("insDictionary query failed", response.status);
115                   return errorMessage;
116                 }
117               })
118               .catch(function (error) {
119                 console.error("insDictionary error received", error);
120                 return "";
121               });
122           }
123
124           static insDictionaryElements(jsonData) {
125             console.log("dictionaryName is", jsonData.name)
126             return fetch('/restservices/clds/v2/dictionary/' + jsonData.name, {
127               method: 'PUT',
128               credentials: 'same-origin',
129               headers: {
130                 "Content-Type": "application/json",
131               },
132               body: JSON.stringify(jsonData)
133             })
134               .then(function (response) {
135                 console.debug("insDictionary response received: ", response.status);
136                 if (response.ok) {
137                   return response.status;
138                 } else {
139                   var errorMessage = response.status;
140                   console.error("insDictionary query failed", response.status);
141                   return errorMessage;
142                 }
143               })
144               .catch(function (error) {
145                 console.error("insDictionary error received", error);
146                 return "";
147               });
148           }
149
150           static deleteDictionary(dictionaryName) {
151             console.log("inside templaemenu service", dictionaryName)
152             return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
153               method: 'DELETE',
154               headers: {
155                 "Content-Type": "application/json",
156               },
157               credentials: 'same-origin',
158             })
159               .then(function (response) {
160                 console.debug("deleteDictionary response received: ", response.status);
161                 if (response.ok) {
162                   return response.status;
163                 } else {
164                   console.error("deleteDictionary query failed");
165                   return {};
166                 }
167               })
168               .catch(function (error) {
169                 console.error("deleteDictionary error received", error);
170                 return {};
171               });
172           }
173
174           static deleteDictionaryElements(dictionaryData) {
175             return fetch('restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName , {
176               method: 'DELETE',
177               headers: {
178                 "Content-Type": "application/json",
179               },
180               credentials: 'same-origin',
181             })
182               .then(function (response) {
183                 console.debug("deleteDictionary response received: ", response.status);
184                 if (response.ok) {
185                   return response.status;
186                 } else {
187                   console.error("deleteDictionary query failed");
188                   return {};
189                 }
190               })
191               .catch(function (error) {
192                 console.error("deleteDictionary error received", error);
193                 return {};
194               });
195           }
196     }