Skip to content

Commit b95559c

Browse files
committed
Copilot review
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
1 parent 4af270e commit b95559c

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

bundles/org.openhab.core.io.rest.sitemap/src/main/java/org/openhab/core/io/rest/sitemap/internal/SitemapResource.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@
8686
import org.openhab.core.model.sitemap.sitemap.Buttongrid;
8787
import org.openhab.core.model.sitemap.sitemap.Chart;
8888
import org.openhab.core.model.sitemap.sitemap.ColorArray;
89+
import org.openhab.core.model.sitemap.sitemap.ColorArrayList;
8990
import org.openhab.core.model.sitemap.sitemap.Colortemperaturepicker;
9091
import org.openhab.core.model.sitemap.sitemap.Condition;
9192
import org.openhab.core.model.sitemap.sitemap.Frame;
9293
import org.openhab.core.model.sitemap.sitemap.IconRule;
94+
import org.openhab.core.model.sitemap.sitemap.IconRuleList;
9395
import org.openhab.core.model.sitemap.sitemap.Image;
9496
import org.openhab.core.model.sitemap.sitemap.Input;
9597
import org.openhab.core.model.sitemap.sitemap.LinkableWidget;
@@ -102,6 +104,7 @@
102104
import org.openhab.core.model.sitemap.sitemap.Switch;
103105
import org.openhab.core.model.sitemap.sitemap.Video;
104106
import org.openhab.core.model.sitemap.sitemap.VisibilityRule;
107+
import org.openhab.core.model.sitemap.sitemap.VisibilityRuleList;
105108
import org.openhab.core.model.sitemap.sitemap.Webview;
106109
import org.openhab.core.model.sitemap.sitemap.Widget;
107110
import org.openhab.core.types.State;
@@ -615,7 +618,8 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
615618
}
616619
bean.widgetId = widgetId;
617620
bean.icon = itemUIRegistry.getCategory(widget);
618-
bean.staticIcon = widget.getStaticIcon() != null || !widget.getIconRules().getElements().isEmpty();
621+
bean.staticIcon = widget.getStaticIcon() != null
622+
|| (widget.getIconRules() != null && !widget.getIconRules().getElements().isEmpty());
619623
bean.labelcolor = convertItemValueColor(itemUIRegistry.getLabelColor(widget), itemState);
620624
bean.valuecolor = convertItemValueColor(itemUIRegistry.getValueColor(widget), itemState);
621625
bean.iconcolor = convertItemValueColor(itemUIRegistry.getIconColor(widget), itemState);
@@ -643,7 +647,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
643647
isLeaf(children), uri, locale, false, evenIfHidden);
644648
}
645649
}
646-
if (widget instanceof Switch switchWidget) {
650+
if (widget instanceof Switch switchWidget && switchWidget.getMappings() != null) {
647651
for (Mapping mapping : switchWidget.getMappings().getElements()) {
648652
MappingDTO mappingBean = new MappingDTO();
649653
mappingBean.command = mapping.getCmd();
@@ -653,7 +657,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
653657
bean.mappings.add(mappingBean);
654658
}
655659
}
656-
if (widget instanceof Selection selectionWidget) {
660+
if (widget instanceof Selection selectionWidget && selectionWidget.getMappings() != null) {
657661
for (Mapping mapping : selectionWidget.getMappings().getElements()) {
658662
MappingDTO mappingBean = new MappingDTO();
659663
mappingBean.command = mapping.getCmd();
@@ -731,7 +735,7 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
731735
if (widget instanceof Button buttonWidget) {
732736
// Get the icon from the widget only
733737
if (widget.getIcon() == null && widget.getStaticIcon() == null
734-
&& widget.getIconRules().getElements().isEmpty()) {
738+
&& (widget.getIconRules() == null || widget.getIconRules().getElements().isEmpty())) {
735739
bean.icon = null;
736740
bean.staticIcon = null;
737741
}
@@ -872,36 +876,42 @@ private Set<GenericItem> getAllItems(List<Widget> widgets) {
872876
items.addAll(getAllItems(grid.getChildren()));
873877
}
874878
// Consider items involved in any icon condition
875-
items.addAll(getItemsInIconCond(widget.getIconRules().getElements()));
879+
items.addAll(getItemsInIconCond(widget.getIconRules()));
876880
// Consider items involved in any visibility, labelcolor, valuecolor and iconcolor condition
877-
items.addAll(getItemsInVisibilityCond(widget.getVisibility().getElements()));
878-
items.addAll(getItemsInColorCond(widget.getLabelColor().getElements()));
879-
items.addAll(getItemsInColorCond(widget.getValueColor().getElements()));
880-
items.addAll(getItemsInColorCond(widget.getIconColor().getElements()));
881+
items.addAll(getItemsInVisibilityCond(widget.getVisibility()));
882+
items.addAll(getItemsInColorCond(widget.getLabelColor()));
883+
items.addAll(getItemsInColorCond(widget.getValueColor()));
884+
items.addAll(getItemsInColorCond(widget.getIconColor()));
881885
}
882886
return items;
883887
}
884888

885-
private Set<GenericItem> getItemsInVisibilityCond(EList<VisibilityRule> ruleList) {
889+
private Set<GenericItem> getItemsInVisibilityCond(@Nullable VisibilityRuleList ruleList) {
886890
Set<GenericItem> items = new HashSet<>();
887-
for (VisibilityRule rule : ruleList) {
888-
getItemsInConditions(rule.getConditions(), items);
891+
if (ruleList != null) {
892+
for (VisibilityRule rule : ruleList.getElements()) {
893+
getItemsInConditions(rule.getConditions(), items);
894+
}
889895
}
890896
return items;
891897
}
892898

893-
private Set<GenericItem> getItemsInColorCond(EList<ColorArray> colorList) {
899+
private Set<GenericItem> getItemsInColorCond(@Nullable ColorArrayList colorList) {
894900
Set<GenericItem> items = new HashSet<>();
895-
for (ColorArray rule : colorList) {
896-
getItemsInConditions(rule.getConditions(), items);
901+
if (colorList != null) {
902+
for (ColorArray rule : colorList.getElements()) {
903+
getItemsInConditions(rule.getConditions(), items);
904+
}
897905
}
898906
return items;
899907
}
900908

901-
private Set<GenericItem> getItemsInIconCond(EList<IconRule> ruleList) {
909+
private Set<GenericItem> getItemsInIconCond(@Nullable IconRuleList ruleList) {
902910
Set<GenericItem> items = new HashSet<>();
903-
for (IconRule rule : ruleList) {
904-
getItemsInConditions(rule.getConditions(), items);
911+
if (ruleList != null) {
912+
for (IconRule rule : ruleList.getElements()) {
913+
getItemsInConditions(rule.getConditions(), items);
914+
}
905915
}
906916
return items;
907917
}

bundles/org.openhab.core.model.sitemap/src/org/openhab/core/model/sitemap/formatting/SitemapIndentationInformation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2010-2025 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
113
package org.openhab.core.model.sitemap.formatting;
214

315
import org.eclipse.xtext.formatting.IIndentationInformation;

bundles/org.openhab.core.model.yaml/src/main/java/org/openhab/core/model/yaml/internal/sitemaps/fileconverter/YamlSitemapFileConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private Map.Entry<String, YamlWidgetDTO> buildWidgetDTO(Widget widget) {
117117
dto.icon = widget.getStaticIcon() != null ? widget.getStaticIcon()
118118
: (widget.getIconRules() == null ? widget.getIcon() : null);
119119
IconRuleList iconRuleList = widget.getIconRules();
120-
if (iconRuleList != null && iconRuleList.getElements() != null && iconRuleList.getElements().size() > 0) {
120+
if (iconRuleList != null && iconRuleList.getElements() != null && !iconRuleList.getElements().isEmpty()) {
121121
dto.iconRules = iconRuleList.getElements().stream().map(e -> buildRuleDTO(e)).toList();
122122
}
123123
dto.staticIcon = widget.getStaticIcon() != null ? true : null;

0 commit comments

Comments
 (0)