2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
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.
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 import {actionTypes as limitEditorActions} from 'sdc-app/onboarding/licenseModel/limits/LimitEditorConstants.js';
21 import getValue from 'nfvo-utils/getValue.js';
23 function baseUrl(licenseModelId, version) {
24 const restPrefix = Configuration.get('restPrefix');
25 const {id: versionId} = version;
26 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/entitlement-pools`;
29 function fetchEntitlementPoolsList(licenseModelId, version) {
30 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
33 function postEntitlementPool(licenseModelId, entitlementPool, version) {
34 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
35 name: entitlementPool.name,
36 description: entitlementPool.description,
37 thresholdValue: entitlementPool.thresholdValue,
38 thresholdUnits: getValue(entitlementPool.thresholdUnits),
39 entitlementMetric: entitlementPool.entitlementMetric,
40 increments: entitlementPool.increments,
41 operationalScope: getValue(entitlementPool.operationalScope),
42 time: entitlementPool.time,
43 startDate: entitlementPool.startDate,
44 expiryDate: entitlementPool.expiryDate
49 function putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version) {
51 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${entitlementPool.id}`, {
52 name: entitlementPool.name,
53 description: entitlementPool.description,
54 thresholdValue: entitlementPool.thresholdValue,
55 thresholdUnits: getValue(entitlementPool.thresholdUnits),
56 entitlementMetric: entitlementPool.entitlementMetric,
57 increments: entitlementPool.increments,
58 operationalScope: getValue(entitlementPool.operationalScope),
59 time: entitlementPool.time,
60 startDate: entitlementPool.startDate,
61 expiryDate: entitlementPool.expiryDate
65 function deleteEntitlementPool(licenseModelId, entitlementPoolId, version) {
66 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}`);
69 function fetchLimitsList(licenseModelId, entitlementPoolId, version) {
70 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits`);
73 function deleteLimit(licenseModelId, entitlementPoolId, version, limitId) {
74 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits/${limitId}`);
77 function postLimit(licenseModelId, entitlementPoolId, version, limit) {
78 return RestAPIUtil.post(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits`, {
81 description: limit.description,
85 aggregationFunction: getValue(limit.aggregationFunction),
86 time: getValue(limit.time)
90 function putLimit(licenseModelId, entitlementPoolId, version, limit) {
92 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}/limits/${limit.id}`, {
95 description: limit.description,
99 aggregationFunction: getValue(limit.aggregationFunction),
100 time: getValue(limit.time)
106 fetchEntitlementPoolsList(dispatch, {licenseModelId, version}) {
107 return fetchEntitlementPoolsList(licenseModelId, version).then(response => dispatch({
108 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_LIST_LOADED,
113 openEntitlementPoolsEditor(dispatch, {entitlementPool, licenseModelId, version} = {}) {
114 if (licenseModelId && version) {
115 this.fetchLimits(dispatch, {licenseModelId, version, entitlementPool});
118 type: entitlementPoolsActionTypes.entitlementPoolsEditor.OPEN,
123 deleteEntitlementPool(dispatch, {licenseModelId, entitlementPoolId, version}) {
124 return deleteEntitlementPool(licenseModelId, entitlementPoolId, version).then(() => {
126 type: entitlementPoolsActionTypes.DELETE_ENTITLEMENT_POOL,
132 entitlementPoolsEditorDataChanged(dispatch, {deltaData}) {
134 type: entitlementPoolsActionTypes.entitlementPoolsEditor.DATA_CHANGED,
139 closeEntitlementPoolsEditor(dispatch) {
141 type: entitlementPoolsActionTypes.entitlementPoolsEditor.CLOSE
145 saveEntitlementPool(dispatch, {licenseModelId, previousEntitlementPool, entitlementPool, version}) {
146 if (previousEntitlementPool) {
147 return putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version).then(() => {
149 type: entitlementPoolsActionTypes.EDIT_ENTITLEMENT_POOL,
155 return postEntitlementPool(licenseModelId, entitlementPool, version).then(response => {
157 type: entitlementPoolsActionTypes.ADD_ENTITLEMENT_POOL,
160 referencingFeatureGroups: [],
168 hideDeleteConfirm(dispatch) {
170 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM,
171 entitlementPoolToDelete: false
174 openDeleteEntitlementPoolConfirm(dispatch, {entitlementPool}) {
176 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM,
177 entitlementPoolToDelete: entitlementPool
181 switchVersion(dispatch, {licenseModelId, version}) {
182 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
183 this.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
188 fetchLimits(dispatch, {licenseModelId, version, entitlementPool}) {
189 return fetchLimitsList(licenseModelId, entitlementPool.id, version). then (response => {
191 type: entitlementPoolsActionTypes.entitlementPoolsEditor.LIMITS_LIST_LOADED,
197 submitLimit(dispatch, {licenseModelId, version, entitlementPool, limit}) {
198 const propmise = limit.id ? putLimit(licenseModelId,entitlementPool.id, version, limit)
199 : postLimit(licenseModelId,entitlementPool.id, version, limit);
200 return propmise.then(() => {
202 type: limitEditorActions.CLOSE
204 this.fetchLimits(dispatch, {licenseModelId, version, entitlementPool});
208 deleteLimit(dispatch, {licenseModelId, version, entitlementPool, limit}) {
209 return deleteLimit(licenseModelId,entitlementPool.id, version, limit.id).then(() => {
210 this.fetchLimits(dispatch, {licenseModelId, version, entitlementPool});