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 RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
23 import {actionTypes} from './SoftwareProductComponentProcessesConstants.js';
25 function baseUrl(softwareProductId, componentId) {
26 const restPrefix = Configuration.get('restPrefix');
27 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/processes`;
30 function fetchProcessesList({softwareProductId, componentId, version}) {
31 let versionQuery = version ? `?version=${version}` : '';
32 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId)}${versionQuery}`);
35 function deleteProcess({softwareProductId, componentId, processId}) {
36 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, componentId)}/${processId}`);
39 function putProcess({softwareProductId, componentId, process}) {
40 return RestAPIUtil.save(`${baseUrl(softwareProductId, componentId)}/${process.id}`, {
42 description: process.description
46 function postProcess({softwareProductId,componentId, process}) {
47 return RestAPIUtil.create(`${baseUrl(softwareProductId, componentId)}`, {
49 description: process.description
53 function uploadFileToProcess({softwareProductId, processId, componentId, formData}) {
54 return RestAPIUtil.create(`${baseUrl(softwareProductId, componentId)}/${processId}/upload`, formData);
59 const SoftwareProductComponentProcessesActionHelper = {
60 fetchProcessesList(dispatch, {softwareProductId, componentId, version}) {
62 type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
66 return fetchProcessesList({softwareProductId, componentId, version}).then(response => {
68 type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
69 processesList: response.results
74 deleteProcess(dispatch, {process, softwareProductId, componentId}) {
75 return deleteProcess({softwareProductId, processId:process.id, componentId}).then(() => {
77 type: actionTypes.DELETE_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
84 saveProcess(dispatch, {softwareProductId, componentId, previousProcess, process}) {
85 if (previousProcess) {
86 return putProcess({softwareProductId,componentId, process}).then(() => {
87 if (process.formData && process.formData.name !== previousProcess.artifactName){
88 uploadFileToProcess({softwareProductId, processId: process.id, formData: process.formData, componentId});
91 type: actionTypes.EDIT_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
97 return postProcess({softwareProductId, componentId, process}).then(response => {
98 if (process.formData) {
99 uploadFileToProcess({softwareProductId, processId: response.value, formData: process.formData, componentId});
102 type: actionTypes.ADD_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
112 hideDeleteConfirm(dispatch) {
114 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_COMPONENTS_CONFIRM,
115 processToDelete: false
119 openDeleteProcessesConfirm(dispatch, {process} ) {
121 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_DELETE_COMPONENTS_CONFIRM,
122 processToDelete: process
126 openEditor(dispatch, process = {}) {
128 type: actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_OPEN,
132 closeEditor(dispatch) {
134 type:actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_CLOSE
137 processEditorDataChanged(dispatch, {deltaData}) {
139 type: actionTypes.processEditor.DATA_CHANGED,
145 export default SoftwareProductComponentProcessesActionHelper;