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(
28 `${baseUrl(softwareProductId, version)}/${process.id}`,
31 description: process.description,
32 type: process.type === '' ? null : process.type
37 function postProcess(softwareProductId, version, process) {
38 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
40 description: process.description,
41 type: process.type === '' ? null : process.type
45 function deleteProcess(softwareProductId, version, processId) {
46 return RestAPIUtil.destroy(
47 `${baseUrl(softwareProductId, version)}/${processId}`
51 function uploadFileToProcess(softwareProductId, version, processId, formData) {
52 return RestAPIUtil.post(
53 `${baseUrl(softwareProductId, version)}/${processId}/upload`,
58 function fetchProcesses(softwareProductId, version) {
59 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
62 const SoftwareProductActionHelper = {
63 fetchProcessesList(dispatch, { softwareProductId, version }) {
65 type: actionTypes.FETCH_SOFTWARE_PRODUCT_PROCESSES,
69 return fetchProcesses(softwareProductId, version).then(response => {
71 type: actionTypes.FETCH_SOFTWARE_PRODUCT_PROCESSES,
72 processesList: response.results
76 openEditor(dispatch, process = {}) {
78 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_OPEN,
83 deleteProcess(dispatch, { process, softwareProductId, version }) {
84 return deleteProcess(softwareProductId, version, process.id).then(
87 type: actionTypes.DELETE_SOFTWARE_PRODUCT_PROCESS,
94 closeEditor(dispatch) {
96 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_CLOSE
102 { softwareProductId, version, previousProcess, process }
104 if (previousProcess) {
105 return putProcess(softwareProductId, version, process).then(() => {
106 if (process.formData) {
115 type: actionTypes.EDIT_SOFTWARE_PRODUCT_PROCESS,
120 return postProcess(softwareProductId, version, process).then(
122 if (process.formData) {
131 type: actionTypes.ADD_SOFTWARE_PRODUCT_PROCESS,
142 hideDeleteConfirm(dispatch) {
144 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
145 processToDelete: false
149 openDeleteProcessesConfirm(dispatch, { process }) {
151 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
152 processToDelete: process
157 export default SoftwareProductActionHelper;