Merge "improve selecting filenames of tempalte and mapping"
authorKAPIL SINGAL <ks220y@att.com>
Mon, 5 Oct 2020 13:02:36 +0000 (13:02 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 5 Oct 2020 13:02:36 +0000 (13:02 +0000)
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts

index 57c2bcb..4712813 100644 (file)
@@ -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;
     }
 
 }
index 8c4eab8..8c1279f 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
+import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
 import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
 import { PackageCreationStore } from '../../package-creation.store';
 import { TemplateInfo, TemplateStore } from '../../template.store';
@@ -290,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);
 
                 };
@@ -373,7 +373,7 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy {
             e.preventDefault();
         }
         this.variables = this.getTemplateVariable(this.templateFileContent);
-        console.log(this.variables);
+        console.log('variables = ' + this.variables);
         if (this.variables && this.variables.length > 0) {
             console.log('base');
             this.packageCreationService.getTemplateAndMapping(this.variables).subscribe(res => {
index 93cd5ec..561642e 100644 (file)
@@ -40,6 +40,8 @@ export class TemplMappListingComponent implements OnInit, OnDestroy {
     }
 
     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 => {
@@ -155,7 +157,9 @@ export class TemplMappListingComponent implements OnInit, OnDestroy {
             }
             this.templateStore.changeTemplateInfo(templateInfo);
             this.openCreationView();
-            this.sharedService.enableEdit();
+            if (templateInfo.fileName && templateInfo.fileName.length > 0) {
+                this.sharedService.enableEdit();
+            }
         });
     }
 
index 11d1ad7..6ecee90 100644 (file)
@@ -4,18 +4,30 @@ export class JinjaYMLParser implements Parser {
     variables: Set<string> = new Set();
     getVariables(fileContent: string): string[] {
         if (fileContent.includes('{{')) {
-            const xmlSplit = fileContent.split(new RegExp('[{]+[ ]*.[V-v]alues.'));
+            // '[{]+[ ]*.[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) {
-                    this.variables.add(res.trim());
+                    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];
+    }
+
 }
 
 /*
index aab37c7..3a1880c 100644 (file)
@@ -72,7 +72,7 @@ fdescribe('ImportsTabComponent', () => {
         const parser = parserFactory.getParser(fileContent, FileExtension.Jinja);
         const res = parser.getVariables(fileContent);
         console.log(res);
-        expect(res.length).toEqual(2);
+        expect(res.length).toEqual(4);
         expect(res[0]).toEqual('vpg_name_0');
         expect(res[1]).toEqual('vnf_name');
 
@@ -115,4 +115,39 @@ fdescribe('ImportsTabComponent', () => {
 
 
     });
+
+
+
+
+
+    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');
+
+    });
+
+
+
 });
index a5c92e4..b64afee 100644 (file)
@@ -23,6 +23,7 @@ export class ParserFactory {
             } else if (this.isASCII(fileContent)) {
                 parser = new ASCIIParser();
             } else {
+                console.log('Velocity YML parser....');
                 parser = new VtlYMLParser();
             }
 
@@ -35,6 +36,7 @@ export class ParserFactory {
             } else if (this.isASCII(fileContent)) {
                 parser = new ASCIIParser();
             } else {
+                console.log('Jinja YML parser....');
                 parser = new JinjaYMLParser();
             }
 
index 4b7d227..6c3a0e0 100644 (file)
@@ -7,7 +7,7 @@ export class VtlYMLParser implements Parser {
             const xmlSplit = fileContent.split('${');
             for (const val of xmlSplit) {
                 const res = val.substring(0, val.indexOf('}'));
-                if (res && res.length > 0) {
+                if (res && res.length > 0 && !res.includes('{')) {
                     this.variables.add(res);
                 }