2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import {actionTypes} from './SoftwareProductProcessesConstants.js';
22 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
23 import Configuration from 'sdc-app/config/Configuration.js';
25 function baseUrl(svpId) {
26 const restPrefix = Configuration.get('restPrefix');
27 return `${restPrefix}/v1.0/vendor-software-products/${svpId}/processes`;
30 function putProcess(softwareProductId, process) {
31 return RestAPIUtil.save(`${baseUrl(softwareProductId)}/${process.id}`, {
33 description: process.description
37 function postProcess(softwareProductId, process) {
38 return RestAPIUtil.create(`${baseUrl(softwareProductId)}`, {
40 description: process.description
44 function deleteProcess(softwareProductId, processId) {
45 return RestAPIUtil.destroy(`${baseUrl(softwareProductId)}/${processId}`);
48 function uploadFileToProcess(softwareProductId, processId, formData)
50 return RestAPIUtil.create(`${baseUrl(softwareProductId)}/${processId}/upload`, formData);
53 function fetchProcesses(softwareProductId, version) {
54 let versionQuery = version ? `?version=${version}` : '';
55 return RestAPIUtil.fetch(`${baseUrl(softwareProductId)}${versionQuery}`);
60 const SoftwareProductActionHelper = {
62 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}) {
84 return deleteProcess(softwareProductId, process.id).then(() => {
86 type: actionTypes.DELETE_SOFTWARE_PRODUCT_PROCESS,
93 closeEditor(dispatch) {
95 type:actionTypes.SOFTWARE_PRODUCT_PROCESS_EDITOR_CLOSE
99 processEditorDataChanged(dispatch, {deltaData}) {
101 type: actionTypes.processEditor.DATA_CHANGED,
106 saveProcess(dispatch, {softwareProductId, previousProcess, process}) {
107 if (previousProcess) {
108 return putProcess(softwareProductId, process).then(() => {
109 if (process.formData){
110 uploadFileToProcess(softwareProductId, process.id, process.formData);
113 type: actionTypes.EDIT_SOFTWARE_PRODUCT_PROCESS,
119 return postProcess(softwareProductId, process).then(response => {
120 if (process.formData) {
121 uploadFileToProcess(softwareProductId, response.value, process.formData);
124 type: actionTypes.ADD_SOFTWARE_PRODUCT_PROCESS,
134 hideDeleteConfirm(dispatch) {
136 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
137 processToDelete: false
141 openDeleteProcessesConfirm(dispatch, {process} ) {
143 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_CONFIRM,
144 processToDelete: process
150 export default SoftwareProductActionHelper;