blob: 7d8a3400efeb82b0c6a393e786ec61a99a42e5b5 [file] [log] [blame]
sebdetaa486be2020-02-18 02:00:11 -08001/*-
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
23export default class TemplateService {
sebdetaa486be2020-02-18 02:00:11 -080024
Ted Humphrey083e5a22020-07-08 16:48:40 -040025 static getLoopNames() {
26 return fetch('/restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' })
27 .then(function (response) {
28 console.debug("getLoopNames response received: ", response.status);
29 if (response.ok) {
30 return response.json();
31 } else {
32 console.error("getLoopNames query failed");
33 return {};
34 }
35 })
36 .catch(function (error) {
37 console.error("getLoopNames error received", error);
38 return {};
39 });
40 }
41
sebdetc0ec0fc2020-05-18 12:31:11 +020042 static getAllLoopTemplates() {
drveerendra50320952020-03-04 20:30:44 -050043 return fetch('restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', })
44 .then(function (response) {
sebdetc0ec0fc2020-05-18 12:31:11 +020045 console.debug("getAllLoopTemplates response received: ", response.status);
drveerendra50320952020-03-04 20:30:44 -050046 if (response.ok) {
47 return response.json();
48 } else {
sebdetc0ec0fc2020-05-18 12:31:11 +020049 console.error("getAllLoopTemplates query failed");
drveerendra50320952020-03-04 20:30:44 -050050 return {};
51 }
52 })
53 .catch(function (error) {
sebdetc0ec0fc2020-05-18 12:31:11 +020054 console.error("getAllLoopTemplates error received", error);
drveerendra50320952020-03-04 20:30:44 -050055 return {};
56 });
57 }
jingjincs3173d552020-03-04 09:11:10 +010058
drveerendra50320952020-03-04 20:30:44 -050059 static getDictionary() {
60 return fetch('restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', })
61 .then(function (response) {
62 console.debug("getDictionary response received: ", response.status);
63 if (response.ok) {
64 return response.json();
65 } else {
66 console.error("getDictionary query failed");
67 return {};
68 }
69 })
70 .catch(function (error) {
71 console.error("getDictionary error received", error);
72 return {};
73 });
74 }
75
76 static getDictionaryElements(dictionaryName) {
77 return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
78 method: 'GET',
79 headers: {
80 "Content-Type": "application/json",
81 },
82 credentials: 'same-origin',
83 })
84 .then(function (response) {
85 console.debug("getDictionaryElements response received: ", response.status);
86 if (response.ok) {
87 return response.json();
88 } else {
89 console.error("getDictionaryElements query failed");
90 return {};
91 }
92 })
93 .catch(function (error) {
94 console.error("getDictionaryElements error received", error);
95 return {};
96 });
97 }
98
99 static insDictionary(jsonData) {
100 console.log("dictionaryName is", jsonData.name)
101 return fetch('/restservices/clds/v2/dictionary/', {
102 method: 'PUT',
103 credentials: 'same-origin',
104 headers: {
105 "Content-Type": "application/json",
106 },
107 body: JSON.stringify(jsonData)
108 })
109 .then(function (response) {
110 console.debug("insDictionary response received: ", response.status);
111 if (response.ok) {
112 return response.status;
113 } else {
114 var errorMessage = response.status;
115 console.error("insDictionary query failed", response.status);
116 return errorMessage;
117 }
118 })
119 .catch(function (error) {
120 console.error("insDictionary error received", error);
121 return "";
122 });
123 }
124
125 static insDictionaryElements(jsonData) {
126 console.log("dictionaryName is", jsonData.name)
127 return fetch('/restservices/clds/v2/dictionary/' + jsonData.name, {
128 method: 'PUT',
129 credentials: 'same-origin',
130 headers: {
131 "Content-Type": "application/json",
132 },
133 body: JSON.stringify(jsonData)
134 })
135 .then(function (response) {
136 console.debug("insDictionary response received: ", response.status);
137 if (response.ok) {
138 return response.status;
139 } else {
140 var errorMessage = response.status;
141 console.error("insDictionary query failed", response.status);
142 return errorMessage;
143 }
144 })
145 .catch(function (error) {
146 console.error("insDictionary error received", error);
147 return "";
148 });
149 }
150
151 static deleteDictionary(dictionaryName) {
152 console.log("inside templaemenu service", dictionaryName)
153 return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
154 method: 'DELETE',
155 headers: {
156 "Content-Type": "application/json",
157 },
158 credentials: 'same-origin',
159 })
160 .then(function (response) {
161 console.debug("deleteDictionary response received: ", response.status);
162 if (response.ok) {
163 return response.status;
164 } else {
165 console.error("deleteDictionary query failed");
166 return {};
167 }
168 })
169 .catch(function (error) {
170 console.error("deleteDictionary error received", error);
171 return {};
172 });
173 }
174
175 static deleteDictionaryElements(dictionaryData) {
176 return fetch('restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName , {
177 method: 'DELETE',
178 headers: {
179 "Content-Type": "application/json",
180 },
181 credentials: 'same-origin',
182 })
183 .then(function (response) {
184 console.debug("deleteDictionary response received: ", response.status);
185 if (response.ok) {
186 return response.status;
187 } else {
188 console.error("deleteDictionary query failed");
189 return {};
190 }
191 })
192 .catch(function (error) {
193 console.error("deleteDictionary error received", error);
194 return {};
195 });
196 }
197 }