blob: b4f03a68cd14f1f9a68112413a2e65af2db44370 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17import Configuration from 'sdc-app/config/Configuration.js';
18import {actionTypes as licenseAgreementActionTypes} from './LicenseAgreementConstants.js';
19import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020020import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js';
Michael Landoefa037d2017-02-19 12:57:33 +020021
AviZi280f8012017-06-09 02:39:56 +030022function baseUrl(licenseModelId, version) {
Michael Landoefa037d2017-02-19 12:57:33 +020023 const restPrefix = Configuration.get('restPrefix');
AviZi280f8012017-06-09 02:39:56 +030024 const {id: versionId} = version;
25 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/license-agreements`;
Michael Landoefa037d2017-02-19 12:57:33 +020026}
27
28function fetchLicenseAgreementList(licenseModelId, version) {
AviZi280f8012017-06-09 02:39:56 +030029 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
Michael Landoefa037d2017-02-19 12:57:33 +020030}
31
talig8e9c0652017-12-20 14:30:43 +020032function fetchLicenseAgreement(licenseModelId, licenseAgreementId, version) {
33 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}/${licenseAgreementId}`);
34}
35
AviZi280f8012017-06-09 02:39:56 +030036function postLicenseAgreement(licenseModelId, licenseAgreement, version) {
37 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
Michael Landoefa037d2017-02-19 12:57:33 +020038 name: licenseAgreement.name,
39 description: licenseAgreement.description,
40 licenseTerm: licenseAgreement.licenseTerm,
41 requirementsAndConstrains: licenseAgreement.requirementsAndConstrains,
42 addedFeatureGroupsIds: licenseAgreement.featureGroupsIds
43 });
44}
45
AviZi280f8012017-06-09 02:39:56 +030046function putLicenseAgreement(licenseModelId, previousLicenseAgreement, licenseAgreement, version) {
Michael Landoefa037d2017-02-19 12:57:33 +020047 const {featureGroupsIds = []} = licenseAgreement;
48 const {featureGroupsIds: prevFeatureGroupsIds = []} = previousLicenseAgreement;
AviZi280f8012017-06-09 02:39:56 +030049 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseAgreement.id}`, {
Michael Landoefa037d2017-02-19 12:57:33 +020050 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)
56 });
57}
58
AviZi280f8012017-06-09 02:39:56 +030059function deleteLicenseAgreement(licenseModelId, licenseAgreementId, version) {
60 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${licenseAgreementId}`);
Michael Landoefa037d2017-02-19 12:57:33 +020061}
62
63export default {
64
65 fetchLicenseAgreementList(dispatch, {licenseModelId, version}) {
66 return fetchLicenseAgreementList(licenseModelId, version).then(response => dispatch({
67 type: licenseAgreementActionTypes.LICENSE_AGREEMENT_LIST_LOADED,
68 response
69 }));
70 },
71
talig8e9c0652017-12-20 14:30:43 +020072 fetchLicenseAgreement(dispatch, {licenseModelId, licenseAgreementId, version}) {
73 return fetchLicenseAgreement(licenseModelId, licenseAgreementId, version);
74 },
75
AviZi280f8012017-06-09 02:39:56 +030076 openLicenseAgreementEditor(dispatch, {licenseModelId, licenseAgreement, version}) {
77 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version});
Michael Landoefa037d2017-02-19 12:57:33 +020078 dispatch({
79 type: licenseAgreementActionTypes.licenseAgreementEditor.OPEN,
80 licenseAgreement
81 });
82 },
83
Michael Landoefa037d2017-02-19 12:57:33 +020084 closeLicenseAgreementEditor(dispatch) {
85 dispatch({
86 type: licenseAgreementActionTypes.licenseAgreementEditor.CLOSE
87 });
88 },
89
90
AviZi280f8012017-06-09 02:39:56 +030091 saveLicenseAgreement(dispatch, {licenseModelId, previousLicenseAgreement, licenseAgreement, version}) {
Michael Landoefa037d2017-02-19 12:57:33 +020092 if (previousLicenseAgreement) {
AviZi280f8012017-06-09 02:39:56 +030093 return putLicenseAgreement(licenseModelId, previousLicenseAgreement, licenseAgreement, version).then(() => {
ilanapcb1d4832017-09-27 11:41:19 +030094 this.fetchLicenseAgreementList(dispatch, {licenseModelId, version});
talig8e9c0652017-12-20 14:30:43 +020095 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
Michael Landoefa037d2017-02-19 12:57:33 +020096 });
97 }
98 else {
ilanapcb1d4832017-09-27 11:41:19 +030099 return postLicenseAgreement(licenseModelId, licenseAgreement, version).then(() => {
100 this.fetchLicenseAgreementList(dispatch, {licenseModelId, version});
101 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version});
talig8e9c0652017-12-20 14:30:43 +0200102 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
Michael Landoefa037d2017-02-19 12:57:33 +0200103 });
104 }
105 },
106
AviZi280f8012017-06-09 02:39:56 +0300107 deleteLicenseAgreement(dispatch, {licenseModelId, licenseAgreementId, version}) {
108 return deleteLicenseAgreement(licenseModelId, licenseAgreementId, version).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +0200109 dispatch({
110 type: licenseAgreementActionTypes.DELETE_LICENSE_AGREEMENT,
111 licenseAgreementId
112 });
talig8e9c0652017-12-20 14:30:43 +0200113 ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
Michael Landoefa037d2017-02-19 12:57:33 +0200114 });
115 },
116
117 selectLicenseAgreementEditorTab(dispatch, {tab}) {
118 dispatch({
119 type: licenseAgreementActionTypes.licenseAgreementEditor.SELECT_TAB,
120 tab
121 });
Michael Landoefa037d2017-02-19 12:57:33 +0200122 }
123};