Search in sources :

Example 6 with MissingParameterException

use of org.opennms.web.servlet.MissingParameterException 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 7 with MissingParameterException

use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.

the class FormProcMainController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String action = request.getParameter("report_action");
    if (action == null) {
        throw new MissingParameterException("report_action");
    }
    if (Actions.View.toString().equals(action)) {
        ModelAndView modelAndView = new ModelAndView("redirect:/KSC/customView.htm");
        modelAndView.addObject("report", getReportIndex(request));
        modelAndView.addObject("type", "custom");
        return modelAndView;
    } else if ((request.isUserInRole(Authentication.ROLE_ADMIN) || !request.isUserInRole(Authentication.ROLE_READONLY)) && (request.getRemoteUser() != null)) {
        // Fetch the KscReportEditor or create one if there isn't one already
        KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), false);
        if (Actions.Customize.toString().equals(action)) {
            editor.loadWorkingReport(getKscReportFactory(), getReportIndex(request));
            return new ModelAndView("redirect:/KSC/customReport.htm");
        } else if (Actions.CreateFrom.toString().equals(action)) {
            editor.loadWorkingReportDuplicate(getKscReportFactory(), getReportIndex(request));
            return new ModelAndView("redirect:/KSC/customReport.htm");
        } else if (Actions.Delete.toString().equals(action)) {
            getKscReportFactory().deleteReportAndSave(getReportIndex(request));
            return new ModelAndView("redirect:/KSC/index.jsp");
        } else if (Actions.Create.toString().equals(action)) {
            editor.loadNewWorkingReport();
            return new ModelAndView("redirect:/KSC/customReport.htm");
        }
    }
    throw new ServletException("Invalid Parameter contents for report_action: " + action);
}
Also used : ServletException(javax.servlet.ServletException) ModelAndView(org.springframework.web.servlet.ModelAndView) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Example 8 with MissingParameterException

use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.

the class OutageDetailController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int outageId = -1;
    String outageIdString = request.getParameter("id");
    if (outageIdString == null) {
        throw new MissingParameterException("id");
    }
    try {
        outageId = WebSecurityUtils.safeParseInt(WebSecurityUtils.sanitizeString(outageIdString, false));
    } catch (NumberFormatException e) {
        throw new OutageIdNotFoundException("The outage id must be an integer.", outageIdString);
    }
    Outage outage = m_webOutageRepository.getOutage(outageId);
    ModelAndView modelAndView = new ModelAndView(getSuccessView());
    modelAndView.addObject("outage", outage);
    return modelAndView;
}
Also used : Outage(org.opennms.web.outage.Outage) OutageIdNotFoundException(org.opennms.web.outage.OutageIdNotFoundException) ModelAndView(org.springframework.web.servlet.ModelAndView) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Example 9 with MissingParameterException

use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.

