Search in sources :

Example 1 with View

use of org.opennms.features.vaadin.surveillanceviews.model.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.features.vaadin.surveillanceviews.model.View)

Example 2 with View

use of org.opennms.features.vaadin.surveillanceviews.model.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.features.vaadin.surveillanceviews.model.View)

Example 3 with View

use of org.opennms.features.vaadin.surveillanceviews.model.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.features.vaadin.surveillanceviews.model.View)

Aggregations

View (org.opennms.features.vaadin.surveillanceviews.model.View)3 VerticalLayout (com.vaadin.ui.VerticalLayout)1 Group (org.opennms.netmgt.config.groups.Group)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1