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';
19 import {actionTypes} from './SoftwareProductComponentsNetworkConstants.js';
20 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
21 import {NIC_QUESTIONNAIRE} from 'sdc-app/onboarding/softwareProduct/components/network/SoftwareProductComponentsNetworkConstants.js';
23 function baseUrl(softwareProductId, version, componentId) {
24 const versionId = version.id;
25 const restPrefix = Configuration.get('restPrefix');
26 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components/${componentId}/nics`;
30 function fetchNICQuestionnaire({softwareProductId, version, componentId, nicId}) {
31 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}/${nicId}/questionnaire`);
34 function fetchNIC({softwareProductId, version, componentId, nicId}) {
35 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}/${nicId}`);
38 function fetchNICsList({softwareProductId, version, componentId}) {
39 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}`);
42 function saveNIC({softwareProductId, version, componentId, nic: {id, name, description, networkId}}) {
43 return RestAPIUtil.put(`${baseUrl(softwareProductId, version, componentId)}/${id}`,{
50 function saveNICQuestionnaire({softwareProductId, version, componentId, nicId, qdata}) {
51 return RestAPIUtil.put(`${baseUrl(softwareProductId, version, componentId)}/${nicId}/questionnaire`, qdata);
54 const SoftwareProductComponentNetworkActionHelper = {
56 fetchNICsList(dispatch, {softwareProductId, version, componentId}) {
57 return fetchNICsList({softwareProductId, version, componentId}).then((response) => {
59 type: actionTypes.NIC_LIST_UPDATE,
60 response: response.results
65 openNICEditor(dispatch, {nic = {}, data = {}}) {
67 type: actionTypes.NICEditor.OPEN,
68 nic: {...data, id: nic.id}
72 closeNICEditor(dispatch) {
74 type: actionTypes.NICEditor.CLOSE
78 loadNICData({softwareProductId, version, componentId, nicId}) {
79 return fetchNIC({softwareProductId, version, componentId, nicId});
82 loadNICQuestionnaire(dispatch, {softwareProductId, version, componentId, nicId}) {
83 return fetchNICQuestionnaire({softwareProductId, version, componentId, nicId}).then((response) => {
84 ValidationHelper.qDataLoaded(dispatch, {qName: NIC_QUESTIONNAIRE ,response: {
85 qdata: response.data ? JSON.parse(response.data) : {},
86 qschema: JSON.parse(response.schema)
91 saveNICDataAndQuestionnaire(dispatch, {softwareProductId, version, componentId, data, qdata}) {
92 SoftwareProductComponentNetworkActionHelper.closeNICEditor(dispatch);
94 saveNICQuestionnaire({softwareProductId, version, componentId, nicId: data.id, qdata}),
95 saveNIC({softwareProductId, version, componentId, nic: data}).then(() => {
97 type: actionTypes.NIC_LIST_EDIT,
105 export default SoftwareProductComponentNetworkActionHelper;