1 import {Injectable} from '@angular/core';
2 import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model';
3 import * as _ from 'lodash';
4 import {Observable} from 'rxjs/Observable';
5 import {NgRedux} from "@angular-redux/store";
6 import {AppState} from "../shared/store/reducers";
7 import {AaiService} from "../shared/services/aaiService/aai.service";
8 import {ServiceModel} from "../shared/models/serviceModel";
9 import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service";
10 import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes";
11 import {updateDrawingBoardStatus} from "../shared/storeUtil/utils/global/global.actions";
12 import {Router, UrlTree} from "@angular/router";
13 import {of} from "rxjs";
14 import {MsoService} from "../shared/services/msoService/mso.service";
15 import {ServiceAction} from "../shared/models/serviceInstanceActions";
17 export let PENDING : string = "pending";
18 export let INPROGRESS : string = "in_progress";
19 export let PAUSE : string = "pause";
20 export let X_O : string = "x-circle-o";
21 export let SUCCESS_CIRCLE : string = "success-circle-o";
22 export let STOPPED : string = "stop";
23 export let COMPLETED_WITH_ERRORS : string = "success_with_warning";
24 export let UNKNOWN : string = "question-mark-circle-o";
28 export class InstantiationStatusComponentService {
29 constructor( private _aaiService: AaiService,
30 private _msoService: MsoService,
31 private _router : Router,
32 private _store: NgRedux<AppState>,
33 private _featureFlagsService:FeatureFlagsService) {
36 generateServiceInfoDataMapping(arr: ServiceInfoModel[]) : { [serviceInstanceId: string]: ServiceInfoModel[]}{
37 let serviceInfoData: { [serviceInstanceId: string]: ServiceInfoModel[]; } = {};
39 if(_.isNil(serviceInfoData[item.templateId])){
40 serviceInfoData[item.templateId] = [item];
42 serviceInfoData[item.templateId].push(item);
45 return serviceInfoData;
48 convertObjectToArray(arr: ServiceInfoModel[]) : Observable<ServiceInfoUiModel[]>{
49 const obj = this.generateServiceInfoDataMapping(arr);
52 for(let item in obj) {
53 obj[item].map(item => {
54 item['serviceStatus'] = this.getStatus(item.jobStatus);
55 item['serviceIndex'] = index;
58 result = result.concat(obj[item]);
65 isDrawingBoardViewEdit(serviceModel: ServiceModel): boolean {
66 if (!_.isNil(serviceModel.vidNotions) && !_.isNil(serviceModel.vidNotions.viewEditUI)
67 && serviceModel.vidNotions.viewEditUI !== 'legacy'){
73 open(item: ServiceInfoModel): void {
74 if (this._featureFlagsService.getFlagState(Features.FLAG_1902_VNF_GROUPING)) {
75 this._aaiService.getServiceModelById(item['serviceModelId']).subscribe((result)=>{
76 const serviceModel = new ServiceModel(result);
78 if (this.isDrawingBoardViewEdit(serviceModel)) {
79 this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT);
83 this.navigateToNewViewOnlyOrOldEditView(item);
88 /*this else is here only to save time in case we don't need to retrieve service model
89 it can be removed once it service model is always needed, and it doesn't save time*/
91 this.navigateToNewViewOnlyOrOldEditView(item);
95 navigateToNewViewOnlyOrOldEditView(item: ServiceInfoModel) {
96 if (this._featureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT)) {
97 this.navigateToNewViewEdit(item, DrawingBoardModes.VIEW);
100 this.navigateToOldViewEdit(item);
104 navigateToOldViewEdit(item: ServiceInfoModel) {
106 `subscriberId=${item.subscriberId}&` +
107 `subscriberName=${item.subscriberName}&` +
108 `serviceType=${item.serviceType}&` +
109 `serviceInstanceId=${item.serviceInstanceId}`;
111 this._store.dispatch(updateDrawingBoardStatus(DrawingBoardModes.OLD_VIEW_EDIT));
112 window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query);
115 navigateToNewViewEdit(item: ServiceInfoModel, mode: DrawingBoardModes): void{
116 this._store.dispatch(updateDrawingBoardStatus(mode));
117 const viewEditUrlTree:UrlTree = this.getNewViewEditUrlTree(item, mode);
118 this._router.navigateByUrl(viewEditUrlTree);
119 window.parent.location.assign(this.getViewEditUrl(viewEditUrlTree));
122 getNewViewEditUrlTree(item: ServiceInfoModel, mode: DrawingBoardModes): UrlTree {
123 return this._router.createUrlTree(
124 ['/servicePlanning/' + mode],
127 mode==DrawingBoardModes.RECREATE ?
128 this.getRecreateQueryParams(item) :
129 this.getDefaultViewEditQueryParams(item)
133 private getDefaultViewEditQueryParams(item: ServiceInfoModel) {
135 serviceModelId: item.serviceModelId,
136 serviceInstanceId: item.serviceInstanceId,
137 serviceType: item.serviceType,
138 subscriberId: item.subscriberId,
143 private getRecreateQueryParams(item: ServiceInfoModel) {
145 serviceModelId: item.serviceModelId,
150 getViewEditUrl(viewEditUrlTree:UrlTree): string {
151 return '../../serviceModels.htm#' + viewEditUrlTree.toString();
154 getStatus(status : string) : ServiceStatus {
155 switch(`${status}`.toUpperCase()) {
157 return new ServiceStatus(PENDING, 'primary', 'Pending: The action required will be sent as soon as possible.');
159 return new ServiceStatus(INPROGRESS, 'primary', 'In-progress: the service is in process of the action required.');
161 return new ServiceStatus(PAUSE, 'primary', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
163 return new ServiceStatus(X_O, 'error', 'Failed: All planned actions have failed.');
165 return new ServiceStatus(SUCCESS_CIRCLE, 'success', 'Completed successfully: Service is successfully instantiated, updated or deleted.');
167 return new ServiceStatus(STOPPED, 'error', 'Stopped: Due to previous failure, will not be instantiated.');
168 case 'COMPLETED_WITH_ERRORS' :
169 return new ServiceStatus(COMPLETED_WITH_ERRORS, 'success', 'Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.');
172 return new ServiceStatus(UNKNOWN, 'primary', `Unexpected status: "${status}"`);
176 retry(item: ServiceInfoModel): void {
177 this.navigateToNewViewEdit(item, DrawingBoardModes.RETRY_EDIT);
180 recreate(item: ServiceInfoModel): void {
181 this.navigateToNewViewEdit(item, DrawingBoardModes.RECREATE);
184 isRecreateEnabled(item: ServiceInfoModel): boolean {
185 return item.action === ServiceAction.INSTANTIATE;
188 isRecreateVisible(): boolean {
189 return this._featureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE);
194 export class ServiceStatus {
195 iconClassName : string;
199 constructor(_iconClassName : string, _color : string, _tooltip : string){
200 this.iconClassName = _iconClassName;
202 this.tooltip = _tooltip;