use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class KscRestService method getReport.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{reportId}")
@Transactional
public KscReport getReport(@PathParam("reportId") final Integer reportId) {
final Map<Integer, Report> reportList = m_kscReportService.getReportMap();
final Report report = reportList.get(reportId);
if (report == null) {
throw getException(Status.NOT_FOUND, "No such report id {}.", Integer.toString(reportId));
}
return new KscReport(report);
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class CustomViewController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] requiredParameters = new String[] { "report", "type" };
// Get Form Variable
int reportId = -1;
String reportType = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.type.toString()));
String reportIdString = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.report.toString()));
if (reportType == null) {
throw new MissingParameterException(Parameters.type.toString(), requiredParameters);
}
if (reportIdString == null) {
throw new MissingParameterException(Parameters.report.toString(), requiredParameters);
}
if (reportType.equals("node") || reportType.equals("custom")) {
reportId = WebSecurityUtils.safeParseInt(reportIdString);
}
String overrideTimespan = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.timespan.toString()));
if ("null".equals(overrideTimespan) || "none".equals(overrideTimespan)) {
overrideTimespan = null;
}
String overrideGraphType = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.graphtype.toString()));
if ("null".equals(overrideGraphType) || "none".equals(overrideGraphType)) {
overrideGraphType = null;
}
// Load report to view
Report report = null;
if ("node".equals(reportType)) {
LOG.debug("handleRequestInternal: buildNodeReport(reportId) {}", reportId);
report = getKscReportService().buildNodeReport(reportId);
} else if ("nodeSource".equals(reportType)) {
LOG.debug("handleRequestInternal: buildNodeSourceReport(nodeSource) {}", reportIdString);
report = getKscReportService().buildNodeSourceReport(reportIdString);
} else if ("domain".equals(reportType)) {
LOG.debug("handleRequestInternal: buildDomainReport(reportIdString) {}", reportIdString);
report = getKscReportService().buildDomainReport(reportIdString);
} else if ("custom".equals(reportType)) {
LOG.debug("handleRequestInternal: getReportByIndex(reportId) {}", reportId);
report = m_kscReportFactory.getReportByIndex(reportId);
if (report == null) {
throw new ServletException("Report could not be found in config file for index '" + reportId + "'");
}
} else {
throw new IllegalArgumentException("value to 'type' parameter of '" + reportType + "' is not supported. Must be one of: node, nodeSource, domain, or custom");
}
// Get the list of available prefabricated graph options
Map<String, OnmsResource> resourceMap = new HashMap<String, OnmsResource>();
Set<PrefabGraph> prefabGraphs = new TreeSet<PrefabGraph>();
if (removeBrokenGraphsFromReport(report) && reportId > -1) {
m_kscReportFactory.setReport(reportId, report);
m_kscReportFactory.saveCurrent();
EventBuilder eb = new EventBuilder(EventConstants.KSC_REPORT_UPDATED_UEI, "Web UI");
eb.addParam(EventConstants.PARAM_REPORT_TITLE, report.getTitle() == null ? "Report #" + report.getId() : report.getTitle());
eb.addParam(EventConstants.PARAM_REPORT_GRAPH_COUNT, report.getGraphs().size());
try {
Util.createEventProxy().send(eb.getEvent());
} catch (Throwable e) {
LOG.error("Can't send event " + eb.getEvent(), e);
}
}
List<Graph> graphCollection = report.getGraphs();
if (!graphCollection.isEmpty()) {
for (Graph graph : graphCollection) {
final OnmsResource resource = getKscReportService().getResourceFromGraph(graph);
resourceMap.put(graph.toString(), resource);
if (resource == null) {
LOG.debug("Could not get resource for graph {} in report {}", graph, report.getTitle());
} else {
prefabGraphs.addAll(Arrays.asList(getResourceService().findPrefabGraphsForResource(resource)));
}
}
}
List<KscResultSet> resultSets = new ArrayList<KscResultSet>(report.getGraphs().size());
for (Graph graph : graphCollection) {
OnmsResource resource = resourceMap.get(graph.toString());
if (resource != null) {
promoteResourceAttributesIfNecessary(resource);
}
String displayGraphType;
if (overrideGraphType == null) {
displayGraphType = graph.getGraphtype();
} else {
displayGraphType = overrideGraphType;
}
PrefabGraph displayGraph;
try {
displayGraph = getResourceService().getPrefabGraph(displayGraphType);
} catch (ObjectRetrievalFailureException e) {
LOG.debug("The prefabricated graph '{}' does not exist: {}", displayGraphType, e, e);
displayGraph = null;
}
boolean foundGraph = false;
if (resource != null) {
for (PrefabGraph availableGraph : getResourceService().findPrefabGraphsForResource(resource)) {
if (availableGraph.equals(displayGraph)) {
foundGraph = true;
break;
}
}
}
if (!foundGraph) {
displayGraph = null;
}
// gather start/stop time information
String displayTimespan = null;
if (overrideTimespan == null) {
displayTimespan = graph.getTimespan();
} else {
displayTimespan = overrideTimespan;
}
Calendar beginTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
KSC_PerformanceReportFactory.getBeginEndTime(displayTimespan, beginTime, endTime);
KscResultSet resultSet = new KscResultSet(graph.getTitle(), beginTime.getTime(), endTime.getTime(), resource, displayGraph);
resultSets.add(resultSet);
}
ModelAndView modelAndView = new ModelAndView("KSC/customView");
modelAndView.addObject("loggedIn", request.getRemoteUser() != null);
modelAndView.addObject("reportType", reportType);
if (report != null) {
modelAndView.addObject("report", reportIdString);
}
modelAndView.addObject("title", report.getTitle());
modelAndView.addObject("resultSets", resultSets);
if (report.getShowTimespanButton().orElse(false)) {
if (overrideTimespan == null || !getKscReportService().getTimeSpans(true).containsKey(overrideTimespan)) {
modelAndView.addObject("timeSpan", "none");
} else {
modelAndView.addObject("timeSpan", overrideTimespan);
}
modelAndView.addObject("timeSpans", getKscReportService().getTimeSpans(true));
} else {
// Make sure it's null so the pulldown list isn't shown
modelAndView.addObject("timeSpan", null);
}
if (report.getShowGraphtypeButton().orElse(false)) {
LinkedHashMap<String, String> graphTypes = new LinkedHashMap<String, String>();
graphTypes.put("none", "none");
for (PrefabGraph graphOption : prefabGraphs) {
graphTypes.put(graphOption.getName(), graphOption.getName());
}
if (overrideGraphType == null || !graphTypes.containsKey(overrideGraphType)) {
modelAndView.addObject("graphType", "none");
} else {
modelAndView.addObject("graphType", overrideGraphType);
}
modelAndView.addObject("graphTypes", graphTypes);
} else {
// Make sure it's null so the pulldown list isn't shown
modelAndView.addObject("graphType", null);
}
modelAndView.addObject("showCustomizeButton", (request.isUserInRole(Authentication.ROLE_ADMIN) || !request.isUserInRole(Authentication.ROLE_READONLY)) && (request.getRemoteUser() != null));
if (report.getGraphsPerLine() != null && report.getGraphsPerLine().get() > 0) {
modelAndView.addObject("graphsPerLine", report.getGraphsPerLine());
} else {
modelAndView.addObject("graphsPerLine", getDefaultGraphsPerLine());
}
return modelAndView;
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class FormProcReportController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), true);
// Get The Customizable Report
Report report = editor.getWorkingReport();
// Get Form Variables
String action = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.action.toString()));
String report_title = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.report_title.toString()));
String show_timespan = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.show_timespan.toString()));
String show_graphtype = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.show_graphtype.toString()));
String g_index = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.graph_index.toString()));
int graph_index = WebSecurityUtils.safeParseInt(g_index);
int graphs_per_line = WebSecurityUtils.safeParseInt(request.getParameter(Parameters.graphs_per_line.toString()));
// Save the global variables into the working report
report.setTitle(report_title);
if (show_graphtype == null) {
report.setShowGraphtypeButton(false);
} else {
report.setShowGraphtypeButton(true);
}
if (show_timespan == null) {
report.setShowTimespanButton(false);
} else {
report.setShowTimespanButton(true);
}
if (graphs_per_line > 0) {
report.setGraphsPerLine(graphs_per_line);
} else {
report.setGraphsPerLine(0);
}
if (Actions.Save.toString().equals(action)) {
// The working model is complete now... lets save working model to configuration file
try {
// First copy working report into report arrays
editor.unloadWorkingReport(getKscReportFactory());
// Save the changes to the config file
getKscReportFactory().saveCurrent();
// Go ahead and unload the editor from the session since we're done using it
KscReportEditor.unloadFromSession(request.getSession());
} catch (Throwable e) {
throw new ServletException("Couldn't save report: " + e.getMessage(), e);
}
} else {
if (Actions.AddGraph.toString().equals(action) || Actions.ModGraph.toString().equals(action)) {
// Making a graph change... load it into the working area (the graph_index of -1 indicates a new graph)
editor.loadWorkingGraph(graph_index);
} else {
if (Actions.DelGraph.toString().equals(action)) {
final int index = graph_index;
report.removeGraph(report.getGraphs().get(index));
} else {
throw new ServletException("Invalid Argument for Customize Form Action.");
}
}
}
if (Actions.Save.toString().equals(action)) {
return new ModelAndView("redirect:/KSC/index.jsp");
} else if (Actions.DelGraph.toString().equals(action)) {
return new ModelAndView("redirect:/KSC/customReport.htm");
} else if (Actions.AddGraph.toString().equals(action)) {
return new ModelAndView("redirect:/KSC/customGraphChooseResource.jsp");
} else if (Actions.ModGraph.toString().equals(action)) {
Graph graph = editor.getWorkingGraph();
OnmsResource resource = getKscReportService().getResourceFromGraph(graph);
String graphType = graph.getGraphtype();
Map<String, String> modelData = new HashMap<String, String>();
modelData.put(CustomGraphEditDetailsController.Parameters.resourceId.toString(), resource.getId().toString());
modelData.put(CustomGraphEditDetailsController.Parameters.graphtype.toString(), graphType);
return new ModelAndView("redirect:/KSC/customGraphEditDetails.htm", modelData);
} else {
throw new IllegalArgumentException("Parameter action of '" + action + "' is not supported. Must be one of: Save, Cancel, Update, AddGraph, or DelGraph");
}
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class FormProcViewController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Get Form Variables
int reportId = -1;
String overrideTimespan = null;
String overrideGraphType = null;
String reportAction = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.action.toString()));
String reportIdString = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.report.toString()));
String reportType = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.type.toString()));
if (reportAction == null) {
throw new MissingParameterException("action", new String[] { "action", "report", "type" });
}
if (reportType == null) {
throw new MissingParameterException("type", new String[] { "action", "report", "type" });
}
if (reportIdString == null) {
throw new MissingParameterException("report", new String[] { "action", "report", "type" });
}
if (Actions.Customize.toString().equals(reportAction) || Actions.Update.toString().equals(reportAction)) {
if (reportType.equals("node") || reportType.equals("custom")) {
reportId = WebSecurityUtils.safeParseInt(reportIdString);
}
overrideTimespan = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.timespan.toString()));
if ((overrideTimespan == null) || overrideTimespan.equals("null")) {
overrideTimespan = "none";
}
overrideGraphType = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.graphtype.toString()));
if (overrideGraphType == null || overrideGraphType.equals("null")) {
overrideGraphType = "none";
}
if (Actions.Customize.toString().equals(reportAction)) {
// Fetch the KscReportEditor or create one if there isn't one already
KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), false);
LOG.debug("handleRequestInternal: build report for reportType {}", reportType);
if (reportType.equals("node")) {
editor.loadWorkingReport(m_kscReportService.buildNodeReport(reportId));
} else if (reportType.equals("nodeSource")) {
editor.loadWorkingReport(m_kscReportService.buildNodeSourceReport(reportIdString));
} else if (reportType.equals("domain")) {
editor.loadWorkingReport(m_kscReportService.buildDomainReport(reportIdString));
} else {
editor.loadWorkingReport(getKscReportFactory(), reportId);
}
// Now inject any override characteristics into the working report model
Report working_report = editor.getWorkingReport();
for (int i = 0; i < working_report.getGraphs().size(); i++) {
final int index = i;
Graph working_graph = working_report.getGraphs().get(index);
if (!overrideTimespan.equals("none")) {
working_graph.setTimespan(overrideTimespan);
}
if (!overrideGraphType.equals("none")) {
working_graph.setGraphtype(overrideGraphType);
}
}
}
} else {
if (!Actions.Exit.toString().equals(reportAction)) {
throw new ServletException("Invalid Parameter contents for report_action");
}
}
if (Actions.Update.toString().equals(reportAction)) {
ModelAndView modelAndView = new ModelAndView("redirect:/KSC/customView.htm");
modelAndView.addObject("type", reportType);
if (reportIdString != null) {
modelAndView.addObject("report", reportIdString);
}
if (overrideTimespan != null) {
modelAndView.addObject("timespan", overrideTimespan);
}
if (overrideGraphType != null) {
modelAndView.addObject("graphtype", overrideGraphType);
}
return modelAndView;
} else if (Actions.Customize.toString().equals(reportAction)) {
return new ModelAndView("redirect:/KSC/customReport.htm");
} else if (Actions.Exit.toString().equals(reportAction)) {
return new ModelAndView("redirect:/KSC/index.jsp");
} else {
throw new IllegalArgumentException("Parameter action of '" + reportAction + "' is not supported. Must be one of: Update, Customize, or Exit");
}
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class KscReportEditor method loadWorkingReport.
/**
* Loads the indexed report into the working report object.
*
* @param factory a {@link org.opennms.netmgt.config.KSC_PerformanceReportFactory} object.
* @param index a int.
*/
public void loadWorkingReport(KSC_PerformanceReportFactory factory, int index) {
Report report = factory.getReportByIndex(index);
if (report == null) {
throw new IllegalArgumentException("Could not find report with ID " + index);
}
m_workingReport = JaxbUtils.duplicateObject(report, Report.class);
}
Aggregations