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 as licenseKeyGroupsConstants} from './LicenseKeyGroupsConstants.js';
19 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
21 function baseUrl(licenseModelId, version) {
22 const restPrefix = Configuration.get('restPrefix');
23 const {id: versionId} = version;
24 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/license-key-groups`;
27 function fetchLicenseKeyGroupsList(licenseModelId, version) {
28 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
31 function deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId, version) {
32 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}`);
35 function postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) {
36 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
37 name: licenseKeyGroup.name,
38 description: licenseKeyGroup.description,
39 operationalScope: licenseKeyGroup.operationalScope,
40 type: licenseKeyGroup.type
44 function putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) {
45 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseKeyGroup.id}`, {
46 name: licenseKeyGroup.name,
47 description: licenseKeyGroup.description,
48 operationalScope: licenseKeyGroup.operationalScope,
49 type: licenseKeyGroup.type
55 fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}) {
56 return fetchLicenseKeyGroupsList(licenseModelId, version).then(response => dispatch({
57 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_LIST_LOADED,
62 openLicenseKeyGroupsEditor(dispatch, {licenseKeyGroup} = {}) {
64 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.OPEN,
69 closeLicenseKeyGroupEditor(dispatch){
71 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.CLOSE
75 saveLicenseKeyGroup(dispatch, {licenseModelId, previousLicenseKeyGroup, licenseKeyGroup, version}) {
76 if (previousLicenseKeyGroup) {
77 return putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version).then(() => {
79 type: licenseKeyGroupsConstants.EDIT_LICENSE_KEY_GROUP,
85 return postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version).then(response => {
87 type: licenseKeyGroupsConstants.ADD_LICENSE_KEY_GROUP,
90 referencingFeatureGroups: [],
100 deleteLicenseKeyGroup(dispatch, {licenseModelId, licenseKeyGroupId, version}){
101 return deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId, version).then(()=> {
103 type: licenseKeyGroupsConstants.DELETE_LICENSE_KEY_GROUP,
109 hideDeleteConfirm(dispatch) {
111 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
112 licenseKeyGroupToDelete: false
116 openDeleteLicenseAgreementConfirm(dispatch, {licenseKeyGroup}) {
118 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
119 licenseKeyGroupToDelete: licenseKeyGroup
123 switchVersion(dispatch, {licenseModelId, version}) {
124 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
125 this.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});