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} from './LicenseModelConstants.js';
24 import {actionsEnum as vcActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
25 import i18n from 'nfvo-utils/i18n/i18n.js';
26 import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
29 const restPrefix = Configuration.get('restPrefix');
30 return `${restPrefix}/v1.0/vendor-license-models/`;
33 function fetchLicenseModels() {
34 return RestAPIUtil.fetch(baseUrl());
37 function fetchFinalizedLicenseModels() {
38 return RestAPIUtil.fetch(`${baseUrl()}?versionFilter=Final`);
41 function fetchLicenseModelById(licenseModelId, version) {
42 let versionQuery = version ? `?version=${version}` : '';
43 return RestAPIUtil.fetch(`${baseUrl()}${licenseModelId}${versionQuery}`);
46 function putLicenseModelAction(id, action) {
47 return RestAPIUtil.save(`${baseUrl()}${id}/actions`, {action: action});
50 const LicenseModelActionHelper = {
52 fetchLicenseModels(dispatch) {
53 return fetchLicenseModels().then(response => {
55 type: actionTypes.LICENSE_MODELS_LIST_LOADED,
61 fetchFinalizedLicenseModels(dispatch) {
62 return fetchFinalizedLicenseModels().then(response => dispatch({
63 type: actionTypes.FINALIZED_LICENSE_MODELS_LIST_LOADED,
69 fetchLicenseModelById(dispatch, {licenseModelId, version}) {
70 return fetchLicenseModelById(licenseModelId, version).then(response => {
72 response.version = version;
75 type: actionTypes.LICENSE_MODEL_LOADED,
81 addLicenseModel(dispatch, {licenseModel}){
83 type: actionTypes.ADD_LICENSE_MODEL,
88 performVCAction(dispatch, {licenseModelId, action}) {
89 return putLicenseModelAction(licenseModelId, action).then(() => {
90 if(action === vcActionsEnum.SUBMIT){
92 type: NotificationConstants.NOTIFY_SUCCESS,
93 data: {title: i18n('Submit Succeeded'), msg: i18n('This license model successfully submitted'), timeout: 2000}
96 return LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId});
101 export default LicenseModelActionHelper;