Search in sources :

Example 1 with Cell

use of org.opennms.web.svclayer.model.SimpleWebTable.Cell in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method assertTableEquals.

public void assertTableEquals(SimpleWebTable expectedTable, SimpleWebTable table) {
    assertEquals("table title", expectedTable.getTitle(), table.getTitle());
    assertEquals("number of table columns headers", expectedTable.getColumnHeaders().size(), table.getColumnHeaders().size());
    ListIterator<Cell> columnHeaderIterator = expectedTable.getColumnHeaders().listIterator();
    for (Cell tableColumnHeader : table.getColumnHeaders()) {
        assertEquals("column header " + (columnHeaderIterator.nextIndex() + 1), columnHeaderIterator.next(), tableColumnHeader);
    }
    assertEquals("number of rows", expectedTable.getRows().size(), table.getRows().size());
    ListIterator<List<Cell>> expectedRowIterator = expectedTable.getRows().listIterator();
    for (List<Cell> row : table.getRows()) {
        List<Cell> expectedRow = expectedRowIterator.next();
        assertEquals("row " + (expectedRowIterator.previousIndex() + 1) + " column count", expectedRow.size(), row.size());
        ListIterator<Cell> expectedColumnIterator = expectedRow.listIterator();
        for (Cell column : row) {
            Cell expectedColumn = expectedColumnIterator.next();
            String rowColumn = "row " + (expectedRowIterator.previousIndex() + 1) + " column " + (expectedColumnIterator.previousIndex() + 1) + " ";
            if (!IGNORE_MATCH.equals(expectedColumn.getContent())) {
                assertEquals(rowColumn + "content", expectedColumn.getContent(), column.getContent());
            }
            if (!IGNORE_MATCH.equals(expectedColumn.getStyleClass())) {
                assertEquals(rowColumn + "styleClass", expectedColumn.getStyleClass(), column.getStyleClass());
            }
            if (!IGNORE_MATCH.equals(expectedColumn.getLink())) {
                assertEquals(rowColumn + "link", expectedColumn.getLink(), column.getLink());
            }
        }
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Cell(org.opennms.web.svclayer.model.SimpleWebTable.Cell)

Example 2 with Cell

use of org.opennms.web.svclayer.model.SimpleWebTable.Cell in project opennms by OpenNMS.

the class DefaultDistributedStatusService method createFacilityStatusTable.

/**
 * {@inheritDoc}
 */
@Override
public SimpleWebTable createFacilityStatusTable(Date start, Date end) {
    Assert.notNull(start, "argument start cannot be null");
    Assert.notNull(end, "argument end cannot be null");
    if (!start.before(end)) {
        throw new IllegalArgumentException("start date (" + start + ") must be older than end date (" + end + ")");
    }
    SimpleWebTable table = new SimpleWebTable();
    List<OnmsMonitoringLocation> locationDefinitions = m_monitoringLocationDao.findAll();
    Collection<OnmsApplication> applications = m_applicationDao.findAll();
    if (applications.size() == 0) {
        throw new IllegalArgumentException("there are no applications");
    }
    List<OnmsApplication> sortedApplications = new ArrayList<OnmsApplication>(applications);
    Collections.sort(sortedApplications);
    Collection<OnmsLocationSpecificStatus> mostRecentStatuses = m_locationMonitorDao.getAllMostRecentStatusChanges();
    Collection<OnmsLocationSpecificStatus> statusesPeriod = new HashSet<>();
    statusesPeriod.addAll(m_locationMonitorDao.getAllStatusChangesAt(start));
    statusesPeriod.addAll(m_locationMonitorDao.getStatusChangesBetween(start, end));
    table.setTitle("Distributed Status Summary");
    table.addColumn("Area", "");
    table.addColumn("Location", "");
    for (OnmsApplication application : sortedApplications) {
        table.addColumn(application.getName(), "");
    }
    for (OnmsMonitoringLocation locationDefinition : locationDefinitions) {
        Collection<OnmsLocationMonitor> monitors = m_locationMonitorDao.findByLocationDefinition(locationDefinition);
        table.newRow();
        table.addCell(locationDefinition.getMonitoringArea(), "");
        table.addCell(locationDefinition.getLocationName(), "");
        for (OnmsApplication application : sortedApplications) {
            Collection<OnmsMonitoredService> memberServices = m_monitoredServiceDao.findByApplication(application);
            Severity status = calculateCurrentStatus(monitors, memberServices, mostRecentStatuses);
            Set<OnmsLocationSpecificStatus> selectedStatuses = filterStatus(statusesPeriod, monitors, memberServices);
            if (selectedStatuses.size() > 0) {
                String percentage = calculatePercentageUptime(memberServices, selectedStatuses, start, end);
                table.addCell(percentage, status.getStyle(), createHistoryPageUrl(locationDefinition, application));
            } else {
                table.addCell("No data", status.getStyle());
            }
        }
    }
    if (isLayoutApplicationsVertically()) {
        SimpleWebTable newTable = new SimpleWebTable();
        newTable.setErrors(table.getErrors());
        newTable.setTitle(table.getTitle());
        newTable.addColumn("Application");
        for (List<Cell> row : table.getRows()) {
            // The location is in the second row
            newTable.addColumn(row.get(1).getContent(), row.get(1).getStyleClass());
        }
        for (Cell columnHeader : table.getColumnHeaders().subList(2, table.getColumnHeaders().size())) {
            // This is the index into collumn list of the old table to get the data for the current application
            int rowColumnIndex = newTable.getRows().size() + 2;
            newTable.newRow();
            newTable.addCell(columnHeader.getContent(), columnHeader.getStyleClass());
            for (List<Cell> row : table.getRows()) {
                newTable.addCell(row.get(rowColumnIndex).getContent(), row.get(rowColumnIndex).getStyleClass(), row.get(rowColumnIndex).getLink());
            }
        }
        return newTable;
    }
    return table;
}
Also used : OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) ArrayList(java.util.ArrayList) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Cell(org.opennms.web.svclayer.model.SimpleWebTable.Cell) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 Cell (org.opennms.web.svclayer.model.SimpleWebTable.Cell)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)1 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)1 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)1 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)1