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 featureGroupsActionConstants} from './FeatureGroupsConstants.js';
19 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
20 import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
21 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.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}/feature-groups`;
29 function fetchFeatureGroupsList(licenseModelId, version) {
30 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
33 function deleteFeatureGroup(licenseModelId, featureGroupId, version) {
34 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${featureGroupId}`);
37 function addFeatureGroup(licenseModelId, featureGroup, version) {
38 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
39 name: featureGroup.name,
40 description: featureGroup.description,
41 partNumber: featureGroup.partNumber,
42 addedLicenseKeyGroupsIds: featureGroup.licenseKeyGroupsIds,
43 addedEntitlementPoolsIds: featureGroup.entitlementPoolsIds
47 function updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup, version) {
49 const {licenseKeyGroupsIds = []} = featureGroup;
50 const {licenseKeyGroupsIds: prevLicenseKeyGroupsIds = []} = previousFeatureGroup;
51 const {entitlementPoolsIds = []} = featureGroup;
52 const {entitlementPoolsIds: prevEntitlementPoolsIds = []} = previousFeatureGroup;
53 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${featureGroup.id}`, {
54 name: featureGroup.name,
55 description: featureGroup.description,
56 partNumber: featureGroup.partNumber,
57 addedLicenseKeyGroupsIds: licenseKeyGroupsIds.filter(licenseKeyGroupId => prevLicenseKeyGroupsIds.indexOf(licenseKeyGroupId) === -1),
58 removedLicenseKeyGroupsIds: prevLicenseKeyGroupsIds.filter(prevLicenseKeyGroupId => licenseKeyGroupsIds.indexOf(prevLicenseKeyGroupId) === -1),
59 addedEntitlementPoolsIds: entitlementPoolsIds.filter(entitlementPoolId => prevEntitlementPoolsIds.indexOf(entitlementPoolId) === -1),
60 removedEntitlementPoolsIds: prevEntitlementPoolsIds.filter(prevEntitlementPoolId => entitlementPoolsIds.indexOf(prevEntitlementPoolId) === -1)
66 fetchFeatureGroupsList(dispatch, {licenseModelId, version}) {
67 return fetchFeatureGroupsList(licenseModelId, version).then(response => dispatch({
68 type: featureGroupsActionConstants.FEATURE_GROUPS_LIST_LOADED,
73 deleteFeatureGroup(dispatch, {licenseModelId, featureGroupId, version}) {
74 return deleteFeatureGroup(licenseModelId, featureGroupId, version).then(() => dispatch({
75 type: featureGroupsActionConstants.DELETE_FEATURE_GROUPS,
80 saveFeatureGroup(dispatch, {licenseModelId, previousFeatureGroup, featureGroup, version}) {
81 if (previousFeatureGroup) {
82 return updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup, version).then(() =>{
84 type: featureGroupsActionConstants.EDIT_FEATURE_GROUPS,
87 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
88 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
92 return addFeatureGroup(licenseModelId, featureGroup, version).then(response => {
94 type: featureGroupsActionConstants.ADD_FEATURE_GROUPS,
98 referencingLicenseAgreements: []
101 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
102 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
107 selectEntitlementPoolsEditorTab(dispatch, {tab}) {
109 type: featureGroupsActionConstants.featureGroupsEditor.SELECT_TAB,
114 openFeatureGroupsEditor(dispatch, {featureGroup, licenseModelId, version}) {
115 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
116 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
118 type: featureGroupsActionConstants.featureGroupsEditor.OPEN,
123 closeFeatureGroupsEditor(dispatch) {
125 type: featureGroupsActionConstants.featureGroupsEditor.CLOSE
130 switchVersion(dispatch, {licenseModelId, version}) {
131 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
132 this.fetchFeatureGroupsList(dispatch, {licenseModelId, version});