the class NodeLabelChangeServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String nodeIdString = request.getParameter("node");
    String labelType = request.getParameter("labeltype");
    String userLabel = request.getParameter("userlabel");
    if (nodeIdString == null) {
        throw new MissingParameterException("node", new String[] { "node", "labeltype", "userlabel" });
    }
    if (labelType == null) {
        throw new MissingParameterException("labeltype", new String[] { "node", "labeltype", "userlabel" });
    }
    if (userLabel == null) {
        throw new MissingParameterException("userlabel", new String[] { "node", "labeltype", "userlabel" });
    }
    try {
        final int nodeId = WebSecurityUtils.safeParseInt(nodeIdString);
        final OnmsNode node = NetworkElementFactory.getInstance(getServletContext()).getNode(nodeId);
        NodeLabel nodeLabel = BeanUtils.getBean("daoContext", "nodeLabel", NodeLabel.class);
        NodeLabel oldLabel = new NodeLabelDaoImpl(node.getLabel(), node.getLabelSource());
        NodeLabel newLabel = null;
        if (labelType.equals("auto")) {
            newLabel = nodeLabel.computeLabel(nodeId);
        } else if (labelType.equals("user")) {
            newLabel = new NodeLabelDaoImpl(userLabel, NodeLabelSource.USER);
        } else {
            throw new ServletException("Unexpected labeltype value: " + labelType);
        }
        final String newNodeLabel = newLabel.getLabel();
        boolean managedByProvisiond = node.getForeignSource() != null && node.getForeignId() != null;
        if (managedByProvisiond) {
            WebApplicationContext beanFactory = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
            final TransactionTemplate transactionTemplate = beanFactory.getBean(TransactionTemplate.class);
            final RequisitionAccessService requisitionService = beanFactory.getBean(RequisitionAccessService.class);
            transactionTemplate.execute(new TransactionCallback<RequisitionNode>() {

                @Override
                public RequisitionNode doInTransaction(TransactionStatus status) {
                    MultivaluedMap<String, String> params = new MultivaluedHashMap<String, String>();
                    params.putSingle("node-label", newNodeLabel);
                    requisitionService.updateNode(node.getForeignSource(), node.getForeignId(), params);
                    return requisitionService.getNode(node.getForeignSource(), node.getForeignId());
                }
            });
        }
        this.sendLabelChangeEvent(nodeId, oldLabel, newLabel);
        if (managedByProvisiond) {
            response.sendRedirect(Util.calculateUrlBase(request, "admin/nodelabelProvisioned.jsp?node=" + nodeIdString + "&foreignSource=" + node.getForeignSource()));
        } else {
            final WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
            final TransactionTemplate transactionTemplate = context.getBean(TransactionTemplate.class);
            final NodeLabel newLabelFinal = newLabel;
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {

                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    try {
                        nodeLabel.assignLabel(nodeId, newLabelFinal);
                    } catch (SQLException e) {
                        LOG.error("Failed to change label on node with id: {} to: {}", nodeId, newLabelFinal, e);
                        throw Throwables.propagate(e);
                    }
                }
            });
            response.sendRedirect(Util.calculateUrlBase(request, "element/node.jsp?node=" + nodeIdString));
        }
    } catch (SQLException e) {
        throw new ServletException("Database exception", e);
    } catch (Throwable e) {
        throw new ServletException("Exception sending node label change event", e);
    }
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) OnmsNode(org.opennms.netmgt.model.OnmsNode) SQLException(java.sql.SQLException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ServletException(javax.servlet.ServletException) NodeLabel(org.opennms.netmgt.dao.api.NodeLabel) RequisitionAccessService(org.opennms.web.svclayer.api.RequisitionAccessService) NodeLabelDaoImpl(org.opennms.netmgt.dao.hibernate.NodeLabelDaoImpl) MissingParameterException(org.opennms.web.servlet.MissingParameterException) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 10 with MissingParameterException

use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.

the class NodeRescanServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // required parameters
    String nodeIdString = request.getParameter("node");
    String returnUrl = request.getParameter("returnUrl");
    if (nodeIdString == null) {
        throw new MissingParameterException("node", new String[] { "node", "returnUrl" });
    }
    if (returnUrl == null) {
        throw new MissingParameterException("returnUrl", new String[] { "node", "returnUrl" });
    }
    try {
        int nodeId = WebSecurityUtils.safeParseInt(nodeIdString);
        EventBuilder bldr = new EventBuilder(EventConstants.FORCE_RESCAN_EVENT_UEI, "NodeRescanServlet");
        bldr.setNodeid(nodeId);
        bldr.setHost("host");
        // send the event
        this.proxy.send(bldr.getEvent());
        // redirect the request for display
        response.sendRedirect(Util.calculateUrlBase(request, returnUrl));
    } catch (Throwable e) {
        throw new ServletException("Exception sending node rescan event", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Aggregations

MissingParameterException (org.opennms.web.servlet.MissingParameterException)25 ServletException (javax.servlet.ServletException)13 ModelAndView (org.springframework.web.servlet.ModelAndView)11 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Filter (org.opennms.web.filter.Filter)6 Calendar (java.util.Calendar)5 RedirectView (org.springframework.web.servlet.view.RedirectView)4 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 Report (org.opennms.netmgt.config.kscReports.Report)3 EventIdFilter (org.opennms.web.event.filter.EventIdFilter)3 Graph (org.opennms.netmgt.config.kscReports.Graph)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 OnmsResource (org.opennms.netmgt.model.OnmsResource)2 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)2 ResourceId (org.opennms.netmgt.model.ResourceId)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1