2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
23 import {actionTypes as licenseAgreementActionTypes} from './LicenseAgreementConstants.js';
24 import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
25 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
27 function baseUrl(licenseModelId) {
28 const restPrefix = Configuration.get('restPrefix');
29 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/license-agreements`;
32 function fetchLicenseAgreementList(licenseModelId, version) {
33 let versionQuery = version ? `?version=${version}` : '';
34 return RestAPIUtil.fetch(`${baseUrl(licenseModelId)}${versionQuery}`);
37 function postLicenseAgreement(licenseModelId, licenseAgreement) {
38 return RestAPIUtil.create(baseUrl(licenseModelId), {
39 name: licenseAgreement.name,
40 description: licenseAgreement.description,
41 licenseTerm: licenseAgreement.licenseTerm,
42 requirementsAndConstrains: licenseAgreement.requirementsAndConstrains,
43 addedFeatureGroupsIds: licenseAgreement.featureGroupsIds
47 function putLicenseAgreement(licenseModelId, previousLicenseAgreement, licenseAgreement) {
48 const {featureGroupsIds = []} = licenseAgreement;
49 const {featureGroupsIds: prevFeatureGroupsIds = []} = previousLicenseAgreement;
50 return RestAPIUtil.save(`${baseUrl(licenseModelId)}/${licenseAgreement.id}`, {
51 name: licenseAgreement.name,
52 description: licenseAgreement.description,
53 licenseTerm: licenseAgreement.licenseTerm,
54 requirementsAndConstrains: licenseAgreement.requirementsAndConstrains,
55 addedFeatureGroupsIds: featureGroupsIds.filter(featureGroupId => prevFeatureGroupsIds.indexOf(featureGroupId) === -1),
56 removedFeatureGroupsIds: prevFeatureGroupsIds.filter(prevFeatureGroupsId => featureGroupsIds.indexOf(prevFeatureGroupsId) === -1)
60 function deleteLicenseAgreement(licenseModelId, licenseAgreementId) {
61 return RestAPIUtil.destroy(`${baseUrl(licenseModelId)}/${licenseAgreementId}`);
66 fetchLicenseAgreementList(dispatch, {licenseModelId, version}) {
67 return fetchLicenseAgreementList(licenseModelId, version).then(response => dispatch({
68 type: licenseAgreementActionTypes.LICENSE_AGREEMENT_LIST_LOADED,
73 openLicenseAgreementEditor(dispatch, {licenseModelId, licenseAgreement}) {
74 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId});
76 type: licenseAgreementActionTypes.licenseAgreementEditor.OPEN,
81 licenseAgreementEditorDataChanged(dispatch, {deltaData}) {
83 type: licenseAgreementActionTypes.licenseAgreementEditor.DATA_CHANGED,
88 closeLicenseAgreementEditor(dispatch) {
90 type: licenseAgreementActionTypes.licenseAgreementEditor.CLOSE
95 saveLicenseAgreement(dispatch, {licenseModelId, previousLicenseAgreement, licenseAgreement}) {
96 if (previousLicenseAgreement) {
97 return putLicenseAgreement(licenseModelId, previousLicenseAgreement, licenseAgreement).then(() => {
99 type: licenseAgreementActionTypes.EDIT_LICENSE_AGREEMENT,
105 return postLicenseAgreement(licenseModelId, licenseAgreement).then(response => {
107 type: licenseAgreementActionTypes.ADD_LICENSE_AGREEMENT,
117 deleteLicenseAgreement(dispatch, {licenseModelId, licenseAgreementId}) {
118 return deleteLicenseAgreement(licenseModelId, licenseAgreementId).then(() => {
120 type: licenseAgreementActionTypes.DELETE_LICENSE_AGREEMENT,
126 selectLicenseAgreementEditorTab(dispatch, {tab}) {
128 type: licenseAgreementActionTypes.licenseAgreementEditor.SELECT_TAB,
133 selectLicenseAgreementEditorFeatureGroupsButtonTab(dispatch, {buttonTab}) {
135 type: licenseAgreementActionTypes.licenseAgreementEditor.SELECT_FEATURE_GROUPS_BUTTONTAB,
140 hideDeleteConfirm(dispatch) {
142 type: licenseAgreementActionTypes.LICENSE_AGREEMENT_DELETE_CONFIRM,
143 licenseAgreementToDelete: false
147 openDeleteLicenseAgreementConfirm(dispatch, {licenseAgreement} ) {
149 type: licenseAgreementActionTypes.LICENSE_AGREEMENT_DELETE_CONFIRM,
150 licenseAgreementToDelete: licenseAgreement
154 switchVersion(dispatch, {licenseModelId, version}) {
155 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
156 this.fetchLicenseAgreementList(dispatch, {licenseModelId, version});