2 * Copyright © 2016-2018 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * 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 actionTypes as modalActionTypes,
25 } from 'nfvo-components/modal/GlobalModalConstants.js';
26 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
27 import i18n from 'nfvo-utils/i18n/i18n.js';
29 function baseUrl(licenseModelId, version) {
30 const restPrefix = Configuration.get('restPrefix');
31 const { id: versionId } = version;
32 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/feature-groups`;
35 function fetchFeatureGroup(licenseModelId, featureGroupId, version) {
36 return RestAPIUtil.fetch(
37 `${baseUrl(licenseModelId, version)}/${featureGroupId}`
41 function fetchFeatureGroupsList(licenseModelId, version) {
42 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
45 function deleteFeatureGroup(licenseModelId, featureGroupId, version) {
46 return RestAPIUtil.destroy(
47 `${baseUrl(licenseModelId, version)}/${featureGroupId}`
51 function addFeatureGroup(licenseModelId, featureGroup, version) {
52 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
53 name: featureGroup.name,
54 description: featureGroup.description,
55 partNumber: featureGroup.partNumber,
56 manufacturerReferenceNumber: featureGroup.manufacturerReferenceNumber,
57 addedLicenseKeyGroupsIds: featureGroup.licenseKeyGroupsIds,
58 addedEntitlementPoolsIds: featureGroup.entitlementPoolsIds
62 function updateFeatureGroup(
68 const { licenseKeyGroupsIds = [] } = featureGroup;
70 licenseKeyGroupsIds: prevLicenseKeyGroupsIds = []
71 } = previousFeatureGroup;
72 const { entitlementPoolsIds = [] } = featureGroup;
74 entitlementPoolsIds: prevEntitlementPoolsIds = []
75 } = previousFeatureGroup;
76 return RestAPIUtil.put(
77 `${baseUrl(licenseModelId, version)}/${featureGroup.id}`,
79 name: featureGroup.name,
80 description: featureGroup.description,
81 partNumber: featureGroup.partNumber,
82 manufacturerReferenceNumber:
83 featureGroup.manufacturerReferenceNumber,
84 addedLicenseKeyGroupsIds: licenseKeyGroupsIds.filter(
86 prevLicenseKeyGroupsIds.indexOf(licenseKeyGroupId) === -1
88 removedLicenseKeyGroupsIds: prevLicenseKeyGroupsIds.filter(
89 prevLicenseKeyGroupId =>
90 licenseKeyGroupsIds.indexOf(prevLicenseKeyGroupId) === -1
92 addedEntitlementPoolsIds: entitlementPoolsIds.filter(
94 prevEntitlementPoolsIds.indexOf(entitlementPoolId) === -1
96 removedEntitlementPoolsIds: prevEntitlementPoolsIds.filter(
97 prevEntitlementPoolId =>
98 entitlementPoolsIds.indexOf(prevEntitlementPoolId) === -1
105 fetchFeatureGroup(dispatch, { licenseModelId, featureGroupId, version }) {
106 return fetchFeatureGroup(licenseModelId, featureGroupId, version);
109 fetchFeatureGroupsList(dispatch, { licenseModelId, version }) {
110 return fetchFeatureGroupsList(licenseModelId, version).then(response =>
112 type: featureGroupsActionConstants.FEATURE_GROUPS_LIST_LOADED,
118 deleteFeatureGroup(dispatch, { licenseModelId, featureGroupId, version }) {
119 return deleteFeatureGroup(licenseModelId, featureGroupId, version).then(
122 type: featureGroupsActionConstants.DELETE_FEATURE_GROUPS,
125 return ItemsHelper.checkItemStatus(dispatch, {
126 itemId: licenseModelId,
127 versionId: version.id
135 { licenseModelId, previousFeatureGroup, featureGroup, version }
137 if (previousFeatureGroup) {
138 return updateFeatureGroup(
140 previousFeatureGroup,
145 type: featureGroupsActionConstants.EDIT_FEATURE_GROUPS,
148 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(
150 { licenseModelId, version }
152 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(
154 { licenseModelId, version }
156 return ItemsHelper.checkItemStatus(dispatch, {
157 itemId: licenseModelId,
158 versionId: version.id
162 return addFeatureGroup(licenseModelId, featureGroup, version).then(
165 type: featureGroupsActionConstants.ADD_FEATURE_GROUPS,
169 referencingLicenseAgreements: []
172 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(
174 { licenseModelId, version }
176 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(
178 { licenseModelId, version }
180 return ItemsHelper.checkItemStatus(dispatch, {
181 itemId: licenseModelId,
182 versionId: version.id
189 selectEntitlementPoolsEditorTab(dispatch, { tab }) {
191 type: featureGroupsActionConstants.featureGroupsEditor.SELECT_TAB,
196 openFeatureGroupsEditor(
198 { featureGroup, licenseModelId, version, isReadOnlyMode }
201 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {
205 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {
211 type: featureGroupsActionConstants.featureGroupsEditor.OPEN,
215 type: featureGroupsActionConstants.featureGroupsEditor.OPEN,
219 type: modalActionTypes.GLOBAL_MODAL_SHOW,
221 modalComponentName: modalContentMapper.FG_EDITOR,
222 modalComponentProps: {
226 size: modalSizes.LARGE
229 licenseModelId && version && featureGroup
230 ? i18n('Edit Feature Group')
231 : i18n('Create New Feature Group')
237 closeFeatureGroupsEditor(dispatch) {
239 type: featureGroupsActionConstants.featureGroupsEditor.CLOSE
242 type: modalActionTypes.GLOBAL_MODAL_CLOSE