Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 2b8ed93

Browse files
BoykoAlexcppwfs
authored andcommitted
Stream editor contents validation
Validation Validation Validation
1 parent fda2f41 commit 2b8ed93

File tree

8 files changed

+57
-10
lines changed

8 files changed

+57
-10
lines changed

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"ngx-pagination": "^3.0.1",
3838
"rxjs": "^5.4.2",
3939
"sockjs-client": "^1.1.4",
40-
"spring-flo": "git://github.com/spring-projects/spring-flo.git#b4e20eb9cd31764e2f96b178d03500c7d7d6628f",
40+
"spring-flo": "git://github.com/spring-projects/spring-flo.git#b584fed1ed201f308bd9a4a6cb9e8f54c824e99d",
4141
"stompjs": "^2.3.3",
4242
"tixif-ngx-busy": "0.0.5",
4343
"zone.js": "^0.8.14"

ui/src/app/shared/services/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ export namespace Parser {
671671
}
672672

673673
export interface Error {
674-
message: String;
674+
message: string;
675675
range: Range;
676676
}
677677

ui/src/app/streams/flo/editor.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ export class EditorService implements Flo.Editor {
514514
this.validateProperties(element, errors);
515515
}
516516

517-
validate(graph: dia.Graph): Promise<Map<string, Array<Flo.Marker>>> {
517+
validate(graph: dia.Graph, dsl: string, flo: Flo.EditorContext): Promise<Map<string, Flo.Marker[]>> {
518518
return new Promise(resolve => {
519519
const allMarkers: Map<string, Array<Flo.Marker>> = new Map();
520520
graph.getElements().filter(e => !e.get('parent') && e.attr('metadata')).forEach(e => {

ui/src/app/streams/flo/metamodel.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ export class MetamodelService implements Flo.Metamodel {
138138
private appsService: SharedAppsService,
139139
) {}
140140

141-
textToGraph(flo: Flo.EditorContext, dsl: string): void {
141+
textToGraph(flo: Flo.EditorContext, dsl: string): Promise<any> {
142142
console.log('> textToGraph ' + dsl);
143-
this.load().then((metamodel) => { convertTextToGraph(dsl, flo, metamodel); });
143+
return new Promise(resolve => {
144+
this.load().then((metamodel) => resolve(convertTextToGraph(dsl, flo, metamodel)));
145+
});
144146
}
145147

146148
graphToText(flo: Flo.EditorContext): Promise<string> {

ui/src/app/streams/flo/text-to-graph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export namespace JsonGraph {
420420
}
421421

422422
export interface Graph {
423-
errors: {}[];
423+
errors: Parser.Error[];
424424
format: string;
425425
streamdefs;
426426
nodes: Node[];

ui/src/app/streams/stream-create/stream-create.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div id="flo-container" class="stream-editor">
22
<flo-editor (floApi)="editorContext = $event" [metamodel]="metamodelService" [renderer]="renderService"
3-
[editor]="editorService" [paletteSize]="paletteSize" [(dsl)]="dsl" [paperPadding]="20">
3+
[editor]="editorService" [paletteSize]="paletteSize" [(dsl)]="dsl" [paperPadding]="20" (validationMarkers)="validationMarkers = $event">
44
<button (click)="createStreamDefs()" class="btn btn-default" type="button" [disabled]="!dsl">Create Stream</button>
55
<button (click)="editorContext.clearGraph()" class="btn btn-default" type="button">Clear</button>
66
<button (click)="arrangeAll()" class="btn btn-default" type="button">Layout</button>
@@ -11,7 +11,7 @@
1111
<div class="flow-definition-container">
1212
<dsl-editor [(dsl)]="dsl" line-numbers="true" line-wrapping="true" (blur)="editorContext.graphToTextSync=true"
1313
(focus)="editorContext.graphToTextSync=false" placeholder="Enter stream definition..."
14-
[hintOptions]="hintOptions"></dsl-editor>
14+
[hintOptions]="hintOptions" [lintOptions]="lintOptions"></dsl-editor>
1515
</div>
1616
</flo-editor>
1717
</div>

ui/src/app/streams/stream-create/stream-create.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {ActivatedRoute} from '@angular/router';
1212
import { FloModule} from 'spring-flo';
1313
import {ModalModule, BsModalService} from 'ngx-bootstrap';
1414
import { ContentAssistService } from '../flo/content-assist.service';
15+
import { ParserService } from '../../shared/services/parser.service';
1516

1617
/**
1718
* Test {@link StreamCreateComponent}.
@@ -25,6 +26,8 @@ describe('StreamCreateComponent', () => {
2526
const streamsService = new MockStreamsService();
2627
const metamodelService = new MockMetamodelService();
2728
const renderService = new RenderService(metamodelService);
29+
const parserService = new ParserService();
30+
2831
// const editorService = new EditorService(null);
2932
const commonTestParams = { id: '1' };
3033

@@ -48,6 +51,7 @@ describe('StreamCreateComponent', () => {
4851
{provide: ContentAssistService},
4952
{provide: BsModalService},
5053
{provide: ActivatedRoute, useValue: activeRoute },
54+
{provide: ParserService, useValue: parserService}
5155
]
5256
})
5357
.compileComponents();

ui/src/app/streams/stream-create/stream-create.component.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
22
import { Flo } from 'spring-flo';
3+
import { ParserService } from '../../shared/services/parser.service';
34
import { MetamodelService } from '../flo/metamodel.service';
45
import { RenderService } from '../flo/render.service';
56
import { EditorService } from '../flo/editor.service';
@@ -25,17 +26,32 @@ export class StreamCreateComponent implements OnInit {
2526

2627
hintOptions: any;
2728

29+
lintOptions: CodeMirror.LintOptions;
30+
31+
validationMarkers: Map<string, Flo.Marker[]>;
32+
2833
constructor(public metamodelService: MetamodelService,
2934
public renderService: RenderService,
3035
public editorService: EditorService,
3136
private bsModalService: BsModalService,
32-
private contentAssistService: ContentAssistService) {
33-
console.log('Building');
37+
private contentAssistService: ContentAssistService,
38+
private parserService: ParserService) {
39+
40+
this.validationMarkers = new Map();
3441

3542
this.hintOptions = {
3643
async: true,
3744
hint: (doc: CodeMirror.EditorFromTextArea) => this.contentAssist(doc)
3845
};
46+
47+
this.lintOptions = {
48+
async: true,
49+
hasGutters: true,
50+
getAnnotations: (content: string,
51+
updateLintingCallback: CodeMirror.UpdateLintingCallback,
52+
options: CodeMirror.LintStateOptions,
53+
editor: CodeMirror.Editor) => this.lint(content, updateLintingCallback, editor)
54+
};
3955
}
4056

4157
ngOnInit() {
@@ -86,6 +102,31 @@ export class StreamCreateComponent implements OnInit {
86102

87103
}
88104

105+
lint(dsl: string, updateLintingCallback: CodeMirror.UpdateLintingCallback, editor: CodeMirror.Editor): void {
106+
const result = this.parserService.parseDsl(dsl, 'stream');
107+
const annotations: CodeMirror.Annotation[] = [];
108+
Array.from(this.validationMarkers.values())
109+
.filter(markers => Array.isArray(markers))
110+
.forEach(markers => markers
111+
.filter(m => m.range && m.severity)
112+
.forEach(m => annotations.push({
113+
message: m.message,
114+
from: m.range.start,
115+
to: m.range.end,
116+
severity: Flo.Severity[m.severity].toLowerCase()
117+
}))
118+
);
119+
if (result.lines) {
120+
result.lines.filter(l => Array.isArray(l.errors)).forEach(l => l.errors.forEach(e => annotations.push({
121+
from: e.range.start,
122+
to: e.range.end,
123+
message: e.message,
124+
severity: 'error'
125+
})));
126+
}
127+
updateLintingCallback(editor, annotations);
128+
}
129+
89130
/**
90131
* The suggestions provided by rest api are very long and include the whole command typed
91132
* from the start of the line. This function determines the start of the 'interesting' part

0 commit comments

Comments
 (0)