blob: 50ac2c85a3c7607b40ed85eb3f3a842313b0f7aa [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20
21import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22import Configuration from 'sdc-app/config/Configuration.js';
23import {actionTypes as licenseKeyGroupsConstants} from './LicenseKeyGroupsConstants.js';
24import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
25
26function baseUrl(licenseModelId) {
27 const restPrefix = Configuration.get('restPrefix');
28 return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/license-key-groups`;
29}
30
31function fetchLicenseKeyGroupsList(licenseModelId, version) {
32 let versionQuery = version ? `?version=${version}` : '';
33 return RestAPIUtil.fetch(`${baseUrl(licenseModelId)}${versionQuery}`);
34}
35
36function deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId) {
37 return RestAPIUtil.destroy(`${baseUrl(licenseModelId)}/${licenseKeyGroupId}`);
38}
39
40function 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
46 });
47}
48
49function 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
55 });
56}
57
58
59export default {
60 fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}) {
61 return fetchLicenseKeyGroupsList(licenseModelId, version).then(response => dispatch({
62 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_LIST_LOADED,
63 response
64 }));
65 },
66
67 openLicenseKeyGroupsEditor(dispatch, {licenseKeyGroup} = {}) {
68 dispatch({
69 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.OPEN,
70 licenseKeyGroup
71 });
72 },
73
74 closeLicenseKeyGroupEditor(dispatch){
75 dispatch({
76 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.CLOSE
77 });
78 },
79
80 saveLicenseKeyGroup(dispatch, {licenseModelId, previousLicenseKeyGroup, licenseKeyGroup}) {
81 if (previousLicenseKeyGroup) {
82 return putLicenseKeyGroup(licenseModelId, licenseKeyGroup).then(() => {
83 dispatch({
84 type: licenseKeyGroupsConstants.EDIT_LICENSE_KEY_GROUP,
85 licenseKeyGroup
86 });
87 });
88 }
89 else {
90 return postLicenseKeyGroup(licenseModelId, licenseKeyGroup).then(response => {
91 dispatch({
92 type: licenseKeyGroupsConstants.ADD_LICENSE_KEY_GROUP,
93 licenseKeyGroup: {
94 ...licenseKeyGroup,
95 id: response.value
96 }
97 });
98 });
99 }
100
101
102 },
103
104 deleteLicenseKeyGroup(dispatch, {licenseModelId, licenseKeyGroupId}){
105 return deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId).then(()=> {
106 dispatch({
107 type: licenseKeyGroupsConstants.DELETE_LICENSE_KEY_GROUP,
108 licenseKeyGroupId
109 });
110 });
111 },
112
113 licenseKeyGroupEditorDataChanged(dispatch, {deltaData}) {
114 dispatch({
115 type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.DATA_CHANGED,
116 deltaData
117 });
118 },
119
120 hideDeleteConfirm(dispatch) {
121 dispatch({
122 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
123 licenseKeyGroupToDelete: false
124 });
125 },
126
127 openDeleteLicenseAgreementConfirm(dispatch, {licenseKeyGroup}) {
128 dispatch({
129 type: licenseKeyGroupsConstants.LICENSE_KEY_GROUPS_DELETE_CONFIRM,
130 licenseKeyGroupToDelete: licenseKeyGroup
131 });
132 },
133
134 switchVersion(dispatch, {licenseModelId, version}) {
135 LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
136 this.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
137 });
138 }
139};