Search in sources :

Example 1 with CategoryGroup

use of org.opennms.netmgt.config.categories.CategoryGroup in project opennms by OpenNMS.

the class DefaultCategoryConfigDao method findAll.

/**
	 * <p>findAll</p>
	 *
	 * @return a {@link java.util.Collection} object.
	 */
@Override
public Collection<Category> findAll() {
    List<Category> catList = new ArrayList<Category>();
    Catinfo catInfo = CategoryFactory.getInstance().getConfig();
    List<CategoryGroup> catGroupList = catInfo.getCategoryGroups();
    if (catGroupList != null) {
        for (final CategoryGroup cg : catGroupList) {
            catList.addAll(cg.getCategories());
        }
    }
    return catList;
}
Also used : Category(org.opennms.netmgt.config.categories.Category) ArrayList(java.util.ArrayList) Catinfo(org.opennms.netmgt.config.categories.Catinfo) CategoryGroup(org.opennms.netmgt.config.categories.CategoryGroup)

Example 2 with CategoryGroup

use of org.opennms.netmgt.config.categories.CategoryGroup in project opennms by OpenNMS.

the class RTCUtils method createCategoriesMap.

/**
	 * Creates the categories map. Reads the categories from the categories.xml
	 * and creates the 'RTCCategory's map
	 */
public static HashMap<String, RTCCategory> createCategoriesMap() {
    CatFactory cFactory = null;
    try {
        CategoryFactory.init();
        cFactory = CategoryFactory.getInstance();
    } catch (IOException ex) {
        LOG.error("Failed to load categories information", ex);
        throw new UndeclaredThrowableException(ex);
    }
    HashMap<String, RTCCategory> retval = new HashMap<String, RTCCategory>();
    cFactory.getReadLock().lock();
    try {
        for (CategoryGroup cg : cFactory.getConfig().getCategoryGroups()) {
            final String commonRule = cg.getCommon().getRule();
            for (final org.opennms.netmgt.config.categories.Category cat : cg.getCategories()) {
                RTCCategory rtcCat = new RTCCategory(cat, commonRule);
                retval.put(rtcCat.getLabel(), rtcCat);
            }
        }
    } finally {
        cFactory.getReadLock().unlock();
    }
    return retval;
}
Also used : HashMap(java.util.HashMap) CatFactory(org.opennms.netmgt.config.api.CatFactory) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IOException(java.io.IOException) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) CategoryGroup(org.opennms.netmgt.config.categories.CategoryGroup)

Example 3 with CategoryGroup

use of org.opennms.netmgt.config.categories.CategoryGroup in project opennms by OpenNMS.

the class CategoryFactory method replaceCategoryGroup.

/**
     * Replace categorygroup.
     *
     * @param group
     *            category group to be replaced
     * @return true if categorygroup is successfully replaced
     */
public boolean replaceCategoryGroup(final CategoryGroup group) {
    try {
        getWriteLock().lock();
        final String groupname = group.getName();
        for (int i = 0; i < m_config.getCategoryGroups().size(); i++) {
            final int index1 = i;
            final CategoryGroup oldCg = m_config.getCategoryGroups().get(index1);
            if (oldCg.getName().equals(groupname)) {
                final int index = i;
                m_config.getCategoryGroups().set(index, group);
                return true;
            }
        }
    } finally {
        getWriteLock().unlock();
    }
    return false;
}
Also used : CategoryGroup(org.opennms.netmgt.config.categories.CategoryGroup)

Aggregations

CategoryGroup (org.opennms.netmgt.config.categories.CategoryGroup)3 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CatFactory (org.opennms.netmgt.config.api.CatFactory)1 Category (org.opennms.netmgt.config.categories.Category)1 Catinfo (org.opennms.netmgt.config.categories.Catinfo)1 RTCCategory (org.opennms.netmgt.rtc.datablock.RTCCategory)1