blob: 404f390fbee3397fdf2acbe6bf110eece9b646d7 [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 ]) => {
Ittay Sternf7926712019-07-07 19:23:03 +030024 this.setIsALaCarte(serviceInstance,serviceModel.service.vidNotions.instantiationType );
Ittay Stern6f900cc2018-08-29 17:01:32 +030025 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) => {
Ittay Sternf7926712019-07-07 19:23:03 +030037 service.isALaCarte = instantiationType === 'ALaCarte';
Ittay Stern6f900cc2018-08-29 17:01:32 +030038 };
39
40}