blob: a379a2c40fc00dadbd67cccbc869d30d854ab91c [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20
21import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22import Configuration from 'sdc-app/config/Configuration.js';
23import {actionTypes} from './LicenseModelConstants.js';
24import {actionsEnum as vcActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
25import i18n from 'nfvo-utils/i18n/i18n.js';
26import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
27
28function baseUrl() {
29 const restPrefix = Configuration.get('restPrefix');
30 return `${restPrefix}/v1.0/vendor-license-models/`;
31}
32
33function fetchLicenseModels() {
34 return RestAPIUtil.fetch(baseUrl());
35}
36
37function fetchFinalizedLicenseModels() {
38 return RestAPIUtil.fetch(`${baseUrl()}?versionFilter=Final`);
39}
40
41function fetchLicenseModelById(licenseModelId, version) {
42 let versionQuery = version ? `?version=${version}` : '';
43 return RestAPIUtil.fetch(`${baseUrl()}${licenseModelId}${versionQuery}`);
44}
45
46function putLicenseModelAction(id, action) {
47 return RestAPIUtil.save(`${baseUrl()}${id}/actions`, {action: action});
48}
49
50const LicenseModelActionHelper = {
51
52 fetchLicenseModels(dispatch) {
53 return fetchLicenseModels().then(response => {
54 dispatch({
55 type: actionTypes.LICENSE_MODELS_LIST_LOADED,
56 response
57 });
58 });
59 },
60
61 fetchFinalizedLicenseModels(dispatch) {
62 return fetchFinalizedLicenseModels().then(response => dispatch({
63 type: actionTypes.FINALIZED_LICENSE_MODELS_LIST_LOADED,
64 response
65 }));
66
67 },
68
69 fetchLicenseModelById(dispatch, {licenseModelId, version}) {
70 return fetchLicenseModelById(licenseModelId, version).then(response => {
71 if(version) {
72 response.version = version;
73 }
74 dispatch({
75 type: actionTypes.LICENSE_MODEL_LOADED,
76 response
77 });
78 });
79 },
80
81 addLicenseModel(dispatch, {licenseModel}){
82 dispatch({
83 type: actionTypes.ADD_LICENSE_MODEL,
84 licenseModel
85 });
86 },
87
88 performVCAction(dispatch, {licenseModelId, action}) {
89 return putLicenseModelAction(licenseModelId, action).then(() => {
90 if(action === vcActionsEnum.SUBMIT){
91 dispatch({
92 type: NotificationConstants.NOTIFY_SUCCESS,
93 data: {title: i18n('Submit Succeeded'), msg: i18n('This license model successfully submitted'), timeout: 2000}
94 });
95 }
96 return LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId});
97 });
98 }
99};
100
101export default LicenseModelActionHelper;