blob: eddd58dff1c96dd61a061bf22706824ecfe1116e [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 {
sebdetd2a4df02020-02-26 15:47:30 -080024 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 }
sebdetaa486be2020-02-18 02:00:11 -080040
drveerendra50320952020-03-04 20:30:44 -050041 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 }
jingjincs3173d552020-03-04 09:11:10 +010057
sebdet84242152020-04-02 15:31:34 +020058 static getBlueprintMicroServiceTemplateSvg(templateName) {
jingjincs3173d552020-03-04 09:11:10 +010059 return fetch('/restservices/clds/v2/templates/' + templateName + ' /svgRepresentation', { method: 'GET', credentials: 'same-origin', })
60 .then(function (response) {
sebdet84242152020-04-02 15:31:34 +020061 console.debug("getBlueprintMicroServiceTemplateSvg response received: ", response.status);
jingjincs3173d552020-03-04 09:11:10 +010062 if (response.ok) {
63 return response.text();
64 } else {
sebdet84242152020-04-02 15:31:34 +020065 console.error("getBlueprintMicroServiceTemplateSvg query failed");
jingjincs3173d552020-03-04 09:11:10 +010066 return {};
67 }
68 })
69 .catch(function (error) {
sebdet84242152020-04-02 15:31:34 +020070 console.error("getBlueprintMicroServiceTemplateSvg error received", error);
jingjincs3173d552020-03-04 09:11:10 +010071 return {};
72 });
73 }
drveerendra50320952020-03-04 20:30:44 -050074
75 static getDictionary() {
76 return fetch('restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', })
77 .then(function (response) {
78 console.debug("getDictionary response received: ", response.status);
79 if (response.ok) {
80 return response.json();
81 } else {
82 console.error("getDictionary query failed");
83 return {};
84 }
85 })
86 .catch(function (error) {
87 console.error("getDictionary error received", error);
88 return {};
89 });
90 }
91
92 static getDictionaryElements(dictionaryName) {
93 return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
94 method: 'GET',
95 headers: {
96 "Content-Type": "application/json",
97 },
98 credentials: 'same-origin',
99 })
100 .then(function (response) {
101 console.debug("getDictionaryElements response received: ", response.status);
102 if (response.ok) {
103 return response.json();
104 } else {
105 console.error("getDictionaryElements query failed");
106 return {};
107 }
108 })
109 .catch(function (error) {
110 console.error("getDictionaryElements error received", error);
111 return {};
112 });
113 }
114
115 static insDictionary(jsonData) {
116 console.log("dictionaryName is", jsonData.name)
117 return fetch('/restservices/clds/v2/dictionary/', {
118 method: 'PUT',
119 credentials: 'same-origin',
120 headers: {
121 "Content-Type": "application/json",
122 },
123 body: JSON.stringify(jsonData)
124 })
125 .then(function (response) {
126 console.debug("insDictionary response received: ", response.status);
127 if (response.ok) {
128 return response.status;
129 } else {
130 var errorMessage = response.status;
131 console.error("insDictionary query failed", response.status);
132 return errorMessage;
133 }
134 })
135 .catch(function (error) {
136 console.error("insDictionary error received", error);
137 return "";
138 });
139 }
140
141 static insDictionaryElements(jsonData) {
142 console.log("dictionaryName is", jsonData.name)
143 return fetch('/restservices/clds/v2/dictionary/' + jsonData.name, {
144 method: 'PUT',
145 credentials: 'same-origin',
146 headers: {
147 "Content-Type": "application/json",
148 },
149 body: JSON.stringify(jsonData)
150 })
151 .then(function (response) {
152 console.debug("insDictionary response received: ", response.status);
153 if (response.ok) {
154 return response.status;
155 } else {
156 var errorMessage = response.status;
157 console.error("insDictionary query failed", response.status);
158 return errorMessage;
159 }
160 })
161 .catch(function (error) {
162 console.error("insDictionary error received", error);
163 return "";
164 });
165 }
166
167 static deleteDictionary(dictionaryName) {
168 console.log("inside templaemenu service", dictionaryName)
169 return fetch('restservices/clds/v2/dictionary/' + dictionaryName, {
170 method: 'DELETE',
171 headers: {
172 "Content-Type": "application/json",
173 },
174 credentials: 'same-origin',
175 })
176 .then(function (response) {
177 console.debug("deleteDictionary response received: ", response.status);
178 if (response.ok) {
179 return response.status;
180 } else {
181 console.error("deleteDictionary query failed");
182 return {};
183 }
184 })
185 .catch(function (error) {
186 console.error("deleteDictionary error received", error);
187 return {};
188 });
189 }
190
191 static deleteDictionaryElements(dictionaryData) {
192 return fetch('restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName , {
193 method: 'DELETE',
194 headers: {
195 "Content-Type": "application/json",
196 },
197 credentials: 'same-origin',
198 })
199 .then(function (response) {
200 console.debug("deleteDictionary response received: ", response.status);
201 if (response.ok) {
202 return response.status;
203 } else {
204 console.error("deleteDictionary query failed");
205 return {};
206 }
207 })
208 .catch(function (error) {
209 console.error("deleteDictionary error received", error);
210 return {};
211 });
212 }
213 }