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 featureGroupsActionConstants} from './FeatureGroupsConstants.js';
24 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
25 import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
26 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
28 function baseUrl(licenseModelId) {
29 const restPrefix = Configuration.get('restPrefix');
30 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/feature-groups`;
33 function fetchFeatureGroupsList(licenseModelId, version) {
34 let versionQuery = version ? `?version=${version}` : '';
35 return RestAPIUtil.fetch(`${baseUrl(licenseModelId)}${versionQuery}`);
38 function deleteFeatureGroup(licenseModelId, featureGroupId) {
39 return RestAPIUtil.destroy(`${baseUrl(licenseModelId)}/${featureGroupId}`);
42 function addFeatureGroup(licenseModelId, featureGroup) {
43 return RestAPIUtil.create(baseUrl(licenseModelId), {
44 name: featureGroup.name,
45 description: featureGroup.description,
46 partNumber: featureGroup.partNumber,
47 addedLicenseKeyGroupsIds: featureGroup.licenseKeyGroupsIds,
48 addedEntitlementPoolsIds: featureGroup.entitlementPoolsIds
52 function updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup) {
54 const {licenseKeyGroupsIds = []} = featureGroup;
55 const {licenseKeyGroupsIds: prevLicenseKeyGroupsIds = []} = previousFeatureGroup;
56 const {entitlementPoolsIds = []} = featureGroup;
57 const {entitlementPoolsIds: prevEntitlementPoolsIds = []} = previousFeatureGroup;
58 return RestAPIUtil.save(`${baseUrl(licenseModelId)}/${featureGroup.id}`, {
59 name: featureGroup.name,
60 description: featureGroup.description,
61 partNumber: featureGroup.partNumber,
62 addedLicenseKeyGroupsIds: licenseKeyGroupsIds.filter(licenseKeyGroupId => prevLicenseKeyGroupsIds.indexOf(licenseKeyGroupId) === -1),
63 removedLicenseKeyGroupsIds: prevLicenseKeyGroupsIds.filter(prevLicenseKeyGroupId => licenseKeyGroupsIds.indexOf(prevLicenseKeyGroupId) === -1),
64 addedEntitlementPoolsIds: entitlementPoolsIds.filter(entitlementPoolId => prevEntitlementPoolsIds.indexOf(entitlementPoolId) === -1),
65 removedEntitlementPoolsIds: prevEntitlementPoolsIds.filter(prevEntitlementPoolId => entitlementPoolsIds.indexOf(prevEntitlementPoolId) === -1)
71 fetchFeatureGroupsList(dispatch, {licenseModelId, version}) {
72 return fetchFeatureGroupsList(licenseModelId, version).then(response => dispatch({
73 type: featureGroupsActionConstants.FEATURE_GROUPS_LIST_LOADED,
78 deleteFeatureGroup(dispatch, {licenseModelId, featureGroupId}) {
79 return deleteFeatureGroup(licenseModelId, featureGroupId).then(() => dispatch({
80 type: featureGroupsActionConstants.DELETE_FEATURE_GROUPS,
85 saveFeatureGroup(dispatch, {licenseModelId, previousFeatureGroup, featureGroup}) {
86 if (previousFeatureGroup) {
87 return updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup).then(() => dispatch({
88 type: featureGroupsActionConstants.EDIT_FEATURE_GROUPS,
93 return addFeatureGroup(licenseModelId, featureGroup).then(response => dispatch({
94 type: featureGroupsActionConstants.ADD_FEATURE_GROUPS,
103 selectEntitlementPoolsEditorTab(dispatch, {tab}) {
105 type: featureGroupsActionConstants.featureGroupsEditor.SELECT_TAB,
110 selectFeatureGroupsEditorEntitlementPoolsButtonTab(dispatch, {buttonTab}) {
112 type: featureGroupsActionConstants.featureGroupsEditor.SELECTED_ENTITLEMENT_POOLS_BUTTONTAB,
117 selectFeatureGroupsEditorLicenseKeyGroupsButtonTab(dispatch, {buttonTab}) {
119 type: featureGroupsActionConstants.featureGroupsEditor.SELECTED_LICENSE_KEY_GROUPS_BUTTONTAB,
124 openFeatureGroupsEditor(dispatch, {featureGroup, licenseModelId}) {
125 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId});
126 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId});
128 type: featureGroupsActionConstants.featureGroupsEditor.OPEN,
133 closeFeatureGroupsEditor(dispatch) {
135 type: featureGroupsActionConstants.featureGroupsEditor.CLOSE
139 featureGroupsEditorDataChanged(dispatch, {deltaData}) {
141 type: featureGroupsActionConstants.featureGroupsEditor.DATA_CHANGED,
146 hideDeleteConfirm(dispatch) {
148 type: featureGroupsActionConstants.FEATURE_GROUPS_DELETE_CONFIRM,
149 featureGroupToDelete: false
153 openDeleteFeatureGroupConfirm(dispatch, {featureGroup}) {
155 type: featureGroupsActionConstants.FEATURE_GROUPS_DELETE_CONFIRM,
156 featureGroupToDelete: featureGroup
160 switchVersion(dispatch, {licenseModelId, version}) {
161 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
162 this.fetchFeatureGroupsList(dispatch, {licenseModelId, version});