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';
22 function baseUrl(softwareProductId, version) {
23 const versionId = version.id;
24 const restPrefix = Configuration.get('restPrefix');
25 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/components`;
28 function fetchSoftwareProductComponents(softwareProductId, version) {
29 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
32 function putSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId, vspComponent) {
33 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`, vspComponent);
36 function fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId){
37 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${vspComponentId}/questionnaire`);
40 function fetchSoftwareProductComponent(softwareProductId, version, vspComponentId){
41 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}/${vspComponentId}`);
44 function putSoftwareProductComponent(softwareProductId, version, vspComponentId, vspComponent) {
45 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${vspComponentId}`, {
46 name: vspComponent.name,
47 displayName: vspComponent.displayName,
48 vfcCode: vspComponent.vfcCode,
49 description: vspComponent.description
53 const SoftwareProductComponentsActionHelper = {
54 fetchSoftwareProductComponents(dispatch, {softwareProductId, version}) {
55 return fetchSoftwareProductComponents(softwareProductId, version).then(response => {
57 type: actionTypes.COMPONENTS_LIST_UPDATE,
58 componentsList: response.results
63 updateSoftwareProductComponent(dispatch, {softwareProductId, version, vspComponentId, componentData, qdata}) {
65 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId, qdata}),
66 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentData(dispatch, {softwareProductId, version, vspComponentId, componentData})
70 updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId, qdata}) {
71 return putSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId, qdata);
74 updateSoftwareProductComponentData(dispatch, {softwareProductId, version, vspComponentId, componentData}) {
75 return putSoftwareProductComponent(softwareProductId, version, vspComponentId, componentData).then(() => dispatch({
76 type: actionTypes.COMPONENTS_LIST_EDIT,
84 fetchSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, version, vspComponentId}) {
85 return fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId).then(response => {
86 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_QUESTIONNAIRE, response: {qdata: response.data ? JSON.parse(response.data) : {},
87 qschema: JSON.parse(response.schema)}});
91 fetchSoftwareProductComponent(dispatch, {softwareProductId, version, vspComponentId}) {
93 fetchSoftwareProductComponent(softwareProductId, version, vspComponentId).then(response => {
95 type: actionTypes.COMPONENT_LOAD,
96 component: response.data
100 fetchSoftwareProductComponentQuestionnaire(softwareProductId, version, vspComponentId).then(response => {
101 ValidationHelper.qDataLoaded(dispatch, {qName: COMPONENTS_QUESTIONNAIRE, response: {qdata: response.data ? JSON.parse(response.data) : {},
102 qschema: JSON.parse(response.schema)}});
108 clearComponentsStore(dispatch) {
110 type: actionTypes.COMPONENTS_LIST_UPDATE,
116 export default SoftwareProductComponentsActionHelper;