Skip to content

Commit ac58b52

Browse files
committed
remove osgi test; initialize tags on start up
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent 4d3853f commit ac58b52

3 files changed

Lines changed: 35 additions & 321 deletions

File tree

bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import org.openhab.core.common.registry.ManagedProvider;
2727
import org.openhab.core.common.registry.RegistryChangeListener;
2828
import org.openhab.core.config.core.Configuration;
29+
import org.openhab.core.events.Event;
2930
import org.openhab.core.events.EventPublisher;
31+
import org.openhab.core.events.EventSubscriber;
32+
import org.openhab.core.events.system.StartlevelEvent;
3033
import org.openhab.core.items.ActiveItem;
3134
import org.openhab.core.items.Item;
3235
import org.openhab.core.items.ItemBuilderFactory;
@@ -60,11 +63,12 @@
6063
* @author Dennis Nobel - Initial contribution
6164
* @author Markus Rathgeb - Linked items returns only existing items
6265
* @author Markus Rathgeb - Rewrite collection handling to improve performance
66+
* @author Andrew Fiddian-Green - Apply channel default tags to items
6367
*/
6468
@NonNullByDefault
6569
@Component(immediate = true, service = ItemChannelLinkRegistry.class, configurationPid = "org.openhab.ItemChannelLinkRegistry")
6670
public class ItemChannelLinkRegistry extends AbstractLinkRegistry<ItemChannelLink, ItemChannelLinkProvider>
67-
implements RegistryChangeListener<Item> {
71+
implements RegistryChangeListener<Item>, EventSubscriber {
6872

6973
public static final String USE_TAGS = "useTags";
7074

@@ -75,6 +79,7 @@ public class ItemChannelLinkRegistry extends AbstractLinkRegistry<ItemChannelLin
7579
private final ItemBuilderFactory itemBuilderFactory;
7680

7781
private boolean useTagsGlobally = false;
82+
private int startlevel = 0;
7883

7984
@Activate
8085
public ItemChannelLinkRegistry(final @Nullable Map<String, @Nullable Object> configuration,
@@ -292,7 +297,7 @@ private void assignChannelDefaultTags(ItemChannelLink link, ActiveItem activeIte
292297
if (!channelDefaultTags.isEmpty()) {
293298
if (alreadyHasPointOrPropertyTag) {
294299
if (!useTagsGlobally) {
295-
logger.warn("Item '{}' already tagged; forbidden to add tags supplied by channel '{}'.",
300+
logger.warn("Item '{}' already tagged; so did not add tags supplied by channel '{}'.",
296301
activeItem.getName(), link.getLinkedUID());
297302
}
298303
} else {
@@ -329,8 +334,8 @@ private void removeChannelDefaultTags(ItemChannelLink oldLink, ActiveItem active
329334
// remove old link's tags
330335
Set<String> oldLinkTags = getChannelDefaultTags(oldLink);
331336
newTags.removeAll(oldLinkTags);
332-
// on OH shutdown tagsLinked may be true but oldLinkTags is already empty so suppress that log
333-
if (oldLinkTags.isEmpty()) {
337+
// on OH shutdown tagsLinked may be true but oldLinkTags has become empty so do not log
338+
if (startlevel >= 100) {
334339
logger.info("Item '{}' removed tags '{}' supplied by channel '{}'.", activeItem.getName(), oldLinkTags,
335340
oldLink.getLinkedUID());
336341
}
@@ -343,7 +348,7 @@ private void removeChannelDefaultTags(ItemChannelLink oldLink, ActiveItem active
343348
if (!otherLinkTags.isEmpty()) {
344349
if (alreadyHasPointOrPropertyTag) {
345350
if (!useTagsGlobally) {
346-
logger.warn("Item '{}' already tagged; forbidden to add tags supplied by channel '{}'.",
351+
logger.warn("Item '{}' already tagged; so did not add tags supplied by channel '{}'.",
347352
activeItem.getName(), otherLink.getLinkedUID());
348353
}
349354
break;
@@ -452,4 +457,28 @@ public void removed(Item item) {
452457
public void updated(Item oldItem, Item item) {
453458
// do nothing
454459
}
460+
461+
/**
462+
* Subscribe to system start level events.
463+
*/
464+
@Override
465+
public Set<String> getSubscribedEventTypes() {
466+
return Set.of(StartlevelEvent.TYPE);
467+
}
468+
469+
/**
470+
* When start level reaches 100 then re-initialize all the channel default tags.
471+
*/
472+
@Override
473+
public void receive(Event event) {
474+
if (event instanceof StartlevelEvent startLevelEvent) {
475+
int newStartLevel = startLevelEvent.getStartlevel();
476+
if (newStartLevel >= 100 && startlevel < 100) {
477+
for (ItemChannelLink link : getAll()) {
478+
assignChannelDefaultTags(link);
479+
}
480+
}
481+
startlevel = newStartLevel;
482+
}
483+
}
455484
}

itests/org.openhab.core.thing.tests/itest.bndrun

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -75,63 +75,4 @@ Fragment-Host: org.openhab.core.thing
7575
org.openhab.core.transform;version='[5.1.0,5.1.1)',\
7676
biz.aQute.tester.junit-platform;version='[7.1.0,7.1.1)',\
7777
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
78-
org.openhab.core.semantics;version='[5.1.0,5.1.1)',\
79-
com.fasterxml.jackson.core.jackson-annotations;version='[2.18.2,2.18.3)',\
80-
com.fasterxml.jackson.core.jackson-core;version='[2.18.2,2.18.3)',\
81-
com.fasterxml.jackson.core.jackson-databind;version='[2.18.2,2.18.3)',\
82-
com.fasterxml.jackson.dataformat.jackson-dataformat-xml;version='[2.18.2,2.18.3)',\
83-
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.18.2,2.18.3)',\
84-
com.google.guava;version='[33.3.1,33.3.2)',\
85-
com.google.guava.failureaccess;version='[1.0.2,1.0.3)',\
86-
com.google.inject;version='[7.0.0,7.0.1)',\
87-
de.focus_shift.jollyday-core;version='[1.5.4,1.5.5)',\
88-
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)',\
89-
io.github.classgraph.classgraph;version='[4.8.176,4.8.177)',\
90-
org.antlr.runtime;version='[3.2.0,3.2.1)',\
91-
org.eclipse.emf.common;version='[2.24.0,2.24.1)',\
92-
org.eclipse.emf.ecore;version='[2.26.0,2.26.1)',\
93-
org.eclipse.emf.ecore.xmi;version='[2.16.0,2.16.1)',\
94-
org.eclipse.equinox.common;version='[3.17.100,3.17.101)',\
95-
org.eclipse.jetty.alpn.client;version='[9.4.57,9.4.58)',\
96-
org.eclipse.jetty.client;version='[9.4.57,9.4.58)',\
97-
org.eclipse.jetty.http2.client;version='[9.4.57,9.4.58)',\
98-
org.eclipse.jetty.http2.common;version='[9.4.57,9.4.58)',\
99-
org.eclipse.jetty.http2.hpack;version='[9.4.57,9.4.58)',\
100-
org.eclipse.jetty.jaas;version='[9.4.57,9.4.58)',\
101-
org.eclipse.jetty.websocket.api;version='[9.4.57,9.4.58)',\
102-
org.eclipse.jetty.websocket.client;version='[9.4.57,9.4.58)',\
103-
org.eclipse.jetty.websocket.common;version='[9.4.57,9.4.58)',\
104-
org.eclipse.jetty.xml;version='[9.4.57,9.4.58)',\
105-
org.eclipse.xtend.lib;version='[2.37.0,2.37.1)',\
106-
org.eclipse.xtend.lib.macro;version='[2.37.0,2.37.1)',\
107-
org.eclipse.xtext;version='[2.37.0,2.37.1)',\
108-
org.eclipse.xtext.common.types;version='[2.37.0,2.37.1)',\
109-
org.eclipse.xtext.util;version='[2.37.0,2.37.1)',\
110-
org.eclipse.xtext.xbase;version='[2.37.0,2.37.1)',\
111-
org.eclipse.xtext.xbase.lib;version='[2.37.0,2.37.1)',\
112-
org.glassfish.hk2.external.aopalliance-repackaged;version='[3.1.1,3.1.2)',\
113-
org.openhab.core.audio;version='[5.1.0,5.1.1)',\
114-
org.openhab.core.automation;version='[5.1.0,5.1.1)',\
115-
org.openhab.core.automation.module.script;version='[5.1.0,5.1.1)',\
116-
org.openhab.core.automation.module.script.rulesupport;version='[5.1.0,5.1.1)',\
117-
org.openhab.core.ephemeris;version='[5.1.0,5.1.1)',\
118-
org.openhab.core.io.net;version='[5.1.0,5.1.1)',\
119-
org.openhab.core.model.core;version='[5.1.0,5.1.1)',\
120-
org.openhab.core.model.item;version='[5.1.0,5.1.1)',\
121-
org.openhab.core.model.persistence;version='[5.1.0,5.1.1)',\
122-
org.openhab.core.model.persistence.runtime;version='[5.1.0,5.1.1)',\
123-
org.openhab.core.model.rule;version='[5.1.0,5.1.1)',\
124-
org.openhab.core.model.script;version='[5.1.0,5.1.1)',\
125-
org.openhab.core.model.script.runtime;version='[5.1.0,5.1.1)',\
126-
org.openhab.core.model.sitemap;version='[5.1.0,5.1.1)',\
127-
org.openhab.core.model.thing;version='[5.1.0,5.1.1)',\
128-
org.openhab.core.persistence;version='[5.1.0,5.1.1)',\
129-
org.openhab.core.voice;version='[5.1.0,5.1.1)',\
130-
org.ops4j.pax.web.pax-web-api;version='[8.0.30,8.0.31)',\
131-
org.ops4j.pax.web.pax-web-jetty;version='[8.0.30,8.0.31)',\
132-
org.ops4j.pax.web.pax-web-runtime;version='[8.0.30,8.0.31)',\
133-
org.ops4j.pax.web.pax-web-spi;version='[8.0.30,8.0.31)',\
134-
org.ops4j.pax.web.pax-web-tomcat-common;version='[8.0.30,8.0.31)',\
135-
org.threeten.extra;version='[1.8.0,1.8.1)',\
136-
org.yaml.snakeyaml;version='[2.3.0,2.3.1)',\
137-
stax2-api;version='[4.2.2,4.2.3)'
78+
org.openhab.core.semantics;version='[5.1.0,5.1.1)'

0 commit comments

Comments
 (0)