From 89a335a2f8c3298ed0c379f8a363bb2beb07d00e Mon Sep 17 00:00:00 2001 From: Yannick Schaus Date: Tue, 5 Jan 2021 22:42:31 +0100 Subject: [PATCH] Fix parsing integer & booleans parameters in UI component based sitemaps (#2072) * Fix parsing integer & booleans parameters in UI component based sitemaps Also catch remaining exceptions and log a warning/ignore the parameter instead of making the whole sitemap building process fail. Fix wrong feature ID for the video widget URL. Fixes #2047. Fixes #1987. Fixes #1898. Fixes #1875. Fixes https://github.com/openhab/openhab-webui/issues/745. Signed-off-by: Yannick Schaus GitOrigin-RevId: fcaf251bd0f06995a449b4a2f412f068b6290e8c --- .../UIComponentSitemapProvider.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bundles/org.opensmarthouse.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java b/bundles/org.opensmarthouse.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java index fedc2cb1692..231b4b44282 100644 --- a/bundles/org.opensmarthouse.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java +++ b/bundles/org.opensmarthouse.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java @@ -12,6 +12,7 @@ */ package org.openhab.core.ui.internal.components; +import java.math.BigDecimal; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -178,7 +179,7 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) { case "Video": VideoImpl videoWidget = (VideoImpl) SitemapFactory.eINSTANCE.createVideo(); widget = videoWidget; - setWidgetPropertyFromComponentConfig(widget, component, "url", SitemapPackage.IMAGE__URL); + setWidgetPropertyFromComponentConfig(widget, component, "url", SitemapPackage.VIDEO__URL); setWidgetPropertyFromComponentConfig(widget, component, "encoding", SitemapPackage.VIDEO__ENCODING); break; case "Chart": @@ -220,7 +221,6 @@ protected Sitemap buildSitemap(RootUIComponent rootComponent) { SelectionImpl selectionWidget = (SelectionImpl) SitemapFactory.eINSTANCE.createSelection(); addWidgetMappings(selectionWidget.getMappings(), component); widget = selectionWidget; - setWidgetPropertyFromComponentConfig(widget, component, "height", SitemapPackage.WEBVIEW__HEIGHT); break; case "List": ListImpl listWidget = (ListImpl) SitemapFactory.eINSTANCE.createList(); @@ -282,8 +282,21 @@ private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UICom if (value == null) { return; } - WidgetImpl widgetImpl = (WidgetImpl) widget; - widgetImpl.eSet(feature, ConfigUtil.normalizeType(value)); + try { + WidgetImpl widgetImpl = (WidgetImpl) widget; + Object normalizedValue = ConfigUtil.normalizeType(value); + if (widgetImpl.eGet(feature, false, false) instanceof Integer) { + normalizedValue = (normalizedValue instanceof BigDecimal) ? ((BigDecimal) normalizedValue).intValue() + : Integer.valueOf(normalizedValue.toString()); + } else if (widgetImpl.eGet(feature, false, false) instanceof Boolean + && !(normalizedValue instanceof Boolean)) { + normalizedValue = Boolean.valueOf(normalizedValue.toString()); + } + widgetImpl.eSet(feature, normalizedValue); + } catch (Exception e) { + logger.warn("Cannot set {} parameter for {} widget parameter: {}", configParamName, component.getType(), + e.getMessage()); + } } private void addWidgetMappings(EList mappings, UIComponent component) {