Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame^] | 1 | import {ActivatedRouteSnapshot, Resolve} from "@angular/router"; |
| 2 | import {Injectable} from "@angular/core"; |
| 3 | import {Observable} from "rxjs"; |
| 4 | import {AaiService} from "../../services/aaiService/aai.service"; |
| 5 | import {forkJoin} from "rxjs/observable/forkJoin"; |
| 6 | import {AppState} from "../../store/reducers"; |
| 7 | import {NgRedux} from "@angular-redux/store"; |
| 8 | import {createServiceInstance} from "../../storeUtil/utils/service/service.actions"; |
| 9 | |
| 10 | @Injectable() |
| 11 | export 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 | } |