blob: fe95b034ddcd371f808d75b8608cf606864f9927 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17import Configuration from 'sdc-app/config/Configuration.js';
18import {actionTypes as entitlementPoolsActionTypes } from './EntitlementPoolsConstants.js';
19import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
20
AviZi280f8012017-06-09 02:39:56 +030021function baseUrl(licenseModelId, version) {
Michael Landoefa037d2017-02-19 12:57:33 +020022 const restPrefix = Configuration.get('restPrefix');
AviZi280f8012017-06-09 02:39:56 +030023 const {id: versionId} = version;
24 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/entitlement-pools`;
Michael Landoefa037d2017-02-19 12:57:33 +020025}
26
AviZi280f8012017-06-09 02:39:56 +030027function fetchEntitlementPoolsList(licenseModelId, version) {
28 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
Michael Landoefa037d2017-02-19 12:57:33 +020029}
30
AviZi280f8012017-06-09 02:39:56 +030031function postEntitlementPool(licenseModelId, entitlementPool, version) {
32 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
Michael Landoefa037d2017-02-19 12:57:33 +020033 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,
42 manufacturerReferenceNumber: entitlementPool.manufacturerReferenceNumber
43 });
44}
45
46
AviZi280f8012017-06-09 02:39:56 +030047function putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version) {
48 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${entitlementPool.id}`, {
Michael Landoefa037d2017-02-19 12:57:33 +020049 name: entitlementPool.name,
50 description: entitlementPool.description,
51 thresholdValue: entitlementPool.thresholdValue,
52 thresholdUnits: entitlementPool.thresholdUnits,
53 entitlementMetric: entitlementPool.entitlementMetric,
54 increments: entitlementPool.increments,
55 aggregationFunction: entitlementPool.aggregationFunction,
56 operationalScope: entitlementPool.operationalScope,
57 time: entitlementPool.time,
58 manufacturerReferenceNumber: entitlementPool.manufacturerReferenceNumber
59 });
60}
61
AviZi280f8012017-06-09 02:39:56 +030062function deleteEntitlementPool(licenseModelId, entitlementPoolId, version) {
63 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${entitlementPoolId}`);
Michael Landoefa037d2017-02-19 12:57:33 +020064}
65
66
67export default {
68 fetchEntitlementPoolsList(dispatch, {licenseModelId, version}) {
69 return fetchEntitlementPoolsList(licenseModelId, version).then(response => dispatch({
70 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_LIST_LOADED,
71 response
72 }));
73 },
74
75 openEntitlementPoolsEditor(dispatch, {entitlementPool} = {}) {
76 dispatch({
77 type: entitlementPoolsActionTypes.entitlementPoolsEditor.OPEN,
78 entitlementPool
79 });
80 },
81
AviZi280f8012017-06-09 02:39:56 +030082 deleteEntitlementPool(dispatch, {licenseModelId, entitlementPoolId, version}) {
83 return deleteEntitlementPool(licenseModelId, entitlementPoolId, version).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +020084 dispatch({
85 type: entitlementPoolsActionTypes.DELETE_ENTITLEMENT_POOL,
86 entitlementPoolId
87 });
88 });
89 },
90
91 entitlementPoolsEditorDataChanged(dispatch, {deltaData}) {
92 dispatch({
93 type: entitlementPoolsActionTypes.entitlementPoolsEditor.DATA_CHANGED,
94 deltaData
95 });
96 },
97
98 closeEntitlementPoolsEditor(dispatch) {
99 dispatch({
100 type: entitlementPoolsActionTypes.entitlementPoolsEditor.CLOSE
101 });
102 },
103
AviZi280f8012017-06-09 02:39:56 +0300104 saveEntitlementPool(dispatch, {licenseModelId, previousEntitlementPool, entitlementPool, version}) {
Michael Landoefa037d2017-02-19 12:57:33 +0200105 if (previousEntitlementPool) {
AviZi280f8012017-06-09 02:39:56 +0300106 return putEntitlementPool(licenseModelId, previousEntitlementPool, entitlementPool, version).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +0200107 dispatch({
108 type: entitlementPoolsActionTypes.EDIT_ENTITLEMENT_POOL,
109 entitlementPool
110 });
111 });
112 }
113 else {
AviZi280f8012017-06-09 02:39:56 +0300114 return postEntitlementPool(licenseModelId, entitlementPool, version).then(response => {
Michael Landoefa037d2017-02-19 12:57:33 +0200115 dispatch({
116 type: entitlementPoolsActionTypes.ADD_ENTITLEMENT_POOL,
117 entitlementPool: {
118 ...entitlementPool,
AviZi280f8012017-06-09 02:39:56 +0300119 referencingFeatureGroups: [],
Michael Landoefa037d2017-02-19 12:57:33 +0200120 id: response.value
121 }
122 });
123 });
124 }
125 },
126
127 hideDeleteConfirm(dispatch) {
128 dispatch({
129 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM,
130 entitlementPoolToDelete: false
131 });
132 },
133 openDeleteEntitlementPoolConfirm(dispatch, {entitlementPool}) {
134 dispatch({
135 type: entitlementPoolsActionTypes.ENTITLEMENT_POOLS_DELETE_CONFIRM,
136 entitlementPoolToDelete: entitlementPool
137 });
138 },
139
140 switchVersion(dispatch, {licenseModelId, version}) {
141 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
142 this.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
143 });
144 }
145};