diff --git a/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/Persistence.xtext b/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/Persistence.xtext index d183c935a..a1513a44b 100644 --- a/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/Persistence.xtext +++ b/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/Persistence.xtext @@ -56,7 +56,8 @@ NotIncludeFilter: PersistenceConfiguration: - items+=(AllConfig | ItemConfig | GroupConfig) (',' items+=(AllConfig | ItemConfig | GroupConfig))* ('->' alias=STRING)? + items+=(AllConfig | ItemConfig | GroupConfig | ItemExcludeConfig | GroupExcludeConfig) + (',' items+=(AllConfig | ItemConfig | GroupConfig | ItemExcludeConfig | GroupExcludeConfig))* ('->' alias=STRING)? ((':' ('strategy' '=' strategies+=[Strategy|ID] (',' strategies+=[Strategy|ID])*)? ('filter' '=' filters+=[Filter|ID] (',' filters+=[Filter|ID])*)?) | ';') @@ -75,6 +76,14 @@ GroupConfig: group=ID '*' ; +ItemExcludeConfig: + '!' itemExclude=ID +; + +GroupExcludeConfig: + '!' groupExclude=ID '*' +; + DECIMAL returns ecore::EBigDecimal : '-'? INT ('.' INT)? ; diff --git a/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/internal/PersistenceModelManager.java b/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/internal/PersistenceModelManager.java index 60fb35d99..f734aab93 100644 --- a/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/internal/PersistenceModelManager.java +++ b/bundles/org.openhab.core.model.persistence/src/org/openhab/core/model/persistence/internal/PersistenceModelManager.java @@ -29,8 +29,10 @@ import org.openhab.core.model.persistence.persistence.CronStrategy; import org.openhab.core.model.persistence.persistence.EqualsFilter; import org.openhab.core.model.persistence.persistence.Filter; import org.openhab.core.model.persistence.persistence.GroupConfig; +import org.openhab.core.model.persistence.persistence.GroupExcludeConfig; import org.openhab.core.model.persistence.persistence.IncludeFilter; import org.openhab.core.model.persistence.persistence.ItemConfig; +import org.openhab.core.model.persistence.persistence.ItemExcludeConfig; import org.openhab.core.model.persistence.persistence.NotEqualsFilter; import org.openhab.core.model.persistence.persistence.NotIncludeFilter; import org.openhab.core.model.persistence.persistence.PersistenceConfiguration; @@ -43,7 +45,9 @@ import org.openhab.core.persistence.PersistenceService; import org.openhab.core.persistence.config.PersistenceAllConfig; import org.openhab.core.persistence.config.PersistenceConfig; import org.openhab.core.persistence.config.PersistenceGroupConfig; +import org.openhab.core.persistence.config.PersistenceGroupExcludeConfig; import org.openhab.core.persistence.config.PersistenceItemConfig; +import org.openhab.core.persistence.config.PersistenceItemExcludeConfig; import org.openhab.core.persistence.filter.PersistenceEqualsFilter; import org.openhab.core.persistence.filter.PersistenceFilter; import org.openhab.core.persistence.filter.PersistenceIncludeFilter; @@ -98,7 +102,11 @@ public class PersistenceModelManager extends AbstractProvider getAllItems(PersistenceItemConfiguration config) { - // first check, if we should return them all - if (config.items().stream().anyMatch(PersistenceAllConfig.class::isInstance)) { - return itemRegistry.getItems(); - } - - // otherwise, go through the detailed definitions Set items = new HashSet<>(); + Set excludeItems = new HashSet<>(); for (Object itemCfg : config.items()) { - if (itemCfg instanceof PersistenceItemConfig persistenceItemConfig) { + if (itemCfg instanceof PersistenceAllConfig) { + items.addAll(itemRegistry.getItems()); + } else if (itemCfg instanceof PersistenceItemConfig persistenceItemConfig) { String itemName = persistenceItemConfig.getItem(); try { items.add(itemRegistry.getItem(itemName)); } catch (ItemNotFoundException e) { logger.debug("Item '{}' does not exist.", itemName); } - } - if (itemCfg instanceof PersistenceGroupConfig persistenceGroupConfig) { + } else if (itemCfg instanceof PersistenceGroupConfig persistenceGroupConfig) { String groupName = persistenceGroupConfig.getGroup(); try { Item gItem = itemRegistry.getItem(groupName); @@ -252,8 +262,26 @@ public class PersistenceManagerImpl implements ItemRegistryChangeListener, State } catch (ItemNotFoundException e) { logger.debug("Item group '{}' does not exist.", groupName); } + } else if (itemCfg instanceof PersistenceItemExcludeConfig persistenceItemConfig) { + String itemName = persistenceItemConfig.getItem(); + try { + excludeItems.add(itemRegistry.getItem(itemName)); + } catch (ItemNotFoundException e) { + logger.debug("Item '{}' does not exist.", itemName); + } + } else if (itemCfg instanceof PersistenceGroupExcludeConfig persistenceGroupConfig) { + String groupName = persistenceGroupConfig.getGroup(); + try { + Item gItem = itemRegistry.getItem(groupName); + if (gItem instanceof GroupItem groupItem) { + excludeItems.addAll(groupItem.getAllMembers()); + } + } catch (ItemNotFoundException e) { + logger.debug("Item group '{}' does not exist.", groupName); + } } } + items.removeAll(excludeItems); return items; } diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/registry/PersistenceServiceConfigurationDTOMapper.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/registry/PersistenceServiceConfigurationDTOMapper.java index c075bed2a..057490a92 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/registry/PersistenceServiceConfigurationDTOMapper.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/registry/PersistenceServiceConfigurationDTOMapper.java @@ -27,7 +27,9 @@ import org.openhab.core.persistence.PersistenceItemConfiguration; import org.openhab.core.persistence.config.PersistenceAllConfig; import org.openhab.core.persistence.config.PersistenceConfig; import org.openhab.core.persistence.config.PersistenceGroupConfig; +import org.openhab.core.persistence.config.PersistenceGroupExcludeConfig; import org.openhab.core.persistence.config.PersistenceItemConfig; +import org.openhab.core.persistence.config.PersistenceItemExcludeConfig; import org.openhab.core.persistence.dto.PersistenceCronStrategyDTO; import org.openhab.core.persistence.dto.PersistenceFilterDTO; import org.openhab.core.persistence.dto.PersistenceItemConfigurationDTO; @@ -113,8 +115,14 @@ public class PersistenceServiceConfigurationDTOMapper { if ("*".equals(string)) { return new PersistenceAllConfig(); } else if (string.endsWith("*")) { + if (string.startsWith("!")) { + return new PersistenceGroupExcludeConfig(string.substring(1, string.length() - 1)); + } return new PersistenceGroupConfig(string.substring(0, string.length() - 1)); } else { + if (string.startsWith("!")) { + return new PersistenceItemExcludeConfig(string.substring(1, string.length() - 1)); + } return new PersistenceItemConfig(string); } } @@ -149,6 +157,10 @@ public class PersistenceServiceConfigurationDTOMapper { return persistenceGroupConfig.getGroup() + "*"; } else if (config instanceof PersistenceItemConfig persistenceItemConfig) { return persistenceItemConfig.getItem(); + } else if (config instanceof PersistenceGroupExcludeConfig persistenceGroupExcludeConfig) { + return "!" + persistenceGroupExcludeConfig.getGroup() + "*"; + } else if (config instanceof PersistenceItemExcludeConfig persistenceItemExcludeConfig) { + return "!" + persistenceItemExcludeConfig.getItem(); } throw new IllegalArgumentException("Unknown persistence config class " + config.getClass()); }