diff options
author | AhmedEldeeb50 <ahmed.eldeeb.ext@orange.com> | 2020-07-15 21:58:59 +0200 |
---|---|---|
committer | AhmedEldeeb50 <ahmed.eldeeb.ext@orange.com> | 2020-07-15 21:58:59 +0200 |
commit | 296d2bdbaba99d34ce62a8483b5d8d4f90761379 (patch) | |
tree | dafa84ac90f98605469e6989f5942f415d509864 /cds-ui/designer-client/src/app/modules/feature-modules | |
parent | 0882e287bbb6aee4543f7659b1f9d001a1b01a1a (diff) |
support XML for "Upload Attributes List" button for mapping
Issue-ID: CCSDK-2571
Signed-off-by: AhmedEldeeb50 <ahmed.eldeeb.ext@orange.com>
Change-Id: I4164fdef145e92faa2cf2550a036d50273127c6a
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules')
5 files changed, 85 insertions, 10 deletions
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 f517cb108..65845a6cc 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 @@ -102,12 +102,12 @@ <br /> <span>Use Current Template Instance</span> </button> - <a href="#" (click)="allowedExt=['.csv']" data-toggle="modal" data-target="#templateModal" + <a href="#" (click)="allowedExt=['.csv','.xml']" data-toggle="modal" data-target="#templateModal" class="mapping-source-load"> <i class="icon-upload-attributes"></i> <br /> <div>Upload Attributes List</div> - <div class="source-load-note">(Should be comma delimited file)</div> + <div class="source-load-note">CSV or XML files</div> </a> <!-- <a href="#" class="mapping-source-load"> <i class="icon-import-cds"></i> 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 af7acc2d0..61ea374a3 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,6 +10,7 @@ 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'; declare var $: any; @Component({ @@ -21,8 +22,8 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { @Output() showListView = new EventEmitter<any>(); @Output() showCreationView = new EventEmitter<any>(); public uploadedFiles: FileSystemFileEntry[] = []; - fileNames: Set<string> = new Set(); - jsonConvert = new JsonConvert(); + fileNames: Set<string> = new Set(); + jsonConvert = new JsonConvert(); public files: NgxFileDropEntry[] = []; fileName: any; templateInfo = new TemplateInfo(); @@ -132,6 +133,11 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { } } + fileExtensionFromString(filename: string): string { + const fileExtension = filename.substring(filename.lastIndexOf('.') + 1); + return fileExtension; + } + public getTemplateVariable(fileContent: string) { const variables: string[] = []; const stringsSlittedByBraces = fileContent.split('${'); @@ -196,22 +202,26 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { uploadFile() { this.dependancies.clear(); this.dependanciesSource.clear(); - if (this.allowedExt.includes('.csv')) { - this.fetchCSVkeys(); + if (this.allowedExt.includes('.csv') || this.allowedExt.includes('.xml')) { + this.fetchkeysfromfile(); } else { this.setTemplateFilesToStore(); } $('.btn-cancel').click(); - - } - fetchCSVkeys() { + fetchkeysfromfile() { for (const droppedFile of this.uploadedFiles) { droppedFile.file((file: File) => { const fileReader = new FileReader(); fileReader.onload = (e) => { - this.variables = fileReader.result.toString().split(','); + const fileExt = this.fileExtensionFromString(droppedFile.name); + if (fileExt === 'csv') { + this.variables = fileReader.result.toString().split(','); + } else { + const parser = new XmlParser(); + this.variables = parser.getVariables(fileReader.result.toString()); + } console.log(this.variables); this.getMappingTableFromTemplate(null); 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 new file mode 100644 index 000000000..e90377e0c --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.spec.ts @@ -0,0 +1,28 @@ +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/Parser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.ts new file mode 100644 index 000000000..495c64307 --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/Parser.ts @@ -0,0 +1,3 @@ +export interface Parser { + getVariables(fileContent: string): string[]; +} 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/XmlParser.ts new file mode 100644 index 000000000..4feb7032a --- /dev/null +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/XmlParser.ts @@ -0,0 +1,34 @@ +import { Parser } from './Parser'; +import { variable } from '@angular/compiler/src/output/output_ast'; + +export class XmlParser implements Parser { + 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); + } + + } + 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> + +*/ |