parameter-definition service- removed unused code
[appc/cdt.git] / src / app / vnfs / build-artifacts / reference-dataform / reference-dataform.component.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
6 Copyright (C) 2018 IBM.
7 ===================================================================
8 Unless otherwise specified, all software contained herein is licensed
9 under the Apache License, Version 2.0 (the License);
10 you may not use this software except in compliance with the License.
11 You may obtain a copy of the License at
12
13     http://www.apache.org/licenses/LICENSE-2.0
14
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
20 ============LICENSE_END============================================
21 */
22
23 import * as XLSX from 'xlsx';
24 import * as _ from 'underscore';
25 import { ActivatedRoute, Router } from '@angular/router';
26 import { Component, OnInit, ViewChild } from '@angular/core';
27 import { BuildDesignComponent } from '../build-artifacts.component';
28 import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
29 import { Location } from '@angular/common';
30 import { MappingEditorService } from '../../..//shared/services/mapping-editor.service';
31 import { ModalComponent } from '../../../shared/modal/modal.component';
32 import { NgProgress } from 'ngx-progressbar';
33 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
34 import { NotificationService } from '../../../shared/services/notification.service';
35 import { NotificationsService } from 'angular2-notifications';
36 import { ParamShareService } from '../../..//shared/services/paramShare.service';
37 import { environment } from '../../../../environments/environment';
38 import { saveAs } from 'file-saver';
39 import { UtilityService } from '../../../shared/services/utilityService/utility.service';
40 import { appConstants } from '../../../../constants/app-constants';
41 declare var $: any;
42 type AOA = Array<Array<any>>;
43 const REFERENCE_DATA:string= "reference_data";
44 @Component({
45     selector: 'reference-dataform',
46     templateUrl: './reference-dataform.component.html',
47     styleUrls: ['./reference-dataform.component.css']
48 })
49 export class ReferenceDataformComponent implements OnInit {
50     @ViewChild(ModalComponent) modalComponent: ModalComponent;
51     public showUploadStatus: boolean = false;
52     public fileUploaded: boolean = false;
53     public uploadedData: any;
54     public statusMsg: string;
55     public uploadStatus: boolean = false;
56     public isCollapsedContent: boolean = true;
57     public vnfcCollLength: number = 0;
58     public vfncCollection = [];
59     public userForm: any;
60     public actionType: any;
61     numberTest: RegExp = /^[^.a-z]+$/;
62     public numberOfVmTest: boolean = true;
63     public tempAllData = [];
64     disableGrpNotationValue: boolean;
65     public noRefData = false;
66     public disableRetrieve = false;
67     public getRefStatus = false;
68     public uploadStatusError: boolean;
69     public showUploadErrorStatus: boolean;
70     public noData: string;
71     selectedActions = [];
72     public appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
73     public downloadData = {
74         reference: {},
75         template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
76         pd: { pdData: '', pdFileName: '' }
77     };
78     fileName: any;
79     public uploadFileName: any;
80     public addVmClickedFlag: boolean = false;
81     public getExcelUploadStatus: boolean = false;
82     public uploadedDataArray: any;
83     public actionFlag = false;
84     currentAction: any;
85     oldAction: any;
86     nonConfigureAction: any;
87     templateId;
88     templateIdentifier;
89     public actionLevels = [
90         'vnfc', 'vnf'
91     ];
92     oldtemplateIdentifier: any
93     identifierDrp: any;
94     identifierDrpValues: any = [];
95     //settings for the notifications.
96     options = {
97         timeOut: 1000,
98         showProgressBar: true,
99         pauseOnHover: true,
100         clickToClose: true,
101         maxLength: 200
102     };
103     //initializing this object to contain all the parameters to be captured
104     public referenceDataObject = {
105         action: '',
106         'action-level': 'vnf',
107         scope: { 'vnf-type': '', 'vnfc-type': '' },
108         'template': 'Y',
109         vm: [],
110         'device-protocol': '',
111         'user-name': '',
112         'port-number': '',
113         'artifact-list': []
114     };
115     public refernceScopeObj = { sourceType: '', from: '', to: '' };
116     public actions = [ appConstants.Actions.blank, 
117                         appConstants.Actions.configure,
118                         appConstants.Actions.ConfigModify,
119                         appConstants.Actions.configBackup,
120                         appConstants.Actions.configRestore,
121                         appConstants.Actions.getRunningConfig,
122                         appConstants.Actions.healthCheck,
123                         appConstants.Actions.startApplication,
124                         appConstants.Actions.stopApplication,
125                         appConstants.Actions.quiesceTraffic,
126                         appConstants.Actions.resumeTraffic,
127                         appConstants.Actions.upgradeBackout,
128                         appConstants.Actions.upgradeBackup,
129                         appConstants.Actions.upgradePostCheck,
130                         appConstants.Actions.upgradePreCheck,
131                         appConstants.Actions.upgradeSoftware,
132                         appConstants.Actions.openStackActions,
133                         appConstants.Actions.configScaleOut
134                     ];
135     public groupAnotationValue = [appConstants.groupAnotationValue.blank, appConstants.groupAnotationValue.pair];
136     public groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue];
137     public deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.ansible, appConstants.DeviceProtocols.chef, appConstants.DeviceProtocols.netconfXML, appConstants.DeviceProtocols.rest, appConstants.DeviceProtocols.cli, appConstants.DeviceProtocols.restConf];
138     public deviceTemplates = [appConstants.deviceTemplates.blank, appConstants.deviceTemplates.y, appConstants.deviceTemplates.n];
139     public sourceTypeColl = [appConstants.sourceTypeColl.blank, appConstants.sourceTypeColl.vnfType, appConstants.sourceTypeColl.vnfcType];
140     public ipAddressBoolean = ['', 'Y', 'N'];
141     public Sample: any = {
142         'vnfc-instance': '1',
143         'vnfc-function-code': '',
144         'ipaddress-v4-oam-vip': '',
145         'group-notation-type': '',
146         'group-notation-value': ''
147     };
148     hideModal: boolean = false;
149     public self: any;
150     public uploadTypes = [{
151         value: 'Reference Data',
152         display: 'Sample Json Param File'
153     },
154     {
155         value: 'Mapping Data',
156         display: 'Sample Json Param File'
157     }
158     ];
159     public selectedUploadType: string = this.uploadTypes[0].value;
160     public vnfcTypeData: string = '';
161     public title: string;
162     public allowAction: boolean = true;
163     public actionExist: boolean = false;
164     public disableVnftype: boolean = false;
165     public otherActions: boolean = false;
166     public actionHealthCheck: boolean = false;
167     public actionChanged: boolean = false;
168     public initialAction: string = '';
169     public noCacheData: boolean;
170     public updateParams: any;
171     public vnfParams: any;
172     public firstArrayElement = [];
173     public remUploadedDataArray = [];
174     isConfigScaleOut = false
175     configScaleOutExist: boolean
176     public versionNoForApiCall: any= "0.0.1"
177     constructor(
178     private buildDesignComponent: BuildDesignComponent,
179     private httpUtils: HttpUtilService, 
180     private route: Router, 
181     private location: Location, 
182     private activeRoutes: ActivatedRoute, 
183     private notificationService: NotificationService,
184     private paramShareService: ParamShareService, 
185     private mappingEditorService: MappingEditorService, 
186     private modalService: NgbModal, 
187     private nService: NotificationsService, 
188     private ngProgress: NgProgress,
189     private utilityService: UtilityService) {
190     }
191
192     ngOnInit() {
193
194         this.self = this;
195         let path = this.location.path;
196         this.title = 'Reference Data';
197         this.referenceDataObject = {
198             action: '',
199             'action-level': 'vnf',
200             scope: { 'vnf-type': '', 'vnfc-type': '' },
201             'template': 'Y',
202             vm: [],
203             'device-protocol': '',
204             'user-name': '',
205             'port-number': '',
206             'artifact-list': []
207         };
208         this.updateParams = sessionStorage.getItem('updateParams');
209         let cacheData = this.mappingEditorService.referenceNameObjects;
210         if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
211             this.tempAllData = cacheData;
212             if (this.mappingEditorService.latestAction != undefined) {
213                 this.referenceDataObject = this.mappingEditorService.latestAction;
214                 this.toggleIdentifier(this.referenceDataObject.action);
215                 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
216                 this.oldAction = this.referenceDataObject.action;
217                 this.populateExistinAction(this.referenceDataObject.action);
218             }
219         } else if (this.updateParams != 'undefined') {
220             this.getArtifact();
221         }
222         var appData = this.mappingEditorService.appDataObject;
223         if (appData != null || appData != undefined) this.appData = appData;
224         var downloadData = this.mappingEditorService.downloadDataObject;
225         if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
226         this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
227         if (this.vnfParams && this.vnfParams.vnfType) {
228             this.referenceDataObject['scope']['vnf-type'] = this.vnfParams.vnfType;
229         }
230         if (this.vnfParams && this.vnfParams.vnfcType) {
231             this.referenceDataObject['scope']['vnfc-type'] = this.vnfParams.vnfcType;
232         }
233         this.uploadedDataArray = [];
234         this.remUploadedDataArray = [];
235         this.firstArrayElement = [];
236         this.uploadFileName = '';
237         this.templateIdentifier = this.mappingEditorService.identifier
238         // Enable or Block Template and PD Tabs
239         this.buildDesignComponent.getRefData(this.referenceDataObject);
240         this.configDrp(this.referenceDataObject.action)
241     }
242     toggleIdentifier(data) {
243         if (data == 'ConfigScaleOut') {
244             this.isConfigScaleOut = true
245
246         } else {
247             this.isConfigScaleOut = false
248         }
249     }
250
251     //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
252     getArtifact() {
253         try {
254             let data = this.utilityService.createPayloadForRetrieve(true, '', '', '');
255             this.ngProgress.start();
256             this.httpUtils.post({
257                 url: environment.getDesigns,
258                 data: data
259             }).subscribe(resp => {
260                 if (resp.output.data.block != undefined) {
261                     this.nService.success(appConstants.notifications.titles.status, appConstants.messages.datafetched);
262                     let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
263                     let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
264                     this.referenceDataObject = reference_data;
265                     this.toggleIdentifier(this.referenceDataObject.action);
266                     if (this.referenceDataObject.action == appConstants.Actions.configScaleOut) {
267                         this.groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue, appConstants.groupAnotationType.existingGroupName];
268                     }
269
270                     // Enable or Block Template and PD Tabs
271                     this.buildDesignComponent.getRefData(this.referenceDataObject);
272                     this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
273                     this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
274                     this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
275                     this.oldAction = this.referenceDataObject.action;
276                     if (this.referenceDataObject.action === appConstants.Actions.openStackActions) {
277                         this.deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.openStack];
278                         this.buildDesignComponent.tabs = [
279                             {
280
281                                 name: 'Reference Data',
282                                 url: 'references',
283                             }];
284                     }
285                     else {
286                         this.buildDesignComponent.tabs = [
287                             {
288                                 name: 'Reference Data',
289                                 url: 'references',
290                             }, {
291                                 name: 'Template',
292                                 url: 'templates/myTemplates',
293                             }, {
294                                 name: 'Parameter Definition',
295                                 url: 'parameterDefinitions/create'
296                             }/*, {
297                                 name: "Test",
298                                 url: 'test',
299                             }*/
300                         ];
301                     }
302                     this.getArtifactsOpenStack();
303                 } else {
304                     this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(sessionStorage.getItem('updateParams')))['artifact-name']);
305                 }
306                 this.ngProgress.done();
307             });
308         }
309         catch (e) {
310             this.nService.warn('status', 'error while reteriving artifact');
311         }
312         setTimeout(() => {
313             this.ngProgress.done();
314         }, 3500);
315     }
316
317     //reinitializing the required values
318     ngOnDestroy() {
319         let referenceObject = this.prepareReferenceObject();
320         this.mappingEditorService.changeNavAppData(this.appData);
321         this.mappingEditorService.changeNavDownloadData(this.downloadData);
322         this.uploadedDataArray = [];
323         this.remUploadedDataArray = [];
324         this.firstArrayElement = [];
325         this.uploadFileName = '';
326     }
327
328     numberValidation(event: any) {
329         if (this.numberTest.test(event) && event != 0) {
330             this.numberOfVmTest = true;
331         }
332         else {
333             this.numberOfVmTest = false;
334         }
335     }
336
337     updateSessionValues(event: any, type: string) {
338         if (type === 'action') {
339             sessionStorage.setItem('action', event);
340         }
341         if (type === 'vnfType') {
342             sessionStorage.setItem('vnfType', event);
343         }
344     }
345
346     addVnfcData(vmNumber: number) {
347         var newObj = {
348             'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
349             'vnfc-type': this.vnfcTypeData,
350             'vnfc-function-code': '',
351             'ipaddress-v4-oam-vip': '',
352             'group-notation-type': '',
353             'group-notation-value': ''
354         };
355         this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
356     }
357
358     //to remove the VM's created by the user
359     removeFeature(vmNumber: any, index: any, templateId) {
360         if (this.referenceDataObject.action == "Configure") {
361             this.referenceDataObject.vm.splice(vmNumber, 1);
362             this.referenceDataObject.vm.forEach((obj, arrIndex) => {
363                 if (arrIndex >= vmNumber) {
364                     obj["vm-instance"] = obj["vm-instance"] - 1
365                 }
366             })
367         } else {
368             let data = this.referenceDataObject.vm.filter(obj => {
369                 return obj['template-id'] == templateId;
370             })
371
372             let vmIndex = this.findVmindex(data, vmNumber, templateId)
373             this.referenceDataObject.vm.splice(vmIndex, 1);
374             let index = 0
375             this.referenceDataObject.vm.forEach((obj, arrIndex) => {
376                 if (obj['template-id'] == templateId) {
377
378                     obj["vm-instance"] = index + 1
379                     index++
380                 }
381
382             })
383         }
384
385     }
386     findVmindex(data, vmNumber, templateId) {
387         return this.referenceDataObject.vm.findIndex(obj => {
388             let x = obj['vm-instance'] == (vmNumber + 1) && templateId == obj['template-id']//true
389             return x
390         })
391
392     }
393
394     //add new VM's to the configure
395     addVms() {
396         let arr = [];
397         let mberOFVm = Number(this.refernceScopeObj.from);
398         if (this.referenceDataObject.action == 'ConfigScaleOut') {
399             let existingVmsLength = this.referenceDataObject.vm.filter(obj => {
400                 return obj['template-id'] == this.templateIdentifier
401             }).length;
402             mberOFVm = existingVmsLength + mberOFVm;
403             let index = 0;
404             for (var i = (existingVmsLength); i < mberOFVm; i++) {
405
406                 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (existingVmsLength + index + 1), vnfc: [Object.assign({}, this.Sample)] });
407                 index++;
408             }
409
410         } else {
411             let arrlength = this.referenceDataObject.vm.length;
412             mberOFVm = arrlength + mberOFVm;
413             for (var i = (arrlength); i < mberOFVm; i++) {
414                 if (this.referenceDataObject.action == 'ConfigScaleOut') {
415                     this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
416                 } else {
417                     this.referenceDataObject.vm.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
418                 }
419             }
420         }
421     }
422
423     //Reference object to create reference data
424     prepareReferenceObject(isSaving?: any) {
425         let scopeName = this.resetParamsOnVnfcType();
426         let extension = this.decideExtension(this.referenceDataObject);
427         this.prepareArtifactList(scopeName, extension);
428         if (this.referenceDataObject.action === 'OpenStack Actions') {
429             this.referenceDataObject['template'] = 'N';
430             this.referenceDataObject['artifact-list'] = [];
431             this.referenceDataObject['firstRowVmSpreadSheet']=this.firstArrayElement;
432         }
433         //detaching the object from the form and processing further
434         let newObj = $.extend(true, {}, this.referenceDataObject);
435         let action = this.referenceDataObject.action;
436         newObj = this.deleteVmsforNonActions(newObj, action)
437         this.pushOrReplaceTempData(newObj, action);
438         this.addAllActionObj(newObj, scopeName);
439         this.resetTempData()
440         //saving data to service
441         this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
442         this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
443         this.mappingEditorService.changeNav(this.tempAllData);
444         //on action change or template identifier change reset the form by restting values of Reference data object
445         this.resetVmsForScaleout(this.currentAction)
446         return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
447     }
448
449     public checkIfelementExistsInArray(element, array) {
450         //// console.log("Element==" + element)
451         var result: boolean = false;
452
453         array.forEach(function (item) {
454             // // console.log("Item==" + item)
455             if (element === item) {
456                 // console.log('Element==' + element + 'Item==' + item);
457                 result = true;
458             }
459         }
460         );
461         return result;
462     }
463
464     upload(evt: any) {
465        /* wire up file reader */
466         const target: DataTransfer = <DataTransfer>(evt.target);
467         //// console.log("filename========" + evt.target.files[0].name)
468         this.uploadFileName = evt.target.files[0].name;
469         var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
470         if (target.files.length != 1) {
471             throw new Error(appConstants.errors.multipleFileUploadError);
472         }
473         if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
474             const reader = new FileReader();
475             reader.onload = (e: any) => {
476                 /* read workbook */
477                 const bstr = e.target.result;
478                 //      // console.log("print 1---" + bstr);
479                 const wb = XLSX.read(bstr, { type: 'binary' });
480                 //    // console.log("print 2---" + JSON.stringify(wb));
481                 /* grab first sheet */
482                 const wsname = wb.SheetNames[0];
483                 //  // console.log("Name:---" + wsname);
484                 const ws = wb.Sheets[wsname];
485
486                 /* save data */
487
488                 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
489                 this.uploadedDataArray = arrData;
490                 this.firstArrayElement = arrData[0];
491                 var remUploadedDataArray = arrData;
492                 remUploadedDataArray.shift();
493                 this.remUploadedDataArray = remUploadedDataArray;
494                 if (arrData != null) {
495                     this.getExcelUploadStatus = true;
496                     this.nService.success(appConstants.notifications.titles.success, appConstants.messages.vmDataUploadSuccess);
497
498                 }
499                 else {
500                     this.nService.success(appConstants.notifications.titles.error, appConstants.messages.emptyVmUpload);
501                 }
502             };
503             reader.readAsBinaryString(target.files[0]);
504         }
505         else {
506             this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectVmUpload);
507         }
508
509     }
510
511     addVmCapabilitiesData() {
512         for (var i = 0; i < this.uploadedDataArray.length; i++) {
513             var vnfcFuncCodeArray = [];
514             var data = this.uploadedDataArray[i];
515             for (var j = 1; j < data.length; j++) {
516                 if (data[j] != undefined) {
517                     if (data[j].toUpperCase() === 'Y') {
518                         vnfcFuncCodeArray.push(this.firstArrayElement[j]);
519                     }
520                 }
521             }
522             var action = this.uploadedDataArray[i][0];
523             if (action && action != undefined) {
524                 var json = {
525                     'action': action,
526                     'action-level': 'vm',
527                     'scope': {
528                         'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
529                         'vnfc-type': null
530                     },
531                     'vnfc-function-code-list': vnfcFuncCodeArray,
532                     'template': 'N',
533                     'device-protocol': 'OS'
534                 };
535
536                 this.tempAllData.push(json);
537             }
538
539         }
540     }
541
542     //download template
543     save(form: any, isValid: boolean) {
544         if (this.referenceDataObject.action === '') {
545             this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
546             return;
547         }
548         if (this.referenceDataObject['device-protocol'] === '') {
549             this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
550             return;
551         }
552
553         if (isValid) {
554             let referenceObject = this.prepareReferenceObject();
555             let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
556             let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
557             this.downloadData.reference = theJSON;
558             this.validateTempAllData();
559             var blob = new Blob([theJSON], {
560                 type: 'text/plain'
561             });
562             let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
563             this.downloadFile(blob, fileName, 100)
564             var templateData = JSON.stringify(this.downloadData.template.templateData);
565             var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
566             var pdData = this.downloadData.pd.pdData;
567             if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
568             if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
569             if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
570         }
571     }
572     downloadFile(blob, fileName, delay) {
573         setTimeout(() => {
574             saveAs(blob, fileName);
575         }, delay)
576     }
577
578     downloadTemplate() {
579         var fileName = this.downloadData.template.templateFileName;
580         var theJSON = this.downloadData.template.templateData;
581         if (fileName != null || fileName != '') {
582             var fileExtensionArr = fileName.split('.');
583             var blob = new Blob([theJSON], {
584                 type: 'text/' + fileExtensionArr[1]
585             });
586             this.downloadFile(blob, fileName, 130)
587         }
588     }
589
590     downloadNameValue() {
591         var fileName = this.downloadData.template.nameValueFileName;
592         var theJSON = this.downloadData.template.nameValueData;
593         var blob = new Blob([theJSON], {
594             type: 'text/json'
595         });
596
597         this.downloadFile(blob, fileName, 160)
598     }
599
600     downloadPd() {
601         let fileName = this.downloadData.pd.pdFileName;
602         let theJSON = this.downloadData.pd.pdData;
603         var blob = new Blob([theJSON], {
604             type: 'text/plain'
605         });
606
607         this.downloadFile(blob, fileName, 180)
608     }
609
610     saveToAppc(valid, form, event) {
611         if (this.referenceDataObject.action === '') {
612             this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
613             return;
614         }
615         if (this.referenceDataObject['device-protocol'] === '') {
616             this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
617             return;
618         }
619
620         try {
621             form._submitted = true;
622             if (valid) {
623
624                 let referenceObject = this.prepareReferenceObject(true);
625                 this.validateTempAllData();
626                 let theJSON = JSON.stringify(this.tempAllData, null, '\t');
627                 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
628                 this.uploadArtifact(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
629                 var templateData = JSON.stringify(this.appData.template.templateData);
630                 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
631                 var pdData = JSON.stringify(this.appData.pd);
632                 if (templateData != '{}' && templateData != null && templateData != undefined) this.saveTemp();
633                 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.saveNameValue();
634                 if (pdData != '{}' && pdData != null && pdData != undefined) this.savePd();
635                 if (this.actionChanged) {
636                     this.clearVnfcData()
637                     if (this.currentAction) {
638                         this.referenceDataObject.action = this.currentAction;
639                     }
640
641                     this.populateExistinAction(this.referenceDataObject.action);
642                     this.actionChanged = false;
643                 }
644             }
645         }
646         catch (e) {
647             this.nService.warn(appConstants.notifications.titles.status, appConstants.messages.artifactSaveError);
648         }
649     }
650
651     validateTempAllData() {
652         if (this.tempAllData) {
653             var updatedData = [];
654             this.tempAllData.forEach(data => {
655                 if (data.action) {
656                     updatedData.push(data);
657                 }
658             });
659             this.tempAllData = updatedData;
660         }
661     }
662
663     appendSlashes(artifactData) {
664         return artifactData.replace(/"/g, '\\"');
665     }
666
667     uploadArtifact(artifactData, dataJson, fileName) {
668         let data = [];
669         let slashedPayload = this.appendSlashes(artifactData);
670         let payload = this.utilityService.createPayLoadForSave(REFERENCE_DATA, dataJson['scope']['vnf-type'], "AllAction", fileName, this.versionNoForApiCall, slashedPayload);
671         this.ngProgress.start();
672         this.httpUtils.post({
673             url: environment.getDesigns,
674             data: payload
675         }).subscribe((resp) => {
676             if (resp != null && resp.output.status.code == appConstants.errorCode["400"]) {
677                 window.scrollTo(0, 0);
678                 this.nService.success(appConstants.notifications.titles.status, appConstants.messages.referenceDataUplaodSuccess);
679             } else {
680                 this.nService.warn(appConstants.notifications.titles.status, appConstants.messages.referenceDataUplaodFailure);
681             }
682             this.uploadStatusError = false;
683             this.getRefStatus = false;
684             this.ngProgress.done();
685         }, (err) => {
686             this.nService.error(appConstants.notifications.titles.status, appConstants.errors.connectionError);
687             window.scrollTo(0, 0);
688         });
689         this.appData.reference = payload;
690         setTimeout(() => {
691             this.ngProgress.done();
692         }, 3500);
693     }
694
695     retriveFromAppc() {
696         if (sessionStorage.getItem('updateParams') != 'undefined') {
697             this.getArtifact();
698             this.noCacheData = false;
699         } else {
700             this.noCacheData = true;
701         }
702     }
703
704     cloneMessage(servermessage) {
705         var clone = {};
706         for (var key in servermessage) {
707             if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
708                 clone[key] = servermessage[key];
709         }
710         return clone;
711     }
712
713     public showUpload() {
714         this.selectedUploadType = this.uploadTypes[0].value;
715     };
716
717     public fileChange(input) {
718         this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
719         this.fileUploaded = true;
720         this.disableRetrieve = true;
721         if (input.target.files && input.target.files[0]) {
722             // Create the file reader
723             let reader = new FileReader();
724             this.readFile(input.target.files[0], reader, (result) => {
725                 // After the callback fires do:
726                 if ('Reference Data' === this.selectedUploadType) {
727                     try {
728                         let obj: any;
729                         let jsonObject = (JSON.parse(result))['reference_data'];
730                         this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
731                         this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
732                         this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
733                         if (jsonObject instanceof Array) {
734                             this.referenceDataObject = jsonObject[0];
735                             jsonObject.forEach(obj => {
736                                 this.selectedActions.push(obj.action);
737                             });
738                         } else {
739                             this.referenceDataObject = jsonObject;
740
741                             this.selectedActions.push(jsonObject.action);
742                         }
743                         this.toggleIdentifier(this.referenceDataObject.action)
744                         this.configDrp(this.referenceDataObject.action)
745                         if (this.referenceDataObject.action === 'OpenStack Actions') {
746                             this.deviceProtocols = ['', 'OpenStack'];
747                             this.buildDesignComponent.tabs = [
748                                 {
749                                     type: 'dropdown',
750                                     name: 'Reference Data',
751                                     url: 'references',
752                                 }];
753                         }
754                         else {
755                             this.buildDesignComponent.tabs = [
756                                 {
757                                     name: 'Reference Data',
758                                     url: 'references',
759                                 }, {
760                                     name: 'Template',
761                                     url: 'templates/myTemplates',
762                                 }, {
763                                     name: 'Parameter Definition',
764                                     url: 'parameterDefinitions/create'
765                                 } /*, {
766         name: "Test",
767         url: 'test',
768       }*/
769                             ];
770                         }
771                         this.getArtifactsOpenStack();
772                         if (this.referenceDataObject.template == null) {
773                             this.referenceDataObject.template = 'Y';
774                         }
775                         if (this.referenceDataObject['action-level'] == null) {
776                             this.referenceDataObject['action-level'] = 'VNF';
777                         }
778                         // Enable or Block Template and PD Tabs
779                         this.buildDesignComponent.getRefData(this.referenceDataObject);
780                     } catch (e) {
781                         this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectFileFormat);
782                     }
783                 }
784                 this.hideModal = true;
785             });
786         } else {
787             this.notificationService.notifyErrorMessage('Failed to read file..');
788         }
789     }
790
791     public readFile(file, reader, callback) {
792         // Set a callback funtion to fire after the file is fully loaded
793         reader.onload = () => {
794             // callback with the results
795             callback(reader.result);
796         };
797         this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
798         // Read the file
799         reader.readAsText(file, 'UTF-8');
800     }
801
802     fileChangeEvent(fileInput: any) {
803         let obj: any = fileInput.target.files;
804     }
805
806     clearVnfcData() {
807         this.Sample = {
808             'vnfc-instance': '1',
809             'vnfc-function-code': '',
810             'ipaddress-v4-oam-vip': '',
811             'group-notation-type': '',
812             'group-notation-value': ''
813         };
814     }
815
816     setVmInstance(index) {
817         this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
818     }
819
820     setVnfcType(str: String) {
821         this.Sample['vnfc-type'] = str;
822     }
823
824     getChange(value: String) {
825         if (value === 'vnfType') {
826             this.referenceDataObject.scope['vnfc-type'] = '';
827         }
828     }
829
830     resetForm() {
831         this.referenceDataObject['action-level'] = 'vnf';
832         this.referenceDataObject.template = 'Y';
833         this.referenceDataObject['device-protocol'] = '';
834         this.referenceDataObject['user-name'] = '';
835         this.referenceDataObject['port-number'] = '';
836         this.refernceScopeObj.sourceType = '';
837         this.Sample['vnfc-type'] = '';
838     }
839
840     populateExistinAction(data) {
841         let existAction = this.tempAllData.findIndex(obj => {
842             return obj.action == data;
843         });
844         if (existAction > -1) {
845             let obj = $.extend(true, {}, this.tempAllData[existAction]);
846             this.referenceDataObject = obj;
847             this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
848             this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
849             this.referenceDataObject['device-protocol'] = obj['device-protocol'];
850             this.refernceScopeObj['sourceType'] = obj['scopeType'];
851         } else {
852             this.resetForm();
853             this.referenceDataObject.action = data;
854         }
855         //# iof healthCeck change deviceprotocol drp vaues
856         switch (data) {
857             case 'HealthCheck':
858                 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
859                 this.actionHealthCheck = true;
860                 break;
861             case 'UpgradeBackout':
862             case 'ResumeTraffic':
863             case 'QuiesceTraffic':
864             case 'UpgradeBackup':
865             case 'UpgradePostCheck':
866             case 'UpgradePreCheck':
867             case 'UpgradeSoftware':
868             case 'ConfigRestore':
869             case 'StartApplication':
870             case 'StopApplication':
871             case 'GetRunningConfig':
872             case 'ConfigBackup':
873                 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
874                 break;
875             case 'OpenStack Actions':
876                 this.deviceProtocols = ['', 'OpenStack'];
877                 break;
878             case 'ConfigScaleOut':
879                 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
880                 break;
881             default:
882                 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
883                 this.actionHealthCheck = false;
884         }
885     }
886
887     //Modal pop up for action change with values entered.
888     actionChange(data, content, userForm) {
889         this.disableGrpNotationValue = false
890         if (data == null) {
891             return;
892         }
893         if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
894             this.actionChanged = true;
895             this.modalService.open(content, { backdrop: 'static', keyboard: false }).result.then(res => {
896                 if (res == 'yes') {
897                     this.currentAction = this.referenceDataObject.action;
898                     this.referenceDataObject.action = this.oldAction;
899                     $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
900                     this.toggleIdentifier(data)
901                     this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
902                     this.referenceDataObject.action = this.currentAction
903
904                     this.populateExistinAction(data);
905                     if (this.oldAction === 'OpenStack Actions') {
906
907                         this.uploadedDataArray = [];
908                         this.remUploadedDataArray = [];
909                         this.firstArrayElement = [];
910                         this.uploadFileName = '';
911                         //this.tempAllData = [];
912                     }
913                     this.clearCache();
914                     this.refernceScopeObj.from = '';
915                     this.getArtifactsOpenStack()
916                 } else {
917                     this.toggleIdentifier(data)
918                     this.currentAction = this.referenceDataObject.action;
919                     this.populateExistinAction(data);
920                     this.resetVmsForScaleout(data);
921                     this.oldAction = this.referenceDataObject.action + '';
922                     this.clearCache();
923                     this.clearVnfcData()
924                     this.refernceScopeObj.from = '';
925                 }
926
927                 // Enable or Block Template and PD Tabs
928                 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
929                     let referenceDataObjectTemp = this.referenceDataObject;
930                     referenceDataObjectTemp['template-id'] = this.templateIdentifier;
931                     this.buildDesignComponent.getRefData(referenceDataObjectTemp);
932                 } else {
933                     this.buildDesignComponent.getRefData(this.referenceDataObject);
934                 }
935             });
936         } else {
937             this.actionChanged = true;
938             this.currentAction = this.referenceDataObject.action;
939             this.oldAction = this.referenceDataObject.action + '';
940             this.populateExistinAction(data);
941             this.resetVmsForScaleout(data);
942             this.toggleIdentifier(data);
943
944             // Enable or Block Template and PD Tabs
945             if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
946                 let referenceDataObjectTemp = this.referenceDataObject;
947                 referenceDataObjectTemp['template-id'] = this.templateIdentifier;
948                 this.buildDesignComponent.getRefData(referenceDataObjectTemp);
949             } else {
950                 this.buildDesignComponent.getRefData(this.referenceDataObject);
951             }
952         }
953         this.configDrp(data)
954     }
955
956     configDrp(data) {
957         if (data == 'ConfigScaleOut') {
958             this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
959         } else {
960             this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
961         }
962         if (data == 'OpenStack Actions') {
963             this.buildDesignComponent.tabs = [
964                 {
965                     type: 'dropdown',
966                     name: 'Reference Data',
967                     url: 'references',
968                 }];
969         }
970         else {
971             this.buildDesignComponent.tabs = [
972                 {
973                     name: 'Reference Data',
974                     url: 'references',
975                 }, {
976                     name: 'Template',
977                     url: 'templates/myTemplates',
978                 }, {
979                     name: 'Parameter Definition',
980                     url: 'parameterDefinitions/create'
981                 }/*, {
982                     name: "Test",
983                     url: 'test',
984                 }*/
985             ];
986         }
987         if (data == 'Configure' || data == 'ConfigModify') {
988             this.nonConfigureAction = false;
989         } else {
990             this.nonConfigureAction = true;
991         }
992     }
993
994     deviceProtocolChange() {
995         // Enable or Block Template and PD Tabs
996         this.buildDesignComponent.getRefData(this.referenceDataObject)
997     }
998
999     // For the issue with multiple template changes
1000     idChange(data, content, userForm) {
1001         if (data == null) {
1002             return;
1003         }
1004         // Enable or Block Template and PD Tabs
1005         let referenceDataObjectTemp = this.referenceDataObject;
1006         referenceDataObjectTemp['template-id'] = data;
1007         this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1008
1009         if ((userForm.valid) && this.oldtemplateIdentifier != '' && this.oldtemplateIdentifier != undefined) {
1010             this.currentAction = "ConfigScaleOut"
1011             this.oldtemplateIdentifier = this.templateIdentifier
1012             let referenceObject = this.prepareReferenceObject();
1013             this.actionChanged = true;
1014             if (this.templateIdentifier) {
1015                 this.modalService.open(content).result.then(res => {
1016                     if (res == 'yes') {
1017                         this.validateTempAllData();
1018                         let theJSON = JSON.stringify(this.tempAllData, null, '\t');
1019                         let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
1020                         this.uploadArtifact(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
1021                         var templateData = JSON.stringify(this.appData.template.templateData);
1022                         var nameValueData = JSON.stringify(this.appData.template.nameValueData);
1023                         var pdData = JSON.stringify(this.appData.pd);
1024                         if (templateData != '{}' && templateData != null && templateData != undefined) this.saveTemp();
1025                         if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.saveNameValue();
1026                         if (pdData != '{}' && pdData != null && pdData != undefined) this.savePd();
1027                         this.clearCache();
1028                         this.clearVnfcData()
1029                         this.refernceScopeObj.from = '';
1030                     }
1031                     else {
1032                         this.clearCache();
1033                         this.refernceScopeObj.from = '';
1034                     }
1035                 });
1036             }
1037         }
1038     }
1039
1040     clearCache() {
1041         // get the value and save the userid and persist it.
1042         this.clearTemplateCache();
1043         this.clearPdCache();
1044         this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
1045         this.downloadData = {
1046             reference: {},
1047             template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
1048             pd: { pdData: '', pdFileName: '' }
1049         };
1050     }
1051
1052     clearTemplateCache() {
1053         this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
1054         localStorage['paramsContent'] = '{}';
1055     }
1056     clearPdCache() {
1057         this.mappingEditorService.setParamContent(undefined);
1058         this.paramShareService.setSessionParamData(undefined);
1059     }
1060
1061     saveTemp() {
1062         this
1063             .httpUtils
1064             .post(
1065                 { url: environment.getDesigns, data: this.appData.template.templateData })
1066             .subscribe(resp => {
1067                 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1068                     this.nService.success('Status', 'Successfully uploaded the Template Data');
1069                 }
1070                 if (resp.output.status.code === '401') {
1071                     this.nService.warn('Status', 'Error in saving the Template to Appc');
1072
1073                 }
1074             },
1075                 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1076     }
1077
1078     saveNameValue() {
1079         this
1080             .httpUtils
1081             .post(
1082                 {
1083                     url: environment.getDesigns, data: this.appData.template.nameValueData
1084                 })
1085             .subscribe(resp => {
1086                 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1087                     this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1088                 }
1089                 if (resp.output.status.code === '401') {
1090                     this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1091                 }
1092             },
1093                 error => {
1094                     this.nService.error('Status', 'Error Connecting to the APPC Network');
1095                     return false;
1096                 });
1097     }
1098
1099     savePd() {
1100         this
1101             .httpUtils
1102             .post(
1103                 {
1104                     url: environment.getDesigns, data: this.appData.pd
1105                 })
1106             .subscribe(resp => {
1107                 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1108                     this.nService.success('Status', 'Successfully uploaded PD file');
1109                 }
1110                 if (resp.output.status.code === '401') {
1111                     this.nService.warn('Status', 'Error in saving the PD to Appc');
1112                 }
1113             },
1114                 error => {
1115                     this.nService.error('Status', 'Error Connecting to the APPC Network');
1116                     return false;
1117                 });
1118     }
1119
1120     openModel(toShow: any, message: any, title: any) {
1121         this.modalComponent.isShow = toShow;
1122         this.modalComponent.message = message;
1123         this.modalComponent.title = title;
1124     }
1125
1126     browseOption() {
1127         $('#inputFile').trigger('click');
1128     }
1129
1130     excelBrowseOption() {
1131         $('#excelInputFile').trigger('click');
1132     }
1133
1134     showIdentifier() {
1135         $('#identifierModal').modal();
1136     }
1137
1138     addToIdentDrp() {
1139         if (!(this.referenceDataObject['template-id-list'])) {
1140             this.referenceDataObject['template-id-list'] = [];
1141         }
1142         if (!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim()) > -1)) {
1143             this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1144         }
1145     }
1146
1147     resetVms() {
1148         this.referenceDataObject.vm = [];
1149     }
1150
1151     dataModified() {
1152         //  this.referenceDataObject.vm = this.referenceDataObject.vm;
1153     }
1154
1155     resetGroupNotation() {
1156         if (this.Sample['group-notation-type'] == "existing-group-name") {
1157             this.Sample['group-notation-value'] = ""
1158             this.disableGrpNotationValue = true
1159         } else {
1160             this.disableGrpNotationValue = false
1161         }
1162     }
1163
1164     resetVmsForScaleout(action) {
1165         //reset currentform vms based on action
1166         if (action == "ConfigScaleOut" || action == "Configure") {
1167             let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1168                 return obj['action'] == action
1169             });
1170             if (ConfigScaleOutIndex > -1) {
1171                 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1172             } else {
1173                 if (this.actionChanged) {
1174                     this.referenceDataObject.vm = []
1175                 }
1176             }
1177         }
1178     }
1179
1180     resetParamsOnVnfcType() {
1181         let scopeName = '';
1182         //if only vnf is there
1183         if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1184             scopeName = this.referenceDataObject.scope['vnf-type'];
1185             this.referenceDataObject.scope['vnfc-type'] = '';
1186             this.referenceDataObject['action-level'] = 'vnf';
1187             this.referenceDataObject['scopeType'] = 'vnf-type';
1188         }
1189         //if VNFC is entered set action level & Scope type to VNFC for configure and configure modify, and default the values to vnf and vnf type for all other actions  
1190         else {
1191             scopeName = this.referenceDataObject.scope['vnfc-type'];
1192             if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify') {
1193                 this.referenceDataObject['action-level'] = 'vnfc';
1194                 this.referenceDataObject['scopeType'] = 'vnfc-type';
1195             } else {
1196                 this.referenceDataObject['action-level'] = 'vnf';
1197                 this.referenceDataObject['scopeType'] = 'vnf-type';
1198             }
1199         }
1200         //replacing / with _ and removing spaces in the scopeName
1201         if (scopeName) {
1202             scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1203         }
1204         return scopeName
1205     }
1206     decideExtension(obj) {
1207         //marking the extension based on the device-protocol selected by the user 
1208         let extension = '.json';
1209         switch (obj['device-protocol']) {
1210             case 'ANSIBLE':
1211             case 'CHEF':
1212             case 'CLI':
1213                 extension = '.json';
1214                 break;
1215             case 'NETCONF-XML':
1216             case 'REST':
1217                 extension = '.xml';
1218                 break;
1219         }
1220         return extension;
1221     }
1222     prepareArtifactList(scopeName, extension) {
1223         this.referenceDataObject['artifact-list'] = [];
1224         //preparing the artifact list array file names along with extension
1225         let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.' + extension;
1226         let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1227         let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1228         let configTemplate = {
1229             'artifact-name': 'template_' + config_template_fileName,
1230             'artifact-type': 'config_template'
1231         };
1232         let pdTemplate = {
1233             'artifact-name': 'pd_' + pd_fileName,
1234             'artifact-type': 'parameter_definitions'
1235         };
1236         if (this.referenceDataObject.action != 'ConfigScaleOut') {
1237             this.referenceDataObject['artifact-list'].push(configTemplate,
1238                 pdTemplate
1239             );
1240         } else {
1241             let identifiers = this.referenceDataObject['template-id-list'];
1242             if (identifiers) {
1243                 for (var x = 0; x < identifiers.length; x++) {
1244                     //for replacing spaces and "/" with "_"
1245                     identifiers[x] = identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1246                     pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1247                     config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.' + extension;
1248
1249                     configTemplate = {
1250                         'artifact-name': 'template_' + config_template_fileName,
1251                         'artifact-type': 'config_template'
1252                     };
1253                     pdTemplate = {
1254                         'artifact-name': 'pd_' + pd_fileName,
1255                         'artifact-type': 'parameter_definitions'
1256                     };
1257                     this.referenceDataObject['artifact-list'].push(configTemplate,
1258                         pdTemplate
1259                     );
1260                 }
1261             }
1262
1263         }
1264     }
1265     deleteVmsforNonActions(newObj, action) {
1266         let configureObject = (action == 'Configure');
1267         let ConfigScaleOut = (action == 'ConfigScaleOut');
1268         //delete VM's if selected action is not configure.
1269         if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1270             if (ConfigScaleOut) {
1271             } else {
1272                 newObj.vm = [];
1273             }
1274         } else {
1275             if (ConfigScaleOut) {
1276             } else {
1277                 delete newObj['template-id-list'];
1278             }
1279         }
1280         return newObj
1281     }
1282     pushOrReplaceTempData(newObj, action) {
1283         let actionObjIndex = this.tempAllData.findIndex(obj => {
1284             return obj['action'] == action;
1285         });
1286         if (newObj.action != 'HealthCheck') {
1287             delete newObj['url'];
1288         }
1289
1290         if (actionObjIndex > -1) {
1291             this.tempAllData[actionObjIndex] = newObj;
1292             this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1293             if (newObj.action == "ConfigScaleOut") {
1294                 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1295             }
1296             else {
1297                 this.templateIdentifier = ('')
1298                 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1299             }
1300         } else {
1301             if (newObj.action != '') {
1302                 this.tempAllData.push(newObj);
1303                 this.mappingEditorService.saveLatestAction(newObj);
1304                 if (newObj.action == "ConfigScaleOut") {
1305                     this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1306                 }
1307                 else {
1308                     this.templateIdentifier = ('')
1309                     this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1310                 }
1311             }
1312         }
1313
1314     }
1315
1316     addAllActionObj(newObj, scopeName) {
1317         //Creating all action block to allow mulitple actions at once
1318         let allAction = {
1319             action: 'AllAction',
1320             'action-level': 'vnf',
1321             scope: newObj.scope,
1322             'artifact-list': [{
1323                 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1324                 'artifact-type': 'reference_template'
1325             }]
1326         };
1327         let allActionIndex = this.tempAllData.findIndex(obj => {
1328             return obj['action'] == 'AllAction';
1329         });
1330         if (allActionIndex > -1) {
1331             this.tempAllData[allActionIndex] = allAction;
1332         } else {
1333             this.tempAllData.push(allAction);
1334         }
1335     }
1336
1337     resetTempData() {
1338         if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1339             if (this.tempAllData && this.tempAllData != undefined) {
1340                 for (var i = 0; i < this.tempAllData.length; i++) {
1341                     var result = false;
1342                     if (this.tempAllData[i].action === 'AllAction') {
1343                         result = true;
1344                     }
1345                     else {
1346                         result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1347                     }
1348                     if (!result) {
1349                         this.tempAllData.splice(i, 1);
1350                         i = i - 1;
1351                     }
1352
1353                 }
1354             }
1355             this.addVmCapabilitiesData();
1356         }
1357     }
1358
1359     trackByFn(index, item) {
1360         return index;
1361     }
1362     getArtifactsOpenStack() {
1363         var array = []
1364         var vnfcFunctionCodeArrayList = [];
1365         var vnfcSetArray=[];
1366         for (var i = 0; i < this.tempAllData.length; i++) {
1367             if (!this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions) && (this.tempAllData[i].action != 'AllAction')) {
1368                 var vnfcFunctionCodeArray = this.tempAllData[i]["vnfc-function-code-list"]
1369                 vnfcFunctionCodeArrayList.push([this.tempAllData[i].action].concat(this.tempAllData[i]["vnfc-function-code-list"]))
1370             }
1371             if(this.tempAllData[i].action==='OpenStack Actions')
1372             {
1373                 vnfcSetArray=this.tempAllData[i]['firstRowVmSpreadSheet']
1374             }
1375         }
1376
1377        if(vnfcSetArray)
1378        {
1379         let vnfcSetArrayLen = vnfcSetArray.length;
1380
1381         for (let i = 0; i < vnfcFunctionCodeArrayList.length; i++) {
1382             let element = vnfcFunctionCodeArrayList[i];
1383             for (let j = 1; j < element.length; j++) {
1384                 for (let k = j; k < vnfcSetArrayLen; k++) {
1385                     if (element[j] === vnfcSetArray[k]) {
1386                         element[j] = 'Y';
1387                     }
1388                     else {
1389                         element.splice(j, 0, '');
1390                     }
1391                     break;
1392                 }
1393             }
1394         }
1395         this.firstArrayElement = vnfcSetArray;
1396         this.remUploadedDataArray = vnfcFunctionCodeArrayList;
1397        }
1398     }
1399 }