Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {Injectable} from "@angular/core"; |
| 2 | import {ModelInformationItem} from "../model-information/model-information.component"; |
| 3 | import {NgRedux} from "@angular-redux/store"; |
| 4 | import {AppState} from "../../store/reducers"; |
| 5 | import {Subscriber} from "../../models/subscriber"; |
| 6 | import {ServiceInfoModel} from "../../server/serviceInfo/serviceInfo.model"; |
| 7 | import * as _ from 'lodash'; |
| 8 | |
| 9 | @Injectable() |
| 10 | export class AuditInfoModalComponentService { |
| 11 | constructor(private _store: NgRedux<AppState>){} |
| 12 | |
| 13 | getModelInfo(model, instance, serviceModelId: string): ModelInformationItem[] { |
| 14 | const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId]; |
| 15 | const modelInformation = !_.isNil(model) ? [ |
| 16 | new ModelInformationItem('Model name', 'model_name', [model.name]), |
| 17 | new ModelInformationItem('Model version', 'model_version', [model.version]), |
| 18 | new ModelInformationItem('Model customization ID', 'model_customization_ID', [model.customizationUuid]), |
| 19 | new ModelInformationItem('Base module', 'base_module', [!_.isNil(model.properties) ? model.properties.baseModule : null]) |
| 20 | ] : []; |
| 21 | |
| 22 | const instanceInfo = !_.isNil(instance) ? [ |
| 23 | new ModelInformationItem('Instance name', 'instance_name', [instance.instanceName]), |
| 24 | new ModelInformationItem('Instance ID', 'instance_ID', [instance.instanceId]) |
| 25 | ] : []; |
| 26 | |
| 27 | const serviceInfo = !_.isNil(serviceInstance) ? [ |
| 28 | new ModelInformationItem("Subscriber name", "subscriberName", [this.extractSubscriberNameBySubscriberId(serviceInstance.globalSubscriberId, this._store)]), |
| 29 | new ModelInformationItem('Service type', 'service_type', [serviceInstance.subscriptionServiceType]) |
| 30 | ] : []; |
| 31 | |
| 32 | const result = [modelInformation, instanceInfo, serviceInfo]; |
| 33 | return _.uniq(_.flatten(result)); |
| 34 | } |
| 35 | |
| 36 | static createModelInformationItemsJob(serviceModel: ServiceInfoModel): ModelInformationItem[] { |
| 37 | return [ |
| 38 | new ModelInformationItem('Subscriber name', 'subscriberName', [serviceModel.subscriberName]), |
| 39 | new ModelInformationItem('Service type', 'serviceType', [serviceModel.serviceType]), |
| 40 | new ModelInformationItem('Service model version', 'serviceModelVersion', [serviceModel.serviceModelVersion]), |
| 41 | new ModelInformationItem('Service instance name', 'serviceInstanceName', [serviceModel.serviceInstanceName || 'Automatically generated'], '', true), |
| 42 | new ModelInformationItem('Service instance ID', 'serviceInstanceId', [serviceModel.serviceInstanceId]), |
| 43 | new ModelInformationItem('Requestor User ID', 'userId', [serviceModel.userId]), |
| 44 | ]; |
| 45 | } |
| 46 | |
| 47 | static getInstanceModelName(model) : string { |
| 48 | return !_.isNil(model) && model.name ? model.name : ''; |
| 49 | } |
| 50 | |
| 51 | static setModalTitlesType(type : string) : string { |
| 52 | return !_.isNil(type) ? AuditInfoModalComponentService.getTypeMap()[type] : 'Service' ; |
| 53 | } |
| 54 | |
| 55 | static getTypeMap(){ |
| 56 | return { |
| 57 | SERVICE : 'Service', |
| 58 | VNFGROUP : 'Vnf Group', |
| 59 | NETWORK : 'Network', |
| 60 | VFMODULE : 'VfModule', |
| 61 | VNF : 'VNF' |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | static setModalTitle(type : string) : string { |
| 66 | return !_.isNil(type) ? (AuditInfoModalComponentService.getTypeMap()[type] + " Instantiation Information") : 'Service Instantiation Information'; |
| 67 | } |
| 68 | |
| 69 | extractSubscriberNameBySubscriberId(subscriberId: string, store: NgRedux<AppState>) { |
| 70 | let result: string = null; |
| 71 | let filteredArray: any = _.filter(store.getState().service.subscribers, function (o: Subscriber) { |
| 72 | return o.id === subscriberId |
| 73 | }); |
| 74 | if (filteredArray.length > 0) { |
| 75 | result = filteredArray[0].name; |
| 76 | } |
| 77 | return result; |
| 78 | } |
| 79 | } |