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';
21 COMPONENTS_QUESTIONNAIRE
22 } from './SoftwareProductComponentsConstants.js';
23 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
24 import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
26 function baseUrl(softwareProductId, version) {
27 const versionId = version.id;
28 const restPrefix = Configuration.get('restPrefix');
29 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components`;
32 function fetchSoftwareProductComponents(softwareProductId, version) {
33 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
36 function putSoftwareProductComponentQuestionnaire(
42 return RestAPIUtil.put(
46 )}/${vspComponentId}/questionnaire`,
51 function fetchSoftwareProductComponentQuestionnaire(
56 return RestAPIUtil.fetch(
57 `${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`
61 function fetchSoftwareProductComponent(
66 return RestAPIUtil.fetch(
67 `${baseUrl(softwareProductId, version)}/${vspComponentId}`
71 function putSoftwareProductComponent(
77 return RestAPIUtil.put(
78 `${baseUrl(softwareProductId, version)}/${vspComponentId}`,
80 name: vspComponent.name,
81 displayName: vspComponent.displayName,
82 vfcCode: vspComponent.vfcCode,
83 nfcFunction: vspComponent.nfcFunction,
84 description: vspComponent.description
89 function deleteSoftwareProductComponent(
94 return RestAPIUtil.destroy(
95 `${baseUrl(softwareProductId, version)}/${componentId}`
99 function postSoftwareProductComponent(
104 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
105 name: vspComponent.displayName,
106 displayName: vspComponent.displayName,
107 description: vspComponent.description
111 const SoftwareProductComponentsActionHelper = {
112 fetchSoftwareProductComponents(dispatch, { softwareProductId, version }) {
113 return fetchSoftwareProductComponents(softwareProductId, version).then(
116 type: actionTypes.COMPONENTS_LIST_UPDATE,
117 componentsList: response.results
124 updateSoftwareProductComponent(
126 { softwareProductId, version, vspComponentId, componentData, qdata }
129 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(
131 { softwareProductId, version, vspComponentId, qdata }
133 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentData(
135 { softwareProductId, version, vspComponentId, componentData }
140 updateSoftwareProductComponentQuestionnaire(
142 { softwareProductId, version, vspComponentId, qdata }
144 return putSoftwareProductComponentQuestionnaire(
152 updateSoftwareProductComponentData(
154 { softwareProductId, version, vspComponentId, componentData }
156 return putSoftwareProductComponent(
163 type: actionTypes.COMPONENTS_LIST_EDIT,
172 fetchSoftwareProductComponentQuestionnaire(
174 { softwareProductId, version, vspComponentId }
176 return fetchSoftwareProductComponentQuestionnaire(
181 ValidationHelper.qDataLoaded(dispatch, {
182 qName: COMPONENTS_QUESTIONNAIRE,
184 qdata: response.data ? JSON.parse(response.data) : {},
185 qschema: JSON.parse(response.schema)
191 fetchSoftwareProductComponent(
193 { softwareProductId, version, vspComponentId }
196 fetchSoftwareProductComponent(
202 type: actionTypes.COMPONENT_LOAD,
203 component: response.data
207 fetchSoftwareProductComponentQuestionnaire(
212 ValidationHelper.qDataLoaded(dispatch, {
213 qName: COMPONENTS_QUESTIONNAIRE,
215 qdata: response.data ? JSON.parse(response.data) : {},
216 qschema: JSON.parse(response.schema)
223 clearComponentsStore(dispatch) {
225 type: actionTypes.COMPONENTS_LIST_UPDATE,
230 createSoftwareProductComponent(
232 { softwareProductId, componentData, version }
234 SoftwareProductComponentsActionHelper.closeComponentCreationModal(
240 type: actionTypes.COMPONENTS_LIST_UPDATE,
241 componentsList: [{ id: '123', ...componentData }]
244 postSoftwareProductComponent(
249 SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(
251 { softwareProductId, version }
256 clearComponentCreationData(dispatch) {
258 type: actionTypes.COMPONENT_DATA_CLEAR
262 closeComponentCreationModal(dispatch) {
264 type: modalActionTypes.GLOBAL_MODAL_CLOSE
266 SoftwareProductComponentsActionHelper.clearComponentCreationData(
271 deleteComponent(dispatch, { softwareProductId, componentId, version }) {
272 deleteSoftwareProductComponent(softwareProductId, componentId, version);
274 type: actionTypes.COMPONENT_DELETE,
275 componentId: componentId
280 export default SoftwareProductComponentsActionHelper;