blob: a850d55da17eaf719842ff3a72a1c1dd24ac5d55 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {Injectable} from '@angular/core';
Ittay Stern6f900cc2018-08-29 17:01:32 +03002import {combineEpics, createEpicMiddleware, ofType} from 'redux-observable';
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03003import 'rxjs/add/operator/catch';
4import 'rxjs/add/operator/map';
5import 'rxjs/add/operator/do';
6import 'rxjs/add/operator/startWith';
7import {
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";
16import {AaiService} from "./aai.service";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030017import {AppState} from "../../store/reducers";
Ittay Stern6f900cc2018-08-29 17:01:32 +030018import {
19 updateAicZones, updateCategoryParameters,
20 updateLcpRegionsAndTenants,
21 updateNetworkCollectionFunction,
22 updateProductFamilies, updateUserId
23} from "../../storeUtil/utils/general/general.actions";
24import {createServiceInstance} from "../../storeUtil/utils/service/service.actions";
25import {delay, mapTo} from "rxjs/operators";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030026
27const notFetchedAlready = (state: AppState): boolean => state.service.productFamilies !== null;
28
29@Injectable()
30export class AAIEpics {
31 constructor(private aaiService: AaiService) {
32 }
33
34 public createEpic() {
Ittay Stern6f900cc2018-08-29 17:01:32 +030035 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)ff76b5e2018-07-10 15:57:37 +030043 }
44
45 private loadLcpTenants = (action$, store) =>
Ittay Stern6f900cc2018-08-29 17:01:32 +030046 action$.ofType(LOAD_LCP_TENANT)
47 .switchMap((action) => this.aaiService.getLcpRegionsAndTenants(action.subscriberId, action.serviceType)
48 .map(data => updateLcpRegionsAndTenants(data)));
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030049
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 Stern6f900cc2018-08-29 17:01:32 +030067 .map(data => createServiceInstance(action.uuid, data)));
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030068
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}