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(`${baseUrl(licenseModelId, version)}/${licenseAgreementId}`);
36 function postLicenseAgreement(licenseModelId, licenseAgreement, version) {
37 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
38 name: licenseAgreement.name,
39 description: licenseAgreement.description,
40 licenseTerm: licenseAgreement.licenseTerm,
41 requirementsAndConstrains: licenseAgreement.requirementsAndConstrains,
42 addedFeatureGroupsIds: licenseAgreement.featureGroupsIds
46 function putLicenseAgreement(licenseModelId, previousLicenseAgreement, licenseAgreement, version) {
47 const {featureGroupsIds = []} = licenseAgreement;
48 const {featureGroupsIds: prevFeatureGroupsIds = []} = previousLicenseAgreement;
49 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseAgreement.id}`, {
50 name: licenseAgreement.name,
51 description: licenseAgreement.description,
52 licenseTerm: licenseAgreement.licenseTerm,
53 requirementsAndConstrains: licenseAgreement.requirementsAndConstrains,
54 addedFeatureGroupsIds: featureGroupsIds.filter(featureGroupId => prevFeatureGroupsIds.indexOf(featureGroupId) === -1),
55 removedFeatureGroupsIds: prevFeatureGroupsIds.filter(prevFeatureGroupsId => featureGroupsIds.indexOf(prevFeatureGroupsId) === -1)
59 function deleteLicenseAgreement(licenseModelId, licenseAgreementId, version) {
60 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${licenseAgreementId}`);
65 fetchLicenseAgreementList(dispatch, {licenseModelId, version}) {
66 return fetchLicenseAgreementList(licenseModelId, version).then(response => dispatch({
67 type: licenseAgreementActionTypes.LICENSE_AGREEMENT_LIST_LOADED,
72 fetchLicenseAgreement(dispatch, {licenseModelId, licenseAgreementId, version}) {
73 return fetchLicenseAgreement(licenseModelId, licenseAgreementId, version);
76 openLicenseAgreementEditor(dispatch, {licenseModelId, licenseAgreement, version}) {
77 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version});
79 type: licenseAgreementActionTypes.licenseAgreementEditor.OPEN,
84 closeLicenseAgreementEditor(dispatch) {
86 type: licenseAgreementActionTypes.licenseAgreementEditor.CLOSE
91 saveLicenseAgreement(dispatch, {licenseModelId, previousLicenseAgreement, licenseAgreement, version}) {
92 if (previousLicenseAgreement) {
93 return putLicenseAgreement(licenseModelId, previousLicenseAgreement, licenseAgreement, version).then(() => {
94 this.fetchLicenseAgreementList(dispatch, {licenseModelId, version});
95 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
99 return postLicenseAgreement(licenseModelId, licenseAgreement, version).then(() => {
100 this.fetchLicenseAgreementList(dispatch, {licenseModelId, version});
101 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version});
102 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
107 deleteLicenseAgreement(dispatch, {licenseModelId, licenseAgreementId, version}) {
108 return deleteLicenseAgreement(licenseModelId, licenseAgreementId, version).then(() => {
110 type: licenseAgreementActionTypes.DELETE_LICENSE_AGREEMENT,
113 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
117 selectLicenseAgreementEditorTab(dispatch, {tab}) {
119 type: licenseAgreementActionTypes.licenseAgreementEditor.SELECT_TAB,