use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class AcknowledgeAlarmController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Acknowledge the alarms specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] alarmIdStrings = request.getParameterValues("alarm");
String action = request.getParameter("actionCode");
if (alarmIdStrings == null) {
throw new MissingParameterException("alarm", new String[] { "alarm", "actionCode" });
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "alarm", "actionCode" });
}
// convert the alarm id strings to ints
int[] alarmIds = new int[alarmIdStrings.length];
for (int i = 0; i < alarmIds.length; i++) {
alarmIds[i] = WebSecurityUtils.safeParseInt(alarmIdStrings[i]);
}
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.acknowledgeAlarms(alarmIds, request.getRemoteUser(), new Date());
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webAlarmRepository.unacknowledgeAlarms(alarmIds, request.getRemoteUser());
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
String redirectParms = request.getParameter("redirectParms");
String redirect = request.getParameter("redirect");
String viewName;
if (redirect != null) {
viewName = redirect;
} else {
viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
}
RedirectView view = new RedirectView(viewName, true);
return new ModelAndView(view);
}
use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class AlarmSeverityChangeController method handleRequestInternal.
/**
* {@inheritDoc}
*
* Adjust the severity of the alarms specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] alarmIdStrings = request.getParameterValues("alarm");
String action = request.getParameter("actionCode");
if (alarmIdStrings == null) {
throw new MissingParameterException("alarm", new String[] { "alarm", "actionCode" });
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "alarm", "actionCode" });
}
// convert the alarm id strings to ints
int[] alarmIds = new int[alarmIdStrings.length];
for (int i = 0; i < alarmIds.length; i++) {
alarmIds[i] = WebSecurityUtils.safeParseInt(alarmIdStrings[i]);
}
if (action.equals(ESCALATE_ACTION)) {
m_webAlarmRepository.escalateAlarms(alarmIds, request.getRemoteUser(), new Date());
} else if (action.equals(CLEAR_ACTION)) {
m_webAlarmRepository.clearAlarms(alarmIds, request.getRemoteUser(), new Date());
} else {
throw new ServletException("Unknown alarm severity action: " + action);
}
String redirectParms = request.getParameter("redirectParms");
String redirect = request.getParameter("redirect");
String viewName;
if (redirect != null) {
viewName = redirect;
} else {
viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
}
RedirectView view = new RedirectView(viewName, true);
return new ModelAndView(view);
}
use of org.opennms.web.servlet.MissingParameterException in project opennms by OpenNMS.
the class EventController method acknowledgeByFilter.
/**
* Acknowledge the events specified in the POST and then redirect the client
* to an appropriate URL for display.
*/
public ModelAndView acknowledgeByFilter(HttpServletRequest request, HttpServletResponse response) throws Exception {
// required parameter
String[] filterStrings = request.getParameterValues("filter");
String action = request.getParameter("actionCode");
if (filterStrings == null) {
filterStrings = new String[0];
}
if (action == null) {
throw new MissingParameterException("actionCode", new String[] { "filter", "actionCode" });
}
// handle the filter parameters
ArrayList<Filter> filterArray = new ArrayList<>();
for (String filterString : filterStrings) {
Filter filter = EventUtil.getFilter(filterString, getServletContext());
if (filter != null) {
filterArray.add(filter);
}
}
Filter[] filters = filterArray.toArray(new Filter[filterArray.size()]);
EventCriteria criteria = new EventCriteria(filters);
if (action.equals(AcknowledgeType.ACKNOWLEDGED.getShortName())) {
m_webEventRepository.acknowledgeMatchingEvents(request.getRemoteUser(), new Date(), criteria);
} else if (action.equals(AcknowledgeType.UNACKNOWLEDGED.getShortName())) {
m_webEventRepository.unacknowledgeMatchingEvents(criteria);
} else {
throw new ServletException("Unknown acknowledge action: " + action);
}
return getRedirectView(request);
}
use of org.opennms.web.servlet.MissingParameterException 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<>();
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().orElse(0) > 0) {
modelAndView.addObject("graphsPerLine", report.getGraphsPerLine().get());
} else {
modelAndView.addObject("graphsPerLine", getDefaultGraphsPerLine());
}
return modelAndView;
}
use of org.opennms.web.servlet.MissingParameterException 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");
}
}
Aggregations