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} from './LicenseModelConstants.js';
19 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
20 import {actionsEnum as vcActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import LicenseAgreementActionHelper from './licenseAgreement/LicenseAgreementActionHelper.js';
23 import FeatureGroupsActionHelper from './featureGroups/FeatureGroupsActionHelper.js';
24 import EntitlementPoolsActionHelper from './entitlementPools/EntitlementPoolsActionHelper.js';
25 import LicenseKeyGroupsActionHelper from './licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
28 const restPrefix = Configuration.get('restPrefix');
29 return `${restPrefix}/v1.0/vendor-license-models/`;
32 function fetchLicenseModels() {
33 return RestAPIUtil.fetch(baseUrl());
36 function fetchFinalizedLicenseModels() {
37 return RestAPIUtil.fetch(`${baseUrl()}?versionFilter=Final`);
40 function fetchLicenseModelById(licenseModelId, version) {
41 const {id: versionId} = version;
42 return RestAPIUtil.fetch(`${baseUrl()}${licenseModelId}/versions/${versionId}`);
45 function putLicenseModelAction(id, action, version) {
46 const {id: versionId} = version;
47 return RestAPIUtil.put(`${baseUrl()}${id}/versions/${versionId}/actions`, {action: action});
50 function putLicenseModel(licenseModel) {
51 let {id, vendorName, description, iconRef, version: {id: versionId}} = licenseModel;
52 return RestAPIUtil.put(`${baseUrl()}${id}/versions/${versionId}`, {
59 function adjustMinorVersion(version, value) {
60 let ar = version.split('.');
61 return ar[0] + '.' + (parseInt(ar[1]) + value);
64 function adjustMajorVersion(version, value) {
65 let ar = version.split('.');
66 return (parseInt(ar[0]) + value) + '.0';
69 const LicenseModelActionHelper = {
71 fetchLicenseModels(dispatch) {
72 return fetchLicenseModels().then(response => {
74 type: actionTypes.LICENSE_MODELS_LIST_LOADED,
80 fetchFinalizedLicenseModels(dispatch) {
81 return fetchFinalizedLicenseModels().then(response => dispatch({
82 type: actionTypes.FINALIZED_LICENSE_MODELS_LIST_LOADED,
88 fetchLicenseModelById(dispatch, {licenseModelId, version}) {
90 return fetchLicenseModelById(licenseModelId, version).then(response => {
92 type: actionTypes.LICENSE_MODEL_LOADED,
93 response: {...response, version}
98 addLicenseModel(dispatch, {licenseModel}){
100 type: actionTypes.ADD_LICENSE_MODEL,
105 fetchLicenseModelItems(dispatch, {licenseModelId, version}) {
107 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version}),
108 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version}),
109 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}),
110 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version})
114 performVCAction(dispatch, {licenseModelId, action, version}) {
115 return putLicenseModelAction(licenseModelId, action, version).then(() => {
116 if(action === vcActionsEnum.SUBMIT){
118 type: modalActionTypes.GLOBAL_MODAL_SUCCESS,
120 title: i18n('Submit Succeeded'),
121 msg: i18n('This license model successfully submitted'),
122 cancelButtonText: i18n('OK'),
128 let newVersionId = version.id;
130 TODO Temorary switch to change version label
133 case vcActionsEnum.CHECK_OUT:
134 newVersionId = adjustMinorVersion(version.label, 1);
136 case vcActionsEnum.UNDO_CHECK_OUT:
137 newVersionId = adjustMinorVersion(version.label, -1);
139 case vcActionsEnum.SUBMIT:
140 newVersionId = adjustMajorVersion(version.label, 1);
143 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version:{id: newVersionId, label: newVersionId}});
144 return Promise.resolve({id: newVersionId, label: newVersionId});
148 switchVersion(dispatch, {licenseModelId, version}) {
149 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version: {id: version.id, label: version.label}}).then(() => {
150 LicenseModelActionHelper.fetchLicenseModelItems(dispatch, {licenseModelId, version});
154 saveLicenseModel(dispatch, {licenseModel}) {
155 return putLicenseModel(licenseModel).then(() => {
157 type: actionTypes.ADD_LICENSE_MODEL,
161 type: actionTypes.LICENSE_MODEL_LOADED,
162 response: licenseModel
169 export default LicenseModelActionHelper;