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(
31 `${baseUrl(licenseModelId, version)}/${featureGroupId}`
35 function fetchFeatureGroupsList(licenseModelId, version) {
36 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
39 function deleteFeatureGroup(licenseModelId, featureGroupId, version) {
40 return RestAPIUtil.destroy(
41 `${baseUrl(licenseModelId, version)}/${featureGroupId}`
45 function addFeatureGroup(licenseModelId, featureGroup, version) {
46 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
47 name: featureGroup.name,
48 description: featureGroup.description,
49 partNumber: featureGroup.partNumber,
50 manufacturerReferenceNumber: featureGroup.manufacturerReferenceNumber,
51 addedLicenseKeyGroupsIds: featureGroup.licenseKeyGroupsIds,
52 addedEntitlementPoolsIds: featureGroup.entitlementPoolsIds
56 function updateFeatureGroup(
62 const { licenseKeyGroupsIds = [] } = featureGroup;
64 licenseKeyGroupsIds: prevLicenseKeyGroupsIds = []
65 } = previousFeatureGroup;
66 const { entitlementPoolsIds = [] } = featureGroup;
68 entitlementPoolsIds: prevEntitlementPoolsIds = []
69 } = previousFeatureGroup;
70 return RestAPIUtil.put(
71 `${baseUrl(licenseModelId, version)}/${featureGroup.id}`,
73 name: featureGroup.name,
74 description: featureGroup.description,
75 partNumber: featureGroup.partNumber,
76 manufacturerReferenceNumber:
77 featureGroup.manufacturerReferenceNumber,
78 addedLicenseKeyGroupsIds: licenseKeyGroupsIds.filter(
80 prevLicenseKeyGroupsIds.indexOf(licenseKeyGroupId) === -1
82 removedLicenseKeyGroupsIds: prevLicenseKeyGroupsIds.filter(
83 prevLicenseKeyGroupId =>
84 licenseKeyGroupsIds.indexOf(prevLicenseKeyGroupId) === -1
86 addedEntitlementPoolsIds: entitlementPoolsIds.filter(
88 prevEntitlementPoolsIds.indexOf(entitlementPoolId) === -1
90 removedEntitlementPoolsIds: prevEntitlementPoolsIds.filter(
91 prevEntitlementPoolId =>
92 entitlementPoolsIds.indexOf(prevEntitlementPoolId) === -1
99 fetchFeatureGroup(dispatch, { licenseModelId, featureGroupId, version }) {
100 return fetchFeatureGroup(licenseModelId, featureGroupId, version);
103 fetchFeatureGroupsList(dispatch, { licenseModelId, version }) {
104 return fetchFeatureGroupsList(licenseModelId, version).then(response =>
106 type: featureGroupsActionConstants.FEATURE_GROUPS_LIST_LOADED,
112 deleteFeatureGroup(dispatch, { licenseModelId, featureGroupId, version }) {
113 return deleteFeatureGroup(licenseModelId, featureGroupId, version).then(
116 type: featureGroupsActionConstants.DELETE_FEATURE_GROUPS,
119 return ItemsHelper.checkItemStatus(dispatch, {
120 itemId: licenseModelId,
121 versionId: version.id
129 { licenseModelId, previousFeatureGroup, featureGroup, version }
131 if (previousFeatureGroup) {
132 return updateFeatureGroup(
134 previousFeatureGroup,
139 type: featureGroupsActionConstants.EDIT_FEATURE_GROUPS,
142 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(
144 { licenseModelId, version }
146 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(
148 { licenseModelId, version }
150 return ItemsHelper.checkItemStatus(dispatch, {
151 itemId: licenseModelId,
152 versionId: version.id
156 return addFeatureGroup(licenseModelId, featureGroup, version).then(
159 type: featureGroupsActionConstants.ADD_FEATURE_GROUPS,
163 referencingLicenseAgreements: []
166 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(
168 { licenseModelId, version }
170 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(
172 { licenseModelId, version }
174 return ItemsHelper.checkItemStatus(dispatch, {
175 itemId: licenseModelId,
176 versionId: version.id
183 selectEntitlementPoolsEditorTab(dispatch, { tab }) {
185 type: featureGroupsActionConstants.featureGroupsEditor.SELECT_TAB,
190 openFeatureGroupsEditor(
192 { featureGroup, licenseModelId, version }
195 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {
199 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {
205 type: featureGroupsActionConstants.featureGroupsEditor.OPEN,
211 closeFeatureGroupsEditor(dispatch) {
213 type: featureGroupsActionConstants.featureGroupsEditor.CLOSE