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 i18n from 'nfvo-utils/i18n/i18n.js';
17 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
18 import Configuration from 'sdc-app/config/Configuration.js';
19 import {actionTypes} from './SoftwareProductComponentsMonitoringConstants.js';
20 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
22 function baseUrl(vspId, version, componentId) {
23 const versionId = version.id;
24 const restPrefix = Configuration.get('restPrefix');
25 return `${restPrefix}/v1.0/vendor-software-products/${vspId}/versions/${versionId}/components/${componentId}/uploads`;
28 let onInvalidFileSizeUpload = (dispatch) => dispatch({
29 type: modalActionTypes.GLOBAL_MODAL_ERROR,
31 title: i18n('Upload Failed'),
32 msg: i18n('no zip file was uploaded or zip file doesn\'t exist')
36 let uploadFile = (dispatch, {softwareProductId, version, componentId, formData, type}) => {
37 return RestAPIUtil.post(`${baseUrl(softwareProductId, version, componentId)}/types/${type}`, formData).then(()=> dispatch({
38 type: actionTypes.MONITOR_UPLOADED, data: {filename: formData.get('upload').name, type : type}
42 let deleteFile = (dispatch, {softwareProductId, version, componentId, type}) => {
43 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version, componentId)}/types/${type}`).then(()=> dispatch({
44 type: actionTypes.MONITOR_DELETED,
50 const SoftwareProductComponentsMonitoringAction = {
52 fetchExistingFiles(dispatch, {softwareProductId, version, componentId}){
53 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}`).then(response =>
55 type: actionTypes.MONITOR_FILES_DATA_CHANGE,
61 uploadFile(dispatch, {softwareProductId, version, componentId, formData, type}){
62 if (formData.get('upload').size) {
63 return uploadFile(dispatch, {softwareProductId, version, componentId, formData, type});
66 onInvalidFileSizeUpload(dispatch);
70 deleteFile(dispatch, {softwareProductId, version, componentId, type}){
71 return deleteFile(dispatch, {softwareProductId, version, componentId, type});
76 export default SoftwareProductComponentsMonitoringAction;