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'; |
| 20 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 21 | function baseUrl(licenseModelId, version) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | const restPrefix = Configuration.get('restPrefix'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | const {id: versionId} = version; |
| 24 | return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/entitlement-pools`; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 25 | } |
| 26 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 27 | function fetchEntitlementPoolsList(licenseModelId, version) { |
| 28 | return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | } |
| 30 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | function postEntitlementPool(licenseModelId, entitlementPool, version) { |
| 32 | return RestAPIUtil.post(baseUrl(licenseModelId, version), { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | name: entitlementPool.name, |
| 34 | description: entitlementPool.description, |
| 35 | thresholdValue: entitlementPool.thresholdValue, |
| 36 | thresholdUnits: entitlementPool.thresholdUnits, |
| 37 | entitlementMetric: entitlementPool.entitlementMetric, |
| 38 | increments: entitlementPool.increments, |
| 39 | aggregationFunction: entitlementPool.aggregationFunction, |
| 40 | operationalScope: entitlementPool.operationalScope, |
| 41 | time: entitlementPool.time, |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame^] | 42 | manufacturerReferenceNumber: entitlementPool.manufacturerReferenceNumber, |
| 43 | startDate: entitlementPool.startDate, |
| 44 | expiryDate: entitlementPool.expiryDate |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | }); |
| 46 | } |
| 47 | |
| 48 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | function putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version) { |
| 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, |
| 54 | thresholdUnits: entitlementPool.thresholdUnits, |
| 55 | entitlementMetric: entitlementPool.entitlementMetric, |
| 56 | increments: entitlementPool.increments, |
| 57 | aggregationFunction: entitlementPool.aggregationFunction, |
| 58 | operationalScope: entitlementPool.operationalScope, |
| 59 | time: entitlementPool.time, |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame^] | 60 | manufacturerReferenceNumber: entitlementPool.manufacturerReferenceNumber, |
| 61 | startDate: entitlementPool.startDate, |
| 62 | expiryDate: entitlementPool.expiryDate |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 63 | }); |
| 64 | } |
| 65 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 66 | function deleteEntitlementPool(licenseModelId, entitlementPoolId, version) { |
| 67 | return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
| 71 | export default { |
| 72 | fetchEntitlementPoolsList(dispatch, {licenseModelId, version}) { |
| 73 | return fetchEntitlementPoolsList(licenseModelId, version).then(response => dispatch({ |
| 74 | type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_LIST_LOADED, |
| 75 | response |
| 76 | })); |
| 77 | }, |
| 78 | |
| 79 | openEntitlementPoolsEditor(dispatch, {entitlementPool} = {}) { |
| 80 | dispatch({ |
| 81 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.OPEN, |
| 82 | entitlementPool |
| 83 | }); |
| 84 | }, |
| 85 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 86 | deleteEntitlementPool(dispatch, {licenseModelId, entitlementPoolId, version}) { |
| 87 | return deleteEntitlementPool(licenseModelId, entitlementPoolId, version).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 88 | dispatch({ |
| 89 | type: entitlementPoolsActionTypes.DELETE_ENTITLEMENT_POOL, |
| 90 | entitlementPoolId |
| 91 | }); |
| 92 | }); |
| 93 | }, |
| 94 | |
| 95 | entitlementPoolsEditorDataChanged(dispatch, {deltaData}) { |
| 96 | dispatch({ |
| 97 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.DATA_CHANGED, |
| 98 | deltaData |
| 99 | }); |
| 100 | }, |
| 101 | |
| 102 | closeEntitlementPoolsEditor(dispatch) { |
| 103 | dispatch({ |
| 104 | type: entitlementPoolsActionTypes.entitlementPoolsEditor.CLOSE |
| 105 | }); |
| 106 | }, |
| 107 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 108 | saveEntitlementPool(dispatch, {licenseModelId, previousEntitlementPool, entitlementPool, version}) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 109 | if (previousEntitlementPool) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 110 | return putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 111 | dispatch({ |
| 112 | type: entitlementPoolsActionTypes.EDIT_ENTITLEMENT_POOL, |
| 113 | entitlementPool |
| 114 | }); |
| 115 | }); |
| 116 | } |
| 117 | else { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 118 | return postEntitlementPool(licenseModelId, entitlementPool, version).then(response => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 119 | dispatch({ |
| 120 | type: entitlementPoolsActionTypes.ADD_ENTITLEMENT_POOL, |
| 121 | entitlementPool: { |
| 122 | ...entitlementPool, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 123 | referencingFeatureGroups: [], |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 124 | id: response.value |
| 125 | } |
| 126 | }); |
| 127 | }); |
| 128 | } |
| 129 | }, |
| 130 | |
| 131 | hideDeleteConfirm(dispatch) { |
| 132 | dispatch({ |
| 133 | type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM, |
| 134 | entitlementPoolToDelete: false |
| 135 | }); |
| 136 | }, |
| 137 | openDeleteEntitlementPoolConfirm(dispatch, {entitlementPool}) { |
| 138 | dispatch({ |
| 139 | type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM, |
| 140 | entitlementPoolToDelete: entitlementPool |
| 141 | }); |
| 142 | }, |
| 143 | |
| 144 | switchVersion(dispatch, {licenseModelId, version}) { |
| 145 | LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => { |
| 146 | this.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}); |
| 147 | }); |
| 148 | } |
| 149 | }; |