blob: 5249cea820a6084c21e91a5f66272ae54e4b4050 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {updateServiceInstance} from './../../service.actions';
2import {Injectable} from '@angular/core';
3import {createEpicMiddleware} from 'redux-observable';
4import 'rxjs/add/operator/catch';
5import 'rxjs/add/operator/map';
6import 'rxjs/add/operator/do';
7import 'rxjs/add/operator/startWith';
8import {
9 LOAD_PRODUCT_FAMILIES,
10 LOAD_LCP_TENANT,
11 LOAD_AIC_ZONES,
12 LOAD_CATEGORY_PARAMETERS,
13 LOAD_SERVICE_MDOEL_BY_UUID,
14 LOAD_NETWORK_ACCORDING_TO_NF,
15 LOAD_USER_ID
16} from "./aai.actions";
17import {AaiService} from "./aai.service";
18import {
19 updateAicZones, updateCategoryParameters, updateLcpRegionsAndTenants, updateNetworkCollectionFunction,
20 updateProductFamilies, updateUserId
21} from "../../service.actions";
22import {AppState} from "../../store/reducers";
23
24const notFetchedAlready = (state: AppState): boolean => state.service.productFamilies !== null;
25
26@Injectable()
27export class AAIEpics {
28 constructor(private aaiService: AaiService) {
29 }
30
31 public createEpic() {
32 return [createEpicMiddleware(this.loadProductFamiliesEpic)
33 , createEpicMiddleware(this.loadLcpTenants)
34 , createEpicMiddleware(this.loadAicZones)
35 , createEpicMiddleware(this.loadCategoryParameters)
36 , createEpicMiddleware(this.loadServiceAccordingToUuid)
37 , createEpicMiddleware(this.loadNetworkAccordingToNetworkFunction)
38 , createEpicMiddleware(this.loadUserId)
39 ];
40 }
41
42 private loadLcpTenants = (action$, store) =>
43 action$
44 .ofType(LOAD_LCP_TENANT)
45 .switchMap(() => this
46 .aaiService
47 .getLcpRegionsAndTenants('e433710f-9217-458d-a79d-1c7aff376d89', 'VIRTUAL USP')
48 .map(data => updateLcpRegionsAndTenants(data)));
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)
67 .map(data => updateServiceInstance(action.uuid, data)));
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}