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 licenseAgreementActionTypes } from './LicenseAgreementConstants.js';
19 import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
20 import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js';
22 actionTypes as modalActionTypes,
24 } from 'nfvo-components/modal/GlobalModalConstants.js';
25 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
26 import i18n from 'nfvo-utils/i18n/i18n.js';
28 function baseUrl(licenseModelId, version) {
29 const restPrefix = Configuration.get('restPrefix');
30 const { id: versionId } = version;
31 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/license-agreements`;
34 function fetchLicenseAgreementList(licenseModelId, version) {
35 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
38 function fetchLicenseAgreement(licenseModelId, licenseAgreementId, version) {
39 return RestAPIUtil.fetch(
40 `${baseUrl(licenseModelId, version)}/${licenseAgreementId}`
44 function postLicenseAgreement(licenseModelId, licenseAgreement, version) {
45 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
46 name: licenseAgreement.name,
47 description: licenseAgreement.description,
48 licenseTerm: licenseAgreement.licenseTerm,
49 addedFeatureGroupsIds: licenseAgreement.featureGroupsIds
53 function putLicenseAgreement(
55 previousLicenseAgreement,
59 const { featureGroupsIds = [] } = licenseAgreement;
61 featureGroupsIds: prevFeatureGroupsIds = []
62 } = previousLicenseAgreement;
63 return RestAPIUtil.put(
64 `${baseUrl(licenseModelId, version)}/${licenseAgreement.id}`,
66 name: licenseAgreement.name,
67 description: licenseAgreement.description,
68 licenseTerm: licenseAgreement.licenseTerm,
69 addedFeatureGroupsIds: featureGroupsIds.filter(
71 prevFeatureGroupsIds.indexOf(featureGroupId) === -1
73 removedFeatureGroupsIds: prevFeatureGroupsIds.filter(
74 prevFeatureGroupsId =>
75 featureGroupsIds.indexOf(prevFeatureGroupsId) === -1
81 function deleteLicenseAgreement(licenseModelId, licenseAgreementId, version) {
82 return RestAPIUtil.destroy(
83 `${baseUrl(licenseModelId, version)}/${licenseAgreementId}`
88 fetchLicenseAgreementList(dispatch, { licenseModelId, version }) {
89 return fetchLicenseAgreementList(licenseModelId, version).then(
93 licenseAgreementActionTypes.LICENSE_AGREEMENT_LIST_LOADED,
99 fetchLicenseAgreement(
101 { licenseModelId, licenseAgreementId, version }
103 return fetchLicenseAgreement(
110 openLicenseAgreementEditor(
112 { licenseModelId, licenseAgreement, version, isReadOnlyMode }
114 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
119 type: licenseAgreementActionTypes.licenseAgreementEditor.OPEN,
123 type: modalActionTypes.GLOBAL_MODAL_SHOW,
125 modalComponentName: modalContentMapper.LA_EDITOR,
126 modalComponentProps: {
130 size: modalSizes.LARGE
133 licenseModelId && version && licenseAgreement
134 ? i18n('Edit License Agreement')
135 : i18n('Create New License Agreement')
140 closeLicenseAgreementEditor(dispatch) {
142 type: licenseAgreementActionTypes.licenseAgreementEditor.CLOSE
145 type: modalActionTypes.GLOBAL_MODAL_CLOSE
149 async saveLicenseAgreement(
151 { licenseModelId, previousLicenseAgreement, licenseAgreement, version }
153 if (previousLicenseAgreement) {
154 await putLicenseAgreement(
156 previousLicenseAgreement,
161 await postLicenseAgreement(
167 await this.fetchLicenseAgreementList(dispatch, {
171 await FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
176 return ItemsHelper.checkItemStatus(dispatch, {
177 itemId: licenseModelId,
178 versionId: version.id
182 deleteLicenseAgreement(
184 { licenseModelId, licenseAgreementId, version }
186 return deleteLicenseAgreement(
192 type: licenseAgreementActionTypes.DELETE_LICENSE_AGREEMENT,
195 return ItemsHelper.checkItemStatus(dispatch, {
196 itemId: licenseModelId,
197 versionId: version.id
202 selectLicenseAgreementEditorTab(dispatch, { tab }) {
204 type: licenseAgreementActionTypes.licenseAgreementEditor.SELECT_TAB,