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';
23 import i18n from 'nfvo-utils/i18n/i18n.js';
24 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
25 import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
26 import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
28 import {actionTypes} from './SoftwareProductConstants.js';
29 import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
30 import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
31 import SoftwareProductComponentsActionHelper from './components/SoftwareProductComponentsActionHelper.js';
32 import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
35 const restPrefix = Configuration.get('restPrefix');
36 return `${restPrefix}/v1.0/vendor-software-products/`;
38 function softwareProductCategoriesUrl() {
39 const restATTPrefix = Configuration.get('restATTPrefix');
40 return `${restATTPrefix}/v1/categories/resources/`;
43 function uploadFile(vspId, formData) {
45 return RestAPIUtil.create(`${baseUrl()}${vspId}/upload`, formData);
49 function putSoftwareProduct(softwareData) {
50 return RestAPIUtil.save(`${baseUrl()}${softwareData.id}`, {
51 name: softwareData.name,
52 description: softwareData.description,
53 category: softwareData.category,
54 subCategory: softwareData.subCategory,
55 vendorId: softwareData.vendorId,
56 vendorName: softwareData.vendorName,
57 licensingVersion: softwareData.licensingVersion,
58 icon: softwareData.icon,
59 licensingData: softwareData.licensingData
63 function putSoftwareProductQuestionnaire(vspId, qdata) {
64 return RestAPIUtil.save(`${baseUrl()}${vspId}/questionnaire`, qdata);
67 function putSoftwareProductAction(id, action) {
68 return RestAPIUtil.save(`${baseUrl()}${id}/actions`, {action: action});
71 function fetchSoftwareProductList() {
72 return RestAPIUtil.fetch(baseUrl());
75 function fetchSoftwareProduct(vspId, version) {
76 let versionQuery = version ? `?version=${version}` : '';
77 return RestAPIUtil.fetch(`${baseUrl()}${vspId}${versionQuery}`);
80 function fetchSoftwareProductQuestionnaire(vspId, version) {
81 let versionQuery = version ? `?version=${version}` : '';
82 return RestAPIUtil.fetch(`${baseUrl()}${vspId}/questionnaire${versionQuery}`);
85 function objToString(obj) {
87 if (obj instanceof Array) {
88 obj.forEach((item) => {
89 str += objToString(item) + '\n';
93 if (obj.hasOwnProperty(p)) {
101 function parseUploadErrorMsg(error) {
103 for (let key in error) {
104 if (error.hasOwnProperty(key)) {
105 message += objToString(error[key]) + '\n';
111 function fetchSoftwareProductCategories(dispatch) {
112 let handleResponse = response => dispatch({
113 type: actionTypes.SOFTWARE_PRODUCT_CATEGORIES_LOADED,
114 softwareProductCategories: response
116 return RestAPIUtil.fetch(softwareProductCategoriesUrl())
117 .then(handleResponse)
118 .fail(() => handleResponse(null));
121 function loadLicensingData(dispatch, {licenseModelId, licensingVersion}) {
122 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version: licensingVersion});
123 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version: licensingVersion});
126 function getExpandedItemsId(items, itemIdToToggle) {
127 for(let i = 0; i < items.length; i++) {
128 if(items[i].id === itemIdToToggle) {
129 if (items[i].expanded) {
132 return {[itemIdToToggle]: true};
135 else if(items[i].items && items[i].items.length > 0) {
136 let mapOfExpandedIds = getExpandedItemsId(items[i].items, itemIdToToggle);
137 if (mapOfExpandedIds !== false) {
138 mapOfExpandedIds[items[i].id] = true;
139 return mapOfExpandedIds;
146 const SoftwareProductActionHelper = {
148 loadSoftwareProductAssociatedData(dispatch) {
149 fetchSoftwareProductCategories(dispatch);
150 LicenseModelActionHelper.fetchFinalizedLicenseModels(dispatch);
153 loadSoftwareProductDetailsData(dispatch, {licenseModelId, licensingVersion}) {
154 SoftwareProductActionHelper.loadSoftwareProductAssociatedData(dispatch);
155 loadLicensingData(dispatch, {licenseModelId, licensingVersion});
158 fetchSoftwareProductList(dispatch) {
159 return fetchSoftwareProductList().then(response => dispatch({
160 type: actionTypes.SOFTWARE_PRODUCT_LIST_LOADED,
165 uploadFile(dispatch, {softwareProductId, formData, failedNotificationTitle}) {
167 .then(() => uploadFile(softwareProductId, formData))
169 if (response.status !== 'Success') {
170 throw new Error(parseUploadErrorMsg(response.errors));
174 SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(dispatch, {softwareProductId});
175 OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId});
176 SoftwareProductActionHelper.fetchSoftwareProduct(dispatch, {softwareProductId});
180 type: NotificationConstants.NOTIFY_ERROR,
181 data: {title: failedNotificationTitle, msg: error.message}
186 uploadConfirmation(dispatch, {softwareProductId, formData, failedNotificationTitle}) {
188 type: actionTypes.softwareProductEditor.UPLOAD_CONFIRMATION,
192 failedNotificationTitle
196 hideUploadConfirm (dispatch) {
198 type: actionTypes.softwareProductEditor.UPLOAD_CONFIRMATION
201 updateSoftwareProduct(dispatch, {softwareProduct, qdata}) {
203 SoftwareProductActionHelper.updateSoftwareProductData(dispatch, {softwareProduct}).then(
205 type: actionTypes.SOFTWARE_PRODUCT_LIST_EDIT,
206 payload: {softwareProduct}
209 SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(dispatch, {
210 softwareProductId: softwareProduct.id,
216 updateSoftwareProductData(dispatch, {softwareProduct}) {
217 return putSoftwareProduct(softwareProduct);
220 updateSoftwareProductQuestionnaire(dispatch, {softwareProductId, qdata}) {
221 return putSoftwareProductQuestionnaire(softwareProductId, qdata);
224 softwareProductEditorDataChanged(dispatch, {deltaData}) {
226 type: actionTypes.softwareProductEditor.DATA_CHANGED,
231 softwareProductQuestionnaireUpdate(dispatch, {data}) {
233 type: actionTypes.SOFTWARE_PRODUCT_QUESTIONNAIRE_UPDATE,
234 payload: {qdata: data}
238 softwareProductEditorVendorChanged(dispatch, {deltaData}) {
239 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId: deltaData.vendorId, version: deltaData.licensingVersion});
240 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId: deltaData.vendorId, version: deltaData.licensingVersion});
241 SoftwareProductActionHelper.softwareProductEditorDataChanged(dispatch, {deltaData});
244 setIsValidityData(dispatch, {isValidityData}) {
246 type: actionTypes.softwareProductEditor.IS_VALIDITY_DATA_CHANGED,
251 addSoftwareProduct(dispatch, {softwareProduct}) {
253 type: actionTypes.ADD_SOFTWARE_PRODUCT,
258 fetchSoftwareProduct(dispatch, {softwareProductId, version}) {
260 fetchSoftwareProduct(softwareProductId, version).then(response => {
262 type: actionTypes.SOFTWARE_PRODUCT_LOADED,
267 fetchSoftwareProductQuestionnaire(softwareProductId, version).then(response => {
269 type: actionTypes.SOFTWARE_PRODUCT_QUESTIONNAIRE_UPDATE,
271 qdata: response.data ? JSON.parse(response.data) : {},
272 qschema: JSON.parse(response.schema)
279 performVCAction(dispatch, {softwareProductId, action}) {
280 if (action === VersionControllerActionsEnum.SUBMIT) {
281 return putSoftwareProductAction(softwareProductId, action).then(() => {
282 return putSoftwareProductAction(softwareProductId, VersionControllerActionsEnum.CREATE_PACKAGE).then(() => {
284 type: NotificationConstants.NOTIFY_SUCCESS,
286 title: i18n('Submit Succeeded'),
287 msg: i18n('This software product successfully submitted'),
291 fetchSoftwareProduct(softwareProductId).then(response => {
293 type: actionTypes.SOFTWARE_PRODUCT_LOADED,
298 }, error => dispatch({
299 type: NotificationConstants.NOTIFY_ERROR,
300 data: {title: i18n('Submit Failed'), validationResponse: error.responseJSON}
304 return putSoftwareProductAction(softwareProductId, action).then(() => {
305 fetchSoftwareProduct(softwareProductId).then(response => {
307 type: actionTypes.SOFTWARE_PRODUCT_LOADED,
315 switchVersion(dispatch, {softwareProductId, licenseModelId, version}) {
316 OnboardingActionHelper.navigateToSoftwareProductLandingPage(dispatch, {softwareProductId, licenseModelId, version});
319 toggleNavigationItems(dispatch, {items, itemIdToExpand}) {
320 let mapOfExpandedIds = getExpandedItemsId(items, itemIdToExpand);
322 type: actionTypes.TOGGLE_NAVIGATION_ITEM,
327 /** for the next verision */
328 addComponent(dispatch) {
333 export default SoftwareProductActionHelper;