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