2 * Copyright © 2016-2018 European Support Limited
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 or implied.
13 * See the License for the specific language governing permissions and
14 * 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 { default as ItemsHelper } from 'sdc-app/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(
42 `${baseUrl()}?versionFilter=${catalogItemStatuses.DRAFT}`
46 function fetchFinalizedLicenseModels() {
47 return RestAPIUtil.fetch(
48 `${baseUrl()}?versionFilter=${catalogItemStatuses.CERTIFIED}`
51 function fetchArchivedLicenseModels() {
52 return RestAPIUtil.fetch(
53 `${baseUrl()}?Status=${catalogItemStatuses.ARCHIVED}`
56 function fetchLicenseModelById(licenseModelId, version) {
57 const { id: versionId } = version;
58 return RestAPIUtil.fetch(
59 `${baseUrl()}${licenseModelId}/versions/${versionId}`
63 function putLicenseModel(licenseModel) {
69 version: { id: versionId }
71 return RestAPIUtil.put(`${baseUrl()}${id}/versions/${versionId}`, {
78 function putLicenseModelAction({ itemId, action, version }) {
79 const { id: versionId } = version;
80 return RestAPIUtil.put(
81 `${baseUrl()}${itemId}/versions/${versionId}/actions`,
86 const LicenseModelActionHelper = {
87 fetchLicenseModels(dispatch) {
88 return fetchLicenseModels().then(response => {
90 type: actionTypes.LICENSE_MODELS_LIST_LOADED,
96 fetchFinalizedLicenseModels(dispatch) {
97 return fetchFinalizedLicenseModels().then(response =>
99 type: actionTypes.FINALIZED_LICENSE_MODELS_LIST_LOADED,
105 fetchArchivedLicenseModels(dispatch) {
106 return fetchArchivedLicenseModels().then(response =>
108 type: actionTypes.ARCHIVED_LICENSE_MODELS_LIST_LOADED,
114 fetchLicenseModelById(dispatch, { licenseModelId, version }) {
115 return fetchLicenseModelById(licenseModelId, version).then(response => {
117 type: actionTypes.LICENSE_MODEL_LOADED,
118 response: { ...response, version }
123 fetchLicenseModelItems(dispatch, { licenseModelId, version }) {
125 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {
129 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
133 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {
137 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {
144 manageSubmitAction(dispatch, { licenseModelId, version, isDirty }) {
146 const onCommit = comment => {
147 return this.performVCAction(dispatch, {
149 action: vcActionsEnum.COMMIT,
153 return this.performSubmitAction(dispatch, {
160 type: modalActionTypes.GLOBAL_MODAL_SHOW,
162 modalComponentName: modalContentMapper.COMMIT_COMMENT,
163 modalComponentProps: {
165 type: CommitModalType.COMMIT_SUBMIT
167 title: i18n('Commit & Submit')
170 return Promise.reject();
172 return this.performSubmitAction(dispatch, { licenseModelId, version });
175 performSubmitAction(dispatch, { licenseModelId, version }) {
176 return putLicenseModelAction({
177 itemId: licenseModelId,
178 action: vcActionsEnum.SUBMIT,
181 return ItemsHelper.checkItemStatus(dispatch, {
182 itemId: licenseModelId,
183 versionId: version.id
184 }).then(updatedVersion => {
186 type: modalActionTypes.GLOBAL_MODAL_SUCCESS,
188 title: i18n('Submit Succeeded'),
189 msg: i18n('This license model successfully submitted'),
190 cancelButtonText: i18n('OK'),
194 versionPageActionHelper.fetchVersions(dispatch, {
195 itemType: itemTypes.LICENSE_MODEL,
196 itemId: licenseModelId
198 return Promise.resolve(updatedVersion);
203 performVCAction(dispatch, { licenseModelId, action, version, comment }) {
204 return MergeEditorActionHelper.analyzeSyncResult(dispatch, {
205 itemId: licenseModelId,
207 }).then(({ inMerge, isDirty, updatedVersion }) => {
209 (updatedVersion.status === catalogItemStatuses.CERTIFIED ||
210 updatedVersion.archivedStatus ===
211 catalogItemStatuses.ARCHIVED) &&
212 (action === VersionControllerActionsEnum.COMMIT ||
213 action === VersionControllerActionsEnum.SYNC)
215 versionPageActionHelper.fetchVersions(dispatch, {
216 itemType: itemTypes.LICENSE_MODEL,
217 itemId: licenseModelId
220 updatedVersion.archivedStatus ===
221 catalogItemStatuses.ARCHIVED
222 ? i18n('Item was Archived')
223 : i18n('Item version already Certified');
225 type: modalActionTypes.GLOBAL_MODAL_WARNING,
227 title: i18n('Commit error'),
229 cancelButtonText: i18n('Cancel')
232 return Promise.resolve(updatedVersion);
235 if (action === vcActionsEnum.SUBMIT) {
236 return this.manageSubmitAction(dispatch, {
242 return ItemsHelper.performVCAction({
243 itemId: licenseModelId,
248 versionPageActionHelper.fetchVersions(dispatch, {
249 itemType: itemTypes.LICENSE_MODEL,
250 itemId: licenseModelId
252 if (action === vcActionsEnum.SYNC) {
253 return MergeEditorActionHelper.analyzeSyncResult(
255 { itemId: licenseModelId, version }
256 ).then(({ updatedVersion }) => {
257 return Promise.resolve(updatedVersion);
260 return ItemsHelper.checkItemStatus(dispatch, {
261 itemId: licenseModelId,
262 versionId: version.id
271 saveLicenseModel(dispatch, { licenseModel }) {
272 return putLicenseModel(licenseModel).then(() => {
274 type: actionTypes.LICENSE_MODEL_LOADED,
275 response: licenseModel
277 const { id, version: { id: versionId } } = licenseModel;
278 return ItemsHelper.checkItemStatus(dispatch, {
281 }).then(updatedVersion => {
282 if (updatedVersion.status !== licenseModel.version.status) {
283 versionPageActionHelper.fetchVersions(dispatch, {
284 itemType: itemTypes.LICENSE_MODEL,
285 itemId: licenseModel.id
293 export default LicenseModelActionHelper;