blob: a77a8bdb0fc0a5b2bb3a9661acaa00b34969d80b [file] [log] [blame]
sebdeteb8e3f12021-01-24 18:12:36 +01001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP POLICY-CLAMP
4 * ================================================================================
5 * Copyright (C) 2021 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 PolicyService {
24 static getPoliciesList() {
sebdeta0a3a032021-02-16 14:53:43 +010025 return fetch(window.location.pathname + 'restservices/clds/v2/policies', {
sebdeteb8e3f12021-01-24 18:12:36 +010026 method: 'GET',
27 credentials: 'same-origin'
28 })
sebdetea2969f2021-02-25 13:58:36 +010029 .then(function(response) {
30 console.debug("getPoliciesList response received: ", response.status);
31 if (response.ok) {
32 console.info("getPoliciesList query successful");
33 return response.json();
34 } else {
35 return response.text().then(responseBody => {
36 throw new Error("HTTP " + response.status + "," + responseBody);
37 })
38 }
39 })
40 .catch(function(error) {
41 console.error("getPoliciesList error occurred ", error);
42 alert("getPoliciesList error occurred " + error);
43 return "";
44 })
sebdeteb8e3f12021-01-24 18:12:36 +010045 }
sebdetc427e642021-02-17 17:53:17 +010046 static createNewPolicy(policyModelType, policyModelVersion, policyJson) {
47 return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' + policyModelVersion, {
48 method: 'POST',
49 credentials: 'same-origin',
50 headers: {
51 "Content-Type": "application/json"
52 },
53 body: JSON.stringify(policyJson)
54 })
sebdetea2969f2021-02-25 13:58:36 +010055 .then(function (response) {
56 console.debug("createNewPolicy response received: ", response.status);
57 if (response.ok) {
58 console.info("createNewPolicy query successful");
59 return response.text();
60 } else {
61 return response.text().then(responseBody => {
62 throw new Error("HTTP " + response.status + "," + responseBody);
63 })
64 }
65 })
66 .catch(function (error) {
67 console.error("createNewPolicy error occurred ", error);
68 alert ("createNewPolicy error occurred " + error);
69 return "";
70 });
71 }
72 static deletePolicy(policyModelType, policyModelVersion, policyName, policyVersion) {
73 return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/'
74 + policyModelVersion + '/' + policyName + '/' + policyVersion, {
75 method: 'DELETE',
76 credentials: 'same-origin'
77 })
78 .then(function (response) {
79 console.debug("deletePolicy response received: ", response.status);
80 if (response.ok) {
81 console.info("deletePolicy query successful");
82 return response.text();
83 } else {
84 return response.text().then(responseBody => {
85 throw new Error("HTTP " + response.status + "," + responseBody);
86 })
87 }
88 })
89 .catch(function (error) {
90 console.error("deletePolicy error occurred ", error);
91 alert ("deletePolicy error occurred " + error);
92 return "";
93 });
sebdetc427e642021-02-17 17:53:17 +010094 }
sebdeteb8e3f12021-01-24 18:12:36 +010095}