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 featureGroupsActionConstants} from './FeatureGroupsConstants.js'; |
| 19 | import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js'; |
| 20 | import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js'; |
| 21 | import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js'; |
| 22 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | function baseUrl(licenseModelId, version) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | const restPrefix = Configuration.get('restPrefix'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | const {id: versionId} = version; |
| 26 | return `${restPrefix}/v1.0/vendor-license-models/${licenseModelId}/versions/${versionId}/feature-groups`; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | function fetchFeatureGroupsList(licenseModelId, version) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 30 | return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 31 | } |
| 32 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 33 | function deleteFeatureGroup(licenseModelId, featureGroupId, version) { |
| 34 | return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${featureGroupId}`); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | } |
| 36 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 37 | function addFeatureGroup(licenseModelId, featureGroup, version) { |
| 38 | return RestAPIUtil.post(baseUrl(licenseModelId, version), { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | name: featureGroup.name, |
| 40 | description: featureGroup.description, |
| 41 | partNumber: featureGroup.partNumber, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame^] | 42 | manufacturerReferenceNumber: featureGroup.manufacturerReferenceNumber, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | addedLicenseKeyGroupsIds: featureGroup.licenseKeyGroupsIds, |
| 44 | addedEntitlementPoolsIds: featureGroup.entitlementPoolsIds |
| 45 | }); |
| 46 | } |
| 47 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 48 | function updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup, version) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | |
| 50 | const {licenseKeyGroupsIds = []} = featureGroup; |
| 51 | const {licenseKeyGroupsIds: prevLicenseKeyGroupsIds = []} = previousFeatureGroup; |
| 52 | const {entitlementPoolsIds = []} = featureGroup; |
| 53 | const {entitlementPoolsIds: prevEntitlementPoolsIds = []} = previousFeatureGroup; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${featureGroup.id}`, { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 55 | name: featureGroup.name, |
| 56 | description: featureGroup.description, |
| 57 | partNumber: featureGroup.partNumber, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame^] | 58 | manufacturerReferenceNumber: featureGroup.manufacturerReferenceNumber, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 59 | addedLicenseKeyGroupsIds: licenseKeyGroupsIds.filter(licenseKeyGroupId => prevLicenseKeyGroupsIds.indexOf(licenseKeyGroupId) === -1), |
| 60 | removedLicenseKeyGroupsIds: prevLicenseKeyGroupsIds.filter(prevLicenseKeyGroupId => licenseKeyGroupsIds.indexOf(prevLicenseKeyGroupId) === -1), |
| 61 | addedEntitlementPoolsIds: entitlementPoolsIds.filter(entitlementPoolId => prevEntitlementPoolsIds.indexOf(entitlementPoolId) === -1), |
| 62 | removedEntitlementPoolsIds: prevEntitlementPoolsIds.filter(prevEntitlementPoolId => entitlementPoolsIds.indexOf(prevEntitlementPoolId) === -1) |
| 63 | |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | export default { |
| 68 | fetchFeatureGroupsList(dispatch, {licenseModelId, version}) { |
| 69 | return fetchFeatureGroupsList(licenseModelId, version).then(response => dispatch({ |
| 70 | type: featureGroupsActionConstants.FEATURE_GROUPS_LIST_LOADED, |
| 71 | response |
| 72 | })); |
| 73 | }, |
| 74 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 75 | deleteFeatureGroup(dispatch, {licenseModelId, featureGroupId, version}) { |
| 76 | return deleteFeatureGroup(licenseModelId, featureGroupId, version).then(() => dispatch({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 77 | type: featureGroupsActionConstants.DELETE_FEATURE_GROUPS, |
| 78 | featureGroupId |
| 79 | })); |
| 80 | }, |
| 81 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | saveFeatureGroup(dispatch, {licenseModelId, previousFeatureGroup, featureGroup, version}) { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 83 | if (previousFeatureGroup) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 84 | return updateFeatureGroup(licenseModelId, previousFeatureGroup, featureGroup, version).then(() =>{ |
| 85 | dispatch({ |
| 86 | type: featureGroupsActionConstants.EDIT_FEATURE_GROUPS, |
| 87 | featureGroup |
| 88 | }); |
| 89 | EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}); |
| 90 | LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}); |
| 91 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | } |
| 93 | else { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 94 | return addFeatureGroup(licenseModelId, featureGroup, version).then(response => { |
| 95 | dispatch({ |
| 96 | type: featureGroupsActionConstants.ADD_FEATURE_GROUPS, |
| 97 | featureGroup: { |
| 98 | ...featureGroup, |
| 99 | id: response.value, |
| 100 | referencingLicenseAgreements: [] |
| 101 | } |
| 102 | }); |
| 103 | EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}); |
| 104 | LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}); |
| 105 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 106 | } |
| 107 | }, |
| 108 | |
| 109 | selectEntitlementPoolsEditorTab(dispatch, {tab}) { |
| 110 | dispatch({ |
| 111 | type: featureGroupsActionConstants.featureGroupsEditor.SELECT_TAB, |
| 112 | tab |
| 113 | }); |
| 114 | }, |
| 115 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 116 | openFeatureGroupsEditor(dispatch, {featureGroup, licenseModelId, version}) { |
| 117 | EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version}); |
| 118 | LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 119 | dispatch({ |
| 120 | type: featureGroupsActionConstants.featureGroupsEditor.OPEN, |
| 121 | featureGroup |
| 122 | }); |
| 123 | }, |
| 124 | |
| 125 | closeFeatureGroupsEditor(dispatch) { |
| 126 | dispatch({ |
| 127 | type: featureGroupsActionConstants.featureGroupsEditor.CLOSE |
| 128 | }); |
| 129 | }, |
| 130 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 131 | |
| 132 | switchVersion(dispatch, {licenseModelId, version}) { |
| 133 | LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => { |
| 134 | this.fetchFeatureGroupsList(dispatch, {licenseModelId, version}); |
| 135 | }); |
| 136 | } |
| 137 | }; |