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';
18 import {actionTypes} from './LicenseModelConstants.js';
19 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
20 import {actionsEnum as vcActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import LicenseAgreementActionHelper from './licenseAgreement/LicenseAgreementActionHelper.js';
23 import FeatureGroupsActionHelper from './featureGroups/FeatureGroupsActionHelper.js';
24 import EntitlementPoolsActionHelper from './entitlementPools/EntitlementPoolsActionHelper.js';
25 import LicenseKeyGroupsActionHelper from './licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
26 import ItemsHelper from '../../common/helpers/ItemsHelper.js';
27 import MergeEditorActionHelper from 'sdc-app/common/merge/MergeEditorActionHelper.js';
28 import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
29 import {CommitModalType} from 'nfvo-components/panel/versionController/components/CommitCommentModal.jsx';
30 import versionPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
31 import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
32 import {catalogItemStatuses} from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js';
33 import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
36 const restPrefix = Configuration.get('restPrefix');
37 return `${restPrefix}/v1.0/vendor-license-models/`;
40 function fetchLicenseModels() {
41 return RestAPIUtil.fetch(`${baseUrl()}?versionFilter=Draft`);
44 function fetchFinalizedLicenseModels() {
45 return RestAPIUtil.fetch(`${baseUrl()}?versionFilter=Certified`);
48 function fetchLicenseModelById(licenseModelId, version) {
49 const {id: versionId} = version;
50 return RestAPIUtil.fetch(`${baseUrl()}${licenseModelId}/versions/${versionId}`);
53 function putLicenseModel(licenseModel) {
54 let {id, vendorName, description, iconRef, version: {id: versionId}} = licenseModel;
55 return RestAPIUtil.put(`${baseUrl()}${id}/versions/${versionId}`, {
62 function putLicenseModelAction({itemId, action, version}) {
63 const {id: versionId} = version;
64 return RestAPIUtil.put(`${baseUrl()}${itemId}/versions/${versionId}/actions`, {action: action});
67 const LicenseModelActionHelper = {
69 fetchLicenseModels(dispatch) {
70 return fetchLicenseModels().then(response => {
72 type: actionTypes.LICENSE_MODELS_LIST_LOADED,
78 fetchFinalizedLicenseModels(dispatch) {
79 return fetchFinalizedLicenseModels().then(response => dispatch({
80 type: actionTypes.FINALIZED_LICENSE_MODELS_LIST_LOADED,
86 fetchLicenseModelById(dispatch, {licenseModelId, version}) {
88 return fetchLicenseModelById(licenseModelId, version).then(response => {
90 type: actionTypes.LICENSE_MODEL_LOADED,
91 response: {...response, version}
96 fetchLicenseModelItems(dispatch, {licenseModelId, version}) {
98 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version}),
99 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version}),
100 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}),
101 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version})
105 manageSubmitAction(dispatch, {licenseModelId, version, isDirty}) {
107 const onCommit = comment => {
108 return this.performVCAction(dispatch, {licenseModelId, action: vcActionsEnum.COMMIT, version, comment}).then(() => {
109 return this.performSubmitAction(dispatch, {licenseModelId, version});
113 type: modalActionTypes.GLOBAL_MODAL_SHOW,
115 modalComponentName: modalContentMapper.COMMIT_COMMENT,
116 modalComponentProps: {
118 type: CommitModalType.COMMIT_SUBMIT
120 title: i18n('Commit & Submit')
123 return Promise.reject();
125 return this.performSubmitAction(dispatch, {licenseModelId, version});
128 performSubmitAction(dispatch, {licenseModelId, version}) {
129 return putLicenseModelAction({itemId: licenseModelId, action: vcActionsEnum.SUBMIT, version}).then(() => {
130 return ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id}).then(updatedVersion => {
132 type: modalActionTypes.GLOBAL_MODAL_SUCCESS,
134 title: i18n('Submit Succeeded'),
135 msg: i18n('This license model successfully submitted'),
136 cancelButtonText: i18n('OK'),
140 versionPageActionHelper.fetchVersions(dispatch, {itemType: itemTypes.LICENSE_MODEL, itemId: licenseModelId});
141 return Promise.resolve(updatedVersion);
146 performVCAction(dispatch, {licenseModelId, action, version, comment}) {
147 return MergeEditorActionHelper.analyzeSyncResult(dispatch, {itemId: licenseModelId, version}).then(({inMerge, isDirty, updatedVersion}) => {
148 if (updatedVersion.status === catalogItemStatuses.CERTIFIED &&
149 (action === VersionControllerActionsEnum.COMMIT || action === VersionControllerActionsEnum.SYNC)) {
150 versionPageActionHelper.fetchVersions(dispatch, {itemType: itemTypes.LICENSE_MODEL, itemId: licenseModelId});
152 type: modalActionTypes.GLOBAL_MODAL_WARNING,
154 title: i18n('Commit error'),
155 msg: i18n('Item version already Certified'),
156 cancelButtonText: i18n('Cancel')
159 return Promise.resolve(updatedVersion);
162 if(action === vcActionsEnum.SUBMIT) {
163 return this.manageSubmitAction(dispatch, {licenseModelId, version, isDirty});
166 return ItemsHelper.performVCAction({itemId: licenseModelId, action, version, comment}).then(() => {
167 versionPageActionHelper.fetchVersions(dispatch, {itemType: itemTypes.LICENSE_MODEL, itemId: licenseModelId});
168 if (action === vcActionsEnum.SYNC) {
169 return MergeEditorActionHelper.analyzeSyncResult(dispatch, {itemId: licenseModelId, version}).then(({updatedVersion}) => {
170 return Promise.resolve(updatedVersion);
173 return ItemsHelper.checkItemStatus(dispatch, {itemId: licenseModelId, versionId: version.id});
181 saveLicenseModel(dispatch, {licenseModel}) {
182 return putLicenseModel(licenseModel).then(() => {
184 type: actionTypes.LICENSE_MODEL_LOADED,
185 response: licenseModel
187 const {id, version: {id: versionId}} = licenseModel;
188 return ItemsHelper.checkItemStatus(dispatch, {itemId: id, versionId}).then(updatedVersion => {
189 if (updatedVersion.status !== licenseModel.version.status) {
190 versionPageActionHelper.fetchVersions(dispatch, {itemType: itemTypes.LICENSE_MODEL, itemId: licenseModel.id});
198 export default LicenseModelActionHelper;