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 EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
20 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
21 import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.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 fetchFeatureGroup(licenseModelId, featureGroupId, version) {
30 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}/${featureGroupId}`);
33 function fetchFeatureGroupsList(licenseModelId, version) {
34 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
37 function deleteFeatureGroup(licenseModelId, featureGroupId, version) {
38 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${featureGroupId}`);
41 function addFeatureGroup(licenseModelId, featureGroup, version) {
42 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
43 name: featureGroup.name,
44 description: featureGroup.description,
45 partNumber: featureGroup.partNumber,
46 manufacturerReferenceNumber: featureGroup.manufacturerReferenceNumber,
47 addedLicenseKeyGroupsIds: featureGroup.licenseKeyGroupsIds,
48 addedEntitlementPoolsIds: featureGroup.entitlementPoolsIds
52 function updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup, version) {
54 const {licenseKeyGroupsIds = []} = featureGroup;
55 const {licenseKeyGroupsIds: prevLicenseKeyGroupsIds = []} = previousFeatureGroup;
56 const {entitlementPoolsIds = []} = featureGroup;
57 const {entitlementPoolsIds: prevEntitlementPoolsIds = []} = previousFeatureGroup;
58 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${featureGroup.id}`, {
59 name: featureGroup.name,
60 description: featureGroup.description,
61 partNumber: featureGroup.partNumber,
62 manufacturerReferenceNumber: featureGroup.manufacturerReferenceNumber,
63 addedLicenseKeyGroupsIds: licenseKeyGroupsIds.filter(licenseKeyGroupId => prevLicenseKeyGroupsIds.indexOf(licenseKeyGroupId) === -1),
64 removedLicenseKeyGroupsIds: prevLicenseKeyGroupsIds.filter(prevLicenseKeyGroupId => licenseKeyGroupsIds.indexOf(prevLicenseKeyGroupId) === -1),
65 addedEntitlementPoolsIds: entitlementPoolsIds.filter(entitlementPoolId => prevEntitlementPoolsIds.indexOf(entitlementPoolId) === -1),
66 removedEntitlementPoolsIds: prevEntitlementPoolsIds.filter(prevEntitlementPoolId => entitlementPoolsIds.indexOf(prevEntitlementPoolId) === -1)
72 fetchFeatureGroup(dispatch, {licenseModelId, featureGroupId, version}) {
73 return fetchFeatureGroup(licenseModelId, featureGroupId, version);
76 fetchFeatureGroupsList(dispatch, {licenseModelId, version}) {
77 return fetchFeatureGroupsList(licenseModelId, version).then(response => dispatch({
78 type: featureGroupsActionConstants.FEATURE_GROUPS_LIST_LOADED,
83 deleteFeatureGroup(dispatch, {licenseModelId, featureGroupId, version}) {
84 return deleteFeatureGroup(licenseModelId, featureGroupId, version).then(() => {
86 type: featureGroupsActionConstants.DELETE_FEATURE_GROUPS,
89 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
93 saveFeatureGroup(dispatch, {licenseModelId, previousFeatureGroup, featureGroup, version}) {
94 if (previousFeatureGroup) {
95 return updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup, version).then(() =>{
97 type: featureGroupsActionConstants.EDIT_FEATURE_GROUPS,
100 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
101 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
102 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
106 return addFeatureGroup(licenseModelId, featureGroup, version).then(response => {
108 type: featureGroupsActionConstants.ADD_FEATURE_GROUPS,
112 referencingLicenseAgreements: []
115 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version});
116 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
117 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
122 selectEntitlementPoolsEditorTab(dispatch, {tab}) {
124 type: featureGroupsActionConstants.featureGroupsEditor.SELECT_TAB,
129 openFeatureGroupsEditor(dispatch, {featureGroup, licenseModelId, version}) {
131 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}),
132 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version})
135 type: featureGroupsActionConstants.featureGroupsEditor.OPEN,
141 closeFeatureGroupsEditor(dispatch) {
143 type: featureGroupsActionConstants.featureGroupsEditor.CLOSE