sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 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 { |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 24 | |
Ted Humphrey | 083e5a2 | 2020-07-08 16:48:40 -0400 | [diff] [blame^] | 25 | 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 | |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 42 | static getAllLoopTemplates() { |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 43 | return fetch('restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', }) |
| 44 | .then(function (response) { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 45 | console.debug("getAllLoopTemplates response received: ", response.status); |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 46 | if (response.ok) { |
| 47 | return response.json(); |
| 48 | } else { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 49 | console.error("getAllLoopTemplates query failed"); |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 50 | return {}; |
| 51 | } |
| 52 | }) |
| 53 | .catch(function (error) { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame] | 54 | console.error("getAllLoopTemplates error received", error); |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 55 | return {}; |
| 56 | }); |
| 57 | } |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 58 | |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 59 | 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 | } |