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