2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
24 import {actionTypes} from './SoftwareProductComponentsConstants.js';
26 function baseUrl(softwareProductId) {
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components`;
31 function fetchSoftwareProductComponents(softwareProductId, version) {
32 let versionQuery = version ? `?version=${version}` : '';
33 return RestAPIUtil.fetch(`${baseUrl(softwareProductId)}${versionQuery}`);
36 function putSoftwareProductComponentQuestionnaire(softwareProductId, vspComponentId, vspComponent) {
37 return RestAPIUtil.save(`${baseUrl(softwareProductId)}/${vspComponentId}/questionnaire`, vspComponent);
40 function fetchSoftwareProductComponentQuestionnaire(softwareProductId, vspComponentId, version){
41 let versionQuery = version ? `?version=${version}` : '';
42 return RestAPIUtil.fetch(`${baseUrl(softwareProductId)}/${vspComponentId}/questionnaire${versionQuery}`);
45 function fetchSoftwareProductComponent(softwareProductId, vspComponentId, version){
46 let versionQuery = version ? `?version=${version}` : '';
47 return RestAPIUtil.fetch(`${baseUrl(softwareProductId)}/${vspComponentId}${versionQuery}`);
50 function putSoftwareProductComponent(softwareProductId, vspComponentId, vspComponent) {
51 return RestAPIUtil.save(`${baseUrl(softwareProductId)}/${vspComponentId}`, {
52 name: vspComponent.name,
53 displayName: vspComponent.displayName,
54 description: vspComponent.description
58 const SoftwareProductComponentsActionHelper = {
59 fetchSoftwareProductComponents(dispatch, {softwareProductId, version}) {
60 return fetchSoftwareProductComponents(softwareProductId, version).then(response => {
62 type: actionTypes.COMPONENTS_LIST_UPDATE,
63 componentsList: response.results
68 componentDataChanged(dispatch, {deltaData}) {
70 type: actionTypes.COMPONENT_DATA_CHANGED,
76 updateSoftwareProductComponent(dispatch, {softwareProductId, vspComponentId, componentData, qdata}) {
78 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, vspComponentId, qdata}),
79 SoftwareProductComponentsActionHelper.updateSoftwareProductComponentData(dispatch, {softwareProductId, vspComponentId, componentData})
83 updateSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, vspComponentId, qdata}) {
84 return putSoftwareProductComponentQuestionnaire(softwareProductId, vspComponentId, qdata);
87 updateSoftwareProductComponentData(dispatch, {softwareProductId, vspComponentId, componentData}) {
88 return putSoftwareProductComponent(softwareProductId, vspComponentId, componentData).then(() => dispatch({
89 type: actionTypes.COMPONENTS_LIST_EDIT,
98 fetchSoftwareProductComponentQuestionnaire(dispatch, {softwareProductId, vspComponentId, version}) {
99 return fetchSoftwareProductComponentQuestionnaire(softwareProductId, vspComponentId, version).then(response => {
101 type: actionTypes.COMPONENT_QUESTIONNAIRE_UPDATE,
103 qdata: response.data ? JSON.parse(response.data) : {},
104 qschema: JSON.parse(response.schema)
110 fetchSoftwareProductComponent(dispatch, {softwareProductId, vspComponentId, version}) {
111 return fetchSoftwareProductComponent(softwareProductId, vspComponentId, version).then(response => {
113 type: actionTypes.COMPONENT_UPDATE,
114 component: response.data
119 componentQuestionnaireUpdated(dispatch, {data}) {
121 type: actionTypes.COMPONENT_QUESTIONNAIRE_UPDATE,
129 export default SoftwareProductComponentsActionHelper;