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 | |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame^] | 25 | static getAllLoopTemplates() { |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 26 | return fetch('restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', }) |
| 27 | .then(function (response) { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame^] | 28 | console.debug("getAllLoopTemplates response received: ", response.status); |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 29 | if (response.ok) { |
| 30 | return response.json(); |
| 31 | } else { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame^] | 32 | console.error("getAllLoopTemplates query failed"); |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 33 | return {}; |
| 34 | } |
| 35 | }) |
| 36 | .catch(function (error) { |
sebdet | c0ec0fc | 2020-05-18 12:31:11 +0200 | [diff] [blame^] | 37 | console.error("getAllLoopTemplates error received", error); |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 38 | return {}; |
| 39 | }); |
| 40 | } |
jingjincs | 3173d55 | 2020-03-04 09:11:10 +0100 | [diff] [blame] | 41 | |
drveerendra | 5032095 | 2020-03-04 20:30:44 -0500 | [diff] [blame] | 42 | static getDictionary() { |
| 43 | return fetch('restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', }) |
| 44 | .then(function (response) { |
| 45 | console.debug("getDictionary response received: ", response.status); |
| 46 | if (response.ok) { |
| 47 | return response.json(); |
| 48 | } else { |
| 49 | console.error("getDictionary query failed"); |
| 50 | return {}; |
| 51 | } |
| 52 | }) |
| 53 | .catch(function (error) { |
| 54 | console.error("getDictionary error received", error); |
| 55 | return {}; |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | static getDictionaryElements(dictionaryName) { |
| 60 | return fetch('restservices/clds/v2/dictionary/' + dictionaryName, { |
| 61 | method: 'GET', |
| 62 | headers: { |
| 63 | "Content-Type": "application/json", |
| 64 | }, |
| 65 | credentials: 'same-origin', |
| 66 | }) |
| 67 | .then(function (response) { |
| 68 | console.debug("getDictionaryElements response received: ", response.status); |
| 69 | if (response.ok) { |
| 70 | return response.json(); |
| 71 | } else { |
| 72 | console.error("getDictionaryElements query failed"); |
| 73 | return {}; |
| 74 | } |
| 75 | }) |
| 76 | .catch(function (error) { |
| 77 | console.error("getDictionaryElements error received", error); |
| 78 | return {}; |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | static insDictionary(jsonData) { |
| 83 | console.log("dictionaryName is", jsonData.name) |
| 84 | return fetch('/restservices/clds/v2/dictionary/', { |
| 85 | method: 'PUT', |
| 86 | credentials: 'same-origin', |
| 87 | headers: { |
| 88 | "Content-Type": "application/json", |
| 89 | }, |
| 90 | body: JSON.stringify(jsonData) |
| 91 | }) |
| 92 | .then(function (response) { |
| 93 | console.debug("insDictionary response received: ", response.status); |
| 94 | if (response.ok) { |
| 95 | return response.status; |
| 96 | } else { |
| 97 | var errorMessage = response.status; |
| 98 | console.error("insDictionary query failed", response.status); |
| 99 | return errorMessage; |
| 100 | } |
| 101 | }) |
| 102 | .catch(function (error) { |
| 103 | console.error("insDictionary error received", error); |
| 104 | return ""; |
| 105 | }); |
| 106 | } |
| 107 | |
| 108 | static insDictionaryElements(jsonData) { |
| 109 | console.log("dictionaryName is", jsonData.name) |
| 110 | return fetch('/restservices/clds/v2/dictionary/' + jsonData.name, { |
| 111 | method: 'PUT', |
| 112 | credentials: 'same-origin', |
| 113 | headers: { |
| 114 | "Content-Type": "application/json", |
| 115 | }, |
| 116 | body: JSON.stringify(jsonData) |
| 117 | }) |
| 118 | .then(function (response) { |
| 119 | console.debug("insDictionary response received: ", response.status); |
| 120 | if (response.ok) { |
| 121 | return response.status; |
| 122 | } else { |
| 123 | var errorMessage = response.status; |
| 124 | console.error("insDictionary query failed", response.status); |
| 125 | return errorMessage; |
| 126 | } |
| 127 | }) |
| 128 | .catch(function (error) { |
| 129 | console.error("insDictionary error received", error); |
| 130 | return ""; |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | static deleteDictionary(dictionaryName) { |
| 135 | console.log("inside templaemenu service", dictionaryName) |
| 136 | return fetch('restservices/clds/v2/dictionary/' + dictionaryName, { |
| 137 | method: 'DELETE', |
| 138 | headers: { |
| 139 | "Content-Type": "application/json", |
| 140 | }, |
| 141 | credentials: 'same-origin', |
| 142 | }) |
| 143 | .then(function (response) { |
| 144 | console.debug("deleteDictionary response received: ", response.status); |
| 145 | if (response.ok) { |
| 146 | return response.status; |
| 147 | } else { |
| 148 | console.error("deleteDictionary query failed"); |
| 149 | return {}; |
| 150 | } |
| 151 | }) |
| 152 | .catch(function (error) { |
| 153 | console.error("deleteDictionary error received", error); |
| 154 | return {}; |
| 155 | }); |
| 156 | } |
| 157 | |
| 158 | static deleteDictionaryElements(dictionaryData) { |
| 159 | return fetch('restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName , { |
| 160 | method: 'DELETE', |
| 161 | headers: { |
| 162 | "Content-Type": "application/json", |
| 163 | }, |
| 164 | credentials: 'same-origin', |
| 165 | }) |
| 166 | .then(function (response) { |
| 167 | console.debug("deleteDictionary response received: ", response.status); |
| 168 | if (response.ok) { |
| 169 | return response.status; |
| 170 | } else { |
| 171 | console.error("deleteDictionary query failed"); |
| 172 | return {}; |
| 173 | } |
| 174 | }) |
| 175 | .catch(function (error) { |
| 176 | console.error("deleteDictionary error received", error); |
| 177 | return {}; |
| 178 | }); |
| 179 | } |
| 180 | } |