Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {Injectable} from '@angular/core'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 2 | import {combineEpics, createEpicMiddleware, ofType} from 'redux-observable'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 3 | import 'rxjs/add/operator/catch'; |
| 4 | import 'rxjs/add/operator/map'; |
| 5 | import 'rxjs/add/operator/do'; |
| 6 | import 'rxjs/add/operator/startWith'; |
| 7 | import { |
| 8 | LOAD_PRODUCT_FAMILIES, |
| 9 | LOAD_LCP_TENANT, |
| 10 | LOAD_AIC_ZONES, |
| 11 | LOAD_CATEGORY_PARAMETERS, |
| 12 | LOAD_SERVICE_MDOEL_BY_UUID, |
| 13 | LOAD_NETWORK_ACCORDING_TO_NF, |
| 14 | LOAD_USER_ID |
| 15 | } from "./aai.actions"; |
| 16 | import {AaiService} from "./aai.service"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 17 | import {AppState} from "../../store/reducers"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 18 | import { |
| 19 | updateAicZones, updateCategoryParameters, |
| 20 | updateLcpRegionsAndTenants, |
| 21 | updateNetworkCollectionFunction, |
| 22 | updateProductFamilies, updateUserId |
| 23 | } from "../../storeUtil/utils/general/general.actions"; |
| 24 | import {createServiceInstance} from "../../storeUtil/utils/service/service.actions"; |
| 25 | import {delay, mapTo} from "rxjs/operators"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 26 | |
| 27 | const notFetchedAlready = (state: AppState): boolean => state.service.productFamilies !== null; |
| 28 | |
| 29 | @Injectable() |
| 30 | export class AAIEpics { |
| 31 | constructor(private aaiService: AaiService) { |
| 32 | } |
| 33 | |
| 34 | public createEpic() { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 35 | return combineEpics( |
| 36 | this.loadProductFamiliesEpic |
| 37 | , this.loadLcpTenants |
| 38 | , this.loadAicZones |
| 39 | , this.loadCategoryParameters |
| 40 | , this.loadServiceAccordingToUuid |
| 41 | , this.loadNetworkAccordingToNetworkFunction |
| 42 | , this.loadUserId) |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | private loadLcpTenants = (action$, store) => |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 46 | action$.ofType(LOAD_LCP_TENANT) |
| 47 | .switchMap((action) => this.aaiService.getLcpRegionsAndTenants(action.subscriberId, action.serviceType) |
| 48 | .map(data => updateLcpRegionsAndTenants(data))); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 49 | |
| 50 | private loadProductFamiliesEpic = (action$, store) => action$ |
| 51 | .ofType(LOAD_PRODUCT_FAMILIES) |
| 52 | .switchMap(() => this.aaiService.getProductFamilies().map(data => updateProductFamilies(data))); |
| 53 | |
| 54 | private loadCategoryParameters = (action$, store) => action$ |
| 55 | .ofType(LOAD_CATEGORY_PARAMETERS) |
| 56 | .switchMap(() => this.aaiService.getCategoryParameters(null).map(data => updateCategoryParameters(data))); |
| 57 | |
| 58 | |
| 59 | private loadNetworkAccordingToNetworkFunction = (action$, store) => action$ |
| 60 | .ofType(LOAD_NETWORK_ACCORDING_TO_NF) |
| 61 | .flatMap((action) => this.aaiService.getCRAccordingToNetworkFunctionId(action.networkFunctions, action.cloudOwner, action.cloudRegionId).map((res) => |
| 62 | updateNetworkCollectionFunction(action.networkFunctions, res))); |
| 63 | |
| 64 | private loadServiceAccordingToUuid = (action$, store) => action$ |
| 65 | .ofType(LOAD_SERVICE_MDOEL_BY_UUID) |
| 66 | .switchMap((action) => this.aaiService.getServiceModelById(action.modelId) |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 67 | .map(data => createServiceInstance(action.uuid, data))); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 68 | |
| 69 | private loadUserId = (action$, store) => action$ |
| 70 | .ofType(LOAD_USER_ID) |
| 71 | .switchMap(() => this.aaiService.getUserId() |
| 72 | .map(res => updateUserId(res))); |
| 73 | |
| 74 | |
| 75 | private loadAicZones = (action$, store) => action$ |
| 76 | .ofType(LOAD_AIC_ZONES) |
| 77 | .switchMap(() => this.aaiService.getAicZones().map(data => updateAicZones(data))); |
| 78 | // .catch(response => of(this.actions.loadFailed(status))) |
| 79 | // .startWith(this.actions.loadStarted())); |
| 80 | |
| 81 | } |