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 './SoftwareProductComponentProcessesConstants.js';
20 function baseUrl(softwareProductId, version, componentId) {
21 const restPrefix = Configuration.get('restPrefix');
22 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${componentId}/processes`;
25 function fetchProcessesList({softwareProductId, version, componentId}) {
26 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}`);
29 function deleteProcess({softwareProductId, version, componentId, processId}) {
30 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version, componentId)}/${processId}`);
33 function putProcess({softwareProductId, version, componentId, process}) {
34 return RestAPIUtil.put(`${baseUrl(softwareProductId, version, componentId)}/${process.id}`, {
36 description: process.description,
37 type: process.type === '' ? null : process.type
41 function postProcess({softwareProductId, version, componentId, process}) {
42 return RestAPIUtil.post(`${baseUrl(softwareProductId, version, componentId)}`, {
44 description: process.description,
45 type: process.type === '' ? null : process.type
49 function uploadFileToProcess({softwareProductId, version, processId, componentId, formData}) {
50 return RestAPIUtil.post(`${baseUrl(softwareProductId, version, componentId)}/${processId}/upload`, formData);
55 const SoftwareProductComponentProcessesActionHelper = {
56 fetchProcessesList(dispatch, {softwareProductId, version, componentId}) {
58 type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
62 return fetchProcessesList({softwareProductId, version, componentId}).then(response => {
64 type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
65 processesList: response.results
70 deleteProcess(dispatch, {process, softwareProductId, version, componentId}) {
71 return deleteProcess({softwareProductId, version, processId:process.id, componentId}).then(() => {
73 type: actionTypes.DELETE_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
80 saveProcess(dispatch, {softwareProductId, version, componentId, previousProcess, process}) {
81 if (previousProcess) {
82 return putProcess({softwareProductId, version, componentId, process}).then(() => {
83 if (process.formData && process.formData.name !== previousProcess.artifactName){
84 uploadFileToProcess({softwareProductId, version, processId: process.id, formData: process.formData, componentId});
87 type: actionTypes.EDIT_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
93 return postProcess({softwareProductId, version, componentId, process}).then(response => {
94 if (process.formData) {
95 uploadFileToProcess({softwareProductId, version, processId: response.value, formData: process.formData, componentId});
98 type: actionTypes.ADD_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
108 hideDeleteConfirm(dispatch) {
110 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_COMPONENTS_CONFIRM,
111 processToDelete: false
115 openDeleteProcessesConfirm(dispatch, {process} ) {
117 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_COMPONENTS_CONFIRM,
118 processToDelete: process
122 openEditor(dispatch, process = {}) {
124 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_OPEN,
128 closeEditor(dispatch) {
130 type:actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_CLOSE
135 export default SoftwareProductComponentProcessesActionHelper;