APPC CDT to Support Multiple Templates for VNFCs
[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 { ReferenceDataFormUtil } from './reference-dataform.util';
40 import { UtilityService } from '../../../shared/services/utilityService/utility.service';
41 import { appConstants } from '../../../../constants/app-constants';
42 // Common Confirm Modal
43 import { DialogService } from 'ng2-bootstrap-modal';
44 import { ConfirmComponent } from "../../../shared/confirmModal/confirm.component";
45
46 declare var $: any;
47 type AOA = Array<Array<any>>;
48 const REFERENCE_DATA:string= "reference_data";
49
50 @Component({
51     selector: 'reference-dataform',
52     templateUrl: './reference-dataform.component.html',
53     styleUrls: ['./reference-dataform.component.css'],
54     providers: [ReferenceDataFormUtil]
55 })
56 export class ReferenceDataformComponent implements OnInit {
57     public classNm= "ReferenceDataformCompon";
58     @ViewChild(ModalComponent) modalComponent: ModalComponent;
59     public showUploadStatus: boolean = false;
60     public fileUploaded: boolean = false;
61     public uploadedData: any;
62     public statusMsg: string;
63     public uploadStatus: boolean = false;
64     public isCollapsedContent: boolean = true;
65     public vnfcCollLength: number = 0;
66     public vfncCollection = [];
67     public userForm: any;
68     public actionType: any;
69     numberTest: RegExp = /^[^.a-z]+$/;
70     public numberOfVmTest: boolean = true;
71     public tempAllData = [];
72     disableGrpNotationValue: boolean;
73     public noRefData = false;
74     public disableRetrieve = false;
75     public getRefStatus = false;
76     public uploadStatusError: boolean;
77     public showUploadErrorStatus: boolean;
78     public noData: string;
79     selectedActions = [];
80     public appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
81     public downloadData = {
82         reference: {},
83         template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
84         pd: { pdData: '', pdFileName: '' }
85     };
86     errorMessage = '';
87     invalid = true;
88     fileName: any;
89     vnfcIdentifier;
90     oldVnfcIdentifier: any;
91     public uploadFileName: any;
92     public addVmClickedFlag: boolean = false;
93     public getExcelUploadStatus: boolean = false;
94     public uploadedDataArray: any;
95     public actionFlag = false;
96     currentAction: any;
97     oldAction: any;
98     nonConfigureAction: any;
99     templateId;
100     newVnfcType;
101     templateIdentifier;
102     public actionLevels = [
103         'vnfc', 'vnf'
104     ];
105     oldtemplateIdentifier: any
106     identifierDrp: any;
107     identifierDrpValues: any = [];
108     //settings for the notifications.
109     options = {
110         timeOut: 1000,
111         showProgressBar: true,
112         pauseOnHover: true,
113         clickToClose: true,
114         maxLength: 200
115     };
116     //initializing this object to contain all the parameters to be captured
117     public referenceDataObject = {
118         action: '',
119         'action-level': 'vnf',
120         scope: { 'vnf-type': '', 'vnfc-type-list': [] },
121         'template': 'Y',
122         vm: [],
123         'device-protocol': '',
124         'user-name': '',
125         'port-number': '',
126         'artifact-list': []
127     };
128     public refernceScopeObj = { sourceType: '', from: '', to: '' };
129     public actions = [ appConstants.Actions.blank, 
130                         appConstants.Actions.configure,
131                         appConstants.Actions.ConfigModify,
132                         appConstants.Actions.configBackup,
133                         appConstants.Actions.configRestore,
134                         appConstants.Actions.getRunningConfig,
135                         appConstants.Actions.healthCheck,
136                         appConstants.Actions.startApplication,
137                         appConstants.Actions.stopApplication,
138                         appConstants.Actions.quiesceTraffic,
139                         appConstants.Actions.resumeTraffic,
140                         appConstants.Actions.upgradeBackout,
141                         appConstants.Actions.upgradeBackup,
142                         appConstants.Actions.upgradePostCheck,
143                         appConstants.Actions.upgradePreCheck,
144                         appConstants.Actions.upgradeSoftware,
145                         appConstants.Actions.openStackActions,
146                         appConstants.Actions.configScaleOut
147                     ];
148     public groupAnotationValue = [appConstants.groupAnotationValue.blank, appConstants.groupAnotationValue.pair];
149     public groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue];
150     public deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.ansible, appConstants.DeviceProtocols.chef, appConstants.DeviceProtocols.netconfXML, appConstants.DeviceProtocols.rest, appConstants.DeviceProtocols.cli, appConstants.DeviceProtocols.restConf];
151     public deviceTemplates = [appConstants.deviceTemplates.blank, appConstants.deviceTemplates.y, appConstants.deviceTemplates.n];
152     public sourceTypeColl = [appConstants.sourceTypeColl.blank, appConstants.sourceTypeColl.vnfType, appConstants.sourceTypeColl.vnfcType];
153     public ipAddressBoolean = ['', 'Y', 'N'];
154     public Sample: any = {
155         'vnfc-instance': '1',
156         'vnfc-function-code': '',
157         'ipaddress-v4-oam-vip': '',
158         'group-notation-type': '',
159         'group-notation-value': ''
160     };
161     hideModal: boolean = false;
162     public self: any;
163     public uploadTypes = [{
164         value: 'Reference Data',
165         display: 'Sample Json Param File'
166     },
167     {
168         value: 'Mapping Data',
169         display: 'Sample Json Param File'
170     }
171     ];
172     public selectedUploadType: string = this.uploadTypes[0].value;
173     public vnfcTypeData: string = '';
174     public title: string;
175     public allowAction: boolean = true;
176     public actionExist: boolean = false;
177     public disableVnftype: boolean = false;
178     public otherActions: boolean = false;
179     public actionHealthCheck: boolean = false;
180     public actionChanged: boolean = false;
181     public initialAction: string = '';
182     public noCacheData: boolean;
183     public updateParams: any;
184     public vnfParams: any;
185     public firstArrayElement = [];
186     public remUploadedDataArray = [];
187     isConfigScaleOut = false
188     isConfigOrConfigModify = false;
189     configScaleOutExist: boolean = true;
190     displayVnfc = 'false';
191     isVnfcType: boolean;
192     isVnfcTypeList: boolean = true;
193     public actionList = {
194         "ConfigScaleOut": "ConfigScaleOut",
195         "Configure": "Configure" 
196     };
197     public versionNoForApiCall = "0.0.1";
198     private displayVMBlock: boolean = true;
199
200     constructor(
201       private buildDesignComponent: BuildDesignComponent,
202       private httpUtils: HttpUtilService, 
203       private route: Router, 
204       private location: Location, 
205       private activeRoutes: ActivatedRoute, 
206       private notificationService: NotificationService,
207       private paramShareService: ParamShareService, 
208       private mappingEditorService: MappingEditorService, 
209       private modalService: NgbModal, 
210       private nService: NotificationsService, 
211       private ngProgress: NgProgress,
212       private utilityService: UtilityService,
213       private dialogService: DialogService,
214       private referenceDataFormUtil: ReferenceDataFormUtil )
215     {
216       console.log( this.classNm+": new: start.");
217     }
218
219     ngOnInit() {
220       console.log( this.classNm+": ngOnInit: start.");
221         this.displayVnfc = sessionStorage.getItem("vnfcSelectionFlag");
222         if (this.configScaleOutExist) {
223             this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions', 'ConfigScaleOut'];
224         } else {
225             this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions'];
226         }
227         this.self = this;
228         let path = this.location.path;
229         this.title = 'Reference Data';
230         this.referenceDataObject = {
231             action: '',
232             'action-level': 'vnf',
233             scope: { 'vnf-type': '', 'vnfc-type-list': [] },
234             'template': 'Y',
235             vm: [],
236             'device-protocol': '',
237             'user-name': '',
238             'port-number': '',
239             'artifact-list': []
240         };
241         this.updateParams = sessionStorage.getItem('updateParams');
242         let cacheData = this.mappingEditorService.referenceNameObjects;
243         if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
244             this.tempAllData = cacheData;
245             if (this.mappingEditorService.latestAction != undefined) {
246                 this.referenceDataObject = this.mappingEditorService.latestAction;
247                 this.toggleIdentifier(this.referenceDataObject.action);
248                 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
249                 this.oldAction = this.referenceDataObject.action;
250                 this.populateExistinAction(this.referenceDataObject.action);
251                 this.displayHideVnfc();
252             }
253         } else if (this.updateParams != 'undefined') {
254             this.getArtifact();
255         }
256         var appData = this.mappingEditorService.appDataObject;
257         if (appData != null || appData != undefined) this.appData = appData;
258         var downloadData = this.mappingEditorService.downloadDataObject;
259         if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
260         if (sessionStorage.getItem('vnfParams')) {
261             this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
262         }
263         if (this.vnfParams && this.vnfParams.vnfType) {
264           console.log( this.classNm+": ngOnInit: vnfParams.vnfType:["+
265             this.vnfParams.vnfType+"]");
266             this.referenceDataObject['scope']['vnf-type']= this.vnfParams.vnfType;
267         }
268         if (this.vnfParams && this.vnfParams.vnfcType) {
269           console.log( this.classNm+": ngOnInit: vnfParams.vnfcType:["+
270             this.vnfParams.vnfcType+"]");
271            this.referenceDataObject['scope']['vnfc-type']= this.vnfParams.vnfcType;
272         }
273         this.uploadedDataArray = [];
274         this.remUploadedDataArray = [];
275         this.firstArrayElement = [];
276         this.uploadFileName = '';
277         this.templateIdentifier = this.mappingEditorService.identifier
278         this.oldVnfcIdentifier = this.vnfcIdentifier;
279           console.log( this.classNm+": ngOnInit: displayVnfc:["+this.displayVnfc+"]");
280           console.log( this.classNm+": ngOnInit: templateIdentifier:["+
281             this.templateIdentifier+"]");
282         // Enable or Block Template and PD Tabs
283         this.buildDesignComponent.getRefData(
284           { ...this.referenceDataObject,  displayVnfc: this.displayVnfc },
285           { reqField: this.templateIdentifier });
286         this.configDrp(this.referenceDataObject.action)
287     }
288
289     toggleIdentifier(data) {
290         if (data == 'ConfigScaleOut') {
291             this.isConfigScaleOut = true
292
293         } else {
294             this.isConfigScaleOut = false
295         }
296     }
297
298     //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
299     getArtifact() {
300         console.log( this.classNm+": getArtifact: start.");
301         try {
302             let data = this.utilityService.createPayloadForRetrieve(true, '', '', '');
303             this.ngProgress.start();
304             this.httpUtils.post({
305                 url: environment.getDesigns,
306                 data: data
307             }).subscribe(resp => {
308                 console.log( this.classNm+": getArtifact: got response ...");
309                 if (resp.output.data.block != undefined) {
310                     console.log( this.classNm+
311                       ": getArtifact: output.data.block not empty.");
312                     this.nService.success(appConstants.notifications.titles.status, appConstants.messages.datafetched);
313                     let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
314                     let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
315                     this.referenceDataObject = reference_data;
316                     this.toggleIdentifier(this.referenceDataObject.action);
317                     if (this.referenceDataObject.action == appConstants.Actions.configScaleOut) {
318                         this.groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue, appConstants.groupAnotationType.existingGroupName];
319                     }
320                     //chck vnfc or vnfcTypeList
321                     this.displayHideVnfc();
322                     // Enable or Block Template and PD Tabs
323                     this.buildDesignComponent.getRefData(
324                       {...this.referenceDataObject, displayVnfc: this.displayVnfc } );
325                     this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
326                     this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
327                     this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
328                     this.oldAction = this.referenceDataObject.action;
329                     this.oldVnfcIdentifier = this.vnfcIdentifier;
330                     if (this.referenceDataObject.action === appConstants.Actions.openStackActions) {
331                         this.deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.openStack];
332                         this.buildDesignComponent.tabs = [
333                             {
334                                 name: 'Reference Data',
335                                 url: 'references',
336                             }];
337                     }
338                     else {
339                         this.buildDesignComponent.tabs = [
340                             {
341                                 name: 'Reference Data',
342                                 url: 'references',
343                             }, {
344                                 name: 'Template',
345                                 url: 'templates/myTemplates',
346                             }, {
347                                 name: 'Parameter Definition',
348                                 url: 'parameterDefinitions/create'
349                             }/*, {
350                                 name: "Test",
351                                 url: 'test',
352                             }*/
353                         ];
354                     }
355                     this.getArtifactsOpenStack();
356                 } else {
357                     this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(sessionStorage.getItem('updateParams')))['artifact-name']);
358                 }
359                 this.ngProgress.done();
360             });
361         }
362         catch (e) {
363             this.nService.warn('status', 'error while reteriving artifact');
364         }
365         setTimeout(() => {
366             this.ngProgress.done();
367         }, 3500);
368     }
369
370     displayHideVnfc() {
371         if( this.utilityService.getTracelvl() > 0 )
372           console.log(this.classNm+": displayHideVnfc: start...");
373         if( this.utilityService.getTracelvl() > 1 ) {
374           if( this.referenceDataObject.scope['vnfc-type-list'] ) {
375             console.log( this.classNm+
376               ": displayHideVnfc: refDataObj.scope.vnfc-type-list.length="+
377               this.referenceDataObject.scope['vnfc-type-list'].length );
378           } else {
379             console.log( this.classNm+
380               ": displayHideVnfc: refDataObj.scope.vnfc-type-list not defined");
381           };
382           console.log( this.classNm+": displayHideVnfc: scope.vnfc-type:["+
383             this.referenceDataObject.scope['vnfc-type']+"]");
384         };
385         if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && (this.referenceDataObject.scope['vnfc-type'] != undefined || this.referenceDataObject.scope['vnfc-type'] != "")) {
386             this.isVnfcType = true
387             this.displayVnfc = 'true'
388             this.isVnfcTypeList = false
389         }
390         if (this.referenceDataObject.scope['vnfc-type-list'] != undefined && this.referenceDataObject.scope['vnfc-type-list'].length != 0 && (this.referenceDataObject.scope['vnfc-type'] == undefined || this.referenceDataObject.scope['vnfc-type'] == "")) {
391             this.isVnfcType = false
392             this.displayVnfc = 'true'
393             this.isVnfcTypeList = true
394             if(!this.mappingEditorService.newObject.vnfc) {
395                 this.vnfcIdentifier = this.referenceDataObject.scope['vnfc-type-list'][0];
396                 // this.mappingEditorService.newObject.vnfc = this.vnfcIdentifier;
397                 // this.referenceDataObject['vnfcIdentifier'] = this.vnfcIdentifier;
398
399             } else {
400                 this.vnfcIdentifier = this.mappingEditorService.newObject.vnfc;
401             }
402             if( this.utilityService.getTracelvl() > 0 )
403               console.log(this.classNm+": displayHideVnfc: vnfcIdentifier:["+
404                 this.vnfcIdentifier+"]");
405         }
406         if (this.referenceDataObject.scope['vnfc-type-list'] != undefined && this.referenceDataObject.scope['vnfc-type-list'].length == 0 && this.referenceDataObject.scope['vnfc-type'] != undefined && this.referenceDataObject.scope['vnfc-type'].length == 0) {
407             if(this.displayVnfc == 'true') {
408                 this.isVnfcType = false
409                 this.displayVnfc = 'true'
410                 this.isVnfcTypeList = true
411             } else {
412                 this.isVnfcType = false
413                 this.displayVnfc = 'false'
414                 this.isVnfcTypeList = false
415             }
416         }
417         if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && this.referenceDataObject.scope['vnfc-type'] == '') {
418             this.isVnfcType = false
419             this.displayVnfc = 'false'
420             this.isVnfcTypeList = false
421         }
422       if( this.utilityService.getTracelvl() > 0 )
423         console.log(this.classNm+": displayHideVnfc: finish. isVnfcType:["+
424           this.isVnfcType+" displayVnfc:["+this.displayVnfc+"] isVnfcTypeList:["+
425           this.isVnfcTypeList+"]");
426     }
427
428     //reinitializing the required values
429     ngOnDestroy() {
430         console.log( this.classNm+": ngOnDestroy: start:"+
431             " vnfcIdentifier:["+this.vnfcIdentifier+"]");
432         let referenceObject = this.prepareReferenceObject();
433         this.mappingEditorService.changeNavAppData(this.appData);
434         this.mappingEditorService.changeNavDownloadData(this.downloadData);
435         this.uploadedDataArray = [];
436         this.remUploadedDataArray = [];
437         this.firstArrayElement = [];
438         this.uploadFileName = '';
439     }
440
441     numberValidation(event: any) {
442         if (this.numberTest.test(event) && event != 0) {
443             this.numberOfVmTest = true;
444         }
445         else {
446             this.numberOfVmTest = false;
447         }
448     }
449     // update my vnf pop up session values
450     updateSessionValues(event: any, type: string) {
451         if (type === 'action') {
452             sessionStorage.setItem('action', event);
453         }
454         if (type === 'vnfType') {
455             sessionStorage.setItem('vnfType', event);
456         }
457     }
458
459     addVnfcData(vmNumber: number) {
460         var newObj = {
461             'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
462             'vnfc-type': this.vnfcTypeData,
463             'vnfc-function-code': '',
464             'ipaddress-v4-oam-vip': '',
465             'group-notation-type': '',
466             'group-notation-value': ''
467         };
468         this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
469     }
470
471     //validating the vnf and vnfc data in the pop up
472     validateVnfcName(name) {
473         console.log( this.classNm+": validateVnfcName: start: name:["+name+"]");
474         if (!name.trim() || name.length < 1) {
475             this.errorMessage = '';
476             this.invalid = true;
477         } else if (name.startsWith(' ') || name.endsWith(' ')) {
478             this.errorMessage = 'Leading and trailing spaces are not allowed';
479             this.invalid = true;
480         } else if (name.includes('  ')) {
481             this.errorMessage = 'More than one space is not allowed in VNFC Type';
482             this.invalid = true;
483         } else if (name.length > 50) {
484             this.errorMessage = 'VNFC Type should be of minimum one character and maximum 50 character';
485             this.invalid = true;
486         } else {
487             this.invalid = false;
488             this.errorMessage = '';
489         }
490     }
491
492     //to remove the VM's created by the user
493     removeFeature(vmNumber: any, index: any, templateId) {
494         if (this.referenceDataObject.action == "Configure") {
495             this.referenceDataObject.vm.splice(vmNumber, 1);
496             this.referenceDataObject.vm.forEach((obj, arrIndex) => {
497                 if (arrIndex >= vmNumber) {
498                     obj["vm-instance"] = obj["vm-instance"] - 1
499                 }
500             })
501         } else {
502             let data = this.referenceDataObject.vm.filter(obj => {
503                 return obj['template-id'] == templateId;
504             })
505
506             let vmIndex = this.findVmindex(data, vmNumber, templateId)
507             this.referenceDataObject.vm.splice(vmIndex, 1);
508             let index = 0
509             this.referenceDataObject.vm.forEach((obj, arrIndex) => {
510                 if (obj['template-id'] == templateId) {
511
512                     obj["vm-instance"] = index + 1
513                     index++
514                 }
515
516             })
517         }
518
519     }
520     findVmindex(data, vmNumber, templateId) {
521         return this.referenceDataObject.vm.findIndex(obj => {
522             let x = obj['vm-instance'] == (vmNumber + 1) && templateId == obj['template-id']//true
523             return x
524         })
525
526     }
527
528     //add new VM's to the configure
529     addVms() {
530         let arr = [];
531         let mberOFVm = Number(this.refernceScopeObj.from);
532         if (this.referenceDataObject.action == 'ConfigScaleOut') {
533             let existingVmsLength = this.referenceDataObject.vm.filter(obj => {
534                 return obj['template-id'] == this.templateIdentifier
535             }).length;
536             mberOFVm = existingVmsLength + mberOFVm;
537             let index = 0;
538             for (var i = (existingVmsLength); i < mberOFVm; i++) {
539
540                 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (existingVmsLength + index + 1), vnfc: [Object.assign({}, this.Sample)] });
541                 index++;
542             }
543
544         } else {
545             let arrlength = this.referenceDataObject.vm.length;
546             mberOFVm = arrlength + mberOFVm;
547             for (var i = (arrlength); i < mberOFVm; i++) {
548                 if (this.referenceDataObject.action == 'ConfigScaleOut') {
549                     this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
550                 } else {
551                     this.referenceDataObject.vm.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
552                 }
553             }
554         }
555     }
556
557     //Reference object to create reference data
558     prepareReferenceObject(isSaving?: any) {
559         console.log( this.classNm+": prepareReferenceObject: start.");
560         let scopeName = this.resetParamsOnVnfcType();
561         let extension = this.decideExtension(this.referenceDataObject);
562         this.prepareArtifactList(scopeName, extension);
563         if (this.referenceDataObject.action === 'OpenStack Actions') {
564             this.referenceDataObject['template'] = 'N';
565             this.referenceDataObject['artifact-list'] = [];
566             this.referenceDataObject['firstRowVmSpreadSheet']=this.firstArrayElement;
567         }
568         //detaching the object from the form and processing further
569         let newObj = $.extend(true, {}, this.referenceDataObject);
570         let action = this.referenceDataObject.action;
571         newObj = this.deleteVmsforNonActions(newObj, action)
572         this.pushOrReplaceTempData(newObj, action);
573         this.addAllActionObj(newObj, scopeName);
574         this.resetTempData()
575         //saving data to service
576         this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
577         this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
578         this.mappingEditorService.changeNav(this.tempAllData);
579         //on action change or template identifier change reset the form by restting values of Reference data object
580         this.resetVmsForScaleout(this.currentAction)
581         return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
582     }
583
584     public checkIfelementExistsInArray(element, array) {
585         //// console.log("Element==" + element)
586         var result: boolean = false;
587
588         array.forEach(function (item) {
589             // // console.log("Item==" + item)
590             if (element === item) {
591                 // console.log('Element==' + element + 'Item==' + item);
592                 result = true;
593             }
594         }
595         );
596         return result;
597     }
598
599     upload(evt: any) {
600         console.log( this.classNm+": upload: start.");
601        /* wire up file reader */
602         const target: DataTransfer = <DataTransfer>(evt.target);
603         this.uploadFileName = evt.target.files[0].name;
604         var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
605         if (target.files.length != 1) {
606           console.log( this.classNm+": upload: Error: got no file !");
607             throw new Error(appConstants.errors.multipleFileUploadError);
608         }
609         console.log( this.classNm+": upload: filename:["+evt.target.files[0].name+"]");
610         if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
611             const reader = new FileReader();
612             reader.onload = (e: any) => {
613                 /* read workbook */
614                 const bstr = e.target.result;
615                 //      // console.log("print 1---" + bstr);
616                 const wb = XLSX.read(bstr, { type: 'binary' });
617                 //    // console.log("print 2---" + JSON.stringify(wb));
618                 /* grab first sheet */
619                 const wsname = wb.SheetNames[0];
620                 //  // console.log("Name:---" + wsname);
621                 const ws = wb.Sheets[wsname];
622
623                 /* save data */
624
625                 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
626                 this.uploadedDataArray = arrData;
627                 this.firstArrayElement = arrData[0];
628                 var remUploadedDataArray = arrData;
629                 remUploadedDataArray.shift();
630                 this.remUploadedDataArray = remUploadedDataArray;
631                 if (arrData != null) {
632                     this.getExcelUploadStatus = true;
633                     this.nService.success(appConstants.notifications.titles.success, appConstants.messages.vmDataUploadSuccess);
634
635                 }
636                 else {
637                     this.nService.success(appConstants.notifications.titles.error, appConstants.messages.emptyVmUpload);
638                 }
639             };
640             reader.readAsBinaryString(target.files[0]);
641         }
642         else {
643             this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectVmUpload);
644         }
645
646     }
647
648     addVmCapabilitiesData() {
649         console.log( this.classNm+": addVmCapabilitiesData: start.");
650         for (var i = 0; i < this.uploadedDataArray.length; i++) {
651             var vnfcFuncCodeArray = [];
652             var data = this.uploadedDataArray[i];
653             for (var j = 1; j < data.length; j++) {
654                 if (data[j] != undefined) {
655                     if (data[j].toUpperCase() === 'Y') {
656                         vnfcFuncCodeArray.push(this.firstArrayElement[j]);
657                     }
658                 }
659             }
660             var action = this.uploadedDataArray[i][0];
661             if (action && action != undefined) {
662                 var json = {
663                     'action': action,
664                     'action-level': 'vm',
665                     'scope': {
666                         'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
667                         'vnfc-type': null
668                     },
669                     'vnfc-function-code-list': vnfcFuncCodeArray,
670                     'template': 'N',
671                     'device-protocol': 'OS'
672                 };
673
674                 this.tempAllData.push(json);
675             }
676
677         }
678     }
679
680     //download template
681     save(form: any, isValid: boolean) {
682         console.log( this.classNm+": save: start: referenceDataObject.action:["+
683           this.referenceDataObject.action+"]");
684         if (this.referenceDataObject.action === '') {
685             this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
686             return;
687         }
688         if (this.referenceDataObject['device-protocol'] === '') {
689             this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
690             return;
691         }
692
693         if (isValid) {
694             let referenceObject = this.prepareReferenceObject();
695             let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
696             let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
697             this.downloadData.reference = theJSON;
698             this.validateTempAllData();
699             var blob = new Blob([theJSON], {
700                 type: 'text/plain'
701             });
702             let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
703             this.downloadFile(blob, fileName, 100)
704             var templateData = JSON.stringify(this.downloadData.template.templateData);
705             var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
706             var pdData = this.downloadData.pd.pdData;
707             if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
708             if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
709             if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
710         }
711     }
712     downloadFile(blob, fileName, delay) {
713         console.log( this.classNm+": downloadFile: start.");
714         setTimeout(() => {
715             saveAs(blob, fileName);
716         }, delay)
717     }
718
719     downloadTemplate() {
720         console.log( this.classNm+": downloadTemplate: start.");
721         var fileName = this.downloadData.template.templateFileName;
722         console.log( this.classNm+": downloadTemplate: fileName:["+fileName+"]");
723         var theJSON = this.downloadData.template.templateData;
724         if (fileName != null || fileName != '') {
725             var fileExtensionArr = fileName.split('.');
726             var blob = new Blob([theJSON], {
727                 type: 'text/' + fileExtensionArr[1]
728             });
729             this.downloadFile(blob, fileName, 130)
730         }
731     }
732
733     downloadNameValue() {
734         var fileName = this.downloadData.template.nameValueFileName;
735         var theJSON = this.downloadData.template.nameValueData;
736         var blob = new Blob([theJSON], {
737             type: 'text/json'
738         });
739
740         this.downloadFile(blob, fileName, 160)
741     }
742
743     downloadPd() {
744         let fileName = this.downloadData.pd.pdFileName;
745         let theJSON = this.downloadData.pd.pdData;
746         var blob = new Blob([theJSON], {
747             type: 'text/plain'
748         });
749
750         this.downloadFile(blob, fileName, 180)
751     }
752
753     // save the values to the cache, on action change without download
754     validateDataAndSaveToAppc( valid, form, event) {
755         console.log( this.classNm+": validateDataAndSaveToAppc: start: valid:"+valid);
756         // will show error message
757         this.showValidationErrors(this.referenceDataObject);
758         try {
759             form._submitted = true;
760             if (valid) {
761                 let referenceObject = this.prepareReferenceObject(true);
762                 let removedKeysArray = []
763                 this.tempAllData.forEach((data, index) => {
764                   if (data.action) {
765                     removedKeysArray.push(JSON.parse(JSON.stringify(this.deleteUnwantedKeys(data))))
766                   }
767                 });
768                 this.tempAllData = removedKeysArray;
769
770                 this.validateTempAllData();
771                 this.saveToAppc();
772                 if (this.actionChanged) {
773                     this.clearVnfcData()
774                     if (this.currentAction) {
775                         this.referenceDataObject.action = this.currentAction;
776                     }
777
778                     this.populateExistinAction(this.referenceDataObject.action);
779                     this.actionChanged = false;
780                 }
781             }
782         }
783         catch (e) {
784             this.nService.warn('status', 'unable to save the artifact');
785         }
786     }
787
788     //this method saves reference, template, param and PD data to APPC
789     saveToAppc() {
790         console.log( this.classNm+": saveToAppc: start: vnf-type:["+
791           this.referenceDataObject.scope['vnf-type']+"]");
792         let theJSON = JSON.stringify(this.tempAllData, null, '\t');
793         let fileName = 'reference_AllAction_' + this.referenceDataObject.scope['vnf-type'].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V.json';
794         this.saveReferenceDataToAppc(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
795
796         var templateData = JSON.stringify(this.appData.template.templateData);
797         var nameValueData = JSON.stringify(this.appData.template.nameValueData);
798         var pdData = JSON.stringify(this.appData.pd);
799         if (templateData != '{}' && templateData != null && templateData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.templateData, 'template data');
800         if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.nameValueData, 'name value pairs');
801         if (pdData != '{}' && pdData != null && pdData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.pd, 'PD file');
802     }
803
804     // valaidation of template data
805     validateTempAllData() {
806         console.log( this.classNm+": validateTempAllData: start.");
807         if (this.tempAllData) {
808             var updatedData = [];
809             this.tempAllData.forEach(data => {
810                 if (data.action) {
811                     updatedData.push(data);
812                 }
813             });
814             this.tempAllData = updatedData;
815         }
816     }
817
818     //.. prepare and send the data to the API.
819     saveReferenceDataToAppc(artifactData, dataJson, fileName) {
820         console.log( this.classNm+": saveReferenceDataToAppc: start.");
821         let data = [];
822         let slashedPayload = this.referenceDataFormUtil.appendSlashes(artifactData);
823         let payload = this.utilityService.createPayLoadForSave("reference_data", dataJson['scope']['vnf-type'], "AllAction", fileName, this.versionNoForApiCall, slashedPayload);
824         this.ngProgress.start();
825         this.httpUtils.post({
826             url: environment.getDesigns,
827             data: payload
828         }).subscribe((resp) => {
829             if (resp != null && resp.output.status.code == '400') {
830                 window.scrollTo(0, 0);
831                 this.nService.success('Status', 'successfully uploaded the Reference Data');
832             } else {
833                 this.nService.warn('Status', 'Error while saving Reference Data');
834             }
835             this.uploadStatusError = false;
836             this.getRefStatus = false;
837             this.ngProgress.done();
838         }, (err) => {
839             this.nService.error('Status', 'Error Connecting to the APPC Network');
840             window.scrollTo(0, 0);
841         });
842         this.appData.reference = payload;
843         setTimeout(() => {
844             this.ngProgress.done();
845         }, 3500);
846     }
847
848     retriveFromAppc() {
849         console.log( this.classNm+": retriveFromAppc: start.");
850         if (sessionStorage.getItem('updateParams') != 'undefined') {
851             this.getArtifact();
852             this.noCacheData = false;
853         } else {
854             this.noCacheData = true;
855         }
856     }
857
858     cloneMessage(servermessage) {
859         var clone = {};
860         for (var key in servermessage) {
861             if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
862                 clone[key] = servermessage[key];
863         }
864         return clone;
865     }
866
867     public showUpload() {
868         this.selectedUploadType = this.uploadTypes[0].value;
869     };
870
871     public fileChange(input) {
872       if( this.utilityService.getTracelvl() > 0 )
873         console.log( this.classNm+": fileChange: start.");
874         this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
875         this.fileUploaded = true;
876         this.disableRetrieve = true;
877         if (input.target.files && input.target.files[0]) {
878             // Create the file reader
879             let reader = new FileReader();
880             this.readFile(input.target.files[0], reader, (result) => {
881                 // After the callback fires do:
882                 if ('Reference Data' === this.selectedUploadType) {
883                     try {
884                         let obj: any;
885                         let jsonObject = (JSON.parse(result))['reference_data'];
886                         this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
887                         //check for legacy artifact and do not allow it
888                         for (let i = 0; i < this.uploadedData.length; i++) {
889                             obj = this.uploadedData[i];
890                             if (obj.scope['vnfc-type'] != undefined && obj.scope['vnfc-type'] != '') {
891                                 this.nService.error('Error', 'The legacy reference artifact not supported');
892                                 return;
893                             }
894                         }
895                         this.displayVnfc = 'false';
896                         this.isVnfcType = false;
897                         this.isVnfcTypeList = false;
898                         for (let i = 0; i < this.uploadedData.length; i++) {
899                             obj = this.uploadedData[i];
900                             if (obj.scope['vnfc-type-list'] && obj.scope['vnfc-type-list'].length > 0) {
901                                 this.displayVnfc = 'true';
902                                 this.isVnfcTypeList = true;
903                                 this.vnfcIdentifier = obj.scope['vnfc-type-list'][0];
904                             }
905                         }
906                         this.oldAction=obj.action;
907                         this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
908                       if( this.utilityService.getTracelvl() > 0 )
909                         console.log( this.classNm+": fileChange: read & parsed.");
910                         this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
911                         if (jsonObject instanceof Array) {
912                             this.referenceDataObject = jsonObject[0];
913                             jsonObject.forEach(obj => {
914                                 this.selectedActions.push(obj.action);
915                             });
916                         } else {
917                             this.referenceDataObject = jsonObject;
918
919                             this.selectedActions.push(jsonObject.action);
920                         }
921                       if( this.utilityService.getTracelvl() > 0 )
922                         console.log( this.classNm+": fileChange: "+
923                           "referenceDataObject.action:["+
924                           this.referenceDataObject.action+"]");
925                         this.toggleIdentifier(this.referenceDataObject.action)
926                         this.configDrp(this.referenceDataObject.action)
927                         if (this.referenceDataObject.action === 'OpenStack Actions') {
928                             this.deviceProtocols = ['', 'OpenStack'];
929                             this.buildDesignComponent.tabs = [
930                                 {
931                                     type: 'dropdown',
932                                     name: 'Reference Data',
933                                     url: 'references',
934                                 }];
935                         }
936                         else {
937                             this.buildDesignComponent.tabs = [
938                                 {
939                                     name: 'Reference Data',
940                                     url: 'references',
941                                 }, {
942                                     name: 'Template',
943                                     url: 'templates/myTemplates',
944                                 }, {
945                                     name: 'Parameter Definition',
946                                     url: 'parameterDefinitions/create'
947                                 } /*, {
948         name: "Test",
949         url: 'test',
950       }*/
951                             ];
952                         }
953                         this.getArtifactsOpenStack();
954                         if (this.referenceDataObject.template == null) {
955                             this.referenceDataObject.template = 'Y';
956                         }
957                         if (this.referenceDataObject['action-level'] == null) {
958                             this.referenceDataObject['action-level'] = 'VNF';
959                         }
960                       if( this.utilityService.getTracelvl() > 0 )
961                         console.log( this.classNm+": fileChange: displayVnfc:["+
962                           this.displayVnfc+"]");
963                         // Enable or Block Template and PD Tabs
964                         this.buildDesignComponent.getRefData(
965                           { ...this.referenceDataObject, displayVnfc: this.displayVnfc });
966                     } catch (e) {
967                         this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectFileFormat);
968                     }
969                 }
970                 this.hideModal = true;
971             });
972         } else {
973           if( this.utilityService.getTracelvl() > 0 )
974             console.log( this.classNm+": fileChange: Error: Failed to read file!");
975             this.notificationService.notifyErrorMessage('Failed to read file..');
976         }
977     }
978
979     public readFile(file, reader, callback) {
980         console.log( this.classNm+": readFile: start.");
981         // Set a callback funtion to fire after the file is fully loaded
982         reader.onload = () => {
983             // callback with the results
984             callback(reader.result);
985         };
986         this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
987         // Read the file
988         reader.readAsText(file, 'UTF-8');
989     }
990
991     fileChangeEvent(fileInput: any) {
992         let obj: any = fileInput.target.files;
993     }
994
995     clearVnfcData() {
996         console.log( this.classNm+": clearVnfcData: start.");
997         this.Sample = {
998             'vnfc-instance': '1',
999             'vnfc-function-code': '',
1000             'ipaddress-v4-oam-vip': '',
1001             'group-notation-type': '',
1002             'group-notation-value': ''
1003         };
1004     }
1005
1006     setVmInstance(index) {
1007         this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
1008     }
1009
1010    // setVnfcType(str: String) {
1011    //     this.Sample['vnfc-type'] = str;
1012    // }
1013
1014    // getChange(value: String) {
1015    //     if (value === 'vnfType') {
1016    //         this.referenceDataObject.scope['vnfc-type'] = '';
1017    //     }
1018    // }
1019
1020     resetForm() {
1021         console.log( this.classNm+": resetForm: start.");
1022         this.referenceDataObject['action-level'] = 'vnf';
1023         this.referenceDataObject.template = 'Y';
1024         this.referenceDataObject['device-protocol'] = '';
1025         this.referenceDataObject['user-name'] = '';
1026         this.referenceDataObject['port-number'] = '';
1027         this.refernceScopeObj.sourceType = '';
1028         this.Sample['vnfc-type'] = '';
1029     }
1030
1031     // this method gets called with the action as parameter and the respective action details are fetched and assigned to the current page
1032     populateExistinAction(data) {
1033         console.log( this.classNm+": populateExistinAction: start.");
1034         let existAction = this.tempAllData.findIndex(obj => {
1035             return obj.action == data;
1036         });
1037         if (existAction > -1) {
1038             let obj = $.extend(true, {}, this.tempAllData[existAction]);
1039             this.referenceDataObject = obj;
1040             this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
1041             this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
1042             this.referenceDataObject['device-protocol'] = obj['device-protocol'];
1043             this.refernceScopeObj['sourceType'] = obj['scopeType'];
1044             if(obj['scope']['vnfc-type-list'] != undefined && obj['scope']['vnfc-type-list'].length >0) {
1045                 this.referenceDataObject['vnfcIdentifier'] = obj['scope']['vnfc-type-list'][0];
1046             }
1047         } else {
1048             console.log( this.classNm+": populateExistinAction: action not found");
1049             this.resetForm();
1050             this.referenceDataObject.action = data;
1051         }
1052         //# iof healthCeck change deviceprotocol drp vaues
1053         switch (data) {
1054             case 'HealthCheck':
1055                 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
1056                 this.actionHealthCheck = true;
1057                 break;
1058             case 'UpgradeBackout':
1059             case 'ResumeTraffic':
1060             case 'QuiesceTraffic':
1061             case 'UpgradeBackup':
1062             case 'UpgradePostCheck':
1063             case 'UpgradePreCheck':
1064             case 'UpgradeSoftware':
1065             case 'ConfigRestore':
1066             case 'StartApplication':
1067             case 'StopApplication':
1068             case 'ConfigBackup':
1069                 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
1070                 break;
1071             case 'OpenStack Actions':
1072                 this.deviceProtocols = ['', 'OpenStack'];
1073                 break;
1074             case 'ConfigScaleOut':
1075                 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
1076                 break;
1077             case 'GetRunningConfig':
1078                 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF', 'CLI', 'REST'];
1079                 break;
1080             default:
1081                 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
1082                 this.actionHealthCheck = false;
1083         }
1084     }
1085
1086     //Modal pop up for action change with values entered.
1087     actionChange(data, userForm) {
1088       var methName= "actionChange";
1089         console.log( this.classNm+": "+methName+": start: data:["+data+"]");
1090         this.disableGrpNotationValue = false
1091         if (data == null) {
1092             console.log( this.classNm+": "+methName+": data == null");
1093             return;
1094         }
1095         if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
1096             this.actionChanged = true;
1097             console.log( this.classNm+": "+methName+
1098               ": userForm valid and oldAction defined");
1099             // Calling common Confirmation Modal
1100             let disposable = this.dialogService.addDialog(ConfirmComponent)
1101                 .subscribe((isConfirmed)=>{
1102                     //We get dialog result
1103                     console.log( this.classNm+": "+methName+":  isConfirmed:["+
1104                       isConfirmed+"]");
1105                     if(isConfirmed) {
1106                         // User clicked on Yes
1107                         this.currentAction = this.referenceDataObject.action;
1108                         console.log( this.classNm+": "+methName+
1109                           ": clicked on Yes: currentAction:["+this.currentAction+
1110                           "] oldAction:["+this.oldAction+"]");
1111                         this.referenceDataObject.action = this.oldAction;
1112                         $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
1113                         this.toggleIdentifier(data)
1114                         this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
1115                         this.referenceDataObject.action = this.currentAction;
1116                         this.populateExistinAction(data);
1117                         if (this.oldAction === 'OpenStack Actions') {
1118
1119                             this.uploadedDataArray = [];
1120                             this.remUploadedDataArray = [];
1121                             this.firstArrayElement = [];
1122                             this.uploadFileName = '';
1123                             //this.tempAllData = [];
1124                         }
1125                         this.clearCache();
1126                         this.refernceScopeObj.from = '';
1127                         this.getArtifactsOpenStack();
1128
1129                         // Clears VNFC Information data on action change
1130                         this.clearVnfcData()
1131                         this.resetVmsForScaleout(data);
1132                     }
1133                     else {
1134                         // User clicked on No
1135                         this.toggleIdentifier(data)
1136                         this.currentAction = this.referenceDataObject.action;
1137                         console.log( this.classNm+": "+methName+
1138                           ": clicked on No: currentAction:["+this.currentAction+"]");
1139                         this.populateExistinAction(data);
1140                         this.resetVmsForScaleout(data);
1141                         this.oldAction = this.referenceDataObject.action + '';
1142                         this.clearCache();
1143                         this.clearVnfcData()
1144                         this.refernceScopeObj.from = '';
1145                     }
1146
1147                     if (this.referenceDataObject.action === 'Configure' || this.referenceDataObject.action === 'ConfigModify') {
1148                         this.isConfigOrConfigModify = true;
1149                     } else {
1150                         this.isConfigOrConfigModify = false;
1151                         delete this.mappingEditorService.newObject['vnfc'];
1152                     }
1153
1154                     // Enable or Block Template and PD Tabs
1155                     if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier && this.templateIdentifier != '') {
1156                         // let referenceDataObjectTemp = this.referenceDataObject;
1157                         // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1158                         // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1159                         this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1160
1161                     } else {
1162                         this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1163                     }
1164                 });
1165         } else {
1166             console.log( this.classNm+": "+methName+
1167               ": userForm Not valid or oldAction not defined");
1168             this.actionChanged = true;
1169             this.currentAction = this.referenceDataObject.action;
1170             this.oldAction = this.referenceDataObject.action + '';
1171             this.populateExistinAction(data);
1172             this.resetVmsForScaleout(data);
1173             this.toggleIdentifier(data);
1174
1175             // Enable or Block Template and PD Tabs
1176             if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
1177                 // let referenceDataObjectTemp = this.referenceDataObject;
1178                 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1179                 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1180                 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1181             } else {
1182                 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1183             }
1184         }
1185         this.configDrp(data)
1186     }
1187
1188     configDrp(data) {
1189         console.log( this.classNm+": configDrp: start: data:["+data+"]");
1190         if (data == 'ConfigScaleOut') {
1191             this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
1192         } else {
1193             this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
1194         }
1195         if (data == 'OpenStack Actions') {
1196             this.buildDesignComponent.tabs = [
1197                 {
1198                     type: 'dropdown',
1199                     name: 'Reference Data',
1200                     url: 'references',
1201                 }];
1202         }
1203         else {
1204             this.buildDesignComponent.tabs = [
1205                 {
1206                     name: 'Reference Data',
1207                     url: 'references',
1208                 }, {
1209                     name: 'Template',
1210                     url: 'templates/myTemplates',
1211                 }, {
1212                     name: 'Parameter Definition',
1213                     url: 'parameterDefinitions/create'
1214                 }/*, {
1215                     name: "Test",
1216                     url: 'test',
1217                 }*/
1218             ];
1219         }
1220         if (data == 'Configure' || data == 'ConfigModify') {
1221             this.nonConfigureAction = false;
1222         } else {
1223             this.nonConfigureAction = true;
1224         }
1225     }
1226
1227     deviceProtocolChange() {
1228         console.log( this.classNm+": deviceProtocolChange: start.");
1229         if (this.referenceDataObject['device-protocol'] == 'REST') {
1230
1231         } else {
1232             delete this.referenceDataObject['context-url']
1233         }
1234         // Enable or Block Template and PD Tabs
1235         this.buildDesignComponent.getRefData(
1236           {...this.referenceDataObject,displayVnfc: this.displayVnfc },
1237           {reqField: this.templateIdentifier});
1238     }
1239
1240     // used to call or trigger save object on template Identifier changes
1241     idChange(data, userForm) {
1242         console.log( this.classNm+": idChange: start: data:["+data+"]");
1243         if (data == null) {
1244             return;
1245         }
1246         // Enable or Block Template and PD Tabs
1247         // let referenceDataObjectTemp = this.referenceDataObject;
1248         // referenceDataObjectTemp['template-id'] = data;
1249         // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1250         this.buildDesignComponent.getRefData(
1251           {...this.referenceDataObject, displayVnfc: this.displayVnfc },
1252           { reqField: data });
1253
1254         if ((userForm.valid)) {
1255             this.currentAction = "ConfigScaleOut"
1256             this.oldtemplateIdentifier = this.templateIdentifier
1257             let referenceObject = this.prepareReferenceObject();
1258             this.actionChanged = true;
1259             if (this.templateIdentifier) {
1260                  // Calling common Confirmation Modal
1261                  let disposable = this.dialogService.addDialog(ConfirmComponent)
1262                  .subscribe((isConfirmed)=>{
1263                      //We get dialog result
1264                      if(isConfirmed) {
1265                          // User clicked on Yes
1266                          this.validateTempAllData();
1267                          this.saveToAppc();
1268                          this.clearCache();
1269                          this.clearVnfcData();
1270                          this.refernceScopeObj.from = '';
1271                      }
1272                      else {
1273                          // User clicked on No
1274                          this.clearCache();
1275                          this.refernceScopeObj.from = '';
1276                      }
1277                  });
1278             }
1279         } else {
1280             this.oldtemplateIdentifier = this.templateIdentifier;
1281         }
1282     }
1283
1284     // used to call or trigger save object on multiple VNFC's changes
1285     vnfcChanged( data, userForm) {
1286         console.log( this.classNm+": vnfcChanged: new vnfcIdentifier:["+data+"]");
1287         console.log( this.classNm+": vnfcChanged: oldVnfcIdentifier:["+
1288           this.oldVnfcIdentifier+"]");
1289         console.log(this.classNm+": vnfcChanged:  scope.vnfc-type:["+
1290           this.referenceDataObject.scope['vnfc-type']+"]");
1291         this.vnfcIdentifier = data;
1292         this.clearCache();
1293         if (data == null) {
1294             return;
1295         }
1296       //.. populate VNFC Type in Sample field
1297       this.setVnfcTypeInSample( this.vnfcIdentifier );
1298         // Enable or Block Template and PD Tabs
1299         let referenceDataObjectTemp = this.referenceDataObject;
1300         referenceDataObjectTemp['vnfcIdentifier'] = data;
1301         console.log( this.classNm+
1302           ": vnfcChanged: displayVnfc:["+this.displayVnfc+"]");
1303         this.buildDesignComponent.getRefData(
1304           {...this.referenceDataObject, displayVnfc: this.displayVnfc },
1305           { reqField: data });
1306         console.log( this.classNm+
1307           ": vnfcChanged: userForm.valid:["+userForm.valid+"]");
1308         if ((userForm.valid) && this.oldVnfcIdentifier != '' && this.oldVnfcIdentifier != undefined) {
1309             this.currentAction = this.referenceDataObject.action
1310             this.oldVnfcIdentifier = this.vnfcIdentifier
1311             let referenceObject = this.prepareReferenceObject();
1312             this.actionChanged = true;
1313             if (this.vnfcIdentifier) {
1314                  // Calling common Confirmation Modal
1315                  let disposable = this.dialogService.addDialog(ConfirmComponent)
1316                  .subscribe((isConfirmed)=>{
1317                      //We get dialog result
1318                      if(isConfirmed) {
1319                          // User clicked on Yes
1320                          this.validateTempAllData();
1321                          this.saveToAppc();
1322                          this.clearCache();
1323                          this.clearVnfcData()
1324                          this.refernceScopeObj.from = '';
1325                      }
1326                      else {
1327                          // User clicked on No
1328                          this.clearCache();
1329                          this.refernceScopeObj.from = '';
1330                      }
1331                  });
1332             }
1333         } else {
1334             if (data != null) {
1335                 this.oldVnfcIdentifier = this.vnfcIdentifier
1336             }
1337         }
1338     }
1339
1340     clearCache() {
1341         console.log( this.classNm+": clearCache: start.");
1342         // get the value and save the userid and persist it.
1343         this.clearTemplateCache();
1344         this.clearPdCache();
1345         this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
1346         this.downloadData = {
1347             reference: {},
1348             template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
1349             pd: { pdData: '', pdFileName: '' }
1350         };
1351     }
1352
1353     clearTemplateCache() {
1354         this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
1355         localStorage['paramsContent'] = '{}';
1356     }
1357     clearPdCache() {
1358         this.mappingEditorService.setParamContent(undefined);
1359         this.paramShareService.setSessionParamData(undefined);
1360     }
1361
1362     saveTemp() {
1363         console.log( this.classNm+": saveTemp: start.");
1364         this
1365             .httpUtils
1366             .post(
1367                 { url: environment.getDesigns, data: this.appData.template.templateData })
1368             .subscribe(resp => {
1369                 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1370                     this.nService.success('Status', 'Successfully uploaded the Template Data');
1371                 }
1372                 if (resp.output.status.code === '401') {
1373                     this.nService.warn('Status', 'Error in saving the Template to Appc');
1374
1375                 }
1376             },
1377                 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1378     }
1379
1380     saveNameValue() {
1381         console.log( this.classNm+": saveNameValue: start.");
1382         this
1383             .httpUtils
1384             .post(
1385                 {
1386                     url: environment.getDesigns, data: this.appData.template.nameValueData
1387                 })
1388             .subscribe(resp => {
1389                 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1390                     this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1391                 }
1392                 if (resp.output.status.code === '401') {
1393                     this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1394                 }
1395             },
1396                 error => {
1397                     this.nService.error('Status', 'Error Connecting to the APPC Network');
1398                     return false;
1399                 });
1400     }
1401
1402     savePd() {
1403         this
1404             .httpUtils
1405             .post(
1406                 {
1407                     url: environment.getDesigns, data: this.appData.pd
1408                 })
1409             .subscribe(resp => {
1410                 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1411                     this.nService.success('Status', 'Successfully uploaded PD file');
1412                 }
1413                 if (resp.output.status.code === '401') {
1414                     this.nService.warn('Status', 'Error in saving the PD to Appc');
1415                 }
1416             },
1417                 error => {
1418                     this.nService.error('Status', 'Error Connecting to the APPC Network');
1419                     return false;
1420                 });
1421     }
1422
1423     openModel(toShow: any, message: any, title: any) {
1424         console.log( this.classNm+": openModel: start: title:["+title+"]");
1425         this.modalComponent.isShow = toShow;
1426         this.modalComponent.message = message;
1427         this.modalComponent.title = title;
1428     }
1429
1430     browseOption() {
1431         $('#inputFile').trigger('click');
1432     }
1433
1434     excelBrowseOption() {
1435         $('#excelInputFile').trigger('click');
1436     }
1437
1438     showIdentifier() {
1439         $('#identifierModal').modal();
1440     }
1441
1442     addToIdentDrp() {
1443         if (!(this.referenceDataObject['template-id-list'])) {
1444             this.referenceDataObject['template-id-list'] = [];
1445         }
1446         if (!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim()) > -1)) {
1447             this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1448         }
1449         // Changing value to blank otherwise it will show previous value in text box of popup
1450         this.templateId = '';
1451     }
1452
1453     // adds the vnfc to the vnfc dropdown list
1454     addVnfc() {
1455       var newVnfcTypeV= this.newVnfcType.trim();
1456         console.log(this.classNm+
1457           ": addVnfc: start: newVnfcTypeV:["+newVnfcTypeV+"]");
1458         if (!(this.referenceDataObject.scope['vnfc-type-list'])) {
1459             this.referenceDataObject.scope['vnfc-type-list'] = [];
1460         //  this.vnfcIdentifier = newVnfcTypeV;
1461         } else if (this.referenceDataObject.scope['vnfc-type-list'].length == 0){
1462         //  this.vnfcIdentifier = newVnfcTypeV;
1463         }
1464         this.vnfcIdentifier = newVnfcTypeV;
1465         console.log(this.classNm+
1466           ": addVnfc: vnfcIdentifier:["+this.vnfcIdentifier+"]");
1467         if (!(this.referenceDataObject.scope['vnfc-type-list'].indexOf(newVnfcTypeV) > -1)) {
1468             this.referenceDataObject.scope['vnfc-type-list'].push(newVnfcTypeV);
1469         }
1470         this.tempAllData.forEach(obj => {
1471             if (obj.action == "Configure" || obj.action == "ConfigModify") {
1472                 obj.scope['vnfc-type-list'] = this.referenceDataObject.scope['vnfc-type-list']
1473             }
1474             this.resetArtifactList(obj);
1475         });
1476         console.log(this.classNm+": addVnfc: scope vnfc-type:["+
1477           this.referenceDataObject.scope['vnfc-type']+"]");
1478       this.setVnfcTypeInSample( newVnfcTypeV );
1479         // Changing newVnfcType value to blank otherwise it will show previous value in text box of popup
1480         this.newVnfcType = ''
1481     }
1482
1483     resetVms() {
1484         console.log( this.classNm+": resetVms: start.");
1485         this.referenceDataObject.vm = [];
1486     }
1487
1488     dataModified() {
1489         //  this.referenceDataObject.vm = this.referenceDataObject.vm;
1490     }
1491
1492     resetGroupNotation() {
1493         if (this.Sample['group-notation-type'] == "existing-group-name") {
1494             this.Sample['group-notation-value'] = ""
1495             this.disableGrpNotationValue = true
1496         } else {
1497             this.disableGrpNotationValue = false
1498         }
1499     }
1500
1501     resetVmsForScaleout(action) {
1502         //reset currentform vms based on action
1503         if (action == "ConfigScaleOut" || action == "Configure") {
1504             let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1505                 return obj['action'] == action
1506             });
1507             if (ConfigScaleOutIndex > -1) {
1508                 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1509             } else {
1510                 if (this.actionChanged) {
1511                     this.referenceDataObject.vm = []
1512                 }
1513             }
1514         }
1515     }
1516
1517     resetParamsOnVnfcType() {
1518         console.log( this.classNm+": resetParamsOnVnfcType: start:\n "+
1519           "ref.DataObject.scope vnfc-type:["+
1520           this.referenceDataObject.scope['vnfc-type']+"]");
1521         let scopeName = '';
1522         //if only vnf is there
1523         if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1524             scopeName = this.referenceDataObject.scope['vnf-type'];
1525             this.referenceDataObject.scope['vnfc-type'] = '';
1526             this.referenceDataObject['action-level'] = 'vnf';
1527             this.referenceDataObject['scopeType'] = 'vnf-type';
1528         }
1529         //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  
1530         else {
1531             scopeName = this.referenceDataObject.scope['vnfc-type'];
1532             if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify') {
1533                 this.referenceDataObject['action-level'] = 'vnfc';
1534                 this.referenceDataObject['scopeType'] = 'vnfc-type';
1535             } else {
1536                 this.referenceDataObject['action-level'] = 'vnf';
1537                 this.referenceDataObject['scopeType'] = 'vnf-type';
1538             }
1539         }
1540         //replacing / with _ and removing spaces in the scopeName
1541         if (scopeName) {
1542             scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1543         }
1544         console.log( this.classNm+": resetParamsOnVnfcType: return scopeName:["+
1545           scopeName+"]");
1546         return scopeName
1547     }
1548
1549     decideExtension(obj) {
1550         //marking the extension based on the device-protocol selected by the user 
1551         let extension = '.json';
1552         switch (obj['device-protocol']) {
1553             case 'ANSIBLE':
1554             case 'CHEF':
1555             case 'CLI':
1556                 extension = '.json';
1557                 break;
1558             case 'NETCONF-XML':
1559             case 'REST':
1560                 extension = '.xml';
1561                 break;
1562         }
1563         return extension;
1564     }
1565     prepareArtifactList(scopeName, extension) {
1566         console.log( this.classNm+": prepareArtifactList: start: scopeName:["+
1567           scopeName+"] extension:["+extension+"]");
1568         this.referenceDataObject['artifact-list'] = [];
1569         //preparing the artifact list array file names along with extension
1570         let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.' + extension;
1571         let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1572         let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1573         let configTemplate = {
1574             'artifact-name': 'template_' + config_template_fileName,
1575             'artifact-type': 'config_template'
1576         };
1577         let pdTemplate = {
1578             'artifact-name': 'pd_' + pd_fileName,
1579             'artifact-type': 'parameter_definitions'
1580         };
1581         if (this.referenceDataObject.action != 'ConfigScaleOut') {
1582             this.referenceDataObject['artifact-list'].push(configTemplate,
1583                 pdTemplate
1584             );
1585         } else {
1586             let identifiers = this.referenceDataObject['template-id-list'];
1587             if (identifiers) {
1588                 for (var x = 0; x < identifiers.length; x++) {
1589                     //for replacing spaces and "/" with "_"
1590                     identifiers[x] = identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1591                     pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1592                     config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.' + extension;
1593
1594                     configTemplate = {
1595                         'artifact-name': 'template_' + config_template_fileName,
1596                         'artifact-type': 'config_template'
1597                     };
1598                     pdTemplate = {
1599                         'artifact-name': 'pd_' + pd_fileName,
1600                         'artifact-type': 'parameter_definitions'
1601                     };
1602                     this.referenceDataObject['artifact-list'].push(configTemplate,
1603                         pdTemplate
1604                     );
1605                 }
1606             }
1607
1608         }
1609     }
1610     deleteVmsforNonActions(newObj, action) {
1611         let configureObject = (action == 'Configure');
1612         let ConfigScaleOut = (action == 'ConfigScaleOut');
1613         //delete VM's if selected action is not configure.
1614         if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1615             if (ConfigScaleOut) {
1616             } else {
1617                 newObj.vm = [];
1618             }
1619         } else {
1620             if (ConfigScaleOut) {
1621             } else {
1622                 delete newObj['template-id-list'];
1623             }
1624         }
1625         return newObj
1626     }
1627     pushOrReplaceTempData(newObj, action) {
1628         console.log( this.classNm+": pushOrReplaceTempData: start: action:["+
1629           action+"]\n newObj.scope vnfc-type:["+newObj.scope['vnfc-type']+"]");
1630         if( newObj.scope['vnfc-type'] == undefined ||
1631             newObj.scope['vnfc-type'] == null ||
1632             newObj.scope['vnfc-type'].length < 1 )
1633         {
1634           console.log( this.classNm+": pushOrReplaceTempData: scope vnfc-type"+
1635             " is empty.\n vnfcIdentifier:["+this.vnfcIdentifier+"]");
1636           if( this.vnfcIdentifier.length > 0 ) {
1637             newObj.scope['vnfc-type']= this.vnfcIdentifier;
1638           }
1639         };
1640         let actionObjIndex = this.tempAllData.findIndex(obj => {
1641             return obj['action'] == action;
1642         });
1643         if (newObj.action != 'HealthCheck') {
1644             delete newObj['url'];
1645         }
1646
1647         if (actionObjIndex > -1) {
1648             this.tempAllData[actionObjIndex] = newObj;
1649             this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1650             if (newObj.action == "ConfigScaleOut") {
1651                 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1652             }
1653             else {
1654                 this.templateIdentifier = ('')
1655                 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1656             }
1657         } else {
1658             if (newObj.action != '') {
1659                 this.tempAllData.push(newObj);
1660                 this.mappingEditorService.saveLatestAction(newObj);
1661                 if (newObj.action == "ConfigScaleOut") {
1662                     this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1663                 }
1664                 else {
1665                     this.templateIdentifier = ('')
1666                     this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1667                 }
1668             }
1669         }
1670
1671     }
1672
1673     // removes the unwanted keys added in the artifact for vnfc level actions
1674     deleteUnwantedKeys(newObj) {
1675         console.log( this.classNm+": deleteUnwantedKeys: start.");
1676         newObj = JSON.parse(JSON.stringify(newObj))
1677         delete newObj['template-id']
1678         delete newObj['vnfcIdentifier']
1679         if (newObj.action != "ConfigScaleOut") {
1680             delete newObj['template-id-list']
1681         }
1682         if (newObj.action != 'HealthCheck') {
1683             delete newObj['url'];
1684         }
1685         if (newObj.action != "Configure" && newObj.action != "ConfigModify") {
1686             newObj.scope['vnfc-type-list'] = [];
1687         }
1688         return newObj
1689     }
1690
1691     addAllActionObj(newObj, scopeName) {
1692         console.log( this.classNm+": addAllActionObj: start.");
1693         //Creating all action block to allow mulitple actions at once
1694         let allAction = {
1695             action: 'AllAction',
1696             'action-level': 'vnf',
1697             scope: newObj.scope,
1698             'artifact-list': [{
1699                 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1700                 'artifact-type': 'reference_template'
1701             }]
1702         };
1703         let allActionIndex = this.tempAllData.findIndex(obj => {
1704             return obj['action'] == 'AllAction';
1705         });
1706         if (allActionIndex > -1) {
1707             this.tempAllData[allActionIndex] = allAction;
1708         } else {
1709             this.tempAllData.push(allAction);
1710         }
1711     }
1712
1713     resetTempData() {
1714         console.log( this.classNm+": resetTempData: start.");
1715         if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1716             if (this.tempAllData && this.tempAllData != undefined) {
1717                 for (var i = 0; i < this.tempAllData.length; i++) {
1718                     var result = false;
1719                     if (this.tempAllData[i].action === 'AllAction') {
1720                         result = true;
1721                     }
1722                     else {
1723                         result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1724                     }
1725                     if (!result) {
1726                         this.tempAllData.splice(i, 1);
1727                         i = i - 1;
1728                     }
1729
1730                 }
1731             }
1732             this.addVmCapabilitiesData();
1733         }
1734     }
1735
1736     trackByFn(index, item) {
1737         return index;
1738     }
1739
1740     getArtifactsOpenStack() {
1741       console.log( this.classNm+": getArtifactsOpenStack: start: "+
1742         "tempAllData length="+this.tempAllData.length );
1743         var array = []
1744         var vnfcFunctionCodeArrayList = [];
1745         var vnfcSetArray=[];
1746         for (var i = 0; i < this.tempAllData.length; i++) {
1747             if (!this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions) && (this.tempAllData[i].action != 'AllAction')) {
1748                 var vnfcFunctionCodeArray = this.tempAllData[i]["vnfc-function-code-list"]
1749                 vnfcFunctionCodeArrayList.push([this.tempAllData[i].action].concat(this.tempAllData[i]["vnfc-function-code-list"]))
1750             }
1751             if(this.tempAllData[i].action==='OpenStack Actions')
1752             {
1753                 vnfcSetArray=this.tempAllData[i]['firstRowVmSpreadSheet']
1754             }
1755         }
1756       console.log( this.classNm+": getArtifactsOpenStack: vnfcSetArray length="+
1757        vnfcSetArray.length );
1758        if(vnfcSetArray)
1759        {
1760         let vnfcSetArrayLen = vnfcSetArray.length;
1761
1762         for (let i = 0; i < vnfcFunctionCodeArrayList.length; i++) {
1763             let element = vnfcFunctionCodeArrayList[i];
1764             for (let j = 1; j < element.length; j++) {
1765                 for (let k = j; k < vnfcSetArrayLen; k++) {
1766                     if (element[j] === vnfcSetArray[k]) {
1767                         element[j] = 'Y';
1768                     }
1769                     else {
1770                         element.splice(j, 0, '');
1771                     }
1772                     break;
1773                 }
1774             }
1775         }
1776         this.firstArrayElement = vnfcSetArray;
1777         this.remUploadedDataArray = vnfcFunctionCodeArrayList;
1778        }
1779     }
1780
1781     /**
1782      * Handles the display of VM block based on the action change
1783      */
1784     handleVMBlockDisplay() {
1785         switch (this.referenceDataObject.action) {
1786             case this.actionList.ConfigScaleOut:
1787             case this.actionList.Configure:
1788             case undefined:
1789             case '':
1790                 this.displayVMBlock = true;
1791                 break;
1792             default:
1793                 this.displayVMBlock = false;
1794         }
1795     }
1796
1797   //.. check VNFC Type equality in Upper Selection vs entered in Sample field
1798   checkVnfcTypeEqual( vnfctp: string ) {
1799     var methName= "checkVnfcTypeEqual";
1800       console.log(this.classNm+": "+methName+": vnfctp:["+vnfctp+"]");
1801       console.log( this.classNm+": "+methName+": vnfcIdentifier:["+
1802         this.vnfcIdentifier+"]");
1803       console.log( this.classNm+": "+methName+":  Sample[vnfc-type]:["+
1804         this.Sample['vnfc-type']+"]");
1805     if( vnfctp != null && vnfctp.length > 0 ) {
1806       if( this.vnfcIdentifier != null && this.vnfcIdentifier.length > 0 ) {
1807         console.log(
1808           this.classNm+": "+methName+": compare non empty VNFC Types...");
1809         if( vnfctp != this.vnfcIdentifier ) {
1810             console.log( this.classNm+": "+methName+": Non-match WARNING !");
1811           //.. display in pop-up
1812           this.nService.warn( 'WARNING',
1813             "The specified VNFC Types don't match."+
1814             " Can cause discrepancy in the artifacts.", this.options );
1815         } else {
1816             console.log(this.classNm+": checkVnfcTypeEqual: VNFC Types're equal.");
1817         };
1818       };
1819     };
1820   };
1821
1822   //.. populating VNFC Type in Sample fields
1823   setVnfcTypeInSample( vnfctp: string ) {
1824    // if( this.utilityService.getTracelvl() > 0 )
1825       console.log( this.classNm+": setVnfcTypeInSample: vnfctp:["+vnfctp+"]");
1826     this.Sample['vnfc-type']= vnfctp;
1827   };
1828
1829     // Common method to show validation errors
1830     private showValidationErrors(referenceDataObject) {
1831         if (this.referenceDataObject.action === '') {
1832             this.nService.error('Error', 'Select a valid Action');
1833             return;
1834         }
1835         if (this.referenceDataObject['device-protocol'] === '') {
1836             this.nService.error('Error', 'Select a valid Device protocol');
1837             return;
1838         }
1839
1840         if (referenceDataObject.action === 'ConfigScaleOut' && !this.templateIdentifier) {
1841             this.nService.error('Error', 'Select a valid Template Identifier');
1842         }
1843     }
1844
1845     resetArtifactList( obj) {
1846         console.log( this.classNm+": resetArtifactList: start...");
1847         let vnfcTypeList = obj.scope['vnfc-type-list'];
1848         let vnf = this.referenceDataObject.scope['vnf-type']
1849         let pd_fileName
1850         let config_template_fileName
1851         let configTemplate
1852         let pdTemplate
1853         let paramValue
1854         let param_fileName
1855         obj['artifact-list'] = [];
1856         for (var x = 0; x < vnfcTypeList.length; x++) {
1857             let extension = this.referenceDataFormUtil.decideExtension(obj)
1858             //for replacing spaces and "/" with "_"
1859             let type = vnfcTypeList[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1860             pd_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.yaml';
1861             config_template_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V' + extension;
1862             param_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.json';
1863             configTemplate = {
1864                 'artifact-name': 'template_' + config_template_fileName,
1865                 'artifact-type': 'config_template'
1866             };
1867             pdTemplate = {
1868                 'artifact-name': 'pd_' + pd_fileName,
1869                 'artifact-type': 'parameter_definitions'
1870             };
1871             paramValue = {
1872                 'artifact-name': 'param_' + param_fileName,
1873                 'artifact-type': 'param_values'
1874             };
1875
1876             this.referenceDataObject['artifact-list'].push(configTemplate,
1877                 pdTemplate, paramValue
1878             );
1879             obj['artifact-list'].push(configTemplate,
1880                 pdTemplate, paramValue
1881             );
1882         }
1883     }
1884 }