blob: dd2a5c60037de80a7378a99e01ef0b4ab3a75bc5 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17import Configuration from 'sdc-app/config/Configuration.js';
18import {actionTypes as licenseKeyGroupsConstants} from './LicenseKeyGroupsConstants.js';
19import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
20
AviZi280f8012017-06-09 02:39:56 +030021function baseUrl(licenseModelId, version) {
Michael Landoefa037d2017-02-19 12:57:33 +020022 const restPrefix = Configuration.get('restPrefix');
AviZi280f8012017-06-09 02:39:56 +030023 const {id: versionId} = version;
24 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/license-key-groups`;
Michael Landoefa037d2017-02-19 12:57:33 +020025}
26
27function fetchLicenseKeyGroupsList(licenseModelId, version) {
AviZi280f8012017-06-09 02:39:56 +030028 return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`);
Michael Landoefa037d2017-02-19 12:57:33 +020029}
30
AviZi280f8012017-06-09 02:39:56 +030031function deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId, version) {
32 return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}`);
Michael Landoefa037d2017-02-19 12:57:33 +020033}
34
AviZi280f8012017-06-09 02:39:56 +030035function postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) {
36 return RestAPIUtil.post(baseUrl(licenseModelId, version), {
Michael Landoefa037d2017-02-19 12:57:33 +020037 name: licenseKeyGroup.name,
38 description: licenseKeyGroup.description,
39 operationalScope: licenseKeyGroup.operationalScope,
40 type: licenseKeyGroup.type
41 });
42}
43
AviZi280f8012017-06-09 02:39:56 +030044function putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) {
45 return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseKeyGroup.id}`, {
Michael Landoefa037d2017-02-19 12:57:33 +020046 name: licenseKeyGroup.name,
47 description: licenseKeyGroup.description,
48 operationalScope: licenseKeyGroup.operationalScope,
49 type: licenseKeyGroup.type
50 });
51}
52
53
54export default {
55 fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}) {
56 return fetchLicenseKeyGroupsList(licenseModelId, version).then(response => dispatch({
57 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_LIST_LOADED,
58 response
59 }));
60 },
61
62 openLicenseKeyGroupsEditor(dispatch, {licenseKeyGroup} = {}) {
63 dispatch({
64 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.OPEN,
65 licenseKeyGroup
66 });
67 },
68
69 closeLicenseKeyGroupEditor(dispatch){
70 dispatch({
71 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.CLOSE
72 });
73 },
74
AviZi280f8012017-06-09 02:39:56 +030075 saveLicenseKeyGroup(dispatch, {licenseModelId, previousLicenseKeyGroup, licenseKeyGroup, version}) {
Michael Landoefa037d2017-02-19 12:57:33 +020076 if (previousLicenseKeyGroup) {
AviZi280f8012017-06-09 02:39:56 +030077 return putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +020078 dispatch({
79 type: licenseKeyGroupsConstants.EDIT_LICENSE_KEY_GROUP,
80 licenseKeyGroup
81 });
82 });
83 }
84 else {
AviZi280f8012017-06-09 02:39:56 +030085 return postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version).then(response => {
Michael Landoefa037d2017-02-19 12:57:33 +020086 dispatch({
87 type: licenseKeyGroupsConstants.ADD_LICENSE_KEY_GROUP,
88 licenseKeyGroup: {
89 ...licenseKeyGroup,
AviZi280f8012017-06-09 02:39:56 +030090 referencingFeatureGroups: [],
Michael Landoefa037d2017-02-19 12:57:33 +020091 id: response.value
92 }
93 });
94 });
95 }
96
97
98 },
99
AviZi280f8012017-06-09 02:39:56 +0300100 deleteLicenseKeyGroup(dispatch, {licenseModelId, licenseKeyGroupId, version}){
101 return deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId, version).then(()=> {
Michael Landoefa037d2017-02-19 12:57:33 +0200102 dispatch({
103 type: licenseKeyGroupsConstants.DELETE_LICENSE_KEY_GROUP,
104 licenseKeyGroupId
105 });
106 });
107 },
108
Michael Landoefa037d2017-02-19 12:57:33 +0200109 hideDeleteConfirm(dispatch) {
110 dispatch({
111 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
112 licenseKeyGroupToDelete: false
113 });
114 },
115
116 openDeleteLicenseAgreementConfirm(dispatch, {licenseKeyGroup}) {
117 dispatch({
118 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
119 licenseKeyGroupToDelete: licenseKeyGroup
120 });
121 },
122
123 switchVersion(dispatch, {licenseModelId, version}) {
124 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
125 this.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
126 });
127 }
128};