Search in sources :

Example 6 with View

use of org.opennms.netmgt.config.surveillanceViews.View in project opennms by OpenNMS.

the class DefaultSurveillanceService method getViewNames.

/**
 * <p>getViewNames</p>
 *
 * @return a {@link java.util.List} object.
 */
@Override
public List<String> getViewNames() {
    final List<String> viewNames = new ArrayList<String>(m_surveillanceConfigDao.getViews().size());
    for (final View view : m_surveillanceConfigDao.getViews()) {
        viewNames.add(view.getName());
    }
    Collections.sort(viewNames);
    return viewNames;
}
Also used : ArrayList(java.util.ArrayList) View(org.opennms.netmgt.config.surveillanceViews.View)

Example 7 with View

use of org.opennms.netmgt.config.surveillanceViews.View in project opennms by OpenNMS.

the class DefaultSurveillanceService method createSurveillanceTable.

/**
 * {@inheritDoc}
 *
 * Creates a custom table object containing intersected rows and
 * columns and categories.
 */
@Override
public SimpleWebTable createSurveillanceTable(final String surveillanceViewName, final ProgressMonitor progressMonitor) {
    CellStatusStrategy strategy = getCellStatusStrategy();
    final String name = (surveillanceViewName == null ? m_surveillanceConfigDao.getDefaultView().getName() : surveillanceViewName);
    final View view = m_surveillanceConfigDao.getView(name);
    final SurveillanceView sView = new SurveillanceView(name, m_surveillanceConfigDao, m_categoryDao);
    progressMonitor.setPhaseCount(strategy.getPhaseCount(sView) + 1);
    /*
         * Initialize a status table 
         */
    final SimpleWebTable webTable = new SimpleWebTable();
    webTable.setTitle(view.getName());
    webTable.addColumn("Nodes Down", "simpleWebTableHeader");
    // set up the column headings
    for (int colIndex = 0; colIndex < sView.getColumnCount(); colIndex++) {
        webTable.addColumn(sView.getColumnLabel(colIndex), "simpleWebTableHeader").setLink(computeReportCategoryLink(sView.getColumnReportCategory(colIndex).orElse(null)));
    }
    // build the set of nodes for each cell
    final SurveillanceStatus[][] cellStatus = strategy.calculateCellStatus(sView, progressMonitor);
    progressMonitor.beginNextPhase("Calculating Status Values");
    for (int rowIndex = 0; rowIndex < sView.getRowCount(); rowIndex++) {
        webTable.newRow();
        webTable.addCell(sView.getRowLabel(rowIndex), "simpleWebTableRowLabel").setLink(computeReportCategoryLink(sView.getRowReportCategory(rowIndex).orElse(null)));
        for (int colIndex = 0; colIndex < sView.getColumnCount(); colIndex++) {
            final SurveillanceStatus survStatus = cellStatus[rowIndex][colIndex];
            final String text = survStatus.getDownEntityCount() + " of " + survStatus.getTotalEntityCount();
            LOG.debug("Text: {}, Style {}", text, survStatus.getStatus());
            final SimpleWebTable.Cell cell = webTable.addCell(text, survStatus.getStatus());
            if (survStatus.getDownEntityCount() > 0) {
                cell.setLink(createNodePageUrl(sView, colIndex, rowIndex));
            }
        }
    }
    progressMonitor.finished(webTable);
    return webTable;
}
Also used : SurveillanceStatus(org.opennms.netmgt.model.SurveillanceStatus) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) View(org.opennms.netmgt.config.surveillanceViews.View)

Example 8 with View

use of org.opennms.netmgt.config.surveillanceViews.View in project opennms by OpenNMS.

the class SurveillanceViewProvider method replaceView.

/**
 * Replaces a {@link View} with a new one.
 *
 * @param oldView the old view to be replaced
 * @param newView the new view
 */
public synchronized void replaceView(View oldView, View newView) {
    View viewFound = null;
    for (View view : m_surveillanceViewConfiguration.getViews()) {
        if (view.getName().equals(oldView.getName())) {
            viewFound = view;
            break;
        }
    }
    if (viewFound != null) {
        int index = getSurveillanceViewConfiguration().getViews().indexOf(viewFound);
        getSurveillanceViewConfiguration().getViews().set(index, newView);
    }
}
Also used : View(org.opennms.netmgt.config.surveillanceViews.View)

