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