From e1f7974f0badbd4440d5b7ea5f1b1cb2d4973818 Mon Sep 17 00:00:00 2001 From: Einat Vinouze Date: Tue, 27 Aug 2019 16:01:01 +0300 Subject: Adding feature: Replace vfmodule Issue-ID: VID-603 Change-Id: I59068a0979d6fb733e4243c8f78921f396dc9d17 Signed-off-by: Einat Vinouze Signed-off-by: Amichai Hemli Signed-off-by: Ittay Stern --- .../shared/resolvers/viewEdit/viewEdit.resolver.ts | 52 +++++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'vid-webpack-master/src/app/shared/resolvers/viewEdit') diff --git a/vid-webpack-master/src/app/shared/resolvers/viewEdit/viewEdit.resolver.ts b/vid-webpack-master/src/app/shared/resolvers/viewEdit/viewEdit.resolver.ts index 404f390fb..d2f76e4f6 100644 --- a/vid-webpack-master/src/app/shared/resolvers/viewEdit/viewEdit.resolver.ts +++ b/vid-webpack-master/src/app/shared/resolvers/viewEdit/viewEdit.resolver.ts @@ -1,11 +1,14 @@ import {ActivatedRouteSnapshot, Resolve} from "@angular/router"; import {Injectable} from "@angular/core"; -import {Observable} from "rxjs"; +import {from, Observable} from "rxjs"; import {AaiService} from "../../services/aaiService/aai.service"; import {forkJoin} from "rxjs/observable/forkJoin"; import {AppState} from "../../store/reducers"; import {NgRedux} from "@angular-redux/store"; import {createServiceInstance} from "../../storeUtil/utils/service/service.actions"; +import {ServiceInstance} from "../../models/serviceInstance"; +import * as _ from "lodash"; +import {ModelInfo} from "../../models/modelInfo"; @Injectable() export class ViewEditResolver implements Resolve> { @@ -14,26 +17,51 @@ export class ViewEditResolver implements Resolve> { } resolve(route: ActivatedRouteSnapshot): Observable { - const serviceModeId: string = route.queryParamMap.get("serviceModelId"); + const serviceModelId: string = route.queryParamMap.get("serviceModelId"); const serviceInstanceId: string = route.queryParamMap.get("serviceInstanceId"); const subscriberId: string = route.queryParamMap.get("subscriberId"); const serviceType: string = route.queryParamMap.get("serviceType"); - let serviceModelApi = this._aaiService.getServiceModelById(serviceModeId); - let serviceInstanceApi = this._aaiService.retrieveAndStoreServiceInstanceTopology(serviceInstanceId, subscriberId, serviceType, serviceModeId); - return forkJoin([serviceModelApi, serviceInstanceApi]).map(([serviceModel, serviceInstance ]) => { - this.setIsALaCarte(serviceInstance,serviceModel.service.vidNotions.instantiationType ); - this.setTestApi(serviceInstance); - this._store.dispatch(createServiceInstance( serviceInstance, serviceModeId)); - return true; - }); + let serviceModelApi = this._aaiService.getServiceModelById(serviceModelId); + let serviceInstanceApi = this._aaiService.retrieveAndStoreServiceInstanceTopology(serviceInstanceId, subscriberId, serviceType, serviceModelId); + let streams: Observable[] = [serviceModelApi, serviceInstanceApi]; + streams = streams.filter( stream => stream !== undefined); + return forkJoin(streams).switchMap(([serviceModel, serviceInstance]) => { + return from(this.retrieveLatestVersionAndSetServiceInstance(serviceInstance.modelInfo.modelInvariantId).then((response)=>{ + this.setServiceLatestAvailableVersion(serviceInstance, response); + this.applyRequestsResponsesToStateAndInitServiceInstance(serviceModelId, serviceInstance, serviceModel); + return true; + })); + + }); + } + + private retrieveLatestVersionAndSetServiceInstance(modelInvariantId: string) :Promise{ + return this._aaiService.retrieveServiceLatestUpdateableVersion(modelInvariantId).toPromise(); + } + + applyRequestsResponsesToStateAndInitServiceInstance(serviceModelId: string, + serviceInstance, serviceModel) { + this.setIsALaCarte(serviceInstance, serviceModel.service.vidNotions.instantiationType); + this.setTestApi(serviceInstance); + this._store.dispatch(createServiceInstance(serviceInstance, serviceModelId)); } - setTestApi = (service: any) => { + setServiceLatestAvailableVersion(serviceInstance :ServiceInstance, modelInfoObject: ModelInfo) :void{ + if(!_.isNil(modelInfoObject) && !_.isNil(modelInfoObject.modelVersion)){ + serviceInstance.latestAvailableVersion = Number(modelInfoObject.modelVersion); + } + else { + serviceInstance.latestAvailableVersion = 0; + } + } + + setTestApi(service: any) :void{ if (this._store.getState().global.flags['FLAG_ADD_MSO_TESTAPI_FIELD'] && service.isALaCarte) { service.testApi = sessionStorage.getItem("msoRequestParametersTestApiValue"); } }; - setIsALaCarte = (service: any, instantiationType) => { + + setIsALaCarte(service: any, instantiationType) :void{ service.isALaCarte = instantiationType === 'ALaCarte'; }; -- cgit 1.2.3-korg