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";
16 import {InstantiationBase} from "../shared/models/serviceBase";
18 export let PENDING : string = "pending";
19 export let INPROGRESS : string = "in_progress";
20 export let PAUSE : string = "pause";
21 export let X_O : string = "x-circle-o";
22 export let SUCCESS_CIRCLE : string = "success-circle-o";
23 export let STOPPED : string = "stop";
24 export let COMPLETED_WITH_ERRORS : string = "success_with_warning";
25 export let UNKNOWN : string = "question-mark-circle-o";
29 export class InstantiationStatusComponentService {
30 constructor( private _aaiService: AaiService,
31 private _msoService: MsoService,
32 private _router : Router,
33 private _store: NgRedux<AppState>,
34 private _featureFlagsService:FeatureFlagsService) {
37 generateServiceInfoDataMapping(arr: ServiceInfoModel[]) : { [serviceInstanceId: string]: ServiceInfoModel[]}{
38 let serviceInfoData: { [serviceInstanceId: string]: ServiceInfoModel[]; } = {};
40 if(_.isNil(serviceInfoData[item.templateId])){
41 serviceInfoData[item.templateId] = [item];
43 serviceInfoData[item.templateId].push(item);
46 return serviceInfoData;
49 convertObjectToArray(arr: ServiceInfoModel[]) : Observable<ServiceInfoUiModel[]>{
50 const obj = this.generateServiceInfoDataMapping(arr);
53 for(let item in obj) {
54 obj[item].map(item => {
55 item['serviceStatus'] = this.getStatus(item.jobStatus);
56 item['serviceIndex'] = index;
59 result = result.concat(obj[item]);
66 isDrawingBoardViewEdit(serviceModel: ServiceModel): boolean {
67 if (!_.isNil(serviceModel.vidNotions) && !_.isNil(serviceModel.vidNotions.viewEditUI)
68 && serviceModel.vidNotions.viewEditUI !== 'legacy'){
74 open(item: ServiceInfoModel): void {
75 if (this._featureFlagsService.getFlagState(Features.FLAG_1902_VNF_GROUPING)) {
76 this._aaiService.getServiceModelById(item['serviceModelId']).subscribe((result)=>{
77 const serviceModel = new ServiceModel(result);
79 if (this.isDrawingBoardViewEdit(serviceModel)) {
80 this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT);
84 this.navigateToNewViewOnlyOrOldEditView(item);
89 /*this else is here only to save time in case we don't need to retrieve service model
90 it can be removed once it service model is always needed, and it doesn't save time*/
92 this.navigateToNewViewOnlyOrOldEditView(item);
96 navigateToNewViewOnlyOrOldEditView(item: ServiceInfoModel) {
97 if (this._featureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT)) {
98 this.navigateToNewViewEdit(item, DrawingBoardModes.VIEW);
101 this.navigateToOldViewEdit(item);
105 navigateToOldViewEdit(item: ServiceInfoModel) {
107 `subscriberId=${item.subscriberId}&` +
108 `subscriberName=${item.subscriberName}&` +
109 `serviceType=${item.serviceType}&` +
110 `serviceInstanceId=${item.serviceInstanceId}`;
112 this._store.dispatch(updateDrawingBoardStatus(DrawingBoardModes.OLD_VIEW_EDIT));
113 window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query);
116 navigateToNewViewEdit(item: InstantiationBase, mode: DrawingBoardModes): void {
117 this._store.dispatch(updateDrawingBoardStatus(mode));
118 const viewEditUrlTree:UrlTree = this.getNewViewEditUrlTree(item, mode);
119 this._router.navigateByUrl(viewEditUrlTree);
120 window.parent.location.assign(this.getViewEditUrl(viewEditUrlTree));
123 getNewViewEditUrlTree(item: InstantiationBase, mode: DrawingBoardModes): UrlTree {
124 return this._router.createUrlTree(
125 ['/servicePlanning/' + mode],
128 mode==DrawingBoardModes.RECREATE ?
129 this.getRecreateQueryParams(item) :
130 this.getDefaultViewEditQueryParams(<ServiceInfoModel> item)
134 private getDefaultViewEditQueryParams(item: ServiceInfoModel) {
136 serviceModelId: item.serviceModelId,
137 serviceInstanceId: item.serviceInstanceId,
138 serviceType: item.serviceType,
139 subscriberId: item.subscriberId,
144 private getRecreateQueryParams(item: InstantiationBase) {
146 serviceModelId: item.serviceModelId,
151 getViewEditUrl(viewEditUrlTree:UrlTree): string {
152 return '../../serviceModels.htm#' + viewEditUrlTree.toString();
155 getStatus(status : string) : ServiceStatus {
156 switch(`${status}`.toUpperCase()) {
158 return new ServiceStatus(PENDING, 'primary', 'Pending: The action required will be sent as soon as possible.');
160 return new ServiceStatus(INPROGRESS, 'primary', 'In-progress: the service is in process of the action required.');
162 return new ServiceStatus(PAUSE, 'primary', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
164 return new ServiceStatus(X_O, 'error', 'Failed: All planned actions have failed.');
166 return new ServiceStatus(SUCCESS_CIRCLE, 'success', 'Completed successfully: Service is successfully instantiated, updated or deleted.');
168 return new ServiceStatus(STOPPED, 'error', 'Stopped: Due to previous failure, will not be instantiated.');
169 case 'COMPLETED_WITH_ERRORS' :
170 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.');
173 return new ServiceStatus(UNKNOWN, 'primary', `Unexpected status: "${status}"`);
177 retry(item: ServiceInfoModel): void {
178 this.navigateToNewViewEdit(item, DrawingBoardModes.RETRY_EDIT);
181 recreate(item: ServiceInfoModel): void {
182 this.navigateToNewViewEdit(item, DrawingBoardModes.RECREATE);
185 isRecreateEnabled(item: ServiceInfoModel): boolean {
186 return item.action === ServiceAction.INSTANTIATE;
189 isRecreateVisible(): boolean {
190 return this._featureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE);
195 export class ServiceStatus {
196 iconClassName : string;
200 constructor(_iconClassName : string, _color : string, _tooltip : string){
201 this.iconClassName = _iconClassName;
203 this.tooltip = _tooltip;