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;
}
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;
}
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);
}
Aggregations