summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/services/aaiService/aai.epics.ts
blob: 3a05157aee590a0799715d0b22939986211f5e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {Injectable} from '@angular/core';
import {combineEpics, createEpicMiddleware, ofType} from 'redux-observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/startWith';
import {
  LOAD_PRODUCT_FAMILIES,
  LOAD_LCP_TENANT,
  LOAD_AIC_ZONES,
  LOAD_CATEGORY_PARAMETERS,
  LOAD_SERVICE_MDOEL_BY_UUID,
  LOAD_NETWORK_ACCORDING_TO_NF,
  LOAD_USER_ID
} from "./aai.actions";
import {AaiService} from "./aai.service";
import {AppState} from "../../store/reducers";
import {
  updateAicZones, updateCategoryParameters,
  updateLcpRegionsAndTenants,
  updateNetworkCollectionFunction,
  updateProductFamilies, updateUserId
} from "../../storeUtil/utils/general/general.actions";
import {createServiceInstance} from "../../storeUtil/utils/service/service.actions";

const notFetchedAlready = (state: AppState): boolean => state.service.productFamilies !== null;

@Injectable()
export class AAIEpics {
  constructor(private aaiService: AaiService) {
  }
  public createEpic() {
    return combineEpics(
        this.loadProductFamiliesEpic
      , this.loadLcpTenants
      , this.loadAicZones
      , this.loadCategoryParameters
      , this.loadServiceAccordingToUuid
      , this.loadNetworkAccordingToNetworkFunction
      , this.loadUserId)
  }

  private loadLcpTenants = (action$, store) =>
   action$.ofType(LOAD_LCP_TENANT)
    .switchMap((action) => this.aaiService.getLcpRegionsAndTenants(action.subscriberId, action.serviceType)
    .map(data => updateLcpRegionsAndTenants(data)));

  private loadProductFamiliesEpic = (action$, store) => action$
    .ofType(LOAD_PRODUCT_FAMILIES)
    .switchMap(() =>
      this.aaiService.getProductFamilies()
        .map(data =>
          updateProductFamilies(data)
      ));

  private loadCategoryParameters = (action$, store) => action$
    .ofType(LOAD_CATEGORY_PARAMETERS)
    .switchMap(() => this.aaiService.getCategoryParameters(null).map(data => updateCategoryParameters(data)));


  private loadNetworkAccordingToNetworkFunction = (action$, store) => action$
    .ofType(LOAD_NETWORK_ACCORDING_TO_NF)
    .flatMap((action) => this.aaiService.getCRAccordingToNetworkFunctionId(action.networkFunctions, action.cloudOwner, action.cloudRegionId).map((res) =>
      updateNetworkCollectionFunction(action.networkFunctions, res)));

  private loadServiceAccordingToUuid = (action$, store) => action$
    .ofType(LOAD_SERVICE_MDOEL_BY_UUID)
    .switchMap((action) => this.aaiService.getServiceModelById(action.modelId)
      .map(data =>
        createServiceInstance(action.uuid, data))
    );

  private loadUserId = (action$, store) => action$
    .ofType(LOAD_USER_ID)
    .switchMap(() => this.aaiService.getUserId()
      .map(res => updateUserId(res)));


  private loadAicZones = (action$, store) => action$
    .ofType(LOAD_AIC_ZONES)
    .switchMap(() => this.aaiService.getAicZones().map(data => updateAicZones(data)));
  // .catch(response => of(this.actions.loadFailed(status)))
  // .startWith(this.actions.loadStarted()));

}