summaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory
diff options
context:
space:
mode:
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory')
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaXML.ts31
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts28
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.ts3
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts32
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlParser.ts51
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/XmlParser.ts33
6 files changed, 178 insertions, 0 deletions
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..7a8042433
--- /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 {
+ getVariables(fileContent: string): string[] {
+ const variables = [];
+ if (fileContent.includes('>[')) {
+ 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;
+ }
+
+}
+
+/*
+
+<?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..e90377e0c
--- /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,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/ParserFactory/Parser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/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/ParserFactory/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/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..6cc62758e
--- /dev/null
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
@@ -0,0 +1,32 @@
+
+import { XmlParser } from './XmlParser';
+import { Parser } from './Parser';
+import { VtlParser } from './VtlParser';
+import { FileExtension } from '../TemplateType';
+import { JinjaXMLParser } from './JinjaXML';
+
+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 {
+ parser = new VtlParser();
+ }
+ } else if (fileExtension === FileExtension.Jinja) {
+ if (this.isXML(fileContent)) {
+ parser = new JinjaXMLParser();
+ }
+ } 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"?>');
+ }
+}
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..2b2e17fb9
--- /dev/null
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlParser.ts
@@ -0,0 +1,51 @@
+import { Parser } from './Parser';
+
+export class VtlParser implements Parser {
+ 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);
+ }
+ }
+ }
+ 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/XmlParser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/XmlParser.ts
new file mode 100644
index 000000000..5cb9c9f81
--- /dev/null
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/XmlParser.ts
@@ -0,0 +1,33 @@
+import { Parser } from './Parser';
+
+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>
+
+*/