Search in sources :

Example 1 with Category

use of org.opennms.netmgt.config.siteStatusViews.Category in project opennms by OpenNMS.

the class DefaultNodeListService method getCategoryNamesForRowDef.

private static Set<String> getCategoryNamesForRowDef(RowDef rowDef) {
    Set<String> categories = new LinkedHashSet<>();
    List<Category> cats = rowDef.getCategories();
    for (Category cat : cats) {
        categories.add(cat.getName());
    }
    return categories;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Category(org.opennms.netmgt.config.siteStatusViews.Category)

Example 2 with Category

use of org.opennms.netmgt.config.siteStatusViews.Category in project opennms by OpenNMS.

the class DefaultSiteStatusViewService method getCategoriesForRowDef.

private Set<OnmsCategory> getCategoriesForRowDef(RowDef rowDef) {
    Set<OnmsCategory> categories = new LinkedHashSet<>();
    // Loop over the defined categories and create model categories (OnmsCategory)
    List<Category> cats = rowDef.getCategories();
    for (Category cat : cats) {
        OnmsCategory category = m_categoryDao.findByName(cat.getName());
        if (category == null) {
            throw new ObjectRetrievalFailureException(OnmsCategory.class, cat.getName(), "Unable to locate OnmsCategory named: " + cat.getName() + " as specified in the site status view configuration file", null);
        }
        categories.add(category);
    }
    return categories;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Category(org.opennms.netmgt.config.siteStatusViews.Category) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 3 with Category

use of org.opennms.netmgt.config.siteStatusViews.Category in project opennms by OpenNMS.

the class DefaultSiteStatusServiceTest method testCreateAggregateStatusUsingNodeId.

@Test
public void testCreateAggregateStatusUsingNodeId() {
    Collection<AggregateStatus> aggrStati;
    Collection<AggregateStatusDefinition> defs = new HashSet<>();
    OnmsCategory catRouters = new OnmsCategory("routers");
    OnmsCategory catSwitches = new OnmsCategory("switches");
    AggregateStatusDefinition definition = new AggregateStatusDefinition("Routers/Switches", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { catRouters, catSwitches })));
    defs.add(definition);
    OnmsCategory catServers = new OnmsCategory("servers");
    definition = new AggregateStatusDefinition("Servers", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { catServers })));
    defs.add(definition);
    DefaultSiteStatusViewService aggregateSvc = new DefaultSiteStatusViewService();
    aggregateSvc.setNodeDao(m_nodeDao);
    aggregateSvc.setCategoryDao(m_categoryDao);
    aggregateSvc.setSiteStatusViewConfigDao(m_siteStatusViewConfigDao);
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.getAssetRecord().setBuilding("HQ");
    List<OnmsNode> nodes = new ArrayList<>();
    nodes.add(node);
    for (AggregateStatusDefinition def : defs) {
        expect(m_nodeDao.findAllByVarCharAssetColumnCategoryList("building", "HQ", def.getCategories())).andReturn(nodes);
    }
    for (OnmsNode n : nodes) {
        expect(m_nodeDao.load(n.getId())).andReturn(n);
    }
    replay(m_nodeDao);
    expect(m_categoryDao.findByName("switches")).andReturn(catSwitches);
    expect(m_categoryDao.findByName("routers")).andReturn(catRouters);
    expect(m_categoryDao.findByName("servers")).andReturn(catServers);
    replay(m_categoryDao);
    List<RowDef> rows = new ArrayList<>();
    RowDef rowDef = new RowDef();
    Category category = new Category();
    category.setName("servers");
    rowDef.addCategory(category);
    rows.add(rowDef);
    rowDef = new RowDef();
    category = new Category();
    category.setName("switches");
    rowDef.addCategory(category);
    category = new Category();
    category.setName("routers");
    rowDef.addCategory(category);
    rows.add(rowDef);
    View view = new View();
    view.setRows(rows);
    expect(m_siteStatusViewConfigDao.getView("building")).andReturn(view);
    replay(m_siteStatusViewConfigDao);
    aggrStati = aggregateSvc.createAggregateStatusesUsingNodeId(node.getId(), "building");
    verify(m_nodeDao);
    verify(m_categoryDao);
    verify(m_siteStatusViewConfigDao);
    assertNotNull(aggrStati);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Category(org.opennms.netmgt.config.siteStatusViews.Category) ArrayList(java.util.ArrayList) RowDef(org.opennms.netmgt.config.siteStatusViews.RowDef) View(org.opennms.netmgt.config.siteStatusViews.View) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) AggregateStatusDefinition(org.opennms.netmgt.model.AggregateStatusDefinition) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3 Category (org.opennms.netmgt.config.siteStatusViews.Category)3 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)1 View (org.opennms.netmgt.config.siteStatusViews.View)1 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)1 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1