AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js'; |
| 17 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 18 | import {actionTypes as entitlementPoolsActionTypes } from './EntitlementPoolsConstants.js'; |
| 19 | import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 20 | import {actionTypes as limitEditorActions} from 'sdc-app/onboarding/licenseModel/limits/LimitEditorConstants.js'; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 21 | import {default as getValue, getStrValue} from 'nfvo-utils/getValue.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | function baseUrl(licenseModelId, version) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | const restPrefix = Configuration.get('restPrefix'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | const {id: versionId} = version; |
| 26 | return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/entitlement-pools`; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | } |
| 28 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 29 | function fetchEntitlementPoolsList(licenseModelId, version) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 30 | return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 31 | } |
| 32 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 33 | function postEntitlementPool(licenseModelId, entitlementPool, version) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | return RestAPIUtil.post(baseUrl(licenseModelId, version), { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | name: entitlementPool.name, |
| 36 | description: entitlementPool.description, |
| 37 | thresholdValue: entitlementPool.thresholdValue, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 38 | thresholdUnits: getValue(entitlementPool.thresholdUnits), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | increments: entitlementPool.increments, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 40 | operationalScope: getValue(entitlementPool.operationalScope), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 41 | time: entitlementPool.time, |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 42 | startDate: entitlementPool.startDate, |
| 43 | expiryDate: entitlementPool.expiryDate |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | }); |
| 45 | } |
| 46 | |
| 47 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 48 | function putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version) { |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 49 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 50 | return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${entitlementPool.id}`, { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 51 | name: entitlementPool.name, |
| 52 | description: entitlementPool.description, |
| 53 | thresholdValue: entitlementPool.thresholdValue, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 54 | thresholdUnits: getValue(entitlementPool.thresholdUnits), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 55 | increments: entitlementPool.increments, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 56 | operationalScope: getValue(entitlementPool.operationalScope), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 57 | time: entitlementPool.time, |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 58 | startDate: entitlementPool.startDate, |
| 59 | expiryDate: entitlementPool.expiryDate |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 60 | }); |
| 61 | } |
| 62 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 63 | function deleteEntitlementPool(licenseModelId, entitlementPoolId, version) { |
| 64 | return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 65 | } |
| 66 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 67 | function fetchLimitsList(licenseModelId, entitlementPoolId, version) { |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 68 | return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits`); |
| 69 | } |
| 70 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 71 | function deleteLimit(licenseModelId, entitlementPoolId, version, limitId) { |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 72 | return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits/${limitId}`); |
| 73 | } |
| 74 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 75 | function postLimit(licenseModelId, entitlementPoolId, version, limit) { |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 76 | return RestAPIUtil.post(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits`, { |
| 77 | name: limit.name, |
| 78 | type: limit.type, |
| 79 | description: limit.description, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 80 | metric: getStrValue(limit.metric), |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 81 | value: limit.value, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 82 | unit: getStrValue(limit.unit), |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 83 | aggregationFunction: getValue(limit.aggregationFunction), |
| 84 | time: getValue(limit.time) |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | function putLimit(licenseModelId, entitlementPoolId, version, limit) { |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 89 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 90 | return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits/${limit.id}`, { |
| 91 | name: limit.name, |
| 92 | type: limit.type, |
| 93 | description: limit.description, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 94 | metric: getStrValue(limit.metric), |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 95 | value: limit.value, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 96 | unit: getStrValue(limit.unit), |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 97 | aggregationFunction: getValue(limit.aggregationFunction), |
| 98 | time: getValue(limit.time) |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 99 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 100 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | |
| 102 | export default { |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 103 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | fetchEntitlementPoolsList(dispatch, {licenseModelId, version}) { |
| 105 | return fetchEntitlementPoolsList(licenseModelId, version).then(response => dispatch({ |
| 106 | type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_LIST_LOADED, |
| 107 | response |
| 108 | })); |
| 109 | }, |
| 110 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 111 | openEntitlementPoolsEditor(dispatch, {entitlementPool, licenseModelId, version} = {}) { |
| 112 | if (licenseModelId && version) { |
| 113 | this.fetchLimits(dispatch, {licenseModelId, version, entitlementPool}); |
| 114 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 115 | dispatch({ |
| 116 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.OPEN, |
| 117 | entitlementPool |
| 118 | }); |
| 119 | }, |
| 120 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 121 | deleteEntitlementPool(dispatch, {licenseModelId, entitlementPoolId, version}) { |
| 122 | return deleteEntitlementPool(licenseModelId, entitlementPoolId, version).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 123 | dispatch({ |
| 124 | type: entitlementPoolsActionTypes.DELETE_ENTITLEMENT_POOL, |
| 125 | entitlementPoolId |
| 126 | }); |
| 127 | }); |
| 128 | }, |
| 129 | |
| 130 | entitlementPoolsEditorDataChanged(dispatch, {deltaData}) { |
| 131 | dispatch({ |
| 132 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.DATA_CHANGED, |
| 133 | deltaData |
| 134 | }); |
| 135 | }, |
| 136 | |
| 137 | closeEntitlementPoolsEditor(dispatch) { |
| 138 | dispatch({ |
| 139 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.CLOSE |
| 140 | }); |
| 141 | }, |
| 142 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 143 | saveEntitlementPool(dispatch, {licenseModelId, previousEntitlementPool, entitlementPool, version}) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 144 | if (previousEntitlementPool) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | return putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 146 | dispatch({ |
| 147 | type: entitlementPoolsActionTypes.EDIT_ENTITLEMENT_POOL, |
| 148 | entitlementPool |
| 149 | }); |
| 150 | }); |
| 151 | } |
| 152 | else { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 153 | return postEntitlementPool(licenseModelId, entitlementPool, version).then(response => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 154 | dispatch({ |
| 155 | type: entitlementPoolsActionTypes.ADD_ENTITLEMENT_POOL, |
| 156 | entitlementPool: { |
| 157 | ...entitlementPool, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | referencingFeatureGroups: [], |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 159 | id: response.value |
| 160 | } |
| 161 | }); |
| 162 | }); |
| 163 | } |
| 164 | }, |
| 165 | |
| 166 | hideDeleteConfirm(dispatch) { |
| 167 | dispatch({ |
| 168 | type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM, |
| 169 | entitlementPoolToDelete: false |
| 170 | }); |
| 171 | }, |
| 172 | openDeleteEntitlementPoolConfirm(dispatch, {entitlementPool}) { |
| 173 | dispatch({ |
| 174 | type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM, |
| 175 | entitlementPoolToDelete: entitlementPool |
| 176 | }); |
| 177 | }, |
| 178 | |
| 179 | switchVersion(dispatch, {licenseModelId, version}) { |
| 180 | LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => { |
| 181 | this.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}); |
| 182 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 183 | }, |
| 184 | |
| 185 | |
| 186 | fetchLimits(dispatch, {licenseModelId, version, entitlementPool}) { |
| 187 | return fetchLimitsList(licenseModelId, entitlementPool.id, version). then (response => { |
| 188 | dispatch({ |
| 189 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.LIMITS_LIST_LOADED, |
| 190 | response |
| 191 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 192 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 193 | }, |
| 194 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 195 | submitLimit(dispatch, {licenseModelId, version, entitlementPool, limit}) { |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 196 | const propmise = limit.id ? putLimit(licenseModelId,entitlementPool.id, version, limit) |
| 197 | : postLimit(licenseModelId,entitlementPool.id, version, limit); |
| 198 | return propmise.then(() => { |
| 199 | dispatch({ |
| 200 | type: limitEditorActions.CLOSE |
| 201 | }); |
| 202 | this.fetchLimits(dispatch, {licenseModelId, version, entitlementPool}); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 203 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 204 | }, |
| 205 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 206 | deleteLimit(dispatch, {licenseModelId, version, entitlementPool, limit}) { |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 207 | return deleteLimit(licenseModelId,entitlementPool.id, version, limit.id).then(() => { |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 208 | this.fetchLimits(dispatch, {licenseModelId, version, entitlementPool}); |
| 209 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 210 | } |
| 211 | }; |