You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2020/03/09 21:11:27 UTC

[incubator-streampipes] branch dev updated: STREAMPIPES-96: Consider schema requirements in widget selection

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 6d3c5b2  STREAMPIPES-96: Consider schema requirements in widget selection
6d3c5b2 is described below

commit 6d3c5b2c94b211ea44cf3a2a5e263d4d55f3f9f7
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Mon Mar 9 22:11:13 2020 +0100

    STREAMPIPES-96: Consider schema requirements in widget selection
---
 .../add-visualization-dialog.component.ts          |  9 +++----
 ui/src/app/dashboard/registry/widget-registry.ts   | 12 +++++++++
 ui/src/app/dashboard/sdk/matching/schema-match.ts  | 30 ++++++++++++++++++++++
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.ts b/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.ts
index f93c651..73efcb8 100644
--- a/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.ts
+++ b/ui/src/app/dashboard/dialogs/add-widget/add-visualization-dialog.component.ts
@@ -85,11 +85,6 @@ export class AddVisualizationDialogComponent {
                     });
                 })
             });
-
-            this.availableWidgets = WidgetRegistry.getAvailableWidgetTemplates()
-            this.availableWidgets.sort((a, b) => {
-                return a.widgetLabel < b.widgetLabel ? -1 : 1;
-            });
         } else {
             this.dialogTitle = "Edit widget";
             this.selectedPipeline = this.data.pipeline;
@@ -151,6 +146,10 @@ export class AddVisualizationDialogComponent {
 
     next() {
         if (this.page == 'select-pipeline') {
+            this.availableWidgets = WidgetRegistry.getCompatibleWidgetTemplates(this.selectedPipeline);
+            this.availableWidgets.sort((a, b) => {
+                return a.widgetLabel < b.widgetLabel ? -1 : 1;
+            });
             this.page = 'select-widget';
         } else if (this.page == 'select-widget') {
             this.page = 'configure-widget';
diff --git a/ui/src/app/dashboard/registry/widget-registry.ts b/ui/src/app/dashboard/registry/widget-registry.ts
index 54d2e29..bd1accd 100644
--- a/ui/src/app/dashboard/registry/widget-registry.ts
+++ b/ui/src/app/dashboard/registry/widget-registry.ts
@@ -28,6 +28,9 @@ import {MapConfig} from "../components/widgets/map/map-config";
 import {RawConfig} from "../components/widgets/raw/raw-config";
 import {HtmlConfig} from "../components/widgets/html/html-config";
 import {TrafficLightConfig} from "../components/widgets/trafficlight/traffic-light-config";
+import {VisualizablePipeline} from "../../core-model/dashboard/VisualizablePipeline";
+import {EventSchema} from "../../connect/schema-editor/model/EventSchema";
+import {SchemaMatch} from "../sdk/matching/schema-match";
 
 export class WidgetRegistry {
 
@@ -49,4 +52,13 @@ export class WidgetRegistry {
         this.availableWidgets.forEach(widget => widgetTemplates.push(widget.getConfig()));
         return widgetTemplates;
     }
+
+    static getCompatibleWidgetTemplates(pipeline: VisualizablePipeline) {
+        let inputSchema: EventSchema = pipeline.schema;
+        return this.getAvailableWidgetTemplates().filter(widget => WidgetRegistry.isCompatible(widget, inputSchema));
+    }
+
+    static isCompatible(widget: DashboardWidgetSettings, inputSchema: EventSchema) {
+        return new SchemaMatch().match(widget.requiredSchema, inputSchema);
+    }
 }
\ No newline at end of file
diff --git a/ui/src/app/dashboard/sdk/matching/schema-match.ts b/ui/src/app/dashboard/sdk/matching/schema-match.ts
new file mode 100644
index 0000000..f24ea54
--- /dev/null
+++ b/ui/src/app/dashboard/sdk/matching/schema-match.ts
@@ -0,0 +1,30 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements.  See the NOTICE file distributed with
+ *   this work for additional information regarding copyright ownership.
+ *   The ASF licenses this file to You under the Apache License, Version 2.0
+ *   (the "License"); you may not use this file except in compliance with
+ *   the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ */
+
+import {EventSchema} from "../../../connect/schema-editor/model/EventSchema";
+import {PropertyMatch} from "./property-match";
+
+export class SchemaMatch {
+
+    match(requirement: EventSchema, offer: EventSchema): boolean {
+        return requirement
+            .eventProperties
+            .every(req => offer
+                .eventProperties
+                .some(of => new PropertyMatch().match(req, of)));
+    }
+}
\ No newline at end of file