Example 9 with View

use of org.opennms.netmgt.config.surveillanceViews.View in project opennms by OpenNMS.

the class DefaultSurveillanceViewService method selectDefaultViewForUsername.

/**
 * {@inheritDoc}
 */
@Override
public View selectDefaultViewForUsername(String username) {
    LOG.debug("Looking for surveillance view that matches user '{}'", username);
    View userView = SurveillanceViewProvider.getInstance().getView(username);
    if (userView != null) {
        LOG.debug("Found surveillance view '{}' matching user name '{}'", userView.getName(), username);
        return userView;
    }
    List<Group> groups = m_groupDao.findGroupsForUser(username);
    for (Group group : groups) {
        View groupView = SurveillanceViewProvider.getInstance().getView(group.getName());
        if (groupView != null) {
            LOG.debug("Found surveillance view '{}' matching group '{}' name for user '{}'", groupView.getName(), group.getName(), username);
            return groupView;
        }
    }
    View defaultView = SurveillanceViewProvider.getInstance().getDefaultView();
    if (defaultView == null) {
        String message = "There is no default surveillance view and we could not find a surveillance view for the user's username ('" + username + "') or any of their groups";
        LOG.warn(message);
        throw new ObjectRetrievalFailureException(View.class, message);
    }
    LOG.debug("Did not find a surveillance view matching the user's user name or one of their group names.  Using the default view for user '{}'", username);
    return defaultView;
}
Also used : Group(org.opennms.netmgt.config.groups.Group) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) View(org.opennms.netmgt.config.surveillanceViews.View)

Example 10 with View

use of org.opennms.netmgt.config.surveillanceViews.View in project opennms by OpenNMS.

the class SurveillanceViewsUI method init.

/**
 * {@inheritDoc}
 */
@Override
protected void init(VaadinRequest request) {
    /**
     * Force the reload of the configuration
     */
    SurveillanceViewProvider.getInstance().load();
    /**
     * create a layout
     */
    VerticalLayout rootLayout = new VerticalLayout();
    rootLayout.setSpacing(true);
    /**
     * check query parameters for viewName, dashboard
     */
    String viewName = request.getParameter("viewName");
    boolean dashboard = request.getParameter("dashboard") != null && "true".equals(request.getParameter("dashboard"));
    /**
     * retrieve the username
     */
    String username = request.getRemoteUser();
    /**
     * now select the right view
     */
    View view;
    if (viewName == null) {
        view = m_surveillanceViewService.selectDefaultViewForUsername(username);
    } else {
        view = SurveillanceViewProvider.getInstance().getView(viewName);
    }
    /**
     * set the poll interval
     */
    setPollInterval(1000);
    /**
     * check for dashboard role
     */
    boolean isDashboardRole = true;
    SecurityContext context = SecurityContextHolder.getContext();
    if ((context != null) && !(context.toString().contains(org.opennms.web.api.Authentication.ROLE_DASHBOARD))) {
        isDashboardRole = false;
    }
    LOG.debug("User {} is in dashboard role? {}", username, isDashboardRole);
    /**
     * now construct the surveillance view/dashboard
     */
    rootLayout.addComponent(new SurveillanceView(view, m_surveillanceViewService, dashboard, !isDashboardRole));
    setContent(rootLayout);
    Page.getCurrent().getJavaScript().execute("function receiveMessage(event){\n" + "if(event.origin !== window.location.origin){ return; }\n" + "\n" + "event.source.postMessage( (document.getElementById('surveillance-window').offsetHeight + 17) + 'px', window.location.origin )\n" + "}\n" + "window.addEventListener(\"message\", receiveMessage, false);");
}
Also used : SecurityContext(org.springframework.security.core.context.SecurityContext) VerticalLayout(com.vaadin.ui.VerticalLayout) View(org.opennms.netmgt.config.surveillanceViews.View)

Aggregations

View (org.opennms.netmgt.config.surveillanceViews.View)15 ColumnDef (org.opennms.netmgt.config.surveillanceViews.ColumnDef)3 RowDef (org.opennms.netmgt.config.surveillanceViews.RowDef)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Group (org.opennms.netmgt.config.groups.Group)1 Category (org.opennms.netmgt.config.surveillanceViews.Category)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 SurveillanceStatus (org.opennms.netmgt.model.SurveillanceStatus)1 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1