Search in sources :

Example 1 with SimpleConfig

use of org.eclipse.smarthome.core.persistence.config.SimpleConfig 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)

Aggregations

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