2 ============LICENSE_START==========================================
 
   3 ===================================================================
 
   4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
 
   5 ===================================================================
 
   6 Copyright (C) 2018 IBM.
 
   7 ===================================================================
 
   9 Unless otherwise specified, all software contained herein is licensed
 
  10 under the Apache License, Version 2.0 (the License);
 
  11 you may not use this software except in compliance with the License.
 
  12 You may obtain a copy of the License at
 
  14     http://www.apache.org/licenses/LICENSE-2.0
 
  16 Unless required by applicable law or agreed to in writing, software
 
  17 distributed under the License is distributed on an "AS IS" BASIS,
 
  18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  19 See the License for the specific language governing permissions and
 
  20 limitations under the License.
 
  22 ============LICENSE_END============================================
 
  25 import { Component, Input, OnInit, ViewChild } from '@angular/core';
 
  26 import { Subscription } from 'rxjs/Subscription';
 
  27 import { HttpUtilService } from '../../../../shared/services/httpUtil/http-util.service';
 
  28 import { MappingEditorService } from '../../../../shared/services/mapping-editor.service';
 
  29 import { ArtifactRequest } from '../../../../shared/models/index';
 
  30 import { ActivatedRoute, Router } from '@angular/router';
 
  31 import { saveAs } from 'file-saver';
 
  32 import { NotificationService } from '../../../../shared/services/notification.service';
 
  33 import { NotificationsService } from 'angular2-notifications';
 
  34 import { ParamShareService } from '../../../../shared/services/paramShare.service';
 
  35 import { DialogService } from 'ng2-bootstrap-modal';
 
  36 import { ConfirmComponent } from '../../../../shared/confirmModal/confirm.component';
 
  37 import { BuildDesignComponent } from '../../build-artifacts.component';
 
  38 import { environment } from '../../../../../environments/environment';
 
  39 import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';
 
  40 import { NgProgress } from 'ngx-progressbar';
 
  41 import { NgxSpinnerService } from 'ngx-spinner';
 
  42 import { UtilityService } from '../../../../shared/services/utilityService/utility.service';
 
  44 const PARAM_DATA:string="param_data";
 
  45 const TEMPLATE_DATA:string="template_data";
 
  46 @Component({ selector: 'app-golden-configuration', templateUrl: './template-configuration.component.html', styleUrls: ['./template-configuration.component.css'] })
 
  47 export class GoldenConfigurationComponent implements OnInit {
 
  48   clName= "TemplateConfigCompon";
 
  49   @ViewChild('templateeditor') templateeditor;
 
  50   @Input() configMappingEditorContent: string;
 
  51   @Input() isMappingComp: boolean;
 
  52   @ViewChild('myInput') myInputVariable: any;
 
  53   @ViewChild('myModal') modal: ModalComponent;
 
  56   showTemplateVersionDiv: any;
 
  57   downloadedTemplateFileName: any;
 
  58   downloadedParamFileName: any;
 
  59   templateVersionNo: any = '0.0.1';
 
  60   saveToGuiCacheFlag = 'false';
 
  62   public referenceData: Array<Object> = [];
 
  63   public scopeName: any;
 
  64   public subscription: Subscription;
 
  65   public templateSubscription : Subscription;
 
  66   public item: any = {};
 
  67   public goldenActions: Array<string> = [];
 
  68   public refNameObj = {};
 
  70   public artifactName = '';
 
  72   public showError: boolean = false;
 
  73   public tempretrieveFlag: boolean = false;
 
  74   public fileNameForTempSave;
 
  76   showDownloadDiv: boolean = false;
 
  78   enableBrowse: boolean = true;
 
  79   enableMerge: boolean = false;
 
  80   uploadValidationSuccess: boolean = false;
 
  81   fileExtension: any = "xml";
 
  82   apiToken = localStorage['apiToken'];
 
  83   public appDataObject: any;
 
  84   public downloadDataObject: any;
 
  85   public checkNameEntered: boolean = true;
 
  86   public selectedWord: any = this.mappingEditorService.getSelectedWord();
 
  88     { action: "ConfigBackup", value: "ConfigBackup" },
 
  89     { action: "ConfigModify", value: "ConfigModify" },
 
  90     { action: "ConfigRestore", value: "ConfigRestore" },
 
  91     { action: "Configure", value: "Configure" },
 
  92     { action: "GetRunningConfig", value: "GetRunningConfig" },
 
  93     { action: "HealthCheck", value: "HealthCheck" },
 
  94     { action: "StartApplication", value: "StartApplication" },
 
  95     { action: "StopApplication", value: "StopApplication" },
 
  96     { action: "DistributeTraffic", value: "DistributeTraffic" }
 
 100     showProgressBar: true,
 
 106   public enableDownloadButtons: boolean = false;
 
 109     private buildDesignComponent: BuildDesignComponent, 
 
 110     private paramShareService: ParamShareService, 
 
 111     private dialogService: DialogService, 
 
 112     private notificationService: NotificationService, 
 
 113     private httpUtil: HttpUtilService, 
 
 114     private mappingEditorService: MappingEditorService, 
 
 115     private activeRoutes: ActivatedRoute, 
 
 116     private router: Router, 
 
 117     private nService: NotificationsService, 
 
 118     private ngProgress: NgProgress,
 
 119     private spinner: NgxSpinnerService,
 
 120     private utilityService: UtilityService) {
 
 121     this.artifactRequest.action = '';
 
 122     this.artifactRequest.version = '';
 
 123     this.artifactRequest.paramsContent = '{}';
 
 124     this.artifactRequest.paramKeysContent = '';
 
 126   public templateEditor: any;
 
 127   public fileType: any = '';
 
 128   public actionType: any;
 
 129   public myfileName: any;
 
 130   userId = localStorage['userId'];
 
 131   public artifactRequest: ArtifactRequest = new ArtifactRequest();
 
 132   public showUploadStatus: boolean = false;
 
 133   public uploadStatus: boolean = false;
 
 134   public uploadTypes = [
 
 136       value: 'Generated Template',
 
 137       display: 'Sample Json Param File'
 
 140       value: 'Mapping Data',
 
 141       display: 'Sample Json Param File'
 
 151   enableValidateTemplate: boolean = false;;
 
 152   public selectedUploadType: string = this.uploadTypes[0].value;
 
 154   public tempRetrievalResponse: any;
 
 155   public mergeStatus: boolean = false;
 
 157   //======================================Start of ngOnInit() Method============================================
 
 159     var methName= "ngOnInit";
 
 160     if( this.utilityService.getTracelvl() > 0 )
 
 161       console.log( this.clName+": "+methName+": start.");
 
 162     var refObj = this.refObj = this.prepareFileName();
 
 163     if( this.utilityService.getTracelvl() > 0 )
 
 164       console.log( this.clName+": "+methName+
 
 165         ": refObj:["+JSON.stringify(refObj)+"]");
 
 166     if (refObj && refObj != undefined) {
 
 169       this.vnfType = this.item.scope["vnf-type"];
 
 170       this.vnfcType = this.item.scope["vnfc-type"];
 
 171       this.protocol = this.item['device-protocol'];
 
 172       this.action = this.item.action;
 
 173       if( this.utilityService.getTracelvl() > 0 )
 
 174         console.log( this.clName+": "+methName+": vnfType:["+this.vnfType+
 
 175           "] vnfcType:["+this.vnfcType+"] protocol:["+this.protocol+"] action:["+
 
 177       this.artifactRequest.action = this.item.action;
 
 178       this.artifactRequest.vnfType = this.vnfType;
 
 179       if (this.vnfcType != undefined && this.vnfcType.length != 0) {
 
 180         this.scopeName = this.vnfcType;
 
 183         this.scopeName = this.vnfType;
 
 187       this.item = { "action": "", "scope": { "vnf-type": "", "vnfc-type": "" }, "vm": [], "protocol": "", "download-dg-reference": "", "user-name": "", "port-number": "", "artifact-list": [], "deviceTemplate": "", "scopeType": "" };
 
 189     this.initialAction = this.item.action;
 
 190     this.subscription = this.activeRoutes.url.subscribe(UrlSegment => {
 
 191       this.actionType = UrlSegment[0].path
 
 193     this.mappingEditorService.fromScreen = 'MappingScreen';
 
 194     this.identifier = this.mappingEditorService.identifier;
 
 196   //========================== End of ngOnInit() Method============================================
 
 198     if (this.refObj && this.refObj != undefined) {
 
 199       if (this.configMappingEditorContent && this.configMappingEditorContent != undefined) {
 
 201         this.prepareAppData();
 
 202         this.prepareDownloadData();
 
 203         this.mappingEditorService.changeNavAppData(this.appDataObject);
 
 204         this.mappingEditorService.changeNavDownloadData(this.downloadDataObject);
 
 208     if(this.subscription) { this.subscription.unsubscribe(); }
 
 209     if(this.templateSubscription) { this.templateSubscription.unsubscribe(); }
 
 211   //========================== End of ngOnDestroy() Method============================================
 
 213     if (this.mappingEditorService.latestAction) {
 
 214       this.refNameObj = this.mappingEditorService.latestAction;
 
 215       if (this.vnfcType !== 'null') {
 
 216         this.type = this.vnfcType;
 
 219         this.type = this.vnfType;
 
 221       for (let i = 0; i < this.refNameObj['artifact-list'].length; i++) {
 
 222         let artifactList = this.refNameObj['artifact-list'];
 
 223         if (artifactList[i]['artifact-type'] === 'config_template') {
 
 224           var artifactName = artifactList[i]['artifact-name'];
 
 225           var artifactNameWithoutExtension = '';
 
 227             artifactNameWithoutExtension = artifactName.substring(0, artifactName.lastIndexOf("."));
 
 229           if(this.mappingEditorService.identifier) {
 
 230             if(artifactNameWithoutExtension.endsWith(this.mappingEditorService.identifier)) {
 
 231                 this.artifactName = artifactName;
 
 235             this.artifactName = artifactName;
 
 242     this.templateEditor = self.templateeditor.getEditor();
 
 243     this.templateeditor.getEditor().commands.addCommand({
 
 244       name: 'annotateCommandAlternate',
 
 245       bindKey: { win: 'CTRL-4', mac: 'Command-4' },
 
 246       exec: (editor: any) => {
 
 247         this.handleAnnotation(this.modal);
 
 250     this.templateeditor.getEditor().$enableBlockSelect = false;
 
 251     this.templateeditor.getEditor().$enableMultiselect = false;
 
 252     if (this.mappingEditorService.fromScreen === 'MappingScreen') {
 
 253       this.configMappingEditorContent = this.mappingEditorService.getTemplateMappingDataFromStore();
 
 254       this.fileType = sessionStorage.getItem('fileType');
 
 256     if (this.configMappingEditorContent) {
 
 257       this.artifactRequest.templateContent = this.configMappingEditorContent;
 
 258       this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal);
 
 261       if (this.mappingEditorService.getTemplateMappingDataFromStore() && this.mappingEditorService.getTemplateMappingDataFromStore() != undefined) {
 
 262         this.configMappingEditorContent = this.mappingEditorService.getTemplateMappingDataFromStore();
 
 265         if (this.artifactName) this.retrieveTemplateFromAppc();
 
 270       this.enableBrowse = false;
 
 271       this.nService.error("Error", "Please enter Action and VNF type in Reference Data screen");
 
 275   //========================== End of ngAfterViewInit() Method============================================
 
 277     $("#inputFile").trigger('click');
 
 279   //========================== End of browseOption() Method============================================
 
 281   public saveTemplate() {
 
 282     this.saveToGuiCacheFlag = 'true';
 
 283     this.mappingEditorService.paramData = [];
 
 284     if (this.configMappingEditorContent) {
 
 285       this.initialData = this.configMappingEditorContent;
 
 286       this.mappingEditorService.refreshEditor();
 
 287       let paramArr: any = []
 
 288       if (this.mappingEditorService.paramData && this.mappingEditorService.paramData != undefined) {
 
 289         if (this.mappingEditorService.paramData.length === 0 && this.mappingEditorService.hasErrorCode === true) {
 
 290           this.nService.error("Error", 'Special characters error', 'Error')
 
 294           this.showError = false;
 
 297       this.showTemplateVersionDiv = true;
 
 299       if (this.mappingEditorService.fromScreen === 'MappingScreen') {
 
 300         this.mappingEditorService.setTemplateMappingDataFromStore(this.configMappingEditorContent);
 
 302       if (this.fileType === 'text/xml') {
 
 303         sessionStorage.setItem('fileType', 'text/xml');
 
 305       if (this.fileType === '') {
 
 306         sessionStorage.setItem('fileType', '');
 
 310   //========================== End of saveTemplate() Method============================================
 
 311   retrieveTemplateFromAppc() {
 
 312     let refObj = this.refObj;
 
 313     if (refObj && refObj != undefined) {
 
 315       let fileName = this.artifactName;
 
 316       let input = this.utilityService.createPayloadForRetrieve(false, this.item.action, this.vnfType, fileName);
 
 317       let artifactContent: any;
 
 318       this.ngProgress.start();
 
 319       this.templateSubscription = this.httpUtil.post({
 
 320         url: environment.getDesigns,
 
 322       }).subscribe(resp => {
 
 323         if (resp.output.status.code === '400' && resp.output.status.message === "success") {
 
 324           this.nService.success("Success", "Template retrieved successfully from APPC");
 
 325           this.tempRetrievalResponse = resp;
 
 326           let result = JSON.parse(resp.output.data.block).artifactInfo[0];
 
 327           result = result['artifact-content'];
 
 328           if ('Generated Template' === this.selectedUploadType) {
 
 329             this.configMappingEditorContent = result
 
 330             this.artifactRequest.templateContent = this.configMappingEditorContent;
 
 331             this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..');
 
 332             if (this.artifactRequest.templateContent) {
 
 333               this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal);
 
 336           this.tempretrieveFlag = true;
 
 337           this.fileNameForTempSave = fileName;
 
 338           this.enableDownloadButtons = true;
 
 339           this.initialData = result;
 
 343           this.nService.info("Information", "There is no template saved in APPC for the selected action!");
 
 345         this.ngProgress.done();
 
 347         error => this.nService.error("Error", "Error in connecting to APPC Server"));
 
 349         this.ngProgress.done();
 
 353   //========================== End of retrieveTemplateFromAppc() Method============================================
 
 355     let refObj = this.refObj;
 
 356     if (refObj && refObj != undefined) {
 
 357       let paramsKeyValueFromEditor: JSON;
 
 359         paramsKeyValueFromEditor = JSON.parse(localStorage["paramsContent"]);
 
 362         console.log("Could not parse name value pairs==" + error);
 
 364       if (paramsKeyValueFromEditor) {
 
 365         this.showTemplateVersionDiv = true;
 
 366         let action = this.item.action;
 
 367         var scopeName = this.scopeName.replace(/ /g, '').replace(new RegExp('/', "g"), '_').replace(/ /g, '');
 
 369         let id = this.mappingEditorService.identifier;
 
 370         if (id) fileName = this.updateFileNameForConfigScaleOut(this.item.action, scopeName, this.templateVersionNo, id);
 
 371         else fileName = this.updateParamFileName(this.item.action, scopeName, this.templateVersionNo);
 
 373         let vnfType = this.vnfType;
 
 374         let Json = [paramsKeyValueFromEditor];
 
 375         let slashedPayload = this.appendSlashes(JSON.stringify(Json));
 
 376         let data = this.utilityService.createPayLoadForSave(PARAM_DATA, this.vnfType, action, fileName, this.templateVersionNo, slashedPayload);
 
 377         this.appDataObject.template.nameValueData = data;
 
 379       if (this.configMappingEditorContent) {
 
 380         let actualContent = this.configMappingEditorContent;
 
 381         this.mappingEditorService.generateTemplate(this.templateEditor);
 
 382         this.showTemplateVersionDiv = true;
 
 383         let action = this.item.action;
 
 384         let versionandFileType: any;
 
 385         if (this.fileType === "text/xml") {
 
 387           versionandFileType = this.templateVersionNo + 'V.xml'
 
 390           versionandFileType = this.templateVersionNo + 'V.json'
 
 393         if (this.tempretrieveFlag) {
 
 394           fileName = this.fileNameForTempSave;
 
 397           fileName = this.artifactName;
 
 399         let vnfType = this.vnfType;
 
 400         let data = this.utilityService.createPayLoadForSave(TEMPLATE_DATA, this.vnfType, action, fileName, this.templateVersionNo, this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}'));
 
 401         this.appDataObject.template.templateData = data;
 
 402         this.mappingEditorService.initialise(this.templateeditor.getEditor(), actualContent, this.modal);
 
 406   //========================== End of prepareAppData() Method============================================
 
 407   prepareFileName(): any {
 
 408     let fileNameObject: any = this.mappingEditorService.latestAction;
 
 409     this.appDataObject = this.mappingEditorService.appDataObject;
 
 410     this.downloadDataObject = this.mappingEditorService.downloadDataObject;
 
 411     this.referenceData = fileNameObject;
 
 412     return fileNameObject;
 
 414   //========================== End of prepareFileName() Method============================================
 
 415   onDownloadParameter() {
 
 416     let refObj = this.refObj;
 
 418       let paramsKeyValueFromEditor: JSON;
 
 420         paramsKeyValueFromEditor = JSON.parse(localStorage["paramsContent"]);
 
 423         console.log("Could not parse name value pairs==" + error);
 
 425       let theJSON = JSON.stringify(paramsKeyValueFromEditor, null, "\t")
 
 426       var blob = new Blob([theJSON], {
 
 429       this.showTemplateVersionDiv = true;
 
 431       var scopeName = this.scopeName.replace(/ /g, '').replace(new RegExp('/', "g"), '_').replace(/ /g, '');
 
 432       let id = this.mappingEditorService.identifier;
 
 433       if (id) fileName = this.updateFileNameForConfigScaleOut(this.item.action, scopeName, this.templateVersionNo, id);
 
 434       else fileName = this.updateParamFileName(this.item.action, scopeName, this.templateVersionNo);
 
 436       this.downloadDataObject.template.nameValueData = theJSON;
 
 437       this.downloadDataObject.template.nameValueFileName = fileName;
 
 440       this.nService.error("Error", "Please enter Action and VNF type in Reference Data screen");
 
 444   //========================== End of onDownloadParameter() Method============================================
 
 445   updateParamFileName(action: any, scopeName: any, versionNo: any) {
 
 446     let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V.json';
 
 447     this.downloadedParamFileName = fileName;
 
 450   //========================== End of updateParamFileName() Method============================================
 
 451   updateFileNameForConfigScaleOut(action: any, scopeName: any, versionNo: any, id: any) {
 
 452     let fileName = 'param_' + action + '_' + scopeName + '_' + versionNo + 'V_' + id + '.json';
 
 453     this.downloadedParamFileName = fileName;
 
 456   //========================== End of updateFileNameForConfigScaleOut() Method============================================
 
 457   public onDownloadTemplate(artifact: string) {
 
 458     let actualContent = this.configMappingEditorContent;
 
 459     var textToSaveAsBlob: any;
 
 460     var config_template_fileName: any
 
 461     let refObj = this.refObj;
 
 462     let versionandFileType: string;
 
 463     if (artifact == 'Template' && this.artifactRequest && this.configMappingEditorContent && refObj) {
 
 464       this.showTemplateVersionDiv = true;
 
 465       if (this.fileType === "text/xml") {
 
 466         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
 
 469         versionandFileType = this.templateVersionNo + 'V.xml'
 
 471       if (this.fileType === "text/plain") {
 
 472         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
 
 475         versionandFileType = this.templateVersionNo + 'V.txt'
 
 477       if (this.fileType === "text/json") {
 
 478         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
 
 481         versionandFileType = this.templateVersionNo + 'V.json'
 
 483       if (this.tempretrieveFlag) {
 
 484         config_template_fileName = this.fileNameForTempSave;
 
 485         var filextension = config_template_fileName.substring(config_template_fileName.indexOf("V") + 2, config_template_fileName.length);
 
 487         textToSaveAsBlob = new Blob([this.configMappingEditorContent], {
 
 488           type: "text/" + filextension
 
 492         config_template_fileName = this.artifactName;
 
 494       this.mappingEditorService.initialise(this.templateeditor.getEditor(), actualContent, this.modal);
 
 495       this.downloadDataObject.template.templateData = this.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}');
 
 496       this.downloadDataObject.template.templateFileName = config_template_fileName;
 
 500   //========================== End of onDownloadTemplate() Method============================================
 
 504     let refObj = this.refObj;
 
 505     this.enableValidateTemplate = true;
 
 507     if (refObj && refObj != undefined) {
 
 508       if (input.files && input.files[0]) {
 
 510         this.myfileName = input.files[0].name;
 
 511         this.fileName = input.files[0].name;
 
 512         this.fileType = input.files[0].type;
 
 513         let reader = new FileReader();
 
 514         this.readFile(input.files[0], reader, (result) => {
 
 515           if (this.fileType === 'text/xml') {
 
 516             sessionStorage.setItem('fileType', 'text/xml');
 
 518           if (this.fileName.endsWith(".json")) {
 
 519             this.fileType = "text/json";
 
 520             sessionStorage.setItem('fileType', 'text/json');
 
 522           if (this.fileType === '') {
 
 523             sessionStorage.setItem('fileType', '');
 
 527           if ('Generated Template' === this.selectedUploadType) {
 
 528             this.configMappingEditorContent = result
 
 529             this.artifactRequest.templateContent = this.configMappingEditorContent;
 
 530             this.notificationService.notifySuccessMessage('Configuration Template file successfully uploaded..');
 
 531             if (this.artifactRequest.templateContent) {
 
 532               this.mappingEditorService.initialise(this.templateeditor.getEditor(), this.artifactRequest.templateContent, this.modal);
 
 535           this.enableDownloadButtons = true;
 
 536           this.initialData = result;
 
 538           this.templateeditor.getEditor().$enableBlockSelect = false;
 
 539           this.templateeditor.getEditor().$enableMultiselect = false;
 
 541                         /** spinner ends after 3.5 seconds */
 
 547         this.nService.error("Error", "Failed to read file");
 
 549       this.myInputVariable.nativeElement.value = "";
 
 552       this.nService.error("Error", "Please enter Action and VNF type in Reference Data screen");
 
 556   //========================== End of fileChange() Method============================================
 
 557   public readFile(file, reader, callback) {
 
 558     // Set a callback funtion to fire after the file is fully loaded
 
 559     reader.onload = () => {
 
 560       // callback with the results
 
 561       callback(reader.result);
 
 563     this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
 
 565     reader.readAsText(file, "UTF-8");
 
 567   //========================== End of readFile() Method============================================
 
 568   validateUploadedFile(fileExtension) {
 
 570     if (fileExtension.toUpperCase() === 'json'.toUpperCase() || fileExtension.toUpperCase() === 'xml'.toUpperCase()) {
 
 578   //========================== End of validateUploadedFile() Method============================================
 
 579   appendSlashes(artifactData) {
 
 580     let x = artifactData.replace(new RegExp(',"', "g"), ',\"');
 
 581     let y = x.replace(new RegExp('":', 'g'), '\":');
 
 582     let z = y.replace(new RegExp('{"', 'g'), '{\"')
 
 583     let t = z.replace(new RegExp(':"', 'g'), ':\"')
 
 584     let m = t.replace(new RegExp('",', 'g'), '\",');
 
 585     let n = y.replace(new RegExp('"}', 'g'), '\"}')
 
 586     let nw = n.replace(new RegExp('{"', 'g'), '{\"');
 
 587     let nw1 = nw.replace(new RegExp(':"', 'g'), ':\"');
 
 588     let nw2 = nw1.replace(new RegExp('",', 'g'), '\",');
 
 591   //========================== End of appendSlashes() Method============================================
 
 592   prepareDownloadData() {
 
 593     this.onDownloadParameter();
 
 594     this.onDownloadTemplate('Template');
 
 596   //========================== End of prepareDownloadData() Method============================================
 
 598     this.mappingEditorService.replaceNamesWithBlankValues();
 
 601     var templateData = this.mappingEditorService.paramData; //template data array
 
 602     var pdData = this.paramShareService.getSessionParamData(); //PD data array
 
 603     var paramsContent = localStorage["paramsContent"];
 
 605     if (paramsContent && paramsContent != undefined) {
 
 607         var paramTabData = JSON.parse(paramsContent);
 
 610         console.log("error is : " + error)
 
 615     var resultParamObj = {};
 
 616     let checkNamesOnlyCondition: boolean = true;
 
 618     if (templateData && templateData != undefined) {
 
 619       templateData.forEach(function (item) {
 
 620         if (item.paramValue !== "" && item.paramValue != undefined && item.paramValue != null) {
 
 621           checkNamesOnlyCondition = false;
 
 626       templateData.forEach(function (item) {
 
 627         resultParamObj[item.paramName] = item.paramValue;
 
 629       if (paramTabData && paramTabData != undefined) {
 
 630         templateData.forEach(function (item) {
 
 631           for (var index in paramTabData) {
 
 632             if (item.paramName === index) {
 
 633               if (checkNamesOnlyCondition) {
 
 634                 resultParamObj[index] = paramTabData[index];
 
 637                 if (item.paramValue === "") {
 
 638                   resultParamObj[index] = paramTabData[index];
 
 641                   resultParamObj[index] = item.paramValue;
 
 651       localStorage["paramsContent"] = JSON.stringify(resultParamObj);
 
 652       templateData = Array.from(new Set(templateData.map((itemInArray) => itemInArray.paramName)))
 
 654       //reformatting arr1 to match with PD
 
 655       templateData.forEach(function (item) {
 
 691           "ruleTypeValues": [null]
 
 696     if (pdData && pdData != undefined) {
 
 697       for (var i = 0; i < resultArr.length; i++) {
 
 699         pdData.forEach(function (arr2item) {
 
 700           if (resultArr[i].name === arr2item.name) {
 
 703               "name": arr2item.name,
 
 704               "type": arr2item.type,
 
 705               "description": arr2item.description,
 
 706               "required": arr2item.required,
 
 707               "default": arr2item.default,
 
 708               "source": arr2item.source,
 
 709               "rule-type": arr2item["rule-type"],
 
 710               "request-keys": arr2item["request-keys"],
 
 711               "response-keys": arr2item["response-keys"],
 
 712               "ruleTypeValues": arr2item.ruleTypeValues
 
 714             resultArr.splice(i, 1, json)
 
 722     this.paramShareService.setSessionParamData(resultArr);
 
 723     this.mappingEditorService.paramData = [];
 
 724     //navigate to PD page after sync
 
 727       .navigate(['../../../vnfs/design/parameterDefinitions/create']);
 
 730   //========================== End of syncTemplate() Method============================================
 
 732     this.mergeStatus = this.mappingEditorService.autoAnnotateDataForParams();
 
 733     if (this.mergeStatus) {
 
 734       this.nService.success("Success", "Merge Successful");
 
 737       this.nService.error("Error", "Merge Unsuccessful");
 
 741   //========================== End of mergeParams() Method============================================  
 
 742   public handleAnnotation(modal) {
 
 744     this.selectedWord = this.templateeditor.getEditor().session.getTextRange(this.templateeditor.getEditor().selectionRange);
 
 745     if (this.selectedWord && this.selectedWord != undefined) modal.open();
 
 747   //========================== End of handleAnnotations() Method============================================ 
 
 748   public submitNameValues() {
 
 750       this.checkNameEntered = true;
 
 752       if (this.selectedWord) {
 
 753         if (this.selectedWord.startsWith('${(')) {
 
 754           var replaceWord: any = this.replaceWord = this.selectedWord.substring(3, this.selectedWord.indexOf(')=(')) + this.tempName;
 
 755           this.templateeditor.getEditor().session.replace(this.templateeditor.getEditor().session.selection.getRange(), replaceWord);
 
 758           let mappingKey = this.mappingEditorService.getKeysForValues(this.selectedWord);
 
 759           var replaceWord: any = this.replaceWord = '${(' + this.selectedWord + ')=(' + this.tempName + ')}';
 
 760           this.templateeditor.getEditor().session.replace(this.templateeditor.getEditor().session.selection.getRange(), replaceWord);
 
 764       this.mappingEditorService.refreshEditor();
 
 770       this.checkNameEntered = false;
 
 774   //========================== End of submitNameValues() Method============================================