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 { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
36 } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
39 const restPrefix = Configuration.get('restPrefix');
40 return `${restPrefix}/v1.0/vendor-license-models/`;
43 function fetchLicenseModels() {
44 return RestAPIUtil.fetch(
45 `${baseUrl()}?versionFilter=${versionStatus.DRAFT}`
49 function fetchFinalizedLicenseModels() {
50 return RestAPIUtil.fetch(
51 `${baseUrl()}?versionFilter=${versionStatus.CERTIFIED}`
54 function fetchArchivedLicenseModels() {
55 return RestAPIUtil.fetch(`${baseUrl()}?Status=${itemStatus.ARCHIVED}`);
57 function fetchLicenseModelById(licenseModelId, version) {
58 const { id: versionId } = version;
59 return RestAPIUtil.fetch(
60 `${baseUrl()}${licenseModelId}/versions/${versionId}`
64 function putLicenseModel(licenseModel) {
70 version: { id: versionId }
72 return RestAPIUtil.put(`${baseUrl()}${id}/versions/${versionId}`, {
79 function putLicenseModelAction({ itemId, action, version }) {
80 const { id: versionId } = version;
81 return RestAPIUtil.put(
82 `${baseUrl()}${itemId}/versions/${versionId}/actions`,
87 const LicenseModelActionHelper = {
88 fetchLicenseModels(dispatch) {
89 return fetchLicenseModels().then(response => {
91 type: actionTypes.LICENSE_MODELS_LIST_LOADED,
97 fetchFinalizedLicenseModels(dispatch) {
98 return fetchFinalizedLicenseModels().then(response =>
100 type: actionTypes.FINALIZED_LICENSE_MODELS_LIST_LOADED,
106 fetchArchivedLicenseModels(dispatch) {
107 return fetchArchivedLicenseModels().then(response =>
109 type: actionTypes.ARCHIVED_LICENSE_MODELS_LIST_LOADED,
115 fetchLicenseModelById(dispatch, { licenseModelId, version }) {
116 return fetchLicenseModelById(licenseModelId, version).then(response => {
118 type: actionTypes.LICENSE_MODEL_LOADED,
119 response: { ...response, version }
124 fetchLicenseModelItems(dispatch, { licenseModelId, version }) {
126 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {
130 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {
134 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {
138 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {
145 manageSubmitAction(dispatch, { licenseModelId, version, isDirty }) {
147 const onCommit = comment => {
148 return this.performVCAction(dispatch, {
150 action: vcActionsEnum.COMMIT,
154 return this.performSubmitAction(dispatch, {
161 type: modalActionTypes.GLOBAL_MODAL_SHOW,
163 modalComponentName: modalContentMapper.COMMIT_COMMENT,
164 modalComponentProps: {
166 type: CommitModalType.COMMIT_SUBMIT
168 title: i18n('Commit & Submit')
171 return Promise.reject();
173 return this.performSubmitAction(dispatch, { licenseModelId, version });
176 performSubmitAction(dispatch, { licenseModelId, version }) {
177 return putLicenseModelAction({
178 itemId: licenseModelId,
179 action: vcActionsEnum.SUBMIT,
182 return ItemsHelper.checkItemStatus(dispatch, {
183 itemId: licenseModelId,
184 versionId: version.id
185 }).then(updatedVersion => {
187 type: modalActionTypes.GLOBAL_MODAL_SUCCESS,
189 title: i18n('Submit Succeeded'),
190 msg: i18n('This license model successfully submitted'),
191 cancelButtonText: i18n('OK'),
195 versionPageActionHelper.fetchVersions(dispatch, {
196 itemType: itemTypes.LICENSE_MODEL,
197 itemId: licenseModelId
199 return Promise.resolve(updatedVersion);
204 performVCAction(dispatch, { licenseModelId, action, version, comment }) {
205 return MergeEditorActionHelper.analyzeSyncResult(dispatch, {
206 itemId: licenseModelId,
208 }).then(({ inMerge, isDirty, updatedVersion }) => {
210 (updatedVersion.status === versionStatus.CERTIFIED ||
211 updatedVersion.archivedStatus === versionStatus.ARCHIVED) &&
212 (action === VersionControllerActionsEnum.COMMIT ||
213 action === VersionControllerActionsEnum.SYNC)
215 versionPageActionHelper.fetchVersions(dispatch, {
216 itemType: itemTypes.LICENSE_MODEL,
217 itemId: licenseModelId
220 updatedVersion.archivedStatus === versionStatus.ARCHIVED
221 ? i18n('Item was Archived')
222 : i18n('Item version already Certified');
224 type: modalActionTypes.GLOBAL_MODAL_WARNING,
226 title: i18n('Commit error'),
228 cancelButtonText: i18n('Cancel')
231 return Promise.resolve(updatedVersion);
234 if (action === vcActionsEnum.SUBMIT) {
235 return this.manageSubmitAction(dispatch, {
241 return ItemsHelper.performVCAction({
242 itemId: licenseModelId,
247 versionPageActionHelper.fetchVersions(dispatch, {
248 itemType: itemTypes.LICENSE_MODEL,
249 itemId: licenseModelId
251 if (action === vcActionsEnum.SYNC) {
252 return MergeEditorActionHelper.analyzeSyncResult(
254 { itemId: licenseModelId, version }
255 ).then(({ updatedVersion }) => {
256 return Promise.resolve(updatedVersion);
259 return ItemsHelper.checkItemStatus(dispatch, {
260 itemId: licenseModelId,
261 versionId: version.id
270 saveLicenseModel(dispatch, { licenseModel }) {
271 return putLicenseModel(licenseModel).then(() => {
273 type: actionTypes.LICENSE_MODEL_LOADED,
274 response: licenseModel
276 const { id, version: { id: versionId } } = licenseModel;
277 return ItemsHelper.checkItemStatus(dispatch, {
280 }).then(updatedVersion => {
281 if (updatedVersion.status !== licenseModel.version.status) {
282 versionPageActionHelper.fetchVersions(dispatch, {
283 itemType: itemTypes.LICENSE_MODEL,
284 itemId: licenseModel.id
292 export default LicenseModelActionHelper;