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, COMPONENTS_QUESTIONNAIRE} from './SoftwareProductComponentsConstants.js';
20 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
21 import SoftwareProductComponentsImageActionHelper from './images/SoftwareProductComponentsImageActionHelper.js';
22 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
24 function baseUrl(softwareProductId, version) {
25 const versionId = version.id;
26 const restPrefix = Configuration.get('restPrefix');
27 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components`;
30 function fetchSoftwareProductComponents(softwareProductId, version) {
31 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
34 function putSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId, vspComponent) {
35 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`, vspComponent);
38 function fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId){
39 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`);
42 function fetchSoftwareProductComponent(softwareProductId, version, vspComponentId){
43 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${vspComponentId}`);
46 function putSoftwareProductComponent(softwareProductId, version, vspComponentId, vspComponent) {
47 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${vspComponentId}`, {
48 name: vspComponent.name,
49 displayName: vspComponent.displayName,
50 vfcCode: vspComponent.vfcCode,
51 nfcFunction: vspComponent.nfcFunction,
52 description: vspComponent.description
56 function deleteSoftwareProductComponent(softwareProductId, componentId, version) {
57 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version)}/${componentId}`,);
61 function postSoftwareProductComponent(softwareProductId, vspComponent, version) {
63 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
64 name: vspComponent.displayName,
65 displayName: vspComponent.displayName,
66 description: vspComponent.description
71 const SoftwareProductComponentsActionHelper = {
72 fetchSoftwareProductComponents(dispatch, {softwareProductId, version, isFetchImageDetails = false}) {
73 return fetchSoftwareProductComponents(softwareProductId, version).then(response => {
74 let componentImagesCalls = [];
75 if (isFetchImageDetails && response.listCount) {
76 response.results.map(component => {
77 let componentId = component.id;
78 componentImagesCalls[componentImagesCalls.length] =
79 SoftwareProductComponentsImageActionHelper.fetchImagesList(dispatch, {
86 return Promise.all(componentImagesCalls).then(() => {
88 type: actionTypes.COMPONENTS_LIST_UPDATE,
89 componentsList: response.results
94 type: actionTypes.COMPONENTS_LIST_UPDATE,
95 componentsList: response.results
101 updateSoftwareProductComponent(dispatch, {softwareProductId, version, vspComponentId, componentData, qdata}) {
103 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId, qdata}),
104 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentData(dispatch, {softwareProductId, version, vspComponentId, componentData})
108 updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId, qdata}) {
109 return putSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId, qdata);
112 updateSoftwareProductComponentData(dispatch, {softwareProductId, version, vspComponentId, componentData}) {
113 return putSoftwareProductComponent(softwareProductId, version, vspComponentId, componentData).then(() => dispatch({
114 type: actionTypes.COMPONENTS_LIST_EDIT,
122 fetchSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId}) {
123 return fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId).then(response => {
124 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_QUESTIONNAIRE, response: {qdata: response.data ? JSON.parse(response.data) : {},
125 qschema: JSON.parse(response.schema)}});
129 fetchSoftwareProductComponent(dispatch, {softwareProductId, version, vspComponentId}) {
131 fetchSoftwareProductComponent(softwareProductId, version, vspComponentId).then(response => {
133 type: actionTypes.COMPONENT_LOAD,
134 component: response.data
138 fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId).then(response => {
139 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_QUESTIONNAIRE, response: {qdata: response.data ? JSON.parse(response.data) : {},
140 qschema: JSON.parse(response.schema)}});
146 clearComponentsStore(dispatch) {
148 type: actionTypes.COMPONENTS_LIST_UPDATE,
153 createSoftwareProductComponent(dispatch,{softwareProductId, componentData, version}) {
154 SoftwareProductComponentsActionHelper.closeComponentCreationModal(dispatch);
158 type: actionTypes.COMPONENTS_LIST_UPDATE,
159 componentsList: [{id: '123', ...componentData}]
162 postSoftwareProductComponent(softwareProductId, componentData, version).then(() => {
163 SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(dispatch, {softwareProductId, version});
167 clearComponentCreationData(dispatch) {
169 type: actionTypes.COMPONENT_DATA_CLEAR
173 closeComponentCreationModal(dispatch) {
175 type: modalActionTypes.GLOBAL_MODAL_CLOSE
177 SoftwareProductComponentsActionHelper.clearComponentCreationData(dispatch);
180 deleteComponent(dispatch, {softwareProductId, componentId, version}) {
181 deleteSoftwareProductComponent(softwareProductId, componentId, version);
183 type: actionTypes.COMPONENT_DELETE,
184 componentId: componentId
192 export default SoftwareProductComponentsActionHelper;