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 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 function baseUrl(licenseModelId, version) {
23 const restPrefix = Configuration.get('restPrefix');
24 const { id: versionId } = version;
25 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/license-agreements`;
28 function fetchLicenseAgreementList(licenseModelId, version) {
29 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
32 function fetchLicenseAgreement(licenseModelId, licenseAgreementId, version) {
33 return RestAPIUtil.fetch(
34 `${baseUrl(licenseModelId, version)}/${licenseAgreementId}`
38 function postLicenseAgreement(licenseModelId, licenseAgreement, version) {
39 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
40 name: licenseAgreement.name,
41 description: licenseAgreement.description,
42 licenseTerm: licenseAgreement.licenseTerm,
43 requirementsAndConstrains: licenseAgreement.requirementsAndConstrains,
44 addedFeatureGroupsIds: licenseAgreement.featureGroupsIds
48 function putLicenseAgreement(
50 previousLicenseAgreement,
54 const { featureGroupsIds = [] } = licenseAgreement;
56 featureGroupsIds: prevFeatureGroupsIds = []
57 } = previousLicenseAgreement;
58 return RestAPIUtil.put(
59 `${baseUrl(licenseModelId, version)}/${licenseAgreement.id}`,
61 name: licenseAgreement.name,
62 description: licenseAgreement.description,
63 licenseTerm: licenseAgreement.licenseTerm,
64 requirementsAndConstrains:
65 licenseAgreement.requirementsAndConstrains,
66 addedFeatureGroupsIds: featureGroupsIds.filter(
68 prevFeatureGroupsIds.indexOf(featureGroupId) === -1
70 removedFeatureGroupsIds: prevFeatureGroupsIds.filter(
71 prevFeatureGroupsId =>
72 featureGroupsIds.indexOf(prevFeatureGroupsId) === -1
78 function deleteLicenseAgreement(licenseModelId, licenseAgreementId, version) {
79 return RestAPIUtil.destroy(
80 `${baseUrl(licenseModelId, version)}/${licenseAgreementId}`
85 fetchLicenseAgreementList(dispatch, { licenseModelId, version }) {
86 return fetchLicenseAgreementList(licenseModelId, version).then(
90 licenseAgreementActionTypes.LICENSE_AGREEMENT_LIST_LOADED,
96 fetchLicenseAgreement(
98 { licenseModelId, licenseAgreementId, version }
100 return fetchLicenseAgreement(
107 openLicenseAgreementEditor(
109 { licenseModelId, licenseAgreement, version }
111 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
116 type: licenseAgreementActionTypes.licenseAgreementEditor.OPEN,
121 closeLicenseAgreementEditor(dispatch) {
123 type: licenseAgreementActionTypes.licenseAgreementEditor.CLOSE
127 saveLicenseAgreement(
129 { licenseModelId, previousLicenseAgreement, licenseAgreement, version }
131 if (previousLicenseAgreement) {
132 return putLicenseAgreement(
134 previousLicenseAgreement,
138 this.fetchLicenseAgreementList(dispatch, {
142 return ItemsHelper.checkItemStatus(dispatch, {
143 itemId: licenseModelId,
144 versionId: version.id
148 return postLicenseAgreement(
153 this.fetchLicenseAgreementList(dispatch, {
157 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
161 return ItemsHelper.checkItemStatus(dispatch, {
162 itemId: licenseModelId,
163 versionId: version.id
169 deleteLicenseAgreement(
171 { licenseModelId, licenseAgreementId, version }
173 return deleteLicenseAgreement(
179 type: licenseAgreementActionTypes.DELETE_LICENSE_AGREEMENT,
182 return ItemsHelper.checkItemStatus(dispatch, {
183 itemId: licenseModelId,
184 versionId: version.id
189 selectLicenseAgreementEditorTab(dispatch, { tab }) {
191 type: licenseAgreementActionTypes.licenseAgreementEditor.SELECT_TAB,