Search in sources :

Example 1 with SimpleGroupConfig

use of org.eclipse.smarthome.core.persistence.config.SimpleGroupConfig in project smarthome by eclipse.

the class PersistenceManagerImpl method appliesToItem.

/**
 * Checks if a given persistence configuration entry is relevant for an item
 *
 * @param config the persistence configuration entry
 * @param item to check if the configuration applies to
 * @return true, if the configuration applies to the item
 */
private boolean appliesToItem(SimpleItemConfiguration config, Item item) {
    for (SimpleConfig itemCfg : config.getItems()) {
        if (itemCfg instanceof SimpleAllConfig) {
            return true;
        }
        if (itemCfg instanceof SimpleItemConfig) {
            SimpleItemConfig singleItemConfig = (SimpleItemConfig) itemCfg;
            if (item.getName().equals(singleItemConfig.getItem())) {
                return true;
            }
        }
        if (itemCfg instanceof SimpleGroupConfig) {
            SimpleGroupConfig groupItemCfg = (SimpleGroupConfig) itemCfg;
            String groupName = groupItemCfg.getGroup();
            try {
                Item gItem = itemRegistry.getItem(groupName);
                if (gItem instanceof GroupItem) {
                    GroupItem groupItem = (GroupItem) gItem;
                    if (groupItem.getAllMembers().contains(item)) {
                        return true;
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    return false;
}
Also used : SimpleConfig(org.eclipse.smarthome.core.persistence.config.SimpleConfig) SimpleGroupConfig(org.eclipse.smarthome.core.persistence.config.SimpleGroupConfig) GroupItem(org.eclipse.smarthome.core.items.GroupItem) HistoricItem(org.eclipse.smarthome.core.persistence.HistoricItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) SimpleAllConfig(org.eclipse.smarthome.core.persistence.config.SimpleAllConfig) SimpleItemConfig(org.eclipse.smarthome.core.persistence.config.SimpleItemConfig) GroupItem(org.eclipse.smarthome.core.items.GroupItem) ParseException(java.text.ParseException) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Example 2 with SimpleGroupConfig

use of org.eclipse.smarthome.core.persistence.config.SimpleGroupConfig in project smarthome by eclipse.

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(SimpleItemConfiguration config) {
    // first check, if we should return them all
    for (Object itemCfg : config.getItems()) {
        if (itemCfg instanceof SimpleAllConfig) {
            return itemRegistry.getItems();
        }
    }
    // otherwise, go through the detailed definitions
    Set<Item> items = new HashSet<Item>();
    for (Object itemCfg : config.getItems()) {
        if (itemCfg instanceof SimpleItemConfig) {
            SimpleItemConfig singleItemConfig = (SimpleItemConfig) itemCfg;
            try {
                Item item = itemRegistry.getItem(singleItemConfig.getItem());
                items.add(item);
            } catch (ItemNotFoundException e) {
                logger.debug("Item '{}' does not exist.", singleItemConfig.getItem());
            }
        }
        if (itemCfg instanceof SimpleGroupConfig) {
            SimpleGroupConfig groupItemCfg = (SimpleGroupConfig) itemCfg;
            String groupName = groupItemCfg.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 : GroupItem(org.eclipse.smarthome.core.items.GroupItem) HistoricItem(org.eclipse.smarthome.core.persistence.HistoricItem) GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) SimpleGroupConfig(org.eclipse.smarthome.core.persistence.config.SimpleGroupConfig) SimpleAllConfig(org.eclipse.smarthome.core.persistence.config.SimpleAllConfig) SimpleItemConfig(org.eclipse.smarthome.core.persistence.config.SimpleItemConfig) GroupItem(org.eclipse.smarthome.core.items.GroupItem) HashSet(java.util.HashSet) ItemNotFoundException(org.eclipse.smarthome.core.items.ItemNotFoundException)

Aggregations

GenericItem (org.eclipse.smarthome.core.items.GenericItem)2 GroupItem (org.eclipse.smarthome.core.items.GroupItem)2 Item (org.eclipse.smarthome.core.items.Item)2 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)2 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)2 SimpleAllConfig (org.eclipse.smarthome.core.persistence.config.SimpleAllConfig)2 SimpleGroupConfig (org.eclipse.smarthome.core.persistence.config.SimpleGroupConfig)2 SimpleItemConfig (org.eclipse.smarthome.core.persistence.config.SimpleItemConfig)2 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 SimpleConfig (org.eclipse.smarthome.core.persistence.config.SimpleConfig)1