blob: 9318b3aa75162a5d2d0a3c16128ca754b8dfc37f [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {Injectable} from "@angular/core";
2import {NgRedux} from "@angular-redux/store";
3import {AppState} from "../../../shared/store/reducers";
4import {AaiService} from "../../../shared/services/aaiService/aai.service";
5import {Subject} from "rxjs";
6import {ComponentInfoModel, ComponentInfoType} from "./component-info-model";
7import {ModelInformationItem} from "../../../shared/components/model-information/model-information.component";
8import * as _ from 'lodash';
9@Injectable()
10export class ComponentInfoService {
11 static triggerComponentInfoChange: Subject<ComponentInfoModel> = new Subject<ComponentInfoModel>();
12 constructor( private _store: NgRedux<AppState>, private _aaiService : AaiService){ }
13
14 getInfoForService(serviceModelId):ComponentInfoModel {
15 if(_.isNil(this._store.getState().service.serviceHierarchy[serviceModelId])) return null;
16
17 let serviceHierarchy = this._store.getState().service.serviceHierarchy[serviceModelId].service;
18 const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId];
19 const modelInfoItems: ModelInformationItem[] = [
20 ModelInformationItem.createInstance("Subscriber Name",this._aaiService.extractSubscriberNameBySubscriberId(serviceInstance.globalSubscriberId)),
21 ModelInformationItem.createInstance("Service Type",serviceInstance.subscriptionServiceType),
22 ModelInformationItem.createInstance("Service Role",serviceHierarchy.serviceRole),
23 ];
24 serviceHierarchy.type = serviceHierarchy.serviceType;
25 return this.addGeneralInfoItems(modelInfoItems, ComponentInfoType.SERVICE, serviceHierarchy, serviceInstance );
26 }
27
28
29 addGeneralInfoItems(modelInfoSpecificItems: ModelInformationItem[], type: ComponentInfoType, model, instance) {
30 let modelInfoItems: ModelInformationItem[] = [
31 ModelInformationItem.createInstance("Type", (model && model.type) ? model.type : ((instance && instance.modelInfo) ? instance.modelInfo.modelType : null)),
32 ModelInformationItem.createInstance("Model Version", model ? model.version : null),
33 ModelInformationItem.createInstance("Model Customization ID", model ? model.customizationUuid : null),
34 ModelInformationItem.createInstance("Instance ID", instance ? instance.instanceId : null),
35 ModelInformationItem.createInstance("In Maintenance", instance? instance.inMaint : null),
36 ];
37 modelInfoItems = modelInfoItems.concat(modelInfoSpecificItems);
38 const modelInfoItemsWithoutEmpty = _.filter(modelInfoItems, function(item){ return !item.values.every(_.isNil)});
39 return new ComponentInfoModel(type, modelInfoItemsWithoutEmpty, []);
40 }
41}