diff options
author | KAPIL SINGAL <ks220y@att.com> | 2020-09-27 16:27:38 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-27 16:27:38 +0000 |
commit | 809ebd8d7974b1a658fb7f7a8a2466ca5d13bf52 (patch) | |
tree | f60c78aac2dd4a6cb8a42ae85ea617d78c70cb2d /cds-ui/designer-client | |
parent | 3e84c6e26fbce878d5f06f4c6f7666e18d020925 (diff) | |
parent | 56133157ca970b5016938ebabbf91052bc2c6110 (diff) |
Merge "Support parsing of ASCII/CLI files within Velocity and Jinja Template"
Diffstat (limited to 'cds-ui/designer-client')
3 files changed, 74 insertions, 0 deletions
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/Parser.spec.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts index d9c4c2b4a..aab37c722 100644 --- 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 @@ -77,4 +77,42 @@ fdescribe('ImportsTabComponent', () => { 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'); + + + }); }); 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 index d8607c764..a5c92e441 100644 --- 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 @@ -6,6 +6,7 @@ import { FileExtension } from '../TemplateType'; import { JinjaXMLParser } from './JinjaXML'; import { VtlYMLParser } from './VtlYMLParser'; import { JinjaYMLParser } from './JinjaYML'; +import { ASCIIParser } from './ASCII-Parser'; export class ParserFactory { @@ -19,6 +20,8 @@ export class ParserFactory { parser = new XmlParser(); } else if (this.isJSON(fileContent)) { parser = new VtlParser(); + } else if (this.isASCII(fileContent)) { + parser = new ASCIIParser(); } else { parser = new VtlYMLParser(); } @@ -29,6 +32,8 @@ export class ParserFactory { parser = new JinjaXMLParser(); } else if (this.isJSON(fileContent)) { // TODO: implement JSON parser + } else if (this.isASCII(fileContent)) { + parser = new ASCIIParser(); } else { parser = new JinjaYMLParser(); } @@ -51,4 +56,16 @@ export class ParserFactory { } return true; } + + private isASCII(fileContent: string): boolean { + if ( + fileContent.includes('end') && + fileContent.includes('set') && + fileContent.includes('$(') + ) { + return true; + } + + return false; + } } |