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