1d1bc4f6af325b18518805bbf408bfa55e1a3ad5
[appc/cdt.git] /
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
6
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 ============LICENSE_END============================================
22 */
23
24 import { Component, Input, OnInit, ViewChild } from '@angular/core';
25 import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service';
26 import { MappingEditorService } from '../../../../shared/services/mapping-editor.service';
27 import { ArtifactRequest } from '../../../../shared/models/index';
28 import { ActivatedRoute, Router } from '@angular/router';
29 import { saveAs } from 'file-saver';
30 import { NotificationService } from '../../../../shared/services/notification.service';
31 import { NotificationsService } from 'angular2-notifications';
32 import { ParamShareService } from '../../../../shared/services/paramShare.service';
33 import { DialogService } from 'ng2-bootstrap-modal';
34 import { ConfirmComponent } from '../../../../shared/confirmModal/confirm.component';
35 import { BuildDesignComponent } from '../../build-artifacts.component';
36 import { environment } from '../../../../../environments/environment';
37 import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';
38 import { NgProgress } from 'ngx-progressbar';
39 declare var $: any
40
41 @Component({ selector: 'app-golden-configuration', templateUrl: './template-configuration.component.html', styleUrls: ['./template-configuration.component.css'] })
42 export class GoldenConfigurationComponent implements OnInit {
43   @ViewChild('templateeditor') templateeditor;
44   @Input() configMappingEditorContent: string;
45   @Input() isMappingComp: boolean;
46   @ViewChild('myInput') myInputVariable: any;
47   @ViewChild('myModal') modal: ModalComponent;
48   aceText: string = ""
49   fileName: string = ""
50   showTemplateVersionDiv: any;
51   downloadedTemplateFileName: any;
52   downloadedParamFileName: any;
53   templateVersionNo: any = '0.0.1';
54   saveToGuiCacheFlag = 'false';
55   initialAction: any;
56   public referenceData: Array<Object> = [];
57   public scopeName: any;
58   public subscription: any;
59   public item: any = {};
60   public goldenActions: Array<string> = [];
61   public refNameObj = {};
62   public action = '';
63   public artifactName = '';
64   public type;
65   public showError: boolean = false;
66   public tempretrieveFlag: boolean = false;
67   public fileNameForTempSave;
68   initialData: any;
69   showDownloadDiv: boolean = false;
70   downloadType: any;
71   enableBrowse: boolean = true;
72   enableMerge: boolean = false;
73   uploadValidationSuccess: boolean = false;
74   fileExtension: any = "xml";
75   apiToken = localStorage['apiToken'];
76   public appDataObject: any;
77   public downloadDataObject: any;
78   public checkNameEntered: boolean = true;
79   public selectedWord: any = this.mappingEditorService.getSelectedWord();
80   public Actions = [
81     { action: "ConfigBackup", value: "ConfigBackup" },
82     { action: "ConfigModify", value: "ConfigModify" },
83     { action: "ConfigRestore", value: "ConfigRestore" },
84     { action: "Configure", value: "Configure" },
85     { action: "GetRunningConfig", value: "GetRunningConfig" },
86     { action: "HealthCheck", value: "HealthCheck" },
87     { action: "StartApplication", value: "StartApplication" },
88     { action: "StopApplication", value: "StopApplication" }
89   ];
90   options = {
91     timeOut: 1000,
92     showProgressBar: true,
93     pauseOnHover: true,
94     clickToClose: true,
95     maxLength: 200
96   }
97   public replaceWord;
98   public enableDownloadButtons: boolean = false;
99   constructor(private buildDesignComponent: BuildDesignComponent, private paramShareService: ParamShareService, private dialogService: DialogService, private notificationService: NotificationService, private httpUtil: HttpUtilService, private mappingEditorService: MappingEditorService, private activeRoutes: ActivatedRoute, private router: Router, private nService: NotificationsService, private ngProgress: NgProgress) {
100     this.artifactRequest.action = '';
101     this.artifactRequest.version = '';
102     this.artifactRequest.paramsContent = '{}';
103     this.artifactRequest.paramKeysContent = '';
104   }
105   public templateEditor: any;
106   public fileType: any = '';
107   public actionType: any;
108   public myfileName: any;
109   userId = localStorage['userId'];
110   public artifactRequest: ArtifactRequest = new ArtifactRequest();
111   public showUploadStatus: boolean = false;
112   public uploadStatus: boolean = false;
113   public uploadTypes = [
114     {
115       value: 'Generated Template',
116       display: 'Sample Json Param File'
117     },
118     {
119       value: 'Mapping Data',
120       display: 'Sample Json Param File'
121     }
122   ];
123   vnfType: any = '';
124   vnfcType: any = '';
125   protocol: any = '';
126   refObj: any;
127   editor: any;
128   editorContent: any;
129   tempName: any;
130   enableValidateTemplate: boolean = false;;
131   public selectedUploadType: string = this.uploadTypes[0].value;
132   identifier: any;
133   public tempRetrievalResponse:any;
134   public mergeStatus:boolean=false;
135   
136   //======================================Start of ngOnInit() Method============================================
137   ngOnInit() {
138     var refObj = this.refObj = this.prepareFileName();
139     if (refObj && refObj != undefined) {
140       this.item = refObj;
141
142       this.vnfType = this.item.scope["vnf-type"];
143       this.vnfcType = this.item.scope["vnfc-type"];
144       this.protocol = this.item['device-protocol'];
145       this.action = this.item.action;
146       this.artifactRequest.action = this.item.action;
147       this.artifactRequest.vnfType = this.vnfType;
148       if (this.vnfcType != undefined && this.vnfcType.length != 0) {
149         this.scopeName = this.vnfcType;
150       }
151       else {
152         this.scopeName = this.vnfType;
153       }
154     }
155     else {
156       this.item = { "action": "", "scope": { "vnf-type": "", "vnfc-type": "" }, "vm": [], "protocol": "", "download-dg-reference": "", "user-name": "", "port-number": "", "artifact-list": [], "deviceTemplate": "", "scopeType": "" };
157     }
158     this.initialAction = this.item.action;
159     this.activeRoutes.url.subscribe(UrlSegment => {
160       this.actionType = UrlSegment[0].path
161     })
162     this.mappingEditorService.fromScreen = 'MappingScreen';
163     this.identifier = this.mappingEditorService.identifier;
164   }
165   //========================== End of ngOnInit() Method============================================
166   ngOnDestroy() {
167     if (this.refObj && this.refObj != undefined) {
168       if (this.configMappingEditorContent && this.configMappingEditorContent != undefined) {
169         this.saveTemplate();
170         this.prepareAppData();
171         this.prepareDownloadData();
172         this.mappingEditorService.changeNavAppData(this.appDataObject);
173         this.mappingEditorService.changeNavDownloadData(this.downloadDataObject);
174       }
175     }
176   }
177   //========================== End of ngOnDestroy() Method============================================
178   ngAfterViewInit() {
179     if (this.mappingEditorService.latestAction) {
180       this.refNameObj = this.mappingEditorService.latestAction;
181       if (this.vnfcType !== 'null') {
182         this.type = this.vnfcType;
183       }
184       else {
185         this.type = this.vnfType;
186       }
187       for (let i = 0; i < this.refNameObj['artifact-list'].length; i++) {
188         let artifactList = this.refNameObj['artifact-list'];
189         if (artifactList[i]['artifact-type'] === 'config_template') {
190           this.artifactName = artifactList[i]['artifact-name'];
191         }
192       }
193     }
194     let self = this;
195     this.templateEditor = self.templateeditor.getEditor();
196     this.templateeditor.getEditor().commands.addCommand({
197       name: 'annotateCommand',
198       bindKey: { win: 'ENTER', mac: 'ENTER' },
199       exec: (editor: any) => {
200         this.handleAnnotation(this.modal);
201       }
202     });
203     if (this.mappingEditorService.fromScreen === 'MappingScreen') {
204       this.configMappingEditorContent = this.mappingEditorService.getTemplateMappingDataFromStore();
205       this.fileType = sessionStorage.getItem('fileType');
206     }
207     if (this.configMappingEditorContent) {
208       this.artifactRequest.templateContent = this.configMappingEditorContent;
209       this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal);
210     }
211     if (this.refObj) {
212       if (this.mappingEditorService.getTemplateMappingDataFromStore() && this.mappingEditorService.getTemplateMappingDataFromStore() != undefined) {
213         this.configMappingEditorContent = this.mappingEditorService.getTemplateMappingDataFromStore();
214       }
215       else {
216         if (this.artifactName) this.retrieveTemplateFromAppc();
217       }
218     }
219     else {
220       this.Actions = [];
221       this.enableBrowse = false;
222       this.nService.error("Error", "Please enter Action and VNF type in Reference Data screen");
223     }
224   }
225
226   //========================== End of ngAfterViewInit() Method============================================
227   browseOption() {
228     $("#inputFile").trigger('click');
229   }
230   //========================== End of browseOption() Method============================================
231   //save to GUI
232   public saveTemplate() {
233     this.saveToGuiCacheFlag = 'true';
234     this.mappingEditorService.paramData = [];
235     if (this.configMappingEditorContent) {
236       this.initialData = this.configMappingEditorContent;
237       this.mappingEditorService.refreshEditor();
238       let paramArr: any = []
239       if (this.mappingEditorService.paramData && this.mappingEditorService.paramData != undefined) {
240         if (this.mappingEditorService.paramData.length === 0 && this.mappingEditorService.hasErrorCode === true) {
241           this.nService.error("Error", 'Special characters error', 'Error')
242           return;
243         }
244         else {
245           this.showError = false;
246         }
247       }
248       this.showTemplateVersionDiv = true;
249
250       if (this.mappingEditorService.fromScreen === 'MappingScreen') {
251         this.mappingEditorService.setTemplateMappingDataFromStore(this.configMappingEditorContent);
252       }
253       if (this.fileType === 'text/xml') {
254         sessionStorage.setItem('fileType', 'text/xml');
255       }
256       if (this.fileType === '') {
257         sessionStorage.setItem('fileType', '');
258       }
259      }
260   }
261   //========================== End of saveTemplate() Method============================================
262   retrieveTemplateFromAppc() {
263     let refObj = this.refObj;
264     if (refObj && refObj != undefined) {
265
266       let fileName = this.artifactName;
267       let payload = '{"userID": "' + this.userId + '","action": "' + this.item.action + '", "vnf-type" : "' + this.vnfType + '", "artifact-type":"APPC-CONFIG", "artifact-name":"' + fileName + '"}';
268       let input = {
269         "input": {
270           "design-request": {
271             "request-id": this.apiToken,
272             "action": "getArtifact",
273             "payload": payload
274           }
275         }
276       };
277       let artifactContent: any;
278       this.ngProgress.start();
279       this.httpUtil.post({
280         url: environment.getDesigns,
281         data: input
282       }).subscribe(resp => {
283         if (resp.output.status.code === '400' && resp.output.status.message === "success") {
284           this.nService.success("Success", "Template retrieved successfully from APPC");
285           this.tempRetrievalResponse=resp;
286           let result = JSON.parse(resp.output.data.block).artifactInfo[0];
287           result = result['artifact-content'];
288           if ('Generated Template' === this.selectedUploadType) {
289             this.configMappingEditorContent = result
290             this.artifactRequest.templateContent = this.configMappingEditorContent;
291             this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..');
292             if (this.artifactRequest.templateContent) {
293               this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal);
294             }
295           }
296           this.tempretrieveFlag = true;
297           this.fileNameForTempSave = fileName;
298           this.enableDownloadButtons = true;
299           this.initialData = result;
300           this.saveTemplate();
301         }
302         else {
303           this.nService.info("Information", "There is no template saved in APPC for the selected action!");
304         }
305         this.ngProgress.done();
306       },
307       error => this.nService.error("Error", "Error in connecting to APPC Server"));
308       setTimeout(() => {
309         this.ngProgress.done();
310       }, 3500);
311     }
312   }
313   //========================== End of retrieveTemplateFromAppc() Method============================================
314   prepareAppData() {
315     let refObj = this.refObj;
316     if (refObj && refObj != undefined) {
317       let paramsKeyValueFromEditor: JSON;
318       try {
319         paramsKeyValueFromEditor = JSON.parse(localStorage["paramsContent"]);
320       }
321       catch (error) {
322         console.log("Could not parse name value pairs==" + error);
323       }
324       if (paramsKeyValueFromEditor) {
325         this.showTemplateVersionDiv = true;
326         let action = this.item.action;
327         var scopeName = this.scopeName.replace(/ /g, '').replace(new RegExp('/', "g"), '_').replace(/ /g, '');
328         let fileName = this.updateParamFileName(refObj.action, scopeName, this.templateVersionNo);
329         let vnfType = this.vnfType;
330         let Json = [paramsKeyValueFromEditor];
331         let slashedPayload = this.appendSlashes(JSON.stringify(Json));
332         let newPayload =
333           {
334             "userID": this.userId,
335             "vnf-type": this.vnfType,
336             "action": action,
337             "artifact-name": fileName,
338             "artifact-type": "APPC-CONFIG",
339             "artifact-version": this.templateVersionNo,
340             "artifact-contents": slashedPayload
341           }
342         let data =
343           {
344             "input": {
345               "design-request": {
346                 "request-id": this.apiToken,
347                 "action": "uploadArtifact",
348                 "payload": JSON.stringify(newPayload)
349
350               }
351             }
352           }
353          this.appDataObject.template.nameValueData = data;
354       }
355       if (this.configMappingEditorContent) {
356         let actualContent = this.configMappingEditorContent;
357         this.mappingEditorService.generateTemplate(this.templateEditor);
358         this.showTemplateVersionDiv = true;
359         let action = this.item.action;
360         let versionandFileType: any;
361         if (this.fileType === "text/xml") {
362
363           versionandFileType = this.templateVersionNo + 'V.xml'
364         } else {
365
366           versionandFileType = this.templateVersionNo + 'V.json'
367         }
368         let fileName: any;
369         if (this.tempretrieveFlag) {
370           fileName = this.fileNameForTempSave;
371         }
372         else {
373           fileName = this.artifactName;
374         }
375         let vnfType = this.vnfType;
376         let newPayload =
377           {
378             "userID": this.userId,
379             "vnf-type": this.vnfType,
380             "action": action,
381             "artifact-name": fileName,
382             "artifact-type": "APPC-CONFIG",
383             "artifact-version": this.templateVersionNo,
384             "artifact-contents": this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}')
385
386           }
387         let data =
388           {
389             "input": {
390               "design-request": {
391                 "request-id": this.apiToken,
392                 "action": "uploadArtifact",
393                 "payload": JSON.stringify(newPayload)
394
395               }
396             }
397           }
398         this.appDataObject.template.templateData = data;
399         this.mappingEditorService.initialise(this.templateeditor.getEditor(), actualContent, this.modal);
400       }
401     }
402   }
403   //========================== End of prepareAppData() Method============================================
404   prepareFileName(): any {
405     let fileNameObject: any = this.mappingEditorService.latestAction;
406     this.appDataObject = this.mappingEditorService.appDataObject;
407     this.downloadDataObject = this.mappingEditorService.downloadDataObject;
408     this.referenceData = fileNameObject;
409     return fileNameObject;
410   }
411   //========================== End of prepareFileName() Method============================================
412   onDownloadParameter() {
413     let refObj = this.refObj;
414     if (refObj) {
415       let paramsKeyValueFromEditor: JSON;
416      try {
417         paramsKeyValueFromEditor = JSON.parse(localStorage["paramsContent"]);
418       }
419       catch (error) {
420         console.log("Could not parse name value pairs==" + error);
421       }
422       let theJSON = JSON.stringify(paramsKeyValueFromEditor, null, "\t")
423       var blob = new Blob([theJSON], {
424         type: "text/json"
425       });
426       this.showTemplateVersionDiv = true;
427       let fileName: any;
428       var scopeName = this.scopeName.replace(/ /g, '').replace(new RegExp('/', "g"), '_').replace(/ /g, '');
429       fileName = this.updateParamFileName(refObj.action, scopeName, this.templateVersionNo);
430       this.downloadDataObject.template.nameValueData = theJSON;
431       this.downloadDataObject.template.nameValueFileName = fileName;
432     }
433     else {
434       this.nService.error("Error", "Please enter Action and VNF type in Reference Data screen");
435     }
436
437   }
438   //========================== End of onDownloadParameter() Method============================================
439   updateParamFileName(action: any, scopeName: any, versionNo: any) {
440     let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V.json';
441     this.downloadedParamFileName = fileName;
442     return fileName;
443   }
444   //========================== End of updateParamFileName() Method============================================
445   public onDownloadTemplate(artifact: string) {
446     let actualContent = this.configMappingEditorContent;
447     var textToSaveAsBlob: any;
448     var config_template_fileName: any
449     let refObj = this.refObj;
450     let versionandFileType: string;
451    if (artifact == 'Template' && this.artifactRequest && this.configMappingEditorContent && refObj) {
452       this.showTemplateVersionDiv = true;
453       if (this.fileType === "text/xml") {
454         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
455           type: "text/xml"
456         });
457         versionandFileType = this.templateVersionNo + 'V.xml'
458       }
459       if (this.fileType === "text/plain") {
460         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
461           type: "text/plain"
462         });
463         versionandFileType = this.templateVersionNo + 'V.txt'
464       }
465       if (this.fileType === "text/json") {
466         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
467           type: "text/json"
468         });
469         versionandFileType = this.templateVersionNo + 'V.json'
470       }
471       if (this.tempretrieveFlag) {
472         config_template_fileName = this.fileNameForTempSave;
473         var filextension = config_template_fileName.substring(config_template_fileName.indexOf("V") + 2, config_template_fileName.length);
474
475         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
476           type: "text/" + filextension
477         });
478       }
479       else {
480         config_template_fileName = this.artifactName;
481       }
482       this.mappingEditorService.initialise(this.templateeditor.getEditor(), actualContent, this.modal);
483       this.downloadDataObject.template.templateData = this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}');
484       this.downloadDataObject.template.templateFileName = config_template_fileName;
485     }
486
487   }
488   //========================== End of onDownloadTemplate() Method============================================
489   fileChange(input) {
490
491     let self = this;
492     let refObj = this.refObj;
493     this.enableValidateTemplate = true;
494
495     if (refObj && refObj != undefined) {
496       if (input.files && input.files[0]) {
497         this.myfileName = input.files[0].name;
498         this.fileName = input.files[0].name;
499         this.fileType = input.files[0].type;
500         let reader = new FileReader();
501         this.readFile(input.files[0], reader, (result) => {
502           if (this.fileType === 'text/xml') {
503             sessionStorage.setItem('fileType', 'text/xml');
504           }
505           if (this.fileName.endsWith(".json")) {
506             this.fileType = "text/json";
507             sessionStorage.setItem('fileType', 'text/json');
508           }
509           if (this.fileType === '') {
510             sessionStorage.setItem('fileType', '');
511           }
512
513
514           if ('Generated Template' === this.selectedUploadType) {
515             this.configMappingEditorContent = result
516             this.artifactRequest.templateContent = this.configMappingEditorContent;
517             this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..');
518             if (this.artifactRequest.templateContent) {
519               this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal);
520             }
521           }
522           this.enableDownloadButtons = true;
523           this.initialData = result;
524           this.saveTemplate();
525
526         });
527         }
528       else {
529         this.nService.error("Error", "Failed to read file");
530       }
531       this.myInputVariable.nativeElement.value = "";
532     }
533     else {
534       this.nService.error("Error", "Please enter Action and VNF type in Reference Data screen");
535       return false;
536     }
537   }
538   //========================== End of fileChange() Method============================================
539   public readFile(file, reader, callback) {
540     // Set a callback funtion to fire after the file is fully loaded
541     reader.onload = () => {
542       // callback with the results
543       callback(reader.result);
544     }
545     this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
546     // Read the file
547     reader.readAsText(file, "UTF-8");
548   }
549   //========================== End of readFile() Method============================================
550   validateUploadedFile(fileExtension) {
551
552     if (fileExtension.toUpperCase() === 'json'.toUpperCase() || fileExtension.toUpperCase() === 'xml'.toUpperCase()) {
553       return true;
554     }
555     else {
556       return false;
557     }
558
559   }
560   //========================== End of validateUploadedFile() Method============================================
561   appendSlashes(artifactData) {
562     let x = artifactData.replace(new RegExp(',"', "g"), ',\"');
563     let y = x.replace(new RegExp('":', 'g'), '\":');
564     let z = y.replace(new RegExp('{"', 'g'), '{\"')
565     let t = z.replace(new RegExp(':"', 'g'), ':\"')
566     let m = t.replace(new RegExp('",', 'g'), '\",');
567     let n = y.replace(new RegExp('"}', 'g'), '\"}')
568     let nw = n.replace(new RegExp('{"', 'g'), '{\"');
569     let nw1 = nw.replace(new RegExp(':"', 'g'), ':\"');
570     let nw2 = nw1.replace(new RegExp('",', 'g'), '\",');
571     return nw2;
572   }
573   //========================== End of appendSlashes() Method============================================
574   prepareDownloadData() {
575     this.onDownloadParameter();
576     this.onDownloadTemplate('Template');
577   }
578   //========================== End of prepareDownloadData() Method============================================
579   syncTemplate() {
580     this.mappingEditorService.replaceNamesWithBlankValues();
581     this.saveTemplate();
582
583     var templateData = this.mappingEditorService.paramData; //template data array
584     var pdData = this.paramShareService.getSessionParamData(); //PD data array
585     var paramsContent = localStorage["paramsContent"];
586     
587     if (paramsContent && paramsContent != undefined) {
588       try {
589         var paramTabData = JSON.parse(paramsContent);
590        }
591       catch (error) {
592         console.log("error is : " + error)
593       }
594     }
595     var resultArr = [];
596     var json = {};
597     var resultParamObj = {};
598     let checkNamesOnlyCondition: boolean = true;
599
600     if (templateData && templateData != undefined) {
601       templateData.forEach(function (item) {
602         if (item.paramValue !== "" && item.paramValue != undefined && item.paramValue != null) {
603           checkNamesOnlyCondition = false;
604         }
605
606       });
607
608       templateData.forEach(function (item) {
609         resultParamObj[item.paramName] = item.paramValue;
610       });
611       if (paramTabData && paramTabData != undefined) {
612         templateData.forEach(function (item) {
613           for (var index in paramTabData) {
614             if (item.paramName === index) {
615               if (checkNamesOnlyCondition) {
616                 resultParamObj[index] = paramTabData[index];
617               }
618               else {
619                 if (item.paramValue === "") {
620                   resultParamObj[index] = paramTabData[index];
621                 }
622                 else {
623                   resultParamObj[index] = item.paramValue;
624                 }
625               }
626             }
627
628           }
629
630         });
631
632       }
633       localStorage["paramsContent"] = JSON.stringify(resultParamObj);
634       templateData = Array.from(new Set(templateData.map((itemInArray) => itemInArray.paramName)))
635
636       //reformatting arr1 to match with PD
637       templateData.forEach(function (item) {
638
639         resultArr.push({
640           "name": item,
641           "type": null,
642           "description": null,
643           "required": null,
644           "default": null,
645           "source": "Manual",
646           "rule-type": null,
647           "request-keys": [{
648             "key-name": null,
649             "key-value": null
650           }, {
651             "key-name": null,
652             "key-value": null
653           }, {
654             "key-name": null,
655             "key-value": null
656           }],
657           "response-keys": [{
658             "key-name": null,
659             "key-value": null
660           }, {
661             "key-name": null,
662             "key-value": null
663           }, {
664             "key-name": null,
665             "key-value": null
666           }, {
667             "key-name": null,
668             "key-value": null
669           }, {
670             "key-name": null,
671             "key-value": null
672           }],
673           "ruleTypeValues": [null]
674
675         })
676       });
677     }
678     if (pdData && pdData != undefined) {
679       for (var i = 0; i < resultArr.length; i++) {
680
681         pdData.forEach(function (arr2item) {
682           if (resultArr[i].name === arr2item.name) {
683
684             var json = {
685               "name": arr2item.name,
686               "type": arr2item.type,
687               "description": arr2item.description,
688               "required": arr2item.required,
689               "default": arr2item.default,
690               "source": arr2item.source,
691               "rule-type": arr2item["rule-type"],
692               "request-keys": arr2item["request-keys"],
693               "response-keys": arr2item["response-keys"],
694               "ruleTypeValues": arr2item.ruleTypeValues
695             };
696             resultArr.splice(i, 1, json)
697             }
698
699         });
700
701       };
702
703     }
704     this.paramShareService.setSessionParamData(resultArr);
705     this.mappingEditorService.paramData = [];
706     //navigate to PD page after sync
707     this
708       .router
709       .navigate(['../../../vnfs/design/parameterDefinitions/create']);
710   }
711
712   //========================== End of syncTemplate() Method============================================
713   mergeParams() {
714     this.mergeStatus = this.mappingEditorService.autoAnnotateDataForParams();
715     if (this.mergeStatus) {
716       this.nService.success("Success", "Merge Successful");
717     }
718     else {
719       this.nService.error("Error", "Merge Unsuccessful");
720     }
721     this.saveTemplate();
722   }
723   //========================== End of mergeParams() Method============================================  
724   public handleAnnotation(modal) {
725
726     this.selectedWord = this.templateeditor.getEditor().session.getTextRange(this.templateeditor.getEditor().selectionRange);
727     modal.open();
728   }
729   //========================== End of handleAnnotations() Method============================================ 
730   public submitNameValues() {
731     if (this.tempName) {
732       this.checkNameEntered = true;
733
734       if (this.selectedWord) {
735         if (this.selectedWord.startsWith('${(')) {
736           var replaceWord: any =this.replaceWord = this.selectedWord.substring(3, this.selectedWord.indexOf(')=(')) + this.tempName;
737           this.templateeditor.getEditor().session.replace(this.templateeditor.getEditor().session.selection.getRange(), replaceWord);
738           
739         } else {
740           let mappingKey = this.mappingEditorService.getKeysForValues(this.selectedWord);
741           var replaceWord: any = this.replaceWord='${(' + this.selectedWord + ')=(' + this.tempName + ')}';
742           this.templateeditor.getEditor().session.replace(this.templateeditor.getEditor().session.selection.getRange(), replaceWord);
743           
744         }
745       }
746       this.mappingEditorService.refreshEditor();
747       this.tempName = '';
748       this.modal.close();
749
750     }
751     else {
752       this.checkNameEntered = false;
753     }
754
755   }
756   //========================== End of submitNameValues() Method============================================
757 }