summaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlParser.ts
blob: ca80a297c630deae10a44f4503214fae0d392f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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>

*/