diff options
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping')
17 files changed, 725 insertions, 141 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts index 57c2bcbfa..47128130c 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts @@ -10,11 +10,17 @@ export class SharedService { // based on edit Mode, edit=false mode = new BehaviorSubject(false); list = new BehaviorSubject(''); + modeState: Observable<boolean>; + listState: Observable<string>; constructor() { + this.mode = new BehaviorSubject(false); + this.list = new BehaviorSubject(''); + this.modeState = this.mode.asObservable(); + this.listState = this.list.asObservable(); } isEdit(): Observable<boolean> { - return this.mode.asObservable(); + return this.modeState; } enableEdit() { this.mode.next(true); @@ -28,7 +34,7 @@ export class SharedService { this.list.next(filename); } listAction(): Observable<string> { - return this.list.asObservable(); + return this.listState; } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/TemplateType.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/TemplateType.ts deleted file mode 100644 index 17a4bfae6..000000000 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/TemplateType.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum TemplateType { - Velocity = 'vtl', - Koltin = 'kt', - Jinja = 'Unknown' -} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html index 4b0ef8b49..de97a4679 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.html @@ -5,12 +5,14 @@ class="fa fa-chevron-left mr-2"></i>Template List</button> </div> <div class="col text-right"> + <button (click)="cancel()" [hidden]="!templatesExist || edit" class="btn btn-outline-danger" + title="Delete Template">Cancel</button> <button data-toggle="modal" [hidden]="!edit" data-target="#templateDeletionModal2" class="btn btn-outline-danger" title="Delete Template">Delete</button> - <button (click)="cancel()" [hidden]="fileName?.length <=0 || edit" + <button (click)="clear()" [hidden]="fileName?.length <=0 || edit" class="btn btn-outline-secondary">Clear</button> - <button tourAnchor="tm-templateFinish" (click)="saveToStore()" [disabled]="fileName?.length <=0" title="Submit template and close" - class="btn btn-primary">Finish</button> + <button tourAnchor="tm-templateFinish" (click)="saveToStore()" [disabled]="fileName?.length <=0" + title="Submit template and close" class="btn btn-primary">Finish</button> </div> </div> <div class="card creat-card"> @@ -31,8 +33,8 @@ <div class="card"> <div class="card-header" id="headingOne"> <h5 class="mb-0 d-flex justify-content-between"> - <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" - aria-controls="collapseOne"> + <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" id="templateTab" + aria-expanded="true" aria-controls="collapseOne"> 1. Template <span class="accordian-title">{{currentTemplate?.fileName?.split('/')[1]}}</span> </button> @@ -44,24 +46,25 @@ <div tourAnchor="tm-templateType" class="single-line"> <label class="label-name">Template Type</label> <div class="label-input"> - <label name="trst" (click)="allowedExt=['.vtl']"> + <label name="trst" (click)="allowedExt=['.vtl'];templateExt='vtl'"> <input class="form-check-input" [(ngModel)]="templateExt" type="radio" - name="exampleRadios" id="exampleRadios1" value=Velcoity> + name="exampleRadios" id="exampleRadios1" value=vtl> <span> - Velcoity + Velocity </span> </label> - <label name="trst" (click)="allowedExt=['.j2','.jinja2']"> + <label name="trst" (click)="allowedExt=['.j2','.jinja2'];templateExt='j2'"> <input class="form-check-input" [(ngModel)]="templateExt" type="radio" - name="exampleRadios" id="exampleRadios1" value=Jinja> + name="exampleRadios" id="exampleRadios1" value=j2> <span> Jinja </span> </label> - <label tourAnchor="tm-templateContent" name="trst" (click)="allowedExt=['.kt']"> + <label tourAnchor="tm-templateContent" name="trst" + (click)="allowedExt=['.kt'];templateExt='kt'"> <input class="form-check-input" [(ngModel)]="templateExt" type="radio" - name="exampleRadios" id="exampleRadios1" value=Kotlin> + name="exampleRadios" id="exampleRadios1" value=kt> <span> Kotlin @@ -70,7 +73,7 @@ </div> </div> <div class="create-template-import">Use the editor to add parameters or you can also - <a href="#" data-toggle="modal" (click)="allowedExt=[getFileExtension()]" + <a href="#" data-toggle="modal" (click)="allowedExt=['.'+templateExt]" data-target="#templateModal"><b>Import File</b></a>. <br /> <span class="templateNote"><i class="icon-info" aria-hidden="true"></i> When you import new file, the new attributes will replace @@ -86,8 +89,9 @@ <div class="card"> <div class="card-header" id="headingTwo"> <h5 class="mb-0"> - <button tourAnchor="tm-mappingContent" class="btn btn-link collapsed" id="mappingTab" data-toggle="collapse" - data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> + <button tourAnchor="tm-mappingContent" class="btn btn-link collapsed" id="mappingTab" + data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" + aria-controls="collapseTwo"> 2. Manage Mapping <span class="accordian-title">{{currentMapping?.fileName?.split('/')[1]}}</span> </button> @@ -97,8 +101,8 @@ <div class="card-body"> <p class="text-center"><b>Select a source to load config parameters</b></p> <div class="text-center"> - <button [disabled]="!(variables?.length>0 && templateFileContent?.trim()?.length > 0)" - (click)="getMappingTableFromTemplate($event)" class="mapping-source-load" [ngClass]="variables?.length>0 && templateFileContent?.trim()?.length > 0 + <button [disabled]="!(templateFileContent?.trim()?.length > 0)" + (click)="getMappingTableFromTemplate($event)" class="mapping-source-load" [ngClass]="templateFileContent?.trim()?.length > 0 ?'hover-enable':'hover-disable'"> <i class="icon-use-attributes"></i> <br /> @@ -122,28 +126,68 @@ </div> + </div> + <div id="mapping-table" [hidden]="resourceDictionaryRes?.length == 0" class="mapping-table mx-4 my-2"> + <div class="btn-group mapping-editBar" role="group"> + <div class="custom-control custom-checkbox" tooltip="Select All" placement="bottom"> + <input type="checkbox" (click)="selectAllProps()" class="custom-control-input" + id="customCheck1" + [checked]="resourceDictionaryRes.length>0&&resourceDictionaryRes.length === this.selectedProps.size"> + <label class="custom-control-label" for="customCheck1"></label> + </div> + <button [disabled]="selectedProps.size <=0" type="button" class="btn" (click)="reMap()" + tooltip="Re-mapping" placement="bottom"><i class="icon-autoMap"></i></button> + <button [disabled]="selectedProps.size <=0" type="button" class="btn" (click)="removeProps()" + tooltip="Remove" placement="bottom"><i class="icon-delete-sm"></i></button> + <div style="line-height: 35px;font-size: 10px;"> + <span>{{selectedProps.size}} selected </span> + <span>({{resourceDictionaryRes.length}} attributes in total)</span> + </div> + </div> <table datatable [dtOptions]="initDtOptions" [dtTrigger]="dtTrigger" class="row-border hover"> <thead> <tr> + <th></th> <th>Required</th> + <th>Template Input</th> <th>Parameter Name</th> <th>Dictionary Name</th> <th>Dictionary Source</th> <th>Dependancies</th> <th>Default</th> + <th>Velocity</th> <th>Data Type</th> <th>Entry Schema</th> </tr> </thead> <tbody> - <tr *ngFor="let dict of resourceDictionaryRes"> + <tr *ngFor="let dict of resourceDictionaryRes;let i=index;trackBy: identify"> + <td> + <div class="custom-control custom-checkbox" tooltip="Select" placement="bottom"> + <input type="checkbox" class="custom-control-input" + id="customCheck-{{dict.name}}" [checked]="selectedProps.has(dict.name)" + (click)="selectProp(dict.name)"> + <label class="custom-control-label" for="customCheck-{{dict.name}}"></label> + </div> + <!-- <input type="checkbox" [checked]="selectedProps.has(dict.name)" + (click)="selectProp(dict.name)"></td> --> + </td> <td> - <img *ngIf="dict.definition?.property?.required" - src="/assets/img/icon-required-yes.svg"> - <img *ngIf="!dict.definition?.property?.required" - src="/assets/img/icon-required-no.svg"> + <div class="custom-control custom-checkbox reuiredInput"> + <input type="checkbox" class="custom-control-input" #requiredInput + (click)="setProp(requiredInput,'required',i)" + id="requiredCheck-{{dict.name}}"> + <label class="custom-control-label" for="requiredCheck-{{dict.name}}"></label> + </div> + </td> + <td> + <div class="custom-control custom-checkbox reuiredInput"> + <input type="checkbox" class="custom-control-input" #tempInput + (click)="setProp(tempInput,'input-param',i)" id="inputCheck-{{dict.name}}"> + <label class="custom-control-label" for="inputCheck-{{dict.name}}"></label> + </div> </td> <td>{{ dict.name }}</td> <td>{{ dict.name }}</td> @@ -159,12 +203,13 @@ <!-- <select class="custom-select"> <option *ngFor="let val of getKeys(dependancies)"> {{ getValue(dict.name)}}</option> - </select> --> <input type="text" class="form-control" [ngModel]="getValue(dict.name)"> <!-- {{ dict.definition.sources }} --> </td> <td>{{ dict.definition?.property?.default }}</td> + <td><input type="text" class="form-control" #velocity + (input)="setVelocity(i,velocity.value)"></td> <td>{{ dict.definition?.property?.type }}</td> <td>{{ dict.definition?.property['entry_schema'] }}</td> </tr> @@ -173,26 +218,51 @@ </div> <div id="mapping-table-res" [hidden]="mappingRes?.length == 0" class="mapping-table mx-4 my-2"> + <!-- <div class="btn-group mapping-editBar" role="group"> + <div class="custom-control custom-checkbox" tooltip="Select All" placement="bottom"> + <input type="checkbox" (click)="selectAllProps()" class="custom-control-input" + id="customCheck2" + [checked]="resourceDictionaryRes.length>0&&resourceDictionaryRes.length === this.selectedProps.size"> + <label class="custom-control-label" for="customCheck2"></label> + </div> + <button [disabled]="selectedProps.size <=0" type="button" class="btn" (click)="reMap()" + tooltip="Re-mapping" placement="bottom"><i class="icon-autoMap"></i></button> + <button [disabled]="selectedProps.size <=0" type="button" class="btn" (click)="removeProps()" + tooltip="Remove" placement="bottom"><i class="icon-delete-sm"></i></button> + </div> --> <table datatable [dtOptions]="dtOptions" [dtTrigger]="resTableDtTrigger" class="row-border hover"> <thead> <tr> + <!-- <th></th> --> <th>Required</th> + <th>Template Input</th> <th>Parameter Name</th> <th>Dictionary Name</th> <th>Dictionary Source</th> <th>Dependancies</th> <th>Default</th> + <th>Velocity</th> <th>Data Type</th> <th>Entry Schema</th> </tr> </thead> <tbody> <tr *ngFor="let dict of mappingRes"> + <!-- <td> + <div class="custom-control custom-checkbox" tooltip="Select" placement="bottom"> + <input type="checkbox" class="custom-control-input" + id="customCheck2-{{dict.name}}" [checked]="selectedProps.has(dict.name)" + (click)="selectProp(dict.name)"> + <label class="custom-control-label" for="customCheck2-{{dict.name}}"></label> + </div> + </td> --> <td> - <img *ngIf="dict.definition?.property?.required" - src="/assets/img/icon-required-yes.svg"> - <img *ngIf="!dict.definition?.property?.required" - src="/assets/img/icon-required-no.svg"> + <img *ngIf="dict?.property?.required" src="/assets/img/icon-required-yes.svg"> + <img *ngIf="!dict?.property?.required" src="/assets/img/icon-required-no.svg"> + </td> + <td> + <img *ngIf="dict['input-param']" src="/assets/img/icon-required-yes.svg"> + <img *ngIf="!dict['input-param']" src="/assets/img/icon-required-no.svg"> </td> <td>{{ dict['name'] }}</td> <td>{{ dict['name'] }}</td> @@ -206,6 +276,10 @@ <!-- {{ dict.definition.sources }} --> </td> <td>{{ dict['property']['default'] }}</td> + <td *ngIf="dict?.property?.metadata"> + {{dict?.property?.metadata['transform-template']}} + </td> + <td *ngIf="!dict?.property?.metadata"></td> <td>{{ dict['property']['type'] }}</td> <td>{{ dict['property']['entry_schema'] }}</td> </tr> diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts index 3e7cfea7b..56ed0422a 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts @@ -10,8 +10,11 @@ import { PackageCreationUtils } from '../../package-creation.utils'; import { JsonConvert, Any } from 'json2typescript'; import { ToastrService } from 'ngx-toastr'; import { SharedService } from '../shared-service'; -import { XmlParser } from '../utils/XmlParser'; +import { XmlParser } from '../utils/ParserFactory/XmlParser'; import { TourService } from 'ngx-tour-md-menu'; +import { PackageCreationService } from '../../package-creation.service'; +import { ParserFactory } from '../utils/ParserFactory/ParserFactory'; +import { TemplateType, FileExtension } from '../utils/TemplateType'; declare var $: any; @Component({ @@ -42,14 +45,17 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { MappingAdapter: MappingAdapter; mapping = new Map(); templateFileContent: string; - templateExt = 'Velcoity'; + templateExt = 'vtl'; dependancies = new Map<string, Array<string>>(); dependanciesSource = new Map<string, string>(); mappingRes = []; currentTemplate: any; currentMapping: any; edit = false; + templatesExist = false; fileToDelete: any = {}; + parserFactory: ParserFactory; + selectedProps: Set<string>; constructor( private packageCreationStore: PackageCreationStore, @@ -57,11 +63,14 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { private packageCreationUtils: PackageCreationUtils, private toastr: ToastrService, private sharedService: SharedService, + private packageCreationService: PackageCreationService, private tourService: TourService, ) { } ngOnInit() { + this.selectedProps = new Set<string>(); + this.parserFactory = new ParserFactory(); this.templateStore.state$.subscribe(templateInfo => { // init Template&mapping vars console.log('Oninit'); @@ -70,7 +79,7 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { this.fileToDelete = templateInfo.fileName; this.fileName = templateInfo.fileName.split('/')[1]; if (this.fileName) { - this.fileName = this.fileName.split('-')[0]; + this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('-')); } if (templateInfo.type === 'mapping' || templateInfo.type.includes('mapping')) { this.mappingRes = templateInfo.mapping; @@ -80,20 +89,27 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { } else { this.mappingRes = []; this.currentMapping = Any; + this.resourceDictionaryRes = []; } this.templateFileContent = templateInfo.fileContent; + this.templateExt = this.templateInfo.ext || this.templateExt; this.currentTemplate = Object.assign({}, templateInfo); if (templateInfo.type === 'template' || templateInfo.type.includes('template')) { - this.currentTemplate.fileName = 'Templates/' + this.fileName + '-template.vtl'; + console.log('template extension ' + this.templateExt); + this.currentTemplate.fileName = 'Templates/' + this.fileName + '-template.' + this.templateExt; + console.log(this.currentTemplate.fileName); } else { this.currentTemplate = Any; } }); + this.sharedService.isEdit().subscribe(res => { - console.log('------------------------'); + console.log('------------------------....'); + this.templatesExist = this.packageCreationStore.state.templates.files.size > 0 + || this.packageCreationStore.state.mapping.files.size > 0; console.log(res); this.edit = res; @@ -113,6 +129,14 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { pageLength: 25, destroy: true, retrieve: true, + columnDefs: [ + { + targets: [0, 1, 2], // column or columns numbers + orderable: false, // set orderable for selected columns + searchable: false, + }, + + ], }; this.dtOptions = { pagingType: 'full_numbers', @@ -122,13 +146,79 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { }; } + setProp(e, propName, index) { + this.resourceDictionaryRes[index][propName] = e.checked; + console.log(this.resourceDictionaryRes[index]); + } + selectProp(value) { + console.log(value); + if (this.selectedProps.has(value)) { + this.selectedProps.delete(value); + } else { + this.selectedProps.add(value); + } + } + + removeProps() { + console.log(this.selectedProps); + this.selectedProps.forEach(prop => { + this.resourceDictionaryRes.forEach((res, index) => { + if (res.name === prop) { + console.log('delete...'); + this.resourceDictionaryRes.splice(index, 1); + this.selectedProps.delete(prop); + } + }); + }); + } + selectAllProps() { + if (this.resourceDictionaryRes.length === this.selectedProps.size) { + this.selectedProps = new Set<string>(); + } else { + this.resourceDictionaryRes.forEach(prop => { + console.log(prop); + this.selectedProps.add(prop.name); + }); + } + + } + reMap() { + let currentResDictionary = []; + if (this.selectedProps && this.selectedProps.size > 0) { + console.log('base'); + this.packageCreationService.getTemplateAndMapping([...this.selectedProps]).subscribe(res => { + let message = 'Re-Auto mapping'; + this.mappingRes = []; + currentResDictionary = res; + console.log(currentResDictionary); + if (currentResDictionary && currentResDictionary.length <= 0) { + message = 'No values for those attributes'; + } + + // Replcae new values with the old ones + currentResDictionary.forEach(curr => { + for (let i = 0; i < this.resourceDictionaryRes.length; i++) { + if (this.resourceDictionaryRes[i].name === curr.name) { + this.resourceDictionaryRes[i] = curr; + } + } + }); + this.rerender(); + this.toastr.success(message, 'Success'); + }, err => { + this.toastr.error('Error'); + }); + } + + } + getFileExtension() { switch (this.templateExt) { - case 'Velcoity': + case 'vtl': return '.vtl'; - case 'Koltin': + case 'kt': return '.ktl'; - case 'Jinja': + case 'j2': return '.j2'; default: return '.vtl'; @@ -141,34 +231,10 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { } public getTemplateVariable(fileContent: string) { - const variables: string[] = []; - const stringsSlittedByBraces = fileContent.split('${'); - const stringsDefaultByDollarSignOnly = fileContent.split('"$'); - - for (let i = 1; i < stringsSlittedByBraces.length; i++) { - const element = stringsSlittedByBraces[i]; - if (element) { - const firstElement = element.split('}')[0]; - if (!variables.includes(firstElement)) { - variables.push(firstElement); - } else { - console.log(firstElement); - } - } - } - - for (let i = 1; i < stringsDefaultByDollarSignOnly.length; i++) { - const element = stringsDefaultByDollarSignOnly[i]; - if (element && !element.includes('$')) { - const firstElement = element.split('"')[0] - .replace('{', '') - .replace('}', '').trim(); - if (!variables.includes(firstElement)) { - variables.push(firstElement); - } - } - } - return variables; + // TODO: implement factory Pattern for parser + console.log('start parsing........ ' + this.templateExt); + const parser = this.parserFactory.getParser(fileContent, this.templateExt); + return parser.getVariables(fileContent); } public dropped(files: NgxFileDropEntry[]) { @@ -224,7 +290,7 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { const parser = new XmlParser(); this.variables = parser.getVariables(fileReader.result.toString()); } - console.log(this.variables); + console.log('variables = ' + this.variables); this.getMappingTableFromTemplate(null); }; @@ -250,7 +316,8 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { const fileReader = new FileReader(); fileReader.onload = (e) => { this.templateFileContent = fileReader.result.toString(); - this.variables = this.getTemplateVariable(this.templateFileContent); + // this.variables = this.getTemplateVariable(this.templateFileContent); + // console.log(this.variables); }; fileReader.readAsText(file); @@ -286,15 +353,30 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { this.showCreationView.emit('close create form and open list'); } + identify(index, item) { + return item.name; + } + setVelocity(index, value) { + // console.log('velocity value = ' + value); + // console.log(this.resourceDictionaryRes[index]); + // tslint:disable-next-line: no-string-literal + this.resourceDictionaryRes[index].definition.property['metadata'] = { + 'transform-template': value + }; + console.log(this.resourceDictionaryRes[index]); + } + getMappingTableFromTemplate(e) { console.log('-' + this.templateFileContent + '-'); this.resourceDictionaryRes = []; if (e) { e.preventDefault(); } + this.variables = this.getTemplateVariable(this.templateFileContent); + console.log('variables = ' + this.variables); if (this.variables && this.variables.length > 0) { console.log('base'); - this.packageCreationStore.getTemplateAndMapping(this.variables).subscribe(res => { + this.packageCreationService.getTemplateAndMapping(this.variables).subscribe(res => { let message = 'Attributes are Fetched'; this.mappingRes = []; this.resourceDictionaryRes = res; @@ -307,6 +389,8 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { }, err => { this.toastr.error('Error'); }); + } else { + this.toastr.error('Empty or Invalid file format. Validate your file first'); } } @@ -316,7 +400,7 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { } return map.key; } - cancel() { + clear() { this.fileName = ''; this.templateFileContent = ''; this.resourceDictionaryRes = []; @@ -325,6 +409,9 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { this.currentTemplate = {}; // this.closeCreationForm(); } + cancel() { + this.openListView(); + } saveToStore() { if (this.fileName) { // check file duplication @@ -350,8 +437,9 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { this.fileName = ''; this.toastr.success('File is created', 'success'); this.openListView(); - console.log(this.tourService.getStatus()); - this.tourService.goto('tm-templateEdit'); + if (localStorage.getItem('tour-guide') !== 'end' && localStorage.getItem('tour-guide') !== 'false') { + this.tourService.goto('tm-templateEdit'); + } } else { console.log('this file already exist'); this.toastr.error('File name already exist', 'Error'); @@ -392,24 +480,13 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { rerender(): void { this.dtTrigger.next(); - - // if (this.dtElement.dtInstance) { - // console.log('rerender'); - // this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => { - // dtInstance.destroy(); - // this.dtElement.dtOptions = this.dtOptions; - // this.dtElement.dtTrigger.next(); - // dtInstance.draw(); - // }); - // } else { - // this.dtTrigger.next(); - // } } ngOnDestroy(): void { // Do not forget to unsubscribe the event this.dtTrigger.unsubscribe(); this.resTableDtTrigger.unsubscribe(); + // this.templateStore.unsubscribe(); } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts index 70e35939b..3a05bcfc5 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, OnInit, Output } from '@angular/core'; +import { Component, EventEmitter, OnDestroy, OnInit, Output } from '@angular/core'; import { PackageCreationStore } from '../../package-creation.store'; import { Mapping, Template } from '../../mapping-models/CBAPacakge.model'; import { TemplateInfo, TemplateStore } from '../../template.store'; @@ -6,6 +6,7 @@ import { TemplateAndMapping } from '../TemplateAndMapping'; import { ActivatedRoute } from '@angular/router'; import { SharedService } from '../shared-service'; import { TourService } from 'ngx-tour-md-menu'; +import { TemplateType } from '../utils/TemplateType'; @Component({ @@ -13,7 +14,7 @@ import { TourService } from 'ngx-tour-md-menu'; templateUrl: './templ-mapp-listing.component.html', styleUrls: ['./templ-mapp-listing.component.css'] }) -export class TemplMappListingComponent implements OnInit { +export class TemplMappListingComponent implements OnInit, OnDestroy { @Output() showCreationView = new EventEmitter<any>(); @Output() showListView = new EventEmitter<any>(); templateAndMappingMap = new Map<string, TemplateAndMapping>(); @@ -22,7 +23,7 @@ export class TemplMappListingComponent implements OnInit { isCreate = true; currentFile: string; edit = false; - fileToDelete: any = {}; + fileToDelete = ''; constructor( private packageCreationStore: PackageCreationStore, @@ -30,11 +31,17 @@ export class TemplMappListingComponent implements OnInit { private route: ActivatedRoute, private sharedService: SharedService, private tourService: TourService, - ) { } + ngOnDestroy(): void { + // this.templateStore.unsubscribe(); + // this.packageCreationStore.unsubscribe(); + } + ngOnInit() { + this.templateAndMappingMap = new Map<string, TemplateAndMapping>(); + this.edit = false; if (this.route.snapshot.paramMap.has('id')) { this.isCreate = false; this.sharedService.isEdit().subscribe(res => { @@ -73,7 +80,9 @@ export class TemplMappListingComponent implements OnInit { } private setIsMappingOrTemplate(key: string, templateAndMapping: TemplateAndMapping, isFromTemplate: boolean) { - const nameOfFile = key.split('/')[1].split('.')[0].split('-')[0]; + const nameOfFile = isFromTemplate ? + key.split('/')[1].split('.')[0].split('-template')[0] + : key.split('/')[1].split('.')[0].split('-mapping')[0]; // const fullName = nameOfFile + ',' + key.split('.'); if (this.templateAndMappingMap.has(nameOfFile)) { const templateAndMappingExisted = this.templateAndMappingMap.get(nameOfFile); @@ -102,12 +111,16 @@ export class TemplMappListingComponent implements OnInit { createNewTemplate() { this.openCreationView(); this.sharedService.disableEdit(); - this.tourService.goto('tm-templateName'); + if (localStorage.getItem('tour-guide') !== 'end' && localStorage.getItem('tour-guide') !== 'false') { + this.tourService.goto('tm-templateName'); + } } + openCreationView() { this.showCreationView.emit('tell parent to open create views'); console.log('disable edit mode'); } + openListView() { console.log('open list view'); this.showListView.emit('show full view'); @@ -115,19 +128,25 @@ export class TemplMappListingComponent implements OnInit { setSourceCodeEditor(key: string) { this.currentFile = key; - const templateKey = 'Templates/' + key + '-template.vtl'; + const templateKey = 'Templates/' + key + '-template'; this.packageCreationStore.state$.subscribe(cba => { console.log('cba ------'); console.log(cba); console.log(key); console.log(this.templateAndMappingMap); const templateInfo = new TemplateInfo(); - if (cba.templates && cba.templates.files.has(templateKey)) { - const fileContent = cba.templates.getValue(templateKey.trim()); - console.log(fileContent); - templateInfo.fileContent = fileContent; - templateInfo.fileName = templateKey; - templateInfo.type = 'template'; + // tslint:disable-next-line: forin + for (const templateType in TemplateType) { + const fileName = templateKey + '.' + TemplateType[templateType]; + if (cba.templates && cba.templates.files.has(fileName)) { + const fileContent = cba.templates.getValue(fileName.trim()); + console.log(templateType + '......ccccccc.... ' + fileName); + templateInfo.fileContent = fileContent; + templateInfo.fileName = fileName; + templateInfo.ext = TemplateType[templateType]; + templateInfo.type = 'template'; + break; + } } const mappingKey = 'Templates/' + key + '-mapping.json'; if (cba.mapping && cba.mapping.files.has(mappingKey)) { @@ -138,7 +157,9 @@ export class TemplMappListingComponent implements OnInit { } this.templateStore.changeTemplateInfo(templateInfo); this.openCreationView(); - this.sharedService.enableEdit(); + if (templateInfo.fileName && templateInfo.fileName.length > 0) { + this.sharedService.enableEdit(); + } }); } @@ -149,20 +170,34 @@ export class TemplMappListingComponent implements OnInit { getValue(file: string) { return this.templateAndMappingMap.get(file); } + initDelete(file) { console.log(file); - this.fileToDelete = file; + const templateKey = 'Templates/' + file + '-template'; + // tslint:disable-next-line: forin + for (const templateType in TemplateType) { + const fileName = templateKey + '.' + TemplateType[templateType]; + if (this.packageCreationStore.state.templates.files.has(fileName)) { + this.fileToDelete = fileName; + break; + } + } + } + condifrmDelete() { - console.log(this.templateAndMappingMap); - this.templateAndMappingMap.delete(this.fileToDelete); + const fullName = this.fileToDelete.split('/')[1]; + const file = fullName.substr(0, fullName.lastIndexOf('-')); + const ext = fullName.substr(fullName.lastIndexOf('.') + 1); + this.templateAndMappingMap.delete(file); if (this.templateAndMappingMap.size <= 0) { this.openCreationView(); } // Delete from templates - this.packageCreationStore.state.templates.files.delete('Templates/' + this.fileToDelete + '-template.vtl'); + this.packageCreationStore.state.templates.files.delete('Templates/' + file + '-template.' + ext); // Delete from Mapping - this.packageCreationStore.state.mapping.files.delete('Templates/' + this.fileToDelete + '-mapping.json'); + this.packageCreationStore.state.mapping.files.delete('Templates/' + file + '-mapping.json'); + console.log(this.templateAndMappingMap); } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/template-mapping.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/template-mapping.component.ts index 341d29f66..15361b8ad 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/template-mapping.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/template-mapping.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { PackageCreationStore } from '../package-creation.store'; import { SharedService } from './shared-service'; @@ -8,7 +8,7 @@ import { SharedService } from './shared-service'; templateUrl: './template-mapping.component.html', styleUrls: ['./template-mapping.component.css'] }) -export class TemplateMappingComponent implements OnInit { +export class TemplateMappingComponent implements OnInit, OnDestroy { creationView = false; listView = true; @@ -18,6 +18,11 @@ export class TemplateMappingComponent implements OnInit { private sharedService: SharedService ) { } + ngOnDestroy(): void { + // this.sharedService.list.unsubscribe(); + // this.sharedService.mode.unsubscribe(); + // this.pakcageStore.unsubscribe(); + } ngOnInit() { diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.spec.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.spec.ts deleted file mode 100644 index e90377e0c..000000000 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.spec.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { XmlParser } from './XmlParser'; - -fdescribe('ImportsTabComponent', () => { - const parser: XmlParser = new XmlParser(); - - - beforeEach(() => { - }); - - it('Test xml Parser', () => { - const fileContent = `<vlb-business-vnf-onap-plugin xmlns="urn:opendaylight:params:xml:ns:yang:vlb-business-vnf-onap-plugin"> - <vdns-instances> - <vdns-instance> - <ip-addr>$vdns_int_private_ip_0</ip-addr> - <oam-ip-addr>$vdns_onap_private_ip_0</oam-ip-addr> - <enabled>false</enabled> - <tag>dddd</tag> - </vdns-instance> - </vdns-instances> - </vlb-business-vnf-onap-plugin>`; - - const res = parser.getVariables(fileContent); - console.log(res); - expect(res.length).toEqual(2); - expect(res[0]).toEqual('vdns_int_private_ip_0'); - expect(res[1]).toEqual('vdns_onap_private_ip_0'); - }); -}); diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ASCII-Parser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ASCII-Parser.ts new file mode 100644 index 000000000..c9e0a1891 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ASCII-Parser.ts @@ -0,0 +1,19 @@ +import { Parser } from './Parser'; + +export class ASCIIParser implements Parser { + variables: Set<string> = new Set(); + getVariables(fileContent: string): string[] { + if (fileContent.includes('$(')) { + const xmlSplit = fileContent.split('$('); + for (const val of xmlSplit) { + const res = val.substring(0, val.indexOf(')')); + if (res && res.length > 0) { + this.variables.add(res); + } + + } + } + return [...this.variables]; + } + +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaXML.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaXML.ts new file mode 100644 index 000000000..cb1359aa0 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaXML.ts @@ -0,0 +1,31 @@ +import { Parser } from './Parser'; + +export class JinjaXMLParser implements Parser { + variables: Set<string> = new Set(); + getVariables(fileContent: string): string[] { + if (fileContent.includes('>[')) { + const xmlSplit = fileContent.split('>['); + for (const val of xmlSplit) { + const res = val.substring(0, val.indexOf(']</')); + if (res && res.length > 0) { + this.variables.add(res); + } + + } + } + return [...this.variables]; + } + +} + +/* + +<?xml version="1.0" encoding="UTF-8"?> +<configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos"> +<system xmlns="http://yang.juniper.net/junos-qfx/conf/system"> +<host-name operation="delete" /> +<host-name operation="create">[hostname]</host-name> +</system> +</configuration> + +*/ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts new file mode 100644 index 000000000..6ecee9070 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts @@ -0,0 +1,43 @@ +import { Parser } from './Parser'; + +export class JinjaYMLParser implements Parser { + variables: Set<string> = new Set(); + getVariables(fileContent: string): string[] { + if (fileContent.includes('{{')) { + // '[{]+[ ]*.[V-v]alues.' old regex + const xmlSplit = fileContent.split(new RegExp('[{]+[ ]*.')); + for (const val of xmlSplit) { + const res = val.substring(0, val.indexOf('}}')); + if (res && res.length > 0) { + console.log(res); + if (res.includes('Value')) { + this.variables.add(this.extractValues(res.trim())); + } else { + this.variables.add(this.extractParent(res.trim()).toLowerCase()); + } + } + } + } + return [...this.variables]; + } + + extractValues(value) { + return value.split('Values.')[1]; + } + extractParent(value): string { + return value.split('.')[0]; + } + +} + +/* +vf-module-name: {{ .Values.vpg_name_0 }} +<?xml version="1.0" encoding="UTF-8"?> +<configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos"> +<system xmlns="http://yang.juniper.net/junos-qfx/conf/system"> +<host-name operation="delete" /> +<host-name operation="create">[hostname]</host-name> +</system> +</configuration> + +*/ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts new file mode 100644 index 000000000..3a1880c99 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts @@ -0,0 +1,153 @@ +import { XmlParser } from './XmlParser'; +import { ParserFactory } from './ParserFactory'; +import { FileExtension } from '../TemplateType'; +import { JinjaXMLParser } from './JinjaXML'; + +fdescribe('ImportsTabComponent', () => { + + const parserFactory = new ParserFactory(); + + + beforeEach(() => { + }); + + it('Test xml Parser', () => { + const fileContent = `<vlb-business-vnf-onap-plugin xmlns="urn:opendaylight:params:xml:ns:yang:vlb-business-vnf-onap-plugin"> + <vdns-instances> + <vdns-instance> + <ip-addr>$vdns_int_private_ip_0</ip-addr> + <oam-ip-addr>$vdns_onap_private_ip_0</oam-ip-addr> + <enabled>false</enabled> + <tag>dddd</tag> + </vdns-instance> + </vdns-instances> + </vlb-business-vnf-onap-plugin>`; + + const parser = parserFactory.getParser(fileContent, FileExtension.XML); + const res = parser.getVariables(fileContent); + console.log(res); + expect(res.length).toEqual(2); + expect(res[0]).toEqual('vdns_int_private_ip_0'); + expect(res[1]).toEqual('vdns_onap_private_ip_0'); + }); + + it('Test J2 XML Parser', () => { + const fileContent = `<?xml version="1.0" encoding="UTF-8"?> + <configuration xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos"> + <system xmlns="http://yang.juniper.net/junos-qfx/conf/system"> + <host-name operation="delete" /> + <host-name operation="create">[hostname]</host-name> + </system> + </configuration>`; + + const parser = parserFactory.getParser(fileContent, FileExtension.Jinja); + const res = parser.getVariables(fileContent); + console.log(typeof (res)); + console.log(res); + expect(res.length).toEqual(1); + expect(res[0]).toEqual('hostname'); + + }); + + it('Test J2 YML Parser', () => { + const fileContent = `apiVersion: v1 + kind: Service + metadata: + name: {{ .Values.vpg_name_0 }}-ssh + labels: + vnf-name: {{ .Values.vnf_name }} + vf-module-name: {{ .Values.vpg_name_0 }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }} + spec: + type: NodePort + ports: + port: 22 + nodePort: \${vpg-management-port} + selector: + vf-module-name: {{ .Values.vpg_name_0 }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }}`; + + const parser = parserFactory.getParser(fileContent, FileExtension.Jinja); + const res = parser.getVariables(fileContent); + console.log(res); + expect(res.length).toEqual(4); + expect(res[0]).toEqual('vpg_name_0'); + expect(res[1]).toEqual('vnf_name'); + + }); + + it('Test ASCII Parser', () => { + const fileContent = ` + config system interface + edit "internal" + set vdom "root" + set ip $(subnet1_fgt_ip) 255.255.255.0 #1 + set allowaccess ping https ssh http fgfm capwap + set type hard-switch + set stp enable + set role lan + next + end + config system dhcp server + edit 1 + set dns-service default + set default-gateway $(subnet1_fgt_ip) #2 + set netmask 255.255.255.0 + set interface "internal" + config ip-range + edit 1 + set start-ip $(subnet1_fgt_ip)4,150 #3 + set end-ip $(subnet1_fgt_ip)4,200 #4 + next + end + next + end + Options + `; + + const parser = parserFactory.getParser(fileContent, FileExtension.Jinja); + const res = parser.getVariables(fileContent); + console.log(res); + expect(res.length).toEqual(1); + expect(res[0]).toEqual('subnet1_fgt_ip'); + + + }); + + + + + + it('Test Velocity YML Parser', () => { + const fileContent = `apiVersion: v1 + kind: Service + metadata: + name: {{ .Values.vpg_name_0 }}-ssh + labels: + vnf-name: {{ .Values.vnf_name }} + vf-module-name: {{ .Values.vpg_name_0 }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }} + spec: + type: NodePort + ports: + port: 22 + nodePort: \${vpg-management-port} + selector: + vf-module-name: {{ .Values.vpg_name_0 }} + release: {{ .Release.Name }} + chart: {{ .Chart.Name }}`; + + const parser = parserFactory.getParser(fileContent, FileExtension.Velocity); + const res = parser.getVariables(fileContent); + console.log(res); + expect(res.length).toEqual(1); + expect(res[0]).toEqual('vpg-management-port'); + + }); + + + +}); diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.ts index 495c64307..f189a84ca 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.ts @@ -1,3 +1,4 @@ export interface Parser { + variables: Set<string>; getVariables(fileContent: string): string[]; } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts new file mode 100644 index 000000000..b64afeed0 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts @@ -0,0 +1,73 @@ + +import { XmlParser } from './XmlParser'; +import { Parser } from './Parser'; +import { VtlParser } from './VtlParser'; +import { FileExtension } from '../TemplateType'; +import { JinjaXMLParser } from './JinjaXML'; +import { VtlYMLParser } from './VtlYMLParser'; +import { JinjaYMLParser } from './JinjaYML'; +import { ASCIIParser } from './ASCII-Parser'; + +export class ParserFactory { + + getParser(fileContent: string, fileExtension: string): Parser { + let parser: Parser; + console.log('file extension =' + fileExtension); + + if (fileExtension === FileExtension.Velocity) { + + if (this.isXML(fileContent)) { + parser = new XmlParser(); + } else if (this.isJSON(fileContent)) { + parser = new VtlParser(); + } else if (this.isASCII(fileContent)) { + parser = new ASCIIParser(); + } else { + console.log('Velocity YML parser....'); + parser = new VtlYMLParser(); + } + + } else if (fileExtension === FileExtension.Jinja) { + + if (this.isXML(fileContent)) { + parser = new JinjaXMLParser(); + } else if (this.isJSON(fileContent)) { + // TODO: implement JSON parser + } else if (this.isASCII(fileContent)) { + parser = new ASCIIParser(); + } else { + console.log('Jinja YML parser....'); + parser = new JinjaYMLParser(); + } + + } else if (fileExtension === FileExtension.XML) { + parser = new XmlParser(); + } + return parser; + } + + private isXML(fileContent: string): boolean { + return fileContent.includes('<?xml version="1.0" encoding="UTF-8"?>'); + } + + private isJSON(fileContent: string): boolean { + try { + JSON.parse(fileContent); + } catch (e) { + return false; + } + return true; + } + + private isASCII(fileContent: string): boolean { + if ( + fileContent.includes('end') && + fileContent.includes('set') && + fileContent.includes('$(') + ) { + return true; + } + + return false; + } +} diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlParser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlParser.ts new file mode 100644 index 000000000..ca80a297c --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlParser.ts @@ -0,0 +1,53 @@ +import { Parser } from './Parser'; + +export class VtlParser implements Parser { + variables: Set<string> = new Set(); + getVariables(fileContent: string): string[] { + const variables: string[] = []; + const stringsSlittedByBraces = fileContent.split('${'); + const stringsDefaultByDollarSignOnly = fileContent.split('"$'); + + for (let i = 1; i < stringsSlittedByBraces.length; i++) { + const element = stringsSlittedByBraces[i]; + if (element) { + const firstElement = element.split('}')[0]; + if (!variables.includes(firstElement)) { + variables.push(firstElement); + } else { + console.log(firstElement); + } + } + } + + for (let i = 1; i < stringsDefaultByDollarSignOnly.length; i++) { + const element = stringsDefaultByDollarSignOnly[i]; + if (element && !element.includes('$')) { + const firstElement = element.split('"')[0] + .replace('{', '') + .replace('}', '').trim(); + if (!variables.includes(firstElement)) { + variables.push(firstElement); + } + } + } + this.variables = new Set(variables); + return [...variables]; + } + +} + +/* + +<vlb-business-vnf-onap-plugin xmlns="urn:opendaylight:params:xml:ns:yang:vlb-business-vnf-onap-plugin"> + <vdns-instances> + <vdns-instance> + <ip-addr>$vdns_int_private_ip_0</ip-addr> + <oam-ip-addr>$vdns_onap_private_ip_0</oam-ip-addr> + <tag>aaaa</tag> + <enabled>false</enabled> + <tag>dddd</tag> + </vdns-instance> + </vdns-instances> +</vlb-business-vnf-onap-plugin> + +*/ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts new file mode 100644 index 000000000..6c3a0e0fd --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts @@ -0,0 +1,35 @@ +import { Parser } from './Parser'; + +export class VtlYMLParser implements Parser { + variables: Set<string> = new Set(); + getVariables(fileContent: string): string[] { + if (fileContent.includes('${')) { + const xmlSplit = fileContent.split('${'); + for (const val of xmlSplit) { + const res = val.substring(0, val.indexOf('}')); + if (res && res.length > 0 && !res.includes('{')) { + this.variables.add(res); + } + + } + } + return [...this.variables]; + } + +} + +/* + +<vlb-business-vnf-onap-plugin xmlns="urn:opendaylight:params:xml:ns:yang:vlb-business-vnf-onap-plugin"> + <vdns-instances> + <vdns-instance> + <ip-addr>$vdns_int_private_ip_0</ip-addr> + <oam-ip-addr>$vdns_onap_private_ip_0</oam-ip-addr> + <tag>aaaa</tag> + <enabled>false</enabled> + <tag>dddd</tag> + </vdns-instance> + </vdns-instances> +</vlb-business-vnf-onap-plugin> + +*/ diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/XmlParser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/XmlParser.ts index 4feb7032a..69bc8b627 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/XmlParser.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/XmlParser.ts @@ -1,18 +1,17 @@ import { Parser } from './Parser'; -import { variable } from '@angular/compiler/src/output/output_ast'; export class XmlParser implements Parser { + variables: Set<string> = new Set(); getVariables(fileContent: string): string[] { - const variables = []; const xmlSplit = fileContent.split('$'); for (const val of xmlSplit) { const res = val.substring(0, val.indexOf('</')); if (res && res.length > 0) { - variables.push(res); + this.variables.add(res); } } - return variables; + return [...this.variables]; } } diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/TemplateType.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/TemplateType.ts new file mode 100644 index 000000000..04a829e8a --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/TemplateType.ts @@ -0,0 +1,13 @@ +export enum TemplateType { + Velocity = 'vtl', + Koltin = 'kt', + Jinja = 'j2', +} + +export enum FileExtension { + Velocity = 'vtl', + Koltin = 'kt', + Jinja = 'j2', + CSV = 'csv', + XML = 'xml' +} |