blob: 540e02fe69fe27d07a64a37c9778c7fc398effcf [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {ActivatedRouteSnapshot, Resolve} from "@angular/router";
2import {Injectable} from "@angular/core";
Eylon Malin5438f8b2019-09-26 10:04:17 +03003import {from, Observable, of} from "rxjs";
Ittay Stern6f900cc2018-08-29 17:01:32 +03004import {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";
Einat Vinouzee1f79742019-08-27 16:01:01 +03009import {ServiceInstance} from "../../models/serviceInstance";
10import * as _ from "lodash";
11import {ModelInfo} from "../../models/modelInfo";
Eylon Malin5438f8b2019-09-26 10:04:17 +030012import {FeatureFlagsService, Features} from "../../services/featureFlag/feature-flags.service";
Ittay Stern6f900cc2018-08-29 17:01:32 +030013
14@Injectable()
15export class ViewEditResolver implements Resolve<Observable<boolean>> {
16
Eylon Malin5438f8b2019-09-26 10:04:17 +030017 constructor(private _aaiService: AaiService,
18 private featureFlagsService:FeatureFlagsService,
19 private _store: NgRedux<AppState>) {
Ittay Stern6f900cc2018-08-29 17:01:32 +030020 }
21
22 resolve(route: ActivatedRouteSnapshot): Observable<boolean> {
Einat Vinouzee1f79742019-08-27 16:01:01 +030023 const serviceModelId: string = route.queryParamMap.get("serviceModelId");
Ittay Stern6f900cc2018-08-29 17:01:32 +030024 const serviceInstanceId: string = route.queryParamMap.get("serviceInstanceId");
25 const subscriberId: string = route.queryParamMap.get("subscriberId");
26 const serviceType: string = route.queryParamMap.get("serviceType");
Einat Vinouzee1f79742019-08-27 16:01:01 +030027 let serviceModelApi = this._aaiService.getServiceModelById(serviceModelId);
28 let serviceInstanceApi = this._aaiService.retrieveAndStoreServiceInstanceTopology(serviceInstanceId, subscriberId, serviceType, serviceModelId);
29 let streams: Observable<any>[] = [serviceModelApi, serviceInstanceApi];
30 streams = streams.filter( stream => stream !== undefined);
31 return forkJoin(streams).switchMap(([serviceModel, serviceInstance]) => {
Eylon Malin5438f8b2019-09-26 10:04:17 +030032 if (this.featureFlagsService.getFlagState(Features.FLAG_FLASH_REPLACE_VF_MODULE)) {
33 return from(this.retrieveLatestVersionAndSetServiceInstance(serviceInstance.modelInfo.modelInvariantId).then((response) => {
34 this.setServiceLatestAvailableVersion(serviceInstance, response);
35 this.applyRequestsResponsesToStateAndInitServiceInstance(serviceModelId, serviceInstance, serviceModel);
36 return true;
37 }));
38 }
39 else {
40 return of(true);
41 }
Einat Vinouzee1f79742019-08-27 16:01:01 +030042 });
Ittay Stern6f900cc2018-08-29 17:01:32 +030043 }
44
Einat Vinouzee1f79742019-08-27 16:01:01 +030045 private retrieveLatestVersionAndSetServiceInstance(modelInvariantId: string) :Promise<ModelInfo>{
46 return this._aaiService.retrieveServiceLatestUpdateableVersion(modelInvariantId).toPromise();
47 }
48
49 applyRequestsResponsesToStateAndInitServiceInstance(serviceModelId: string,
50 serviceInstance, serviceModel) {
51 this.setIsALaCarte(serviceInstance, serviceModel.service.vidNotions.instantiationType);
52 this.setTestApi(serviceInstance);
53 this._store.dispatch(createServiceInstance(serviceInstance, serviceModelId));
54 }
55
56 setServiceLatestAvailableVersion(serviceInstance :ServiceInstance, modelInfoObject: ModelInfo) :void{
57 if(!_.isNil(modelInfoObject) && !_.isNil(modelInfoObject.modelVersion)){
58 serviceInstance.latestAvailableVersion = Number(modelInfoObject.modelVersion);
59 }
60 else {
61 serviceInstance.latestAvailableVersion = 0;
62 }
63 }
64
65 setTestApi(service: any) :void{
Ittay Stern6f900cc2018-08-29 17:01:32 +030066 if (this._store.getState().global.flags['FLAG_ADD_MSO_TESTAPI_FIELD'] && service.isALaCarte) {
67 service.testApi = sessionStorage.getItem("msoRequestParametersTestApiValue");
68 }
69 };
Einat Vinouzee1f79742019-08-27 16:01:01 +030070
71 setIsALaCarte(service: any, instantiationType) :void{
Ittay Sternf7926712019-07-07 19:23:03 +030072 service.isALaCarte = instantiationType === 'ALaCarte';
Ittay Stern6f900cc2018-08-29 17:01:32 +030073 };
74
75}