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 {actionTypes} from './SoftwareProductProcessesConstants.js';
17 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
18 import Configuration from 'sdc-app/config/Configuration.js';
20 function baseUrl(vspId, version) {
21 let {id: versionId} = version;
22 const restPrefix = Configuration.get('restPrefix');
23 return `${restPrefix}/v1.0/vendor-software-products/${vspId}/versions/${versionId}/processes`;
26 function putProcess(softwareProductId, version, process) {
27 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${process.id}`, {
29 description: process.description,
30 type: process.type === '' ? null : process.type
34 function postProcess(softwareProductId, version, process) {
35 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
37 description: process.description,
38 type: process.type === '' ? null : process.type
42 function deleteProcess(softwareProductId, version, processId) {
43 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version)}/${processId}`);
46 function uploadFileToProcess(softwareProductId, version, processId, formData)
48 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}/${processId}/upload`, formData);
51 function fetchProcesses(softwareProductId, version) {
52 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
55 const SoftwareProductActionHelper = {
57 fetchProcessesList(dispatch, {softwareProductId, version}) {
60 type: actionTypes.FETCH_SOFTWARE_PRODUCT_PROCESSES,
64 return fetchProcesses(softwareProductId, version).then(response => {
66 type: actionTypes.FETCH_SOFTWARE_PRODUCT_PROCESSES,
67 processesList: response.results
71 openEditor(dispatch, process = {}) {
73 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_OPEN,
78 deleteProcess(dispatch, {process, softwareProductId, version}) {
79 return deleteProcess(softwareProductId, version, process.id).then(() => {
81 type: actionTypes.DELETE_SOFTWARE_PRODUCT_PROCESS,
88 closeEditor(dispatch) {
90 type:actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_CLOSE
94 saveProcess(dispatch, {softwareProductId, version, previousProcess, process}) {
95 if (previousProcess) {
96 return putProcess(softwareProductId, version, process).then(() => {
97 if (process.formData){
98 uploadFileToProcess(softwareProductId, version, process.id, process.formData);
101 type: actionTypes.EDIT_SOFTWARE_PRODUCT_PROCESS,
107 return postProcess(softwareProductId, version, process).then(response => {
108 if (process.formData) {
109 uploadFileToProcess(softwareProductId, version, response.value, process.formData);
112 type: actionTypes.ADD_SOFTWARE_PRODUCT_PROCESS,
122 hideDeleteConfirm(dispatch) {
124 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
125 processToDelete: false
129 openDeleteProcessesConfirm(dispatch, {process} ) {
131 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
132 processToDelete: process
138 export default SoftwareProductActionHelper;