blob: d4aef1937f6081809b609eb72abb738e3afb53c8 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {ActivatedRouteSnapshot, Resolve} from "@angular/router";
2import {Injectable} from "@angular/core";
3import {Observable} from "rxjs";
4import {AaiService} from "../../services/aaiService/aai.service";
5import {forkJoin} from "rxjs/observable/forkJoin";
6import {AppState} from "../../store/reducers";
7import {NgRedux} from "@angular-redux/store";
8import {createServiceInstance} from "../../storeUtil/utils/service/service.actions";
9
10@Injectable()
11export class ViewEditResolver implements Resolve<Observable<boolean>> {
12
13 constructor(private _aaiService: AaiService, private _store: NgRedux<AppState>) {
14 }
15
16 resolve(route: ActivatedRouteSnapshot): Observable<boolean> {
17 const serviceModeId: string = route.queryParamMap.get("serviceModelId");
18 const serviceInstanceId: string = route.queryParamMap.get("serviceInstanceId");
19 const subscriberId: string = route.queryParamMap.get("subscriberId");
20 const serviceType: string = route.queryParamMap.get("serviceType");
21 let serviceModelApi = this._aaiService.getServiceModelById(serviceModeId);
22 let serviceInstanceApi = this._aaiService.retrieveAndStoreServiceInstanceTopology(serviceInstanceId, subscriberId, serviceType, serviceModeId);
23 return forkJoin([serviceModelApi, serviceInstanceApi]).map(([serviceModel, serviceInstance ]) => {
24 this.setIsALaCarte(serviceInstance,serviceModel.service.instantiationType );
25 this.setTestApi(serviceInstance);
26 this._store.dispatch(createServiceInstance( serviceInstance, serviceModeId));
27 return true;
28 });
29 }
30
31 setTestApi = (service: any) => {
32 if (this._store.getState().global.flags['FLAG_ADD_MSO_TESTAPI_FIELD'] && service.isALaCarte) {
33 service.testApi = sessionStorage.getItem("msoRequestParametersTestApiValue");
34 }
35 };
36 setIsALaCarte = (service: any, instantiationType) => {
37 service.isALaCarte = instantiationType === 'A-La-Carte';
38 };
39
40}