AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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'; |
| 20 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 21 | function baseUrl(licenseModelId, version) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | const restPrefix = Configuration.get('restPrefix'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 23 | const {id: versionId} = version; |
| 24 | return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/license-key-groups`; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | function fetchLicenseKeyGroupsList(licenseModelId, version) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 28 | return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | } |
| 30 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 31 | function deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId, version) { |
| 32 | return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | } |
| 34 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 35 | function postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) { |
| 36 | return RestAPIUtil.post(baseUrl(licenseModelId, version), { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | name: licenseKeyGroup.name, |
| 38 | description: licenseKeyGroup.description, |
| 39 | operationalScope: licenseKeyGroup.operationalScope, |
| 40 | type: licenseKeyGroup.type |
| 41 | }); |
| 42 | } |
| 43 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 44 | function putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) { |
| 45 | return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseKeyGroup.id}`, { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 46 | name: licenseKeyGroup.name, |
| 47 | description: licenseKeyGroup.description, |
| 48 | operationalScope: licenseKeyGroup.operationalScope, |
| 49 | type: licenseKeyGroup.type |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | export 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 75 | saveLicenseKeyGroup(dispatch, {licenseModelId, previousLicenseKeyGroup, licenseKeyGroup, version}) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 76 | if (previousLicenseKeyGroup) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 77 | return putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | dispatch({ |
| 79 | type: licenseKeyGroupsConstants.EDIT_LICENSE_KEY_GROUP, |
| 80 | licenseKeyGroup |
| 81 | }); |
| 82 | }); |
| 83 | } |
| 84 | else { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 85 | return postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version).then(response => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 86 | dispatch({ |
| 87 | type: licenseKeyGroupsConstants.ADD_LICENSE_KEY_GROUP, |
| 88 | licenseKeyGroup: { |
| 89 | ...licenseKeyGroup, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 90 | referencingFeatureGroups: [], |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 91 | id: response.value |
| 92 | } |
| 93 | }); |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | }, |
| 99 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 100 | deleteLicenseKeyGroup(dispatch, {licenseModelId, licenseKeyGroupId, version}){ |
| 101 | return deleteLicenseKeyGroup(licenseModelId, licenseKeyGroupId, version).then(()=> { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | dispatch({ |
| 103 | type: licenseKeyGroupsConstants.DELETE_LICENSE_KEY_GROUP, |
| 104 | licenseKeyGroupId |
| 105 | }); |
| 106 | }); |
| 107 | }, |
| 108 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 109 | 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 | }; |