2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
23 import {actionTypes as entitlementPoolsActionTypes } from './EntitlementPoolsConstants.js';
24 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
26 function baseUrl(licenseModelId) {
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/entitlement-pools`;
31 function fetchEntitlementPoolsList(licenseModelId, version) {
32 let versionQuery = version ? `?version=${version}` : '';
33 return RestAPIUtil.fetch(`${baseUrl(licenseModelId)}${versionQuery}`);
36 function postEntitlementPool(licenseModelId, entitlementPool) {
37 return RestAPIUtil.create(baseUrl(licenseModelId), {
38 name: entitlementPool.name,
39 description: entitlementPool.description,
40 thresholdValue: entitlementPool.thresholdValue,
41 thresholdUnits: entitlementPool.thresholdUnits,
42 entitlementMetric: entitlementPool.entitlementMetric,
43 increments: entitlementPool.increments,
44 aggregationFunction: entitlementPool.aggregationFunction,
45 operationalScope: entitlementPool.operationalScope,
46 time: entitlementPool.time,
47 manufacturerReferenceNumber: entitlementPool.manufacturerReferenceNumber
52 function putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool) {
53 return RestAPIUtil.save(`${baseUrl(licenseModelId)}/${entitlementPool.id}`, {
54 name: entitlementPool.name,
55 description: entitlementPool.description,
56 thresholdValue: entitlementPool.thresholdValue,
57 thresholdUnits: entitlementPool.thresholdUnits,
58 entitlementMetric: entitlementPool.entitlementMetric,
59 increments: entitlementPool.increments,
60 aggregationFunction: entitlementPool.aggregationFunction,
61 operationalScope: entitlementPool.operationalScope,
62 time: entitlementPool.time,
63 manufacturerReferenceNumber: entitlementPool.manufacturerReferenceNumber
67 function deleteEntitlementPool(licenseModelId, entitlementPoolId) {
68 return RestAPIUtil.destroy(`${baseUrl(licenseModelId)}/${entitlementPoolId}`);
73 fetchEntitlementPoolsList(dispatch, {licenseModelId, version}) {
74 return fetchEntitlementPoolsList(licenseModelId, version).then(response => dispatch({
75 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_LIST_LOADED,
80 openEntitlementPoolsEditor(dispatch, {entitlementPool} = {}) {
82 type: entitlementPoolsActionTypes.entitlementPoolsEditor.OPEN,
87 deleteEntitlementPool(dispatch, {licenseModelId, entitlementPoolId}) {
88 return deleteEntitlementPool(licenseModelId, entitlementPoolId).then(() => {
90 type: entitlementPoolsActionTypes.DELETE_ENTITLEMENT_POOL,
96 entitlementPoolsEditorDataChanged(dispatch, {deltaData}) {
98 type: entitlementPoolsActionTypes.entitlementPoolsEditor.DATA_CHANGED,
103 closeEntitlementPoolsEditor(dispatch) {
105 type: entitlementPoolsActionTypes.entitlementPoolsEditor.CLOSE
109 saveEntitlementPool(dispatch, {licenseModelId, previousEntitlementPool, entitlementPool}) {
110 if (previousEntitlementPool) {
111 return putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool).then(() => {
113 type: entitlementPoolsActionTypes.EDIT_ENTITLEMENT_POOL,
119 return postEntitlementPool(licenseModelId, entitlementPool).then(response => {
121 type: entitlementPoolsActionTypes.ADD_ENTITLEMENT_POOL,
131 hideDeleteConfirm(dispatch) {
133 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM,
134 entitlementPoolToDelete: false
137 openDeleteEntitlementPoolConfirm(dispatch, {entitlementPool}) {
139 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM,
140 entitlementPoolToDelete: entitlementPool
144 switchVersion(dispatch, {licenseModelId, version}) {
145 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
146 this.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});