Search in sources :

Example 1 with Section

use of org.opennms.netmgt.config.viewsdisplay.Section in project opennms by OpenNMS.

the class CategoryList method getSections.

/**
     * For the given map of category names to Category objects, organize the
     * categories into the currently active display rules.
     *
     * <p>
     * If there are no display rules, a single section named <em>Category</em>
     * will be returned. It will include all the categories in the category map,
     * in alphabetical order by category name.
     * </p>
     *
     * @param categoryMap a {@link java.util.Map} object.
     * @return a {@link java.util.List} object.
     * @throws java.io.IOException if any.
     */
private List<Section> getSections(Map<String, Category> categoryMap) throws IOException {
    if (m_sections != null) {
        // Just return the display rules as a list.
        return m_sections;
    }
    List<Section> sectionList = null;
    Section section = new Section();
    section.setSectionName("Category");
    // Put the categories in a TreeMap to sort them alphabetically.
    TreeMap<String, Category> orderedMap = new TreeMap<String, Category>(categoryMap);
    // Iterate over the categories, adding each to the name list.
    for (Iterator<Map.Entry<String, Category>> i = orderedMap.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry<String, Category> entry = i.next();
        Category category = (Category) entry.getValue();
        section.addCategory(category.getName());
    }
    // Add our one section to the sections list.
    sectionList = new ArrayList<Section>();
    sectionList.add(section);
    return sectionList;
}
Also used : Entry(java.util.Map.Entry) TreeMap(java.util.TreeMap) Section(org.opennms.netmgt.config.viewsdisplay.Section) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with Section

use of org.opennms.netmgt.config.viewsdisplay.Section in project opennms by OpenNMS.

the class DefaultCategoryStatusServiceTest method testGetCategoriesStatus.

public void testGetCategoriesStatus() {
    View view = new View();
    Section section = new Section();
    section.setSectionName("Section One");
    section.addCategory("Category One");
    OnmsOutage outage = new OnmsOutage();
    Collection<OnmsOutage> outages = new ArrayList<OnmsOutage>();
    outage.setId(300);
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("superLabel");
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    //iface.setId(9);
    OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    outage.setMonitoredService(monSvc);
    outages.add(outage);
    view.addSection(section);
    List<String> services = new ArrayList<String>();
    services.add("HTTP");
    //		ServiceSelector selector = new ServiceSelector("isHTTP",(List<String>) services);
    expect(viewDisplayDao.getView()).andReturn(view);
    expect(categoryDao.getCategoryByLabel("Category One")).andReturn(createCategoryFromLabel("Category One"));
    expect(outageDao.matchingCurrentOutages(isA(ServiceSelector.class))).andReturn(outages);
    replay(categoryDao);
    replay(viewDisplayDao);
    replay(outageDao);
    Collection<StatusSection> statusSections = categoryStatusService.getCategoriesStatus();
    verify(viewDisplayDao);
    verify(categoryDao);
    verify(outageDao);
    assertEquals("Wrong Number of StatusSections", view.getSections().size(), statusSections.size());
    for (StatusSection statusSection : statusSections) {
        assertEquals("StatusSection Name Does Not Match", "Section One", statusSection.getName());
        Collection<StatusCategory> statusCategorys = statusSection.getCategories();
        for (StatusCategory statusCategory : statusCategorys) {
            assertEquals("StatusCategoryName does not match", "Category One", statusCategory.getLabel());
            //assertEquals("Category Comment Does not match","Category One Comment",statusCategory.getComment());				
            assertTrue("Nodes >= 1", statusCategory.getNodes().size() >= 1);
            for (StatusNode statusNode : statusCategory.getNodes()) {
                assertEquals("Label does not match", "superLabel", statusNode.getLabel());
            }
        }
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) StatusNode(org.opennms.web.svclayer.catstatus.model.StatusNode) ServiceSelector(org.opennms.netmgt.model.ServiceSelector) ArrayList(java.util.ArrayList) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) View(org.opennms.netmgt.config.viewsdisplay.View) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) Section(org.opennms.netmgt.config.viewsdisplay.Section) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) StatusCategory(org.opennms.web.svclayer.catstatus.model.StatusCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType)

Example 3 with Section

use of org.opennms.netmgt.config.viewsdisplay.Section in project opennms by OpenNMS.

the class CategoryList method getCategoryData.

/**
     * <p>getCategoryData</p>
     *
     * @return a {@link java.util.Map} object.
     * @throws java.io.IOException if any.
     */
public Map<String, List<Category>> getCategoryData() throws IOException {
    Map<String, Category> categoryMap = m_model.getCategoryMap();
    List<Section> sectionList = getSections(categoryMap);
    Map<String, List<Category>> categoryData = new LinkedHashMap<String, List<Category>>();
    for (Section section : sectionList) {
        List<Category> categories = new LinkedList<Category>();
        for (final String categoryName : section.getCategories()) {
            final Category category = (Category) categoryMap.get(categoryName);
            if (category == null) {
                categories.add(new Category(categoryName));
            } else {
                categories.add(category);
            }
        }
        categoryData.put(section.getSectionName(), categories);
    }
    return Collections.unmodifiableMap(categoryData);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Section(org.opennms.netmgt.config.viewsdisplay.Section) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Section

use of org.opennms.netmgt.config.viewsdisplay.Section in project opennms by OpenNMS.

the class DefaultCategoryStatusService method getCategoriesStatus.

/**
	 * <p>getCategoriesStatus</p>
	 *
	 * @return a {@link java.util.Collection} object.
	 */
@Override
public Collection<StatusSection> getCategoriesStatus() {
    View view = m_viewDisplayDao.getView();
    Collection<Section> sections = getSectionsForView(view);
    Collection<StatusSection> statusSections = new ArrayList<StatusSection>();
    for (Section section : sections) {
        statusSections.add(createSection(section));
    }
    return statusSections;
}
Also used : ArrayList(java.util.ArrayList) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) View(org.opennms.netmgt.config.viewsdisplay.View) StatusSection(org.opennms.web.svclayer.catstatus.model.StatusSection) Section(org.opennms.netmgt.config.viewsdisplay.Section)

Aggregations

Section (org.opennms.netmgt.config.viewsdisplay.Section)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)2 View (org.opennms.netmgt.config.viewsdisplay.View)2 StatusSection (org.opennms.web.svclayer.catstatus.model.StatusSection)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)1 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 ServiceSelector (org.opennms.netmgt.model.ServiceSelector)1 StatusCategory (org.opennms.web.svclayer.catstatus.model.StatusCategory)1 StatusNode (org.opennms.web.svclayer.catstatus.model.StatusNode)1