Search in sources :

Example 1 with KscResultSet

use of org.opennms.web.graph.KscResultSet in project opennms by OpenNMS.

the class CustomGraphEditDetailsController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String resourceId = request.getParameter(Parameters.resourceId.toString());
    if (resourceId == null) {
        throw new MissingParameterException(Parameters.resourceId.toString());
    }
    //optional parameter graphtype
    String prefabReportName = request.getParameter(Parameters.graphtype.toString());
    KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), true);
    Report report = editor.getWorkingReport();
    org.opennms.netmgt.config.kscReports.Graph sample_graph = editor.getWorkingGraph();
    if (sample_graph == null) {
        throw new IllegalArgumentException("Invalid working graph argument -- null pointer. Possibly missing prefab report in snmp-graph.properties?");
    }
    // Set the resourceId in the working graph in case it changed
    sample_graph.setResourceId(resourceId);
    OnmsResource resource = getKscReportService().getResourceFromGraph(sample_graph);
    PrefabGraph[] graph_options = getResourceService().findPrefabGraphsForResource(resource);
    PrefabGraph display_graph = null;
    if (graph_options.length > 0) {
        if (prefabReportName == null) {
            display_graph = graph_options[0];
        } else {
            display_graph = getPrefabGraphFromList(graph_options, sample_graph.getGraphtype());
        }
    }
    Calendar begin_time = Calendar.getInstance();
    Calendar end_time = Calendar.getInstance();
    KSC_PerformanceReportFactory.getBeginEndTime(sample_graph.getTimespan(), begin_time, end_time);
    KscResultSet resultSet = new KscResultSet(sample_graph.getTitle(), begin_time.getTime(), end_time.getTime(), resource, display_graph);
    ModelAndView modelAndView = new ModelAndView("KSC/customGraphEditDetails");
    modelAndView.addObject("resultSet", resultSet);
    modelAndView.addObject("prefabGraphs", graph_options);
    modelAndView.addObject("timeSpans", getKscReportService().getTimeSpans(false));
    modelAndView.addObject("timeSpan", sample_graph.getTimespan());
    int graph_index = editor.getWorkingGraphIndex();
    int max_graphs = report.getGraphs().size();
    if (graph_index == -1) {
        graph_index = max_graphs++;
    }
    modelAndView.addObject("graphIndex", graph_index);
    modelAndView.addObject("maxGraphIndex", max_graphs);
    return modelAndView;
}
Also used : Report(org.opennms.netmgt.config.kscReports.Report) KscResultSet(org.opennms.web.graph.KscResultSet) Calendar(java.util.Calendar) ModelAndView(org.springframework.web.servlet.ModelAndView) OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Example 2 with KscResultSet

use of org.opennms.web.graph.KscResultSet in project opennms by OpenNMS.

the class CustomReportController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // Get Form Variables
    Report report = KscReportEditor.getFromSession(request.getSession(), true).getWorkingReport();
    if (report == null) {
        throw new IllegalStateException("There is no working report");
    }
    //        int report_index = getReportFactory().getWorkingReportIndex();      
    //        String number_graphs[] = {"1", "2", "3", "4", "5", "6"};
    ArrayList<KscResultSet> resultSets = new ArrayList<KscResultSet>(report.getGraphs().size());
    for (int i = 0; i < report.getGraphs().size(); i++) {
        final int index = i;
        Graph current_graph = report.getGraphs().get(index);
        PrefabGraph display_graph = getResourceService().getPrefabGraph(current_graph.getGraphtype());
        OnmsResource resource = getKscReportService().getResourceFromGraph(current_graph);
        Calendar begin_time = Calendar.getInstance();
        Calendar end_time = Calendar.getInstance();
        KSC_PerformanceReportFactory.getBeginEndTime(current_graph.getTimespan(), begin_time, end_time);
        KscResultSet resultSet = new KscResultSet(current_graph.getTitle(), begin_time.getTime(), end_time.getTime(), resource, display_graph);
        resultSets.add(resultSet);
    }
    ModelAndView modelAndView = new ModelAndView("KSC/customReport");
    modelAndView.addObject("showTimeSpan", report.getShowTimespanButton());
    modelAndView.addObject("showGraphType", report.getShowGraphtypeButton());
    modelAndView.addObject("graphsPerLine", report.getGraphsPerLine());
    modelAndView.addObject("title", report.getTitle());
    modelAndView.addObject("resultSets", resultSets);
    return modelAndView;
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Graph(org.opennms.netmgt.config.kscReports.Graph) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsResource(org.opennms.netmgt.model.OnmsResource) Report(org.opennms.netmgt.config.kscReports.Report) KscResultSet(org.opennms.web.graph.KscResultSet) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 3 with KscResultSet

use of org.opennms.web.graph.KscResultSet 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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) KscResultSet(org.opennms.web.graph.KscResultSet) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) LinkedHashMap(java.util.LinkedHashMap) ServletException(javax.servlet.ServletException) TreeSet(java.util.TreeSet) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) Report(org.opennms.netmgt.config.kscReports.Report) Calendar(java.util.Calendar) OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Graph(org.opennms.netmgt.config.kscReports.Graph) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Aggregations

Calendar (java.util.Calendar)3 Report (org.opennms.netmgt.config.kscReports.Report)3 OnmsResource (org.opennms.netmgt.model.OnmsResource)3 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)3 KscResultSet (org.opennms.web.graph.KscResultSet)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ArrayList (java.util.ArrayList)2 Graph (org.opennms.netmgt.config.kscReports.Graph)2 MissingParameterException (org.opennms.web.servlet.MissingParameterException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeSet (java.util.TreeSet)1 ServletException (javax.servlet.ServletException)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1