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