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 {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
23 function baseUrl(softwareProductId, version) {
24 const versionId = version.id;
25 const restPrefix = Configuration.get('restPrefix');
26 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components`;
29 function fetchSoftwareProductComponents(softwareProductId, version) {
30 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
33 function putSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId, vspComponent) {
34 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`, vspComponent);
37 function fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId){
38 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`);
41 function fetchSoftwareProductComponent(softwareProductId, version, vspComponentId){
42 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${vspComponentId}`);
45 function putSoftwareProductComponent(softwareProductId, version, vspComponentId, vspComponent) {
46 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${vspComponentId}`, {
47 name: vspComponent.name,
48 displayName: vspComponent.displayName,
49 vfcCode: vspComponent.vfcCode,
50 nfcFunction: vspComponent.nfcFunction,
51 description: vspComponent.description
55 function deleteSoftwareProductComponent(softwareProductId, componentId, version) {
56 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version)}/${componentId}`,);
60 function postSoftwareProductComponent(softwareProductId, vspComponent, version) {
62 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
63 name: vspComponent.displayName,
64 displayName: vspComponent.displayName,
65 description: vspComponent.description
70 const SoftwareProductComponentsActionHelper = {
71 fetchSoftwareProductComponents(dispatch, {softwareProductId, version}) {
72 return fetchSoftwareProductComponents(softwareProductId, version).then(response => {
74 type: actionTypes.COMPONENTS_LIST_UPDATE,
75 componentsList: response.results
81 updateSoftwareProductComponent(dispatch, {softwareProductId, version, vspComponentId, componentData, qdata}) {
83 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId, qdata}),
84 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentData(dispatch, {softwareProductId, version, vspComponentId, componentData})
88 updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId, qdata}) {
89 return putSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId, qdata);
92 updateSoftwareProductComponentData(dispatch, {softwareProductId, version, vspComponentId, componentData}) {
93 return putSoftwareProductComponent(softwareProductId, version, vspComponentId, componentData).then(() => dispatch({
94 type: actionTypes.COMPONENTS_LIST_EDIT,
102 fetchSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId}) {
103 return fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId).then(response => {
104 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_QUESTIONNAIRE, response: {qdata: response.data ? JSON.parse(response.data) : {},
105 qschema: JSON.parse(response.schema)}});
109 fetchSoftwareProductComponent(dispatch, {softwareProductId, version, vspComponentId}) {
111 fetchSoftwareProductComponent(softwareProductId, version, vspComponentId).then(response => {
113 type: actionTypes.COMPONENT_LOAD,
114 component: response.data
118 fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId).then(response => {
119 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_QUESTIONNAIRE, response: {qdata: response.data ? JSON.parse(response.data) : {},
120 qschema: JSON.parse(response.schema)}});
126 clearComponentsStore(dispatch) {
128 type: actionTypes.COMPONENTS_LIST_UPDATE,
133 createSoftwareProductComponent(dispatch,{softwareProductId, componentData, version}) {
134 SoftwareProductComponentsActionHelper.closeComponentCreationModal(dispatch);
138 type: actionTypes.COMPONENTS_LIST_UPDATE,
139 componentsList: [{id: '123', ...componentData}]
142 postSoftwareProductComponent(softwareProductId, componentData, version).then(() => {
143 SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(dispatch, {softwareProductId, version});
147 clearComponentCreationData(dispatch) {
149 type: actionTypes.COMPONENT_DATA_CLEAR
153 closeComponentCreationModal(dispatch) {
155 type: modalActionTypes.GLOBAL_MODAL_CLOSE
157 SoftwareProductComponentsActionHelper.clearComponentCreationData(dispatch);
160 deleteComponent(dispatch, {softwareProductId, componentId, version}) {
161 deleteSoftwareProductComponent(softwareProductId, componentId, version);
163 type: actionTypes.COMPONENT_DELETE,
164 componentId: componentId
172 export default SoftwareProductComponentsActionHelper;