[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / processes / SoftwareProductComponentProcessesActionHelper.js
index d535a34..b2133ad 100644 (file)
@@ -1,69 +1,65 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
+/*!
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
  */
-
 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
 import Configuration from 'sdc-app/config/Configuration.js';
 import {actionTypes} from './SoftwareProductComponentProcessesConstants.js';
 
-function baseUrl(softwareProductId, componentId) {
+function baseUrl(softwareProductId, version, componentId) {
        const restPrefix = Configuration.get('restPrefix');
-       return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/processes`;
+       return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${componentId}/processes`;
 }
 
-function fetchProcessesList({softwareProductId, componentId, version}) {
-       let versionQuery = version ? `?version=${version}` : '';
-       return RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId)}${versionQuery}`);
+function fetchProcessesList({softwareProductId, version, componentId}) {
+       return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}`);
 }
 
-function deleteProcess({softwareProductId, componentId, processId}) {
-       return RestAPIUtil.destroy(`${baseUrl(softwareProductId, componentId)}/${processId}`);
+function deleteProcess({softwareProductId, version, componentId, processId}) {
+       return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version, componentId)}/${processId}`);
 }
 
-function putProcess({softwareProductId, componentId, process}) {
-       return RestAPIUtil.save(`${baseUrl(softwareProductId, componentId)}/${process.id}`, {
+function putProcess({softwareProductId, version, componentId, process}) {
+       return RestAPIUtil.put(`${baseUrl(softwareProductId, version, componentId)}/${process.id}`, {
                name: process.name,
-               description: process.description
+               description: process.description,
+               type: process.type === '' ? null : process.type
        });
 }
 
-function postProcess({softwareProductId,componentId, process}) {
-       return RestAPIUtil.create(`${baseUrl(softwareProductId, componentId)}`, {
+function postProcess({softwareProductId, version, componentId, process}) {
+       return RestAPIUtil.post(`${baseUrl(softwareProductId, version, componentId)}`, {
                name: process.name,
-               description: process.description
+               description: process.description,
+               type: process.type === '' ? null : process.type
        });
 }
 
-function uploadFileToProcess({softwareProductId, processId, componentId, formData}) {
-       return RestAPIUtil.create(`${baseUrl(softwareProductId, componentId)}/${processId}/upload`, formData);
+function uploadFileToProcess({softwareProductId, version, processId, componentId, formData}) {
+       return RestAPIUtil.post(`${baseUrl(softwareProductId, version, componentId)}/${processId}/upload`, formData);
 }
 
 
 
 const SoftwareProductComponentProcessesActionHelper = {
-       fetchProcessesList(dispatch, {softwareProductId, componentId, version}) {
+       fetchProcessesList(dispatch, {softwareProductId, version, componentId}) {
                dispatch({
                        type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
                        processesList: []
                });
 
-               return fetchProcessesList({softwareProductId, componentId, version}).then(response => {
+               return fetchProcessesList({softwareProductId, version, componentId}).then(response => {
                        dispatch({
                                type: actionTypes.FETCH_SOFTWARE_PRODUCT_COMPONENTS_PROCESSES,
                                processesList: response.results
@@ -71,8 +67,8 @@ const SoftwareProductComponentProcessesActionHelper = {
                });
        },
 
-       deleteProcess(dispatch, {process, softwareProductId, componentId}) {
-               return deleteProcess({softwareProductId, processId:process.id, componentId}).then(() => {
+       deleteProcess(dispatch, {process, softwareProductId, version, componentId}) {
+               return deleteProcess({softwareProductId, version, processId:process.id, componentId}).then(() => {
                        dispatch({
                                type: actionTypes.DELETE_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
                                processId: process.id
@@ -81,11 +77,11 @@ const SoftwareProductComponentProcessesActionHelper = {
 
        },
 
-       saveProcess(dispatch, {softwareProductId, componentId, previousProcess, process}) {
+       saveProcess(dispatch, {softwareProductId, version, componentId, previousProcess, process}) {
                if (previousProcess) {
-                       return putProcess({softwareProductId,componentId,  process}).then(() => {
+                       return putProcess({softwareProductId, version, componentId,  process}).then(() => {
                                if (process.formData && process.formData.name !== previousProcess.artifactName){
-                                       uploadFileToProcess({softwareProductId, processId: process.id, formData: process.formData, componentId});
+                                       uploadFileToProcess({softwareProductId, version, processId: process.id, formData: process.formData, componentId});
                                }
                                dispatch({
                                        type: actionTypes.EDIT_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
@@ -94,9 +90,9 @@ const SoftwareProductComponentProcessesActionHelper = {
                        });
                }
                else {
-                       return postProcess({softwareProductId, componentId, process}).then(response => {
+                       return postProcess({softwareProductId, version, componentId, process}).then(response => {
                                if (process.formData) {
-                                       uploadFileToProcess({softwareProductId, processId: response.value, formData: process.formData, componentId});
+                                       uploadFileToProcess({softwareProductId, version, processId: response.value, formData: process.formData, componentId});
                                }
                                dispatch({
                                        type: actionTypes.ADD_SOFTWARE_PRODUCT_COMPONENTS_PROCESS,
@@ -133,12 +129,6 @@ const SoftwareProductComponentProcessesActionHelper = {
                dispatch({
                        type:actionTypes.SOFTWARE_PRODUCT_PROCESS_COMPONENTS_EDITOR_CLOSE
                });
-       },
-       processEditorDataChanged(dispatch, {deltaData}) {
-               dispatch({
-                       type: actionTypes.processEditor.DATA_CHANGED,
-                       deltaData
-               });
        }
 };