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
13 http://www.apache.org/licenses/LICENSE-2.0
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============================================
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";
47 type AOA = Array<Array<any>>;
48 const REFERENCE_DATA:string= "reference_data";
51 selector: 'reference-dataform',
52 templateUrl: './reference-dataform.component.html',
53 styleUrls: ['./reference-dataform.component.css'],
54 providers: [ReferenceDataFormUtil]
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 = [];
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;
80 public appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
81 public downloadData = {
83 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
84 pd: { pdData: '', pdFileName: '' }
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;
98 nonConfigureAction: any;
102 public actionLevels = [
105 oldtemplateIdentifier: any
107 identifierDrpValues: any = [];
108 //settings for the notifications.
111 showProgressBar: true,
116 //initializing this object to contain all the parameters to be captured
117 public referenceDataObject = {
119 'action-level': 'vnf',
120 scope: { 'vnf-type': '', 'vnfc-type-list': [] },
123 'device-protocol': '',
128 public refernceScopeObj = { sourceType: '', from: '', to: '' };
129 public actions = [ appConstants.Actions.blank,
130 appConstants.Actions.configure,
131 appConstants.Actions.ConfigModify,
132 appConstants.Actions.configBackup,
133 appConstants.Actions.configRestore,
134 appConstants.Actions.getRunningConfig,
135 appConstants.Actions.healthCheck,
136 appConstants.Actions.startApplication,
137 appConstants.Actions.stopApplication,
138 appConstants.Actions.quiesceTraffic,
139 appConstants.Actions.resumeTraffic,
140 appConstants.Actions.upgradeBackout,
141 appConstants.Actions.upgradeBackup,
142 appConstants.Actions.upgradePostCheck,
143 appConstants.Actions.upgradePreCheck,
144 appConstants.Actions.upgradeSoftware,
145 appConstants.Actions.openStackActions,
146 appConstants.Actions.configScaleOut
148 public groupAnotationValue = [appConstants.groupAnotationValue.blank, appConstants.groupAnotationValue.pair];
149 public groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue];
150 public deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.ansible, appConstants.DeviceProtocols.chef, appConstants.DeviceProtocols.netconfXML, appConstants.DeviceProtocols.rest, appConstants.DeviceProtocols.cli, appConstants.DeviceProtocols.restConf];
151 public deviceTemplates = [appConstants.deviceTemplates.blank, appConstants.deviceTemplates.y, appConstants.deviceTemplates.n];
152 public sourceTypeColl = [appConstants.sourceTypeColl.blank, appConstants.sourceTypeColl.vnfType, appConstants.sourceTypeColl.vnfcType];
153 public ipAddressBoolean = ['', 'Y', 'N'];
154 public Sample: any = {
155 'vnfc-instance': '1',
156 'vnfc-function-code': '',
157 'ipaddress-v4-oam-vip': '',
158 'group-notation-type': '',
159 'group-notation-value': ''
161 hideModal: boolean = false;
163 public uploadTypes = [{
164 value: 'Reference Data',
165 display: 'Sample Json Param File'
168 value: 'Mapping Data',
169 display: 'Sample Json Param File'
172 public selectedUploadType: string = this.uploadTypes[0].value;
173 public vnfcTypeData: string = '';
174 public title: string;
175 public allowAction: boolean = true;
176 public actionExist: boolean = false;
177 public disableVnftype: boolean = false;
178 public otherActions: boolean = false;
179 public actionHealthCheck: boolean = false;
180 public actionChanged: boolean = false;
181 public initialAction: string = '';
182 public noCacheData: boolean;
183 public updateParams: any;
184 public vnfParams: any;
185 public firstArrayElement = [];
186 public remUploadedDataArray = [];
187 isConfigScaleOut = false
188 isConfigOrConfigModify = false;
189 configScaleOutExist: boolean = true;
190 displayVnfc = 'false';
192 isVnfcTypeList: boolean = true;
193 public actionList = {
194 "ConfigScaleOut": "ConfigScaleOut",
195 "Configure": "Configure"
197 public versionNoForApiCall = "0.0.1";
198 private displayVMBlock: boolean = true;
201 private buildDesignComponent: BuildDesignComponent,
202 private httpUtils: HttpUtilService,
203 private route: Router,
204 private location: Location,
205 private activeRoutes: ActivatedRoute,
206 private notificationService: NotificationService,
207 private paramShareService: ParamShareService,
208 private mappingEditorService: MappingEditorService,
209 private modalService: NgbModal,
210 private nService: NotificationsService,
211 private ngProgress: NgProgress,
212 private utilityService: UtilityService,
213 private dialogService: DialogService,
214 private referenceDataFormUtil: ReferenceDataFormUtil )
216 console.log( this.classNm+": new: start.");
220 console.log( this.classNm+": ngOnInit: start.");
221 this.displayVnfc = sessionStorage.getItem("vnfcSelectionFlag");
222 if (this.configScaleOutExist) {
223 this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions', 'ConfigScaleOut'];
225 this.actions = ['', 'Configure', 'ConfigModify', 'ConfigBackup', 'ConfigRestore', 'GetRunningConfig', 'HealthCheck', 'StartApplication', 'StopApplication', 'QuiesceTraffic', 'ResumeTraffic', 'UpgradeBackout', 'UpgradeBackup', 'UpgradePostCheck', 'UpgradePreCheck', 'UpgradeSoftware', 'OpenStack Actions'];
228 let path = this.location.path;
229 this.title = 'Reference Data';
230 this.referenceDataObject = {
232 'action-level': 'vnf',
233 scope: { 'vnf-type': '', 'vnfc-type-list': [] },
236 'device-protocol': '',
241 this.updateParams = sessionStorage.getItem('updateParams');
242 let cacheData = this.mappingEditorService.referenceNameObjects;
243 if (cacheData != undefined && cacheData != null && cacheData.length > 0) {
244 this.tempAllData = cacheData;
245 if (this.mappingEditorService.latestAction != undefined) {
246 this.referenceDataObject = this.mappingEditorService.latestAction;
247 this.toggleIdentifier(this.referenceDataObject.action);
248 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
249 this.oldAction = this.referenceDataObject.action;
250 this.populateExistinAction(this.referenceDataObject.action);
251 this.displayHideVnfc();
253 } else if (this.updateParams != 'undefined') {
256 var appData = this.mappingEditorService.appDataObject;
257 if (appData != null || appData != undefined) this.appData = appData;
258 var downloadData = this.mappingEditorService.downloadDataObject;
259 if (downloadData != null || downloadData != undefined) this.downloadData = downloadData;
260 if (sessionStorage.getItem('vnfParams')) {
261 this.vnfParams = JSON.parse(sessionStorage.getItem('vnfParams'));
263 if (this.vnfParams && this.vnfParams.vnfType) {
264 console.log( this.classNm+": ngOnInit: vnfParams.vnfType:["+
265 this.vnfParams.vnfType+"]");
266 this.referenceDataObject['scope']['vnf-type']= this.vnfParams.vnfType;
268 if (this.vnfParams && this.vnfParams.vnfcType) {
269 console.log( this.classNm+": ngOnInit: vnfParams.vnfcType:["+
270 this.vnfParams.vnfcType+"]");
271 this.referenceDataObject['scope']['vnfc-type']= this.vnfParams.vnfcType;
273 this.uploadedDataArray = [];
274 this.remUploadedDataArray = [];
275 this.firstArrayElement = [];
276 this.uploadFileName = '';
277 this.templateIdentifier = this.mappingEditorService.identifier
278 this.oldVnfcIdentifier = this.vnfcIdentifier;
279 console.log( this.classNm+": ngOnInit: displayVnfc:["+this.displayVnfc+"]");
280 console.log( this.classNm+": ngOnInit: templateIdentifier:["+
281 this.templateIdentifier+"]");
282 // Enable or Block Template and PD Tabs
283 this.buildDesignComponent.getRefData(
284 { ...this.referenceDataObject, displayVnfc: this.displayVnfc },
285 { reqField: this.templateIdentifier });
286 this.configDrp(this.referenceDataObject.action)
289 toggleIdentifier(data) {
290 if (data == 'ConfigScaleOut') {
291 this.isConfigScaleOut = true
294 this.isConfigScaleOut = false
298 //to retrive the data from appc and assign it to the vaiables, if no data display the message reterived from the API
300 console.log( this.classNm+": getArtifact: start.");
302 let data = this.utilityService.createPayloadForRetrieve(true, '', '', '');
303 this.ngProgress.start();
304 this.httpUtils.post({
305 url: environment.getDesigns,
307 }).subscribe(resp => {
308 console.log( this.classNm+": getArtifact: got response ...");
309 if (resp.output.data.block != undefined) {
310 console.log( this.classNm+
311 ": getArtifact: output.data.block not empty.");
312 this.nService.success(appConstants.notifications.titles.status, appConstants.messages.datafetched);
313 let artifactInfo = JSON.parse(resp.output.data.block).artifactInfo[0];
314 let reference_data = JSON.parse(artifactInfo['artifact-content'])['reference_data'][0];
315 this.referenceDataObject = reference_data;
316 this.toggleIdentifier(this.referenceDataObject.action);
317 if (this.referenceDataObject.action == appConstants.Actions.configScaleOut) {
318 this.groupAnotationType = [appConstants.groupAnotationType.blank, appConstants.groupAnotationType.firstVnfcName, appConstants.groupAnotationType.fixedValue, appConstants.groupAnotationType.relativeValue, appConstants.groupAnotationType.existingGroupName];
320 //chck vnfc or vnfcTypeList
321 this.displayHideVnfc();
322 // Enable or Block Template and PD Tabs
323 this.buildDesignComponent.getRefData(
324 {...this.referenceDataObject, displayVnfc: this.displayVnfc } );
325 this.refernceScopeObj.sourceType = this.referenceDataObject['scopeType'];
326 this.mappingEditorService.getReferenceList().push(JSON.parse(artifactInfo['artifact-content']));
327 this.tempAllData = JSON.parse(artifactInfo['artifact-content'])['reference_data'];
328 this.oldAction = this.referenceDataObject.action;
329 this.oldVnfcIdentifier = this.vnfcIdentifier;
330 if (this.referenceDataObject.action === appConstants.Actions.openStackActions) {
331 this.deviceProtocols = [appConstants.DeviceProtocols.blank, appConstants.DeviceProtocols.openStack];
332 this.buildDesignComponent.tabs = [
334 name: 'Reference Data',
339 this.buildDesignComponent.tabs = [
341 name: 'Reference Data',
345 url: 'templates/myTemplates',
347 name: 'Parameter Definition',
348 url: 'parameterDefinitions/create'
355 this.getArtifactsOpenStack();
357 this.nService.success('Status', 'Sorry !!! I dont have any artifact Named : ' + (JSON.parse(sessionStorage.getItem('updateParams')))['artifact-name']);
359 this.ngProgress.done();
363 this.nService.warn('status', 'error while reteriving artifact');
366 this.ngProgress.done();
371 if( this.utilityService.getTracelvl() > 0 )
372 console.log(this.classNm+": displayHideVnfc: start...");
373 if( this.utilityService.getTracelvl() > 1 ) {
374 if( this.referenceDataObject.scope['vnfc-type-list'] ) {
375 console.log( this.classNm+
376 ": displayHideVnfc: refDataObj.scope.vnfc-type-list.length="+
377 this.referenceDataObject.scope['vnfc-type-list'].length );
379 console.log( this.classNm+
380 ": displayHideVnfc: refDataObj.scope.vnfc-type-list not defined");
382 console.log( this.classNm+": displayHideVnfc: scope.vnfc-type:["+
383 this.referenceDataObject.scope['vnfc-type']+"]");
385 if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && (this.referenceDataObject.scope['vnfc-type'] != undefined || this.referenceDataObject.scope['vnfc-type'] != "")) {
386 this.isVnfcType = true
387 this.displayVnfc = 'true'
388 this.isVnfcTypeList = false
390 if (this.referenceDataObject.scope['vnfc-type-list'] != undefined && this.referenceDataObject.scope['vnfc-type-list'].length != 0 && (this.referenceDataObject.scope['vnfc-type'] == undefined || this.referenceDataObject.scope['vnfc-type'] == "")) {
391 this.isVnfcType = false
392 this.displayVnfc = 'true'
393 this.isVnfcTypeList = true
394 if(!this.mappingEditorService.newObject.vnfc) {
395 this.vnfcIdentifier = this.referenceDataObject.scope['vnfc-type-list'][0];
396 // this.mappingEditorService.newObject.vnfc = this.vnfcIdentifier;
397 // this.referenceDataObject['vnfcIdentifier'] = this.vnfcIdentifier;
400 this.vnfcIdentifier = this.mappingEditorService.newObject.vnfc;
402 if( this.utilityService.getTracelvl() > 0 )
403 console.log(this.classNm+": displayHideVnfc: vnfcIdentifier:["+
404 this.vnfcIdentifier+"]");
406 if (this.referenceDataObject.scope['vnfc-type-list'] != undefined && this.referenceDataObject.scope['vnfc-type-list'].length == 0 && this.referenceDataObject.scope['vnfc-type'] != undefined && this.referenceDataObject.scope['vnfc-type'].length == 0) {
407 if(this.displayVnfc == 'true') {
408 this.isVnfcType = false
409 this.displayVnfc = 'true'
410 this.isVnfcTypeList = true
412 this.isVnfcType = false
413 this.displayVnfc = 'false'
414 this.isVnfcTypeList = false
417 if (this.referenceDataObject.scope['vnfc-type-list'] == undefined && this.referenceDataObject.scope['vnfc-type'] == '') {
418 this.isVnfcType = false
419 this.displayVnfc = 'false'
420 this.isVnfcTypeList = false
422 if( this.utilityService.getTracelvl() > 0 )
423 console.log(this.classNm+": displayHideVnfc: finish. isVnfcType:["+
424 this.isVnfcType+" displayVnfc:["+this.displayVnfc+"] isVnfcTypeList:["+
425 this.isVnfcTypeList+"]");
428 //reinitializing the required values
430 console.log( this.classNm+": ngOnDestroy: start:"+
431 " vnfcIdentifier:["+this.vnfcIdentifier+"]");
432 let referenceObject = this.prepareReferenceObject();
433 this.mappingEditorService.changeNavAppData(this.appData);
434 this.mappingEditorService.changeNavDownloadData(this.downloadData);
435 this.uploadedDataArray = [];
436 this.remUploadedDataArray = [];
437 this.firstArrayElement = [];
438 this.uploadFileName = '';
441 numberValidation(event: any) {
442 if (this.numberTest.test(event) && event != 0) {
443 this.numberOfVmTest = true;
446 this.numberOfVmTest = false;
449 // update my vnf pop up session values
450 updateSessionValues(event: any, type: string) {
451 if (type === 'action') {
452 sessionStorage.setItem('action', event);
454 if (type === 'vnfType') {
455 sessionStorage.setItem('vnfType', event);
459 addVnfcData(vmNumber: number) {
461 'vnfc-instance': this.referenceDataObject.vm[vmNumber].vnfc.length + 1,
462 'vnfc-type': this.vnfcTypeData,
463 'vnfc-function-code': '',
464 'ipaddress-v4-oam-vip': '',
465 'group-notation-type': '',
466 'group-notation-value': ''
468 this.referenceDataObject.vm[vmNumber].vnfc.push(newObj);
471 //validating the vnf and vnfc data in the pop up
472 validateVnfcName(name) {
473 console.log( this.classNm+": validateVnfcName: start: name:["+name+"]");
474 if (!name.trim() || name.length < 1) {
475 this.errorMessage = '';
477 } else if (name.startsWith(' ') || name.endsWith(' ')) {
478 this.errorMessage = 'Leading and trailing spaces are not allowed';
480 } else if (name.includes(' ')) {
481 this.errorMessage = 'More than one space is not allowed in VNFC Type';
483 } else if (name.length > 50) {
484 this.errorMessage = 'VNFC Type should be of minimum one character and maximum 50 character';
487 this.invalid = false;
488 this.errorMessage = '';
492 //to remove the VM's created by the user
493 removeFeature(vmNumber: any, index: any, templateId) {
494 if (this.referenceDataObject.action == "Configure") {
495 this.referenceDataObject.vm.splice(vmNumber, 1);
496 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
497 if (arrIndex >= vmNumber) {
498 obj["vm-instance"] = obj["vm-instance"] - 1
502 let data = this.referenceDataObject.vm.filter(obj => {
503 return obj['template-id'] == templateId;
506 let vmIndex = this.findVmindex(data, vmNumber, templateId)
507 this.referenceDataObject.vm.splice(vmIndex, 1);
509 this.referenceDataObject.vm.forEach((obj, arrIndex) => {
510 if (obj['template-id'] == templateId) {
512 obj["vm-instance"] = index + 1
520 findVmindex(data, vmNumber, templateId) {
521 return this.referenceDataObject.vm.findIndex(obj => {
522 let x = obj['vm-instance'] == (vmNumber + 1) && templateId == obj['template-id']//true
528 //add new VM's to the configure
531 let mberOFVm = Number(this.refernceScopeObj.from);
532 if (this.referenceDataObject.action == 'ConfigScaleOut') {
533 let existingVmsLength = this.referenceDataObject.vm.filter(obj => {
534 return obj['template-id'] == this.templateIdentifier
536 mberOFVm = existingVmsLength + mberOFVm;
538 for (var i = (existingVmsLength); i < mberOFVm; i++) {
540 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (existingVmsLength + index + 1), vnfc: [Object.assign({}, this.Sample)] });
545 let arrlength = this.referenceDataObject.vm.length;
546 mberOFVm = arrlength + mberOFVm;
547 for (var i = (arrlength); i < mberOFVm; i++) {
548 if (this.referenceDataObject.action == 'ConfigScaleOut') {
549 this.referenceDataObject.vm.push({ 'template-id': this.templateIdentifier, 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
551 this.referenceDataObject.vm.push({ 'vm-instance': (i + 1), vnfc: [Object.assign({}, this.Sample)] });
557 //Reference object to create reference data
558 prepareReferenceObject(isSaving?: any) {
559 console.log( this.classNm+": prepareReferenceObject: start.");
560 let scopeName = this.resetParamsOnVnfcType();
561 let extension = this.decideExtension(this.referenceDataObject);
562 this.prepareArtifactList(scopeName, extension);
563 if (this.referenceDataObject.action === 'OpenStack Actions') {
564 this.referenceDataObject['template'] = 'N';
565 this.referenceDataObject['artifact-list'] = [];
566 this.referenceDataObject['firstRowVmSpreadSheet']=this.firstArrayElement;
568 //detaching the object from the form and processing further
569 let newObj = $.extend(true, {}, this.referenceDataObject);
570 let action = this.referenceDataObject.action;
571 newObj = this.deleteVmsforNonActions(newObj, action)
572 this.pushOrReplaceTempData(newObj, action);
573 this.addAllActionObj(newObj, scopeName);
575 //saving data to service
576 this.mappingEditorService.getReferenceList().push(JSON.parse(JSON.stringify(this.referenceDataObject)));
577 this.buildDesignComponent.updateAccessUpdatePages(this.referenceDataObject.action, this.mappingEditorService.getReferenceList());
578 this.mappingEditorService.changeNav(this.tempAllData);
579 //on action change or template identifier change reset the form by restting values of Reference data object
580 this.resetVmsForScaleout(this.currentAction)
581 return { totlaRefDtaa: this.tempAllData, scopeName: scopeName };
584 public checkIfelementExistsInArray(element, array) {
585 //// console.log("Element==" + element)
586 var result: boolean = false;
588 array.forEach(function (item) {
589 // // console.log("Item==" + item)
590 if (element === item) {
591 // console.log('Element==' + element + 'Item==' + item);
600 console.log( this.classNm+": upload: start.");
601 /* wire up file reader */
602 const target: DataTransfer = <DataTransfer>(evt.target);
603 this.uploadFileName = evt.target.files[0].name;
604 var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1);
605 if (target.files.length != 1) {
606 console.log( this.classNm+": upload: Error: got no file !");
607 throw new Error(appConstants.errors.multipleFileUploadError);
609 console.log( this.classNm+": upload: filename:["+evt.target.files[0].name+"]");
610 if (fileExtension.toUpperCase() === 'XLS' || fileExtension.toUpperCase() === 'XLSX') {
611 const reader = new FileReader();
612 reader.onload = (e: any) => {
614 const bstr = e.target.result;
615 // // console.log("print 1---" + bstr);
616 const wb = XLSX.read(bstr, { type: 'binary' });
617 // // console.log("print 2---" + JSON.stringify(wb));
618 /* grab first sheet */
619 const wsname = wb.SheetNames[0];
620 // // console.log("Name:---" + wsname);
621 const ws = wb.Sheets[wsname];
625 let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1 })));
626 this.uploadedDataArray = arrData;
627 this.firstArrayElement = arrData[0];
628 var remUploadedDataArray = arrData;
629 remUploadedDataArray.shift();
630 this.remUploadedDataArray = remUploadedDataArray;
631 if (arrData != null) {
632 this.getExcelUploadStatus = true;
633 this.nService.success(appConstants.notifications.titles.success, appConstants.messages.vmDataUploadSuccess);
637 this.nService.success(appConstants.notifications.titles.error, appConstants.messages.emptyVmUpload);
640 reader.readAsBinaryString(target.files[0]);
643 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectVmUpload);
648 addVmCapabilitiesData() {
649 console.log( this.classNm+": addVmCapabilitiesData: start.");
650 for (var i = 0; i < this.uploadedDataArray.length; i++) {
651 var vnfcFuncCodeArray = [];
652 var data = this.uploadedDataArray[i];
653 for (var j = 1; j < data.length; j++) {
654 if (data[j] != undefined) {
655 if (data[j].toUpperCase() === 'Y') {
656 vnfcFuncCodeArray.push(this.firstArrayElement[j]);
660 var action = this.uploadedDataArray[i][0];
661 if (action && action != undefined) {
664 'action-level': 'vm',
666 'vnf-type': this.referenceDataObject['scope']['vnf-type'], //need to confirm what should be this value
669 'vnfc-function-code-list': vnfcFuncCodeArray,
671 'device-protocol': 'OS'
674 this.tempAllData.push(json);
681 save(form: any, isValid: boolean) {
682 console.log( this.classNm+": save: start: referenceDataObject.action:["+
683 this.referenceDataObject.action+"]");
684 if (this.referenceDataObject.action === '') {
685 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noActionError);
688 if (this.referenceDataObject['device-protocol'] === '') {
689 this.nService.error(appConstants.notifications.titles.error, appConstants.errors.noDeviceProtocolError);
694 let referenceObject = this.prepareReferenceObject();
695 let theJSON = JSON.stringify({ 'reference_data': this.tempAllData }, null, '\t');
696 let uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(theJSON);
697 this.downloadData.reference = theJSON;
698 this.validateTempAllData();
699 var blob = new Blob([theJSON], {
702 let fileName = 'reference_AllAction_' + referenceObject.scopeName + '_' + '0.0.1V.json';
703 this.downloadFile(blob, fileName, 100)
704 var templateData = JSON.stringify(this.downloadData.template.templateData);
705 var nameValueData = JSON.stringify(this.downloadData.template.nameValueData);
706 var pdData = this.downloadData.pd.pdData;
707 if (templateData != '{}' && templateData != null && templateData != undefined) this.downloadTemplate();
708 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.downloadNameValue();
709 if (pdData != '' && pdData != null && pdData != undefined) this.downloadPd();
712 downloadFile(blob, fileName, delay) {
713 console.log( this.classNm+": downloadFile: start.");
715 saveAs(blob, fileName);
720 console.log( this.classNm+": downloadTemplate: start.");
721 var fileName = this.downloadData.template.templateFileName;
722 console.log( this.classNm+": downloadTemplate: fileName:["+fileName+"]");
723 var theJSON = this.downloadData.template.templateData;
724 if (fileName != null || fileName != '') {
725 var fileExtensionArr = fileName.split('.');
726 var blob = new Blob([theJSON], {
727 type: 'text/' + fileExtensionArr[1]
729 this.downloadFile(blob, fileName, 130)
733 downloadNameValue() {
734 var fileName = this.downloadData.template.nameValueFileName;
735 var theJSON = this.downloadData.template.nameValueData;
736 var blob = new Blob([theJSON], {
740 this.downloadFile(blob, fileName, 160)
744 let fileName = this.downloadData.pd.pdFileName;
745 let theJSON = this.downloadData.pd.pdData;
746 var blob = new Blob([theJSON], {
750 this.downloadFile(blob, fileName, 180)
753 // save the values to the cache, on action change without download
754 validateDataAndSaveToAppc( valid, form, event) {
755 console.log( this.classNm+": validateDataAndSaveToAppc: start: valid:"+valid);
756 // will show error message
757 this.showValidationErrors(this.referenceDataObject);
759 form._submitted = true;
761 let referenceObject = this.prepareReferenceObject(true);
762 let removedKeysArray = []
763 this.tempAllData.forEach((data, index) => {
765 removedKeysArray.push(JSON.parse(JSON.stringify(this.deleteUnwantedKeys(data))))
768 this.tempAllData = removedKeysArray;
770 this.validateTempAllData();
772 if (this.actionChanged) {
774 if (this.currentAction) {
775 this.referenceDataObject.action = this.currentAction;
778 this.populateExistinAction(this.referenceDataObject.action);
779 this.actionChanged = false;
784 this.nService.warn('status', 'unable to save the artifact');
788 //this method saves reference, template, param and PD data to APPC
790 console.log( this.classNm+": saveToAppc: start: vnf-type:["+
791 this.referenceDataObject.scope['vnf-type']+"]");
792 let theJSON = JSON.stringify(this.tempAllData, null, '\t');
793 let fileName = 'reference_AllAction_' + this.referenceDataObject.scope['vnf-type'].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + '0.0.1V.json';
794 this.saveReferenceDataToAppc(JSON.stringify({ reference_data: this.tempAllData }), this.tempAllData[this.tempAllData.length - 1], fileName);
796 var templateData = JSON.stringify(this.appData.template.templateData);
797 var nameValueData = JSON.stringify(this.appData.template.nameValueData);
798 var pdData = JSON.stringify(this.appData.pd);
799 if (templateData != '{}' && templateData != null && templateData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.templateData, 'template data');
800 if (nameValueData != '{}' && nameValueData != null && nameValueData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.template.nameValueData, 'name value pairs');
801 if (pdData != '{}' && pdData != null && pdData != undefined) this.referenceDataFormUtil.handleApiData(this.appData.pd, 'PD file');
804 // valaidation of template data
805 validateTempAllData() {
806 console.log( this.classNm+": validateTempAllData: start.");
807 if (this.tempAllData) {
808 var updatedData = [];
809 this.tempAllData.forEach(data => {
811 updatedData.push(data);
814 this.tempAllData = updatedData;
818 //.. prepare and send the data to the API.
819 saveReferenceDataToAppc(artifactData, dataJson, fileName) {
820 console.log( this.classNm+": saveReferenceDataToAppc: start.");
822 let slashedPayload = this.referenceDataFormUtil.appendSlashes(artifactData);
823 let payload = this.utilityService.createPayLoadForSave("reference_data", dataJson['scope']['vnf-type'], "AllAction", fileName, this.versionNoForApiCall, slashedPayload);
824 this.ngProgress.start();
825 this.httpUtils.post({
826 url: environment.getDesigns,
828 }).subscribe((resp) => {
829 if (resp != null && resp.output.status.code == '400') {
830 window.scrollTo(0, 0);
831 this.nService.success('Status', 'successfully uploaded the Reference Data');
833 this.nService.warn('Status', 'Error while saving Reference Data');
835 this.uploadStatusError = false;
836 this.getRefStatus = false;
837 this.ngProgress.done();
839 this.nService.error('Status', 'Error Connecting to the APPC Network');
840 window.scrollTo(0, 0);
842 this.appData.reference = payload;
844 this.ngProgress.done();
849 console.log( this.classNm+": retriveFromAppc: start.");
850 if (sessionStorage.getItem('updateParams') != 'undefined') {
852 this.noCacheData = false;
854 this.noCacheData = true;
858 cloneMessage(servermessage) {
860 for (var key in servermessage) {
861 if (servermessage.hasOwnProperty(key)) //ensure not adding inherited props
862 clone[key] = servermessage[key];
867 public showUpload() {
868 this.selectedUploadType = this.uploadTypes[0].value;
871 public fileChange(input) {
872 if( this.utilityService.getTracelvl() > 0 )
873 console.log( this.classNm+": fileChange: start.");
874 this.fileName = input.target.files[0].name.replace(/C:\\fakepath\\/i, '');
875 this.fileUploaded = true;
876 this.disableRetrieve = true;
877 if (input.target.files && input.target.files[0]) {
878 // Create the file reader
879 let reader = new FileReader();
880 this.readFile(input.target.files[0], reader, (result) => {
881 // After the callback fires do:
882 if ('Reference Data' === this.selectedUploadType) {
885 let jsonObject = (JSON.parse(result))['reference_data'];
886 this.uploadedData = JSON.parse(JSON.stringify(jsonObject));
887 //check for legacy artifact and do not allow it
888 for (let i = 0; i < this.uploadedData.length; i++) {
889 obj = this.uploadedData[i];
890 if (obj.scope['vnfc-type'] != undefined && obj.scope['vnfc-type'] != '') {
891 this.nService.error('Error', 'The legacy reference artifact not supported');
895 this.displayVnfc = 'false';
896 this.isVnfcType = false;
897 this.isVnfcTypeList = false;
898 for (let i = 0; i < this.uploadedData.length; i++) {
899 obj = this.uploadedData[i];
900 if (obj.scope['vnfc-type-list'] && obj.scope['vnfc-type-list'].length > 0) {
901 this.displayVnfc = 'true';
902 this.isVnfcTypeList = true;
903 this.vnfcIdentifier = obj.scope['vnfc-type-list'][0];
906 this.oldAction=obj.action;
907 this.tempAllData = JSON.parse(JSON.stringify(jsonObject));
908 if( this.utilityService.getTracelvl() > 0 )
909 console.log( this.classNm+": fileChange: read & parsed.");
910 this.notificationService.notifySuccessMessage('Reference Data file successfully uploaded..');
911 if (jsonObject instanceof Array) {
912 this.referenceDataObject = jsonObject[0];
913 jsonObject.forEach(obj => {
914 this.selectedActions.push(obj.action);
917 this.referenceDataObject = jsonObject;
919 this.selectedActions.push(jsonObject.action);
921 if( this.utilityService.getTracelvl() > 0 )
922 console.log( this.classNm+": fileChange: "+
923 "referenceDataObject.action:["+
924 this.referenceDataObject.action+"]");
925 this.toggleIdentifier(this.referenceDataObject.action)
926 this.configDrp(this.referenceDataObject.action)
927 if (this.referenceDataObject.action === 'OpenStack Actions') {
928 this.deviceProtocols = ['', 'OpenStack'];
929 this.buildDesignComponent.tabs = [
932 name: 'Reference Data',
937 this.buildDesignComponent.tabs = [
939 name: 'Reference Data',
943 url: 'templates/myTemplates',
945 name: 'Parameter Definition',
946 url: 'parameterDefinitions/create'
953 this.getArtifactsOpenStack();
954 if (this.referenceDataObject.template == null) {
955 this.referenceDataObject.template = 'Y';
957 if (this.referenceDataObject['action-level'] == null) {
958 this.referenceDataObject['action-level'] = 'VNF';
960 if( this.utilityService.getTracelvl() > 0 )
961 console.log( this.classNm+": fileChange: displayVnfc:["+
962 this.displayVnfc+"]");
963 // Enable or Block Template and PD Tabs
964 this.buildDesignComponent.getRefData(
965 { ...this.referenceDataObject, displayVnfc: this.displayVnfc });
967 this.nService.error(appConstants.notifications.titles.error, appConstants.messages.incorrectFileFormat);
970 this.hideModal = true;
973 if( this.utilityService.getTracelvl() > 0 )
974 console.log( this.classNm+": fileChange: Error: Failed to read file!");
975 this.notificationService.notifyErrorMessage('Failed to read file..');
979 public readFile(file, reader, callback) {
980 console.log( this.classNm+": readFile: start.");
981 // Set a callback funtion to fire after the file is fully loaded
982 reader.onload = () => {
983 // callback with the results
984 callback(reader.result);
986 this.notificationService.notifySuccessMessage('Uploading File ' + file.name + ':' + file.type + ':' + file.size);
988 reader.readAsText(file, 'UTF-8');
991 fileChangeEvent(fileInput: any) {
992 let obj: any = fileInput.target.files;
996 console.log( this.classNm+": clearVnfcData: start.");
998 'vnfc-instance': '1',
999 'vnfc-function-code': '',
1000 'ipaddress-v4-oam-vip': '',
1001 'group-notation-type': '',
1002 'group-notation-value': ''
1006 setVmInstance(index) {
1007 this.referenceDataObject.vm[index]['vm-instance'] = index + 1;
1010 // setVnfcType(str: String) {
1011 // this.Sample['vnfc-type'] = str;
1014 // getChange(value: String) {
1015 // if (value === 'vnfType') {
1016 // this.referenceDataObject.scope['vnfc-type'] = '';
1021 console.log( this.classNm+": resetForm: start.");
1022 this.referenceDataObject['action-level'] = 'vnf';
1023 this.referenceDataObject.template = 'Y';
1024 this.referenceDataObject['device-protocol'] = '';
1025 this.referenceDataObject['user-name'] = '';
1026 this.referenceDataObject['port-number'] = '';
1027 this.refernceScopeObj.sourceType = '';
1028 this.Sample['vnfc-type'] = '';
1031 // this method gets called with the action as parameter and the respective action details are fetched and assigned to the current page
1032 populateExistinAction(data) {
1033 console.log( this.classNm+": populateExistinAction: start.");
1034 let existAction = this.tempAllData.findIndex(obj => {
1035 return obj.action == data;
1037 if (existAction > -1) {
1038 let obj = $.extend(true, {}, this.tempAllData[existAction]);
1039 this.referenceDataObject = obj;
1040 this.referenceDataObject.scope['vnf-type'] = obj['scope']['vnf-type'];
1041 this.referenceDataObject.scope['vnfc-type-list'] = obj['scope']['vnfc-type-list'];
1042 this.referenceDataObject['device-protocol'] = obj['device-protocol'];
1043 this.refernceScopeObj['sourceType'] = obj['scopeType'];
1044 if(obj['scope']['vnfc-type-list'] != undefined && obj['scope']['vnfc-type-list'].length >0) {
1045 this.referenceDataObject['vnfcIdentifier'] = obj['scope']['vnfc-type-list'][0];
1048 console.log( this.classNm+": populateExistinAction: action not found");
1050 this.referenceDataObject.action = data;
1052 //# iof healthCeck change deviceprotocol drp vaues
1055 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'REST'];
1056 this.actionHealthCheck = true;
1058 case 'UpgradeBackout':
1059 case 'ResumeTraffic':
1060 case 'QuiesceTraffic':
1061 case 'UpgradeBackup':
1062 case 'UpgradePostCheck':
1063 case 'UpgradePreCheck':
1064 case 'UpgradeSoftware':
1065 case 'ConfigRestore':
1066 case 'StartApplication':
1067 case 'StopApplication':
1068 case 'ConfigBackup':
1069 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE'];
1071 case 'OpenStack Actions':
1072 this.deviceProtocols = ['', 'OpenStack'];
1074 case 'ConfigScaleOut':
1075 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF'];
1077 case 'GetRunningConfig':
1078 this.deviceProtocols = ['', 'CHEF', 'ANSIBLE', 'NETCONF-XML', 'RESTCONF', 'CLI', 'REST'];
1081 this.deviceProtocols = ['', 'ANSIBLE', 'CHEF', 'NETCONF-XML', 'RESTCONF', 'CLI'];
1082 this.actionHealthCheck = false;
1086 //Modal pop up for action change with values entered.
1087 actionChange(data, userForm) {
1088 var methName= "actionChange";
1089 console.log( this.classNm+": "+methName+": start: data:["+data+"]");
1090 this.disableGrpNotationValue = false
1092 console.log( this.classNm+": "+methName+": data == null");
1095 if ((userForm.valid) && this.oldAction != '' && this.oldAction != undefined) {
1096 this.actionChanged = true;
1097 console.log( this.classNm+": "+methName+
1098 ": userForm valid and oldAction defined");
1099 // Calling common Confirmation Modal
1100 let disposable = this.dialogService.addDialog(ConfirmComponent)
1101 .subscribe((isConfirmed)=>{
1102 //We get dialog result
1103 console.log( this.classNm+": "+methName+": isConfirmed:["+
1106 // User clicked on Yes
1107 this.currentAction = this.referenceDataObject.action;
1108 console.log( this.classNm+": "+methName+
1109 ": clicked on Yes: currentAction:["+this.currentAction+
1110 "] oldAction:["+this.oldAction+"]");
1111 this.referenceDataObject.action = this.oldAction;
1112 $('#saveToAppc').click();//make sure the save all is done before the tempall obj is saved form the API
1113 this.toggleIdentifier(data)
1114 this.oldAction = this.currentAction;// this.referenceDataObject.action + '';
1115 this.referenceDataObject.action = this.currentAction;
1116 this.populateExistinAction(data);
1117 if (this.oldAction === 'OpenStack Actions') {
1119 this.uploadedDataArray = [];
1120 this.remUploadedDataArray = [];
1121 this.firstArrayElement = [];
1122 this.uploadFileName = '';
1123 //this.tempAllData = [];
1126 this.refernceScopeObj.from = '';
1127 this.getArtifactsOpenStack();
1129 // Clears VNFC Information data on action change
1130 this.clearVnfcData()
1131 this.resetVmsForScaleout(data);
1134 // User clicked on No
1135 this.toggleIdentifier(data)
1136 this.currentAction = this.referenceDataObject.action;
1137 console.log( this.classNm+": "+methName+
1138 ": clicked on No: currentAction:["+this.currentAction+"]");
1139 this.populateExistinAction(data);
1140 this.resetVmsForScaleout(data);
1141 this.oldAction = this.referenceDataObject.action + '';
1143 this.clearVnfcData()
1144 this.refernceScopeObj.from = '';
1147 if (this.referenceDataObject.action === 'Configure' || this.referenceDataObject.action === 'ConfigModify') {
1148 this.isConfigOrConfigModify = true;
1150 this.isConfigOrConfigModify = false;
1151 delete this.mappingEditorService.newObject['vnfc'];
1154 // Enable or Block Template and PD Tabs
1155 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier && this.templateIdentifier != '') {
1156 // let referenceDataObjectTemp = this.referenceDataObject;
1157 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1158 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1159 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1162 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1166 console.log( this.classNm+": "+methName+
1167 ": userForm Not valid or oldAction not defined");
1168 this.actionChanged = true;
1169 this.currentAction = this.referenceDataObject.action;
1170 this.oldAction = this.referenceDataObject.action + '';
1171 this.populateExistinAction(data);
1172 this.resetVmsForScaleout(data);
1173 this.toggleIdentifier(data);
1175 // Enable or Block Template and PD Tabs
1176 if (this.currentAction == 'ConfigScaleOut' && this.templateIdentifier) {
1177 // let referenceDataObjectTemp = this.referenceDataObject;
1178 // referenceDataObjectTemp['template-id'] = this.templateIdentifier;
1179 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1180 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc }, { reqField: this.templateIdentifier });
1182 this.buildDesignComponent.getRefData({ ...this.referenceDataObject, displayVnfc: this.displayVnfc });
1185 this.configDrp(data)
1189 console.log( this.classNm+": configDrp: start: data:["+data+"]");
1190 if (data == 'ConfigScaleOut') {
1191 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value', 'existing-group-name'];
1193 this.groupAnotationType = ['', 'first-vnfc-name', 'fixed-value', 'relative-value'];
1195 if (data == 'OpenStack Actions') {
1196 this.buildDesignComponent.tabs = [
1199 name: 'Reference Data',
1204 this.buildDesignComponent.tabs = [
1206 name: 'Reference Data',
1210 url: 'templates/myTemplates',
1212 name: 'Parameter Definition',
1213 url: 'parameterDefinitions/create'
1220 if (data == 'Configure' || data == 'ConfigModify') {
1221 this.nonConfigureAction = false;
1223 this.nonConfigureAction = true;
1227 deviceProtocolChange() {
1228 console.log( this.classNm+": deviceProtocolChange: start.");
1229 if (this.referenceDataObject['device-protocol'] == 'REST') {
1232 delete this.referenceDataObject['context-url']
1234 // Enable or Block Template and PD Tabs
1235 this.buildDesignComponent.getRefData(
1236 {...this.referenceDataObject,displayVnfc: this.displayVnfc },
1237 {reqField: this.templateIdentifier});
1240 // used to call or trigger save object on template Identifier changes
1241 idChange(data, userForm) {
1242 console.log( this.classNm+": idChange: start: data:["+data+"]");
1246 // Enable or Block Template and PD Tabs
1247 // let referenceDataObjectTemp = this.referenceDataObject;
1248 // referenceDataObjectTemp['template-id'] = data;
1249 // this.buildDesignComponent.getRefData(referenceDataObjectTemp);
1250 this.buildDesignComponent.getRefData(
1251 {...this.referenceDataObject, displayVnfc: this.displayVnfc },
1252 { reqField: data });
1254 if ((userForm.valid)) {
1255 this.currentAction = "ConfigScaleOut"
1256 this.oldtemplateIdentifier = this.templateIdentifier
1257 let referenceObject = this.prepareReferenceObject();
1258 this.actionChanged = true;
1259 if (this.templateIdentifier) {
1260 // Calling common Confirmation Modal
1261 let disposable = this.dialogService.addDialog(ConfirmComponent)
1262 .subscribe((isConfirmed)=>{
1263 //We get dialog result
1265 // User clicked on Yes
1266 this.validateTempAllData();
1269 this.clearVnfcData();
1270 this.refernceScopeObj.from = '';
1273 // User clicked on No
1275 this.refernceScopeObj.from = '';
1280 this.oldtemplateIdentifier = this.templateIdentifier;
1284 // used to call or trigger save object on multiple VNFC's changes
1285 vnfcChanged( data, userForm) {
1286 console.log( this.classNm+": vnfcChanged: new vnfcIdentifier:["+data+"]");
1287 console.log( this.classNm+": vnfcChanged: oldVnfcIdentifier:["+
1288 this.oldVnfcIdentifier+"]");
1289 console.log(this.classNm+": vnfcChanged: scope.vnfc-type:["+
1290 this.referenceDataObject.scope['vnfc-type']+"]");
1291 this.vnfcIdentifier = data;
1296 //.. populate VNFC Type in Sample field
1297 this.setVnfcTypeInSample( this.vnfcIdentifier );
1298 // Enable or Block Template and PD Tabs
1299 let referenceDataObjectTemp = this.referenceDataObject;
1300 referenceDataObjectTemp['vnfcIdentifier'] = data;
1301 console.log( this.classNm+
1302 ": vnfcChanged: displayVnfc:["+this.displayVnfc+"]");
1303 this.buildDesignComponent.getRefData(
1304 {...this.referenceDataObject, displayVnfc: this.displayVnfc },
1305 { reqField: data });
1306 console.log( this.classNm+
1307 ": vnfcChanged: userForm.valid:["+userForm.valid+"]");
1308 if ((userForm.valid) && this.oldVnfcIdentifier != '' && this.oldVnfcIdentifier != undefined) {
1309 this.currentAction = this.referenceDataObject.action
1310 this.oldVnfcIdentifier = this.vnfcIdentifier
1311 let referenceObject = this.prepareReferenceObject();
1312 this.actionChanged = true;
1313 if (this.vnfcIdentifier) {
1314 // Calling common Confirmation Modal
1315 let disposable = this.dialogService.addDialog(ConfirmComponent)
1316 .subscribe((isConfirmed)=>{
1317 //We get dialog result
1319 // User clicked on Yes
1320 this.validateTempAllData();
1323 this.clearVnfcData()
1324 this.refernceScopeObj.from = '';
1327 // User clicked on No
1329 this.refernceScopeObj.from = '';
1335 this.oldVnfcIdentifier = this.vnfcIdentifier
1341 console.log( this.classNm+": clearCache: start.");
1342 // get the value and save the userid and persist it.
1343 this.clearTemplateCache();
1344 this.clearPdCache();
1345 this.appData = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} };
1346 this.downloadData = {
1348 template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' },
1349 pd: { pdData: '', pdFileName: '' }
1353 clearTemplateCache() {
1354 this.mappingEditorService.setTemplateMappingDataFromStore(undefined);
1355 localStorage['paramsContent'] = '{}';
1358 this.mappingEditorService.setParamContent(undefined);
1359 this.paramShareService.setSessionParamData(undefined);
1363 console.log( this.classNm+": saveTemp: start.");
1367 { url: environment.getDesigns, data: this.appData.template.templateData })
1368 .subscribe(resp => {
1369 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1370 this.nService.success('Status', 'Successfully uploaded the Template Data');
1372 if (resp.output.status.code === '401') {
1373 this.nService.warn('Status', 'Error in saving the Template to Appc');
1377 (err) => this.nService.error('Status', 'Error Connecting to the APPC Network'));
1381 console.log( this.classNm+": saveNameValue: start.");
1386 url: environment.getDesigns, data: this.appData.template.nameValueData
1388 .subscribe(resp => {
1389 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1390 this.nService.success('Status', 'Successfully uploaded the Name Value Pairs');
1392 if (resp.output.status.code === '401') {
1393 this.nService.warn('Status', 'Error in saving the Name value pairs to Appc');
1397 this.nService.error('Status', 'Error Connecting to the APPC Network');
1407 url: environment.getDesigns, data: this.appData.pd
1409 .subscribe(resp => {
1410 if (resp.output.status.code === '400' && resp.output.status.message === 'success') {
1411 this.nService.success('Status', 'Successfully uploaded PD file');
1413 if (resp.output.status.code === '401') {
1414 this.nService.warn('Status', 'Error in saving the PD to Appc');
1418 this.nService.error('Status', 'Error Connecting to the APPC Network');
1423 openModel(toShow: any, message: any, title: any) {
1424 console.log( this.classNm+": openModel: start: title:["+title+"]");
1425 this.modalComponent.isShow = toShow;
1426 this.modalComponent.message = message;
1427 this.modalComponent.title = title;
1431 $('#inputFile').trigger('click');
1434 excelBrowseOption() {
1435 $('#excelInputFile').trigger('click');
1439 $('#identifierModal').modal();
1443 if (!(this.referenceDataObject['template-id-list'])) {
1444 this.referenceDataObject['template-id-list'] = [];
1446 if (!(this.referenceDataObject['template-id-list'].indexOf(this.templateId.trim()) > -1)) {
1447 this.referenceDataObject['template-id-list'].push(this.templateId.trim());
1449 // Changing value to blank otherwise it will show previous value in text box of popup
1450 this.templateId = '';
1453 // adds the vnfc to the vnfc dropdown list
1455 var newVnfcTypeV= this.newVnfcType.trim();
1456 console.log(this.classNm+
1457 ": addVnfc: start: newVnfcTypeV:["+newVnfcTypeV+"]");
1458 if (!(this.referenceDataObject.scope['vnfc-type-list'])) {
1459 this.referenceDataObject.scope['vnfc-type-list'] = [];
1460 // this.vnfcIdentifier = newVnfcTypeV;
1461 } else if (this.referenceDataObject.scope['vnfc-type-list'].length == 0){
1462 // this.vnfcIdentifier = newVnfcTypeV;
1464 this.vnfcIdentifier = newVnfcTypeV;
1465 console.log(this.classNm+
1466 ": addVnfc: vnfcIdentifier:["+this.vnfcIdentifier+"]");
1467 if (!(this.referenceDataObject.scope['vnfc-type-list'].indexOf(newVnfcTypeV) > -1)) {
1468 this.referenceDataObject.scope['vnfc-type-list'].push(newVnfcTypeV);
1470 this.tempAllData.forEach(obj => {
1471 if (obj.action == "Configure" || obj.action == "ConfigModify") {
1472 obj.scope['vnfc-type-list'] = this.referenceDataObject.scope['vnfc-type-list']
1474 this.resetArtifactList(obj);
1476 console.log(this.classNm+": addVnfc: scope vnfc-type:["+
1477 this.referenceDataObject.scope['vnfc-type']+"]");
1478 this.setVnfcTypeInSample( newVnfcTypeV );
1479 // Changing newVnfcType value to blank otherwise it will show previous value in text box of popup
1480 this.newVnfcType = ''
1484 console.log( this.classNm+": resetVms: start.");
1485 this.referenceDataObject.vm = [];
1489 // this.referenceDataObject.vm = this.referenceDataObject.vm;
1492 resetGroupNotation() {
1493 if (this.Sample['group-notation-type'] == "existing-group-name") {
1494 this.Sample['group-notation-value'] = ""
1495 this.disableGrpNotationValue = true
1497 this.disableGrpNotationValue = false
1501 resetVmsForScaleout(action) {
1502 //reset currentform vms based on action
1503 if (action == "ConfigScaleOut" || action == "Configure") {
1504 let ConfigScaleOutIndex = this.tempAllData.findIndex(obj => {
1505 return obj['action'] == action
1507 if (ConfigScaleOutIndex > -1) {
1508 this.referenceDataObject.vm = this.tempAllData[ConfigScaleOutIndex].vm
1510 if (this.actionChanged) {
1511 this.referenceDataObject.vm = []
1517 resetParamsOnVnfcType() {
1518 console.log( this.classNm+": resetParamsOnVnfcType: start:\n "+
1519 "ref.DataObject.scope vnfc-type:["+
1520 this.referenceDataObject.scope['vnfc-type']+"]");
1522 //if only vnf is there
1523 if (this.referenceDataObject.scope['vnfc-type'] == '' || this.referenceDataObject.scope['vnfc-type'] == null || this.referenceDataObject.scope['vnfc-type'] == 'null') {
1524 scopeName = this.referenceDataObject.scope['vnf-type'];
1525 this.referenceDataObject.scope['vnfc-type'] = '';
1526 this.referenceDataObject['action-level'] = 'vnf';
1527 this.referenceDataObject['scopeType'] = 'vnf-type';
1529 //if VNFC is entered set action level & Scope type to VNFC for configure and configure modify, and default the values to vnf and vnf type for all other actions
1531 scopeName = this.referenceDataObject.scope['vnfc-type'];
1532 if (this.referenceDataObject.action == 'Configure' || this.referenceDataObject.action == 'ConfigModify') {
1533 this.referenceDataObject['action-level'] = 'vnfc';
1534 this.referenceDataObject['scopeType'] = 'vnfc-type';
1536 this.referenceDataObject['action-level'] = 'vnf';
1537 this.referenceDataObject['scopeType'] = 'vnf-type';
1540 //replacing / with _ and removing spaces in the scopeName
1542 scopeName = scopeName.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1544 console.log( this.classNm+": resetParamsOnVnfcType: return scopeName:["+
1549 decideExtension(obj) {
1550 //marking the extension based on the device-protocol selected by the user
1551 let extension = '.json';
1552 switch (obj['device-protocol']) {
1556 extension = '.json';
1565 prepareArtifactList(scopeName, extension) {
1566 console.log( this.classNm+": prepareArtifactList: start: scopeName:["+
1567 scopeName+"] extension:["+extension+"]");
1568 this.referenceDataObject['artifact-list'] = [];
1569 //preparing the artifact list array file names along with extension
1570 let config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.' + extension;
1571 let pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.yaml';
1572 let reference_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V.json';
1573 let configTemplate = {
1574 'artifact-name': 'template_' + config_template_fileName,
1575 'artifact-type': 'config_template'
1578 'artifact-name': 'pd_' + pd_fileName,
1579 'artifact-type': 'parameter_definitions'
1581 if (this.referenceDataObject.action != 'ConfigScaleOut') {
1582 this.referenceDataObject['artifact-list'].push(configTemplate,
1586 let identifiers = this.referenceDataObject['template-id-list'];
1588 for (var x = 0; x < identifiers.length; x++) {
1589 //for replacing spaces and "/" with "_"
1590 identifiers[x] = identifiers[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1591 pd_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.yaml';
1592 config_template_fileName = this.referenceDataObject.action + '_' + scopeName + '_' + '0.0.1V_' + identifiers[x] + '.' + extension;
1595 'artifact-name': 'template_' + config_template_fileName,
1596 'artifact-type': 'config_template'
1599 'artifact-name': 'pd_' + pd_fileName,
1600 'artifact-type': 'parameter_definitions'
1602 this.referenceDataObject['artifact-list'].push(configTemplate,
1610 deleteVmsforNonActions(newObj, action) {
1611 let configureObject = (action == 'Configure');
1612 let ConfigScaleOut = (action == 'ConfigScaleOut');
1613 //delete VM's if selected action is not configure.
1614 if (!ConfigScaleOut && !configureObject && this.tempAllData.length != 0) {
1615 if (ConfigScaleOut) {
1620 if (ConfigScaleOut) {
1622 delete newObj['template-id-list'];
1627 pushOrReplaceTempData(newObj, action) {
1628 console.log( this.classNm+": pushOrReplaceTempData: start: action:["+
1629 action+"]\n newObj.scope vnfc-type:["+newObj.scope['vnfc-type']+"]");
1630 if( newObj.scope['vnfc-type'] == undefined ||
1631 newObj.scope['vnfc-type'] == null ||
1632 newObj.scope['vnfc-type'].length < 1 )
1634 console.log( this.classNm+": pushOrReplaceTempData: scope vnfc-type"+
1635 " is empty.\n vnfcIdentifier:["+this.vnfcIdentifier+"]");
1636 if( this.vnfcIdentifier.length > 0 ) {
1637 newObj.scope['vnfc-type']= this.vnfcIdentifier;
1640 let actionObjIndex = this.tempAllData.findIndex(obj => {
1641 return obj['action'] == action;
1643 if (newObj.action != 'HealthCheck') {
1644 delete newObj['url'];
1647 if (actionObjIndex > -1) {
1648 this.tempAllData[actionObjIndex] = newObj;
1649 this.mappingEditorService.saveLatestAction(this.tempAllData[actionObjIndex]);
1650 if (newObj.action == "ConfigScaleOut") {
1651 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1654 this.templateIdentifier = ('')
1655 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1658 if (newObj.action != '') {
1659 this.tempAllData.push(newObj);
1660 this.mappingEditorService.saveLatestAction(newObj);
1661 if (newObj.action == "ConfigScaleOut") {
1662 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier);
1665 this.templateIdentifier = ('')
1666 this.mappingEditorService.saveLatestIdentifier(this.templateIdentifier)
1673 // removes the unwanted keys added in the artifact for vnfc level actions
1674 deleteUnwantedKeys(newObj) {
1675 console.log( this.classNm+": deleteUnwantedKeys: start.");
1676 newObj = JSON.parse(JSON.stringify(newObj))
1677 delete newObj['template-id']
1678 delete newObj['vnfcIdentifier']
1679 if (newObj.action != "ConfigScaleOut") {
1680 delete newObj['template-id-list']
1682 if (newObj.action != 'HealthCheck') {
1683 delete newObj['url'];
1685 if (newObj.action != "Configure" && newObj.action != "ConfigModify") {
1686 newObj.scope['vnfc-type-list'] = [];
1691 addAllActionObj(newObj, scopeName) {
1692 console.log( this.classNm+": addAllActionObj: start.");
1693 //Creating all action block to allow mulitple actions at once
1695 action: 'AllAction',
1696 'action-level': 'vnf',
1697 scope: newObj.scope,
1699 'artifact-name': 'reference_AllAction' + '_' + scopeName + '_' + '0.0.1V.json',
1700 'artifact-type': 'reference_template'
1703 let allActionIndex = this.tempAllData.findIndex(obj => {
1704 return obj['action'] == 'AllAction';
1706 if (allActionIndex > -1) {
1707 this.tempAllData[allActionIndex] = allAction;
1709 this.tempAllData.push(allAction);
1714 console.log( this.classNm+": resetTempData: start.");
1715 if (this.uploadedDataArray && this.uploadedDataArray != undefined && this.uploadedDataArray.length != 0) {
1716 if (this.tempAllData && this.tempAllData != undefined) {
1717 for (var i = 0; i < this.tempAllData.length; i++) {
1719 if (this.tempAllData[i].action === 'AllAction') {
1723 result = this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions);
1726 this.tempAllData.splice(i, 1);
1732 this.addVmCapabilitiesData();
1736 trackByFn(index, item) {
1740 getArtifactsOpenStack() {
1741 console.log( this.classNm+": getArtifactsOpenStack: start: "+
1742 "tempAllData length="+this.tempAllData.length );
1744 var vnfcFunctionCodeArrayList = [];
1745 var vnfcSetArray=[];
1746 for (var i = 0; i < this.tempAllData.length; i++) {
1747 if (!this.checkIfelementExistsInArray(this.tempAllData[i].action, this.actions) && (this.tempAllData[i].action != 'AllAction')) {
1748 var vnfcFunctionCodeArray = this.tempAllData[i]["vnfc-function-code-list"]
1749 vnfcFunctionCodeArrayList.push([this.tempAllData[i].action].concat(this.tempAllData[i]["vnfc-function-code-list"]))
1751 if(this.tempAllData[i].action==='OpenStack Actions')
1753 vnfcSetArray=this.tempAllData[i]['firstRowVmSpreadSheet']
1756 console.log( this.classNm+": getArtifactsOpenStack: vnfcSetArray length="+
1757 vnfcSetArray.length );
1760 let vnfcSetArrayLen = vnfcSetArray.length;
1762 for (let i = 0; i < vnfcFunctionCodeArrayList.length; i++) {
1763 let element = vnfcFunctionCodeArrayList[i];
1764 for (let j = 1; j < element.length; j++) {
1765 for (let k = j; k < vnfcSetArrayLen; k++) {
1766 if (element[j] === vnfcSetArray[k]) {
1770 element.splice(j, 0, '');
1776 this.firstArrayElement = vnfcSetArray;
1777 this.remUploadedDataArray = vnfcFunctionCodeArrayList;
1782 * Handles the display of VM block based on the action change
1784 handleVMBlockDisplay() {
1785 switch (this.referenceDataObject.action) {
1786 case this.actionList.ConfigScaleOut:
1787 case this.actionList.Configure:
1790 this.displayVMBlock = true;
1793 this.displayVMBlock = false;
1797 //.. check VNFC Type equality in Upper Selection vs entered in Sample field
1798 checkVnfcTypeEqual( vnfctp: string ) {
1799 var methName= "checkVnfcTypeEqual";
1800 console.log(this.classNm+": "+methName+": vnfctp:["+vnfctp+"]");
1801 console.log( this.classNm+": "+methName+": vnfcIdentifier:["+
1802 this.vnfcIdentifier+"]");
1803 console.log( this.classNm+": "+methName+": Sample[vnfc-type]:["+
1804 this.Sample['vnfc-type']+"]");
1805 if( vnfctp != null && vnfctp.length > 0 ) {
1806 if( this.vnfcIdentifier != null && this.vnfcIdentifier.length > 0 ) {
1808 this.classNm+": "+methName+": compare non empty VNFC Types...");
1809 if( vnfctp != this.vnfcIdentifier ) {
1810 console.log( this.classNm+": "+methName+": Non-match WARNING !");
1811 //.. display in pop-up
1812 this.nService.warn( 'WARNING',
1813 "The specified VNFC Types don't match."+
1814 " Can cause discrepancy in the artifacts.", this.options );
1816 console.log(this.classNm+": checkVnfcTypeEqual: VNFC Types're equal.");
1822 //.. populating VNFC Type in Sample fields
1823 setVnfcTypeInSample( vnfctp: string ) {
1824 // if( this.utilityService.getTracelvl() > 0 )
1825 console.log( this.classNm+": setVnfcTypeInSample: vnfctp:["+vnfctp+"]");
1826 this.Sample['vnfc-type']= vnfctp;
1829 // Common method to show validation errors
1830 private showValidationErrors(referenceDataObject) {
1831 if (this.referenceDataObject.action === '') {
1832 this.nService.error('Error', 'Select a valid Action');
1835 if (this.referenceDataObject['device-protocol'] === '') {
1836 this.nService.error('Error', 'Select a valid Device protocol');
1840 if (referenceDataObject.action === 'ConfigScaleOut' && !this.templateIdentifier) {
1841 this.nService.error('Error', 'Select a valid Template Identifier');
1845 resetArtifactList( obj) {
1846 console.log( this.classNm+": resetArtifactList: start...");
1847 let vnfcTypeList = obj.scope['vnfc-type-list'];
1848 let vnf = this.referenceDataObject.scope['vnf-type']
1850 let config_template_fileName
1855 obj['artifact-list'] = [];
1856 for (var x = 0; x < vnfcTypeList.length; x++) {
1857 let extension = this.referenceDataFormUtil.decideExtension(obj)
1858 //for replacing spaces and "/" with "_"
1859 let type = vnfcTypeList[x].replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '');
1860 pd_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.yaml';
1861 config_template_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V' + extension;
1862 param_fileName = this.referenceDataObject.action + '_' + vnf.replace(/ /g, '').replace(new RegExp('/', 'g'), '_').replace(/ /g, '') + '_' + type + '_' + '0.0.1V.json';
1864 'artifact-name': 'template_' + config_template_fileName,
1865 'artifact-type': 'config_template'
1868 'artifact-name': 'pd_' + pd_fileName,
1869 'artifact-type': 'parameter_definitions'
1872 'artifact-name': 'param_' + param_fileName,
1873 'artifact-type': 'param_values'
1876 this.referenceDataObject['artifact-list'].push(configTemplate,
1877 pdTemplate, paramValue
1879 obj['artifact-list'].push(configTemplate,
1880 pdTemplate, paramValue