Search in sources :

Example 1 with PersistenceAllConfig

use of org.openhab.core.persistence.config.PersistenceAllConfig in project openhab-core by openhab.

the class PersistenceManagerImpl method getDefaultConfig.

@Nullable
private PersistenceServiceConfiguration getDefaultConfig(PersistenceService persistenceService) {
    List<PersistenceStrategy> strategies = persistenceService.getDefaultStrategies();
    List<PersistenceItemConfiguration> configs = List.of(new PersistenceItemConfiguration(List.of(new PersistenceAllConfig()), null, strategies, null));
    return new PersistenceServiceConfiguration(configs, strategies, strategies);
}
Also used : PersistenceStrategy(org.openhab.core.persistence.strategy.PersistenceStrategy) PersistenceServiceConfiguration(org.openhab.core.persistence.PersistenceServiceConfiguration) PersistenceItemConfiguration(org.openhab.core.persistence.PersistenceItemConfiguration) PersistenceAllConfig(org.openhab.core.persistence.config.PersistenceAllConfig) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with PersistenceAllConfig

use of org.openhab.core.persistence.config.PersistenceAllConfig in project openhab-core by openhab.

the class PersistenceManagerImpl method getAllItems.

/**
 * Retrieves all items for which the persistence configuration applies to.
 *
 * @param config the persistence configuration entry
 * @return all items that this configuration applies to
 */
Iterable<Item> getAllItems(PersistenceItemConfiguration config) {
    // first check, if we should return them all
    for (Object itemCfg : config.getItems()) {
        if (itemCfg instanceof PersistenceAllConfig) {
            return itemRegistry.getItems();
        }
    }
    // otherwise, go through the detailed definitions
    Set<Item> items = new HashSet<>();
    for (Object itemCfg : config.getItems()) {
        if (itemCfg instanceof PersistenceItemConfig) {
            PersistenceItemConfig singleItemConfig = (PersistenceItemConfig) itemCfg;
            String itemName = singleItemConfig.getItem();
            try {
                items.add(itemRegistry.getItem(itemName));
            } catch (ItemNotFoundException e) {
                logger.debug("Item '{}' does not exist.", itemName);
            }
        }
        if (itemCfg instanceof PersistenceGroupConfig) {
            PersistenceGroupConfig groupItemConfig = (PersistenceGroupConfig) itemCfg;
            String groupName = groupItemConfig.getGroup();
            try {
                Item gItem = itemRegistry.getItem(groupName);
                if (gItem instanceof GroupItem) {
                    GroupItem groupItem = (GroupItem) gItem;
                    items.addAll(groupItem.getAllMembers());
                }
            } catch (ItemNotFoundException e) {
                logger.debug("Item group '{}' does not exist.", groupName);
            }
        }
    }
    return items;
}
Also used : GenericItem(org.openhab.core.items.GenericItem) HistoricItem(org.openhab.core.persistence.HistoricItem) GroupItem(org.openhab.core.items.GroupItem) Item(org.openhab.core.items.Item) PersistenceGroupConfig(org.openhab.core.persistence.config.PersistenceGroupConfig) PersistenceItemConfig(org.openhab.core.persistence.config.PersistenceItemConfig) GroupItem(org.openhab.core.items.GroupItem) PersistenceAllConfig(org.openhab.core.persistence.config.PersistenceAllConfig) HashSet(java.util.HashSet) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Aggregations

PersistenceAllConfig (org.openhab.core.persistence.config.PersistenceAllConfig)2 HashSet (java.util.HashSet)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 GenericItem (org.openhab.core.items.GenericItem)1 GroupItem (org.openhab.core.items.GroupItem)1 Item (org.openhab.core.items.Item)1 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)1 HistoricItem (org.openhab.core.persistence.HistoricItem)1 PersistenceItemConfiguration (org.openhab.core.persistence.PersistenceItemConfiguration)1 PersistenceServiceConfiguration (org.openhab.core.persistence.PersistenceServiceConfiguration)1 PersistenceGroupConfig (org.openhab.core.persistence.config.PersistenceGroupConfig)1 PersistenceItemConfig (org.openhab.core.persistence.config.PersistenceItemConfig)1 PersistenceStrategy (org.openhab.core.persistence.strategy.PersistenceStrategy)1