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 {actionTypes as licenseKeyGroupsConstants} from './LicenseKeyGroupsConstants.js';
24 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
26 function baseUrl(licenseModelId) {
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/license-key-groups`;
31 function fetchLicenseKeyGroupsList(licenseModelId, version) {
32 let versionQuery = version ? `?version=${version}` : '';
33 return RestAPIUtil.fetch(`${baseUrl(licenseModelId)}${versionQuery}`);
36 function deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId) {
37 return RestAPIUtil.destroy(`${baseUrl(licenseModelId)}/${licenseKeyGroupId}`);
40 function postLicenseKeyGroup(licenseModelId, licenseKeyGroup) {
41 return RestAPIUtil.create(baseUrl(licenseModelId), {
42 name: licenseKeyGroup.name,
43 description: licenseKeyGroup.description,
44 operationalScope: licenseKeyGroup.operationalScope,
45 type: licenseKeyGroup.type
49 function putLicenseKeyGroup(licenseModelId, licenseKeyGroup) {
50 return RestAPIUtil.save(`${baseUrl(licenseModelId)}/${licenseKeyGroup.id}`, {
51 name: licenseKeyGroup.name,
52 description: licenseKeyGroup.description,
53 operationalScope: licenseKeyGroup.operationalScope,
54 type: licenseKeyGroup.type
60 fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}) {
61 return fetchLicenseKeyGroupsList(licenseModelId, version).then(response => dispatch({
62 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_LIST_LOADED,
67 openLicenseKeyGroupsEditor(dispatch, {licenseKeyGroup} = {}) {
69 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.OPEN,
74 closeLicenseKeyGroupEditor(dispatch){
76 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.CLOSE
80 saveLicenseKeyGroup(dispatch, {licenseModelId, previousLicenseKeyGroup, licenseKeyGroup}) {
81 if (previousLicenseKeyGroup) {
82 return putLicenseKeyGroup(licenseModelId, licenseKeyGroup).then(() => {
84 type: licenseKeyGroupsConstants.EDIT_LICENSE_KEY_GROUP,
90 return postLicenseKeyGroup(licenseModelId, licenseKeyGroup).then(response => {
92 type: licenseKeyGroupsConstants.ADD_LICENSE_KEY_GROUP,
104 deleteLicenseKeyGroup(dispatch, {licenseModelId, licenseKeyGroupId}){
105 return deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId).then(()=> {
107 type: licenseKeyGroupsConstants.DELETE_LICENSE_KEY_GROUP,
113 licenseKeyGroupEditorDataChanged(dispatch, {deltaData}) {
115 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.DATA_CHANGED,
120 hideDeleteConfirm(dispatch) {
122 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
123 licenseKeyGroupToDelete: false
127 openDeleteLicenseAgreementConfirm(dispatch, {licenseKeyGroup}) {
129 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
130 licenseKeyGroupToDelete: licenseKeyGroup
134 switchVersion(dispatch, {licenseModelId, version}) {
135 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
136 this.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});