Search in sources :

Example 91 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project opennms by OpenNMS.

the class AlarmFilterController method createListModelAndView.

private ModelAndView createListModelAndView(HttpServletRequest request, List<Filter> filterList, AcknowledgeType ackType) {
    final AlarmQueryParms parms = createAlarmQueryParms(request, filterList, ackType);
    AlarmCriteria queryCriteria = new AlarmCriteria(parms);
    AlarmCriteria countCriteria = new AlarmCriteria(filterList, ackType);
    final OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(AlarmUtil.getOnmsCriteria(queryCriteria));
    final long alarmCount = m_webAlarmRepository.countMatchingAlarms(AlarmUtil.getOnmsCriteria(countCriteria));
    final ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("alarms", alarms);
    modelAndView.addObject("alarmCount", alarmCount);
    modelAndView.addObject("parms", new NormalizedQueryParameters(parms));
    modelAndView.addObject("callback", getFilterCallback());
    modelAndView.addObject("favorites", favoriteService.getFavorites(request.getRemoteUser(), OnmsFilterFavorite.Page.ALARM).toArray());
    return modelAndView;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmQueryParms(org.opennms.web.alarm.AlarmQueryParms) ModelAndView(org.springframework.web.servlet.ModelAndView) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) NormalizedQueryParameters(org.opennms.web.filter.NormalizedQueryParameters)

Example 92 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project opennms by OpenNMS.

the class ThresholdController method gotoEditThreshold.

private ModelAndView gotoEditThreshold(String thresholdIndexString, String groupName) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    if (thresholdIndexString == null) {
        throw new ServletException("thresholdIndex parameter required to edit a threshold");
    }
    int thresholdIndex = WebSecurityUtils.safeParseInt(thresholdIndexString);
    Threshold threshold = configFactory.getGroup(groupName).getThresholds().get(thresholdIndex);
    modelAndView = new ModelAndView("admin/thresholds/editThreshold");
    modelAndView.addObject("threshold", threshold);
    modelAndView.addObject("thresholdIndex", thresholdIndex);
    modelAndView.addObject("groupName", groupName);
    modelAndView.addObject("isNew", false);
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Threshold(org.opennms.netmgt.config.threshd.Threshold)

Example 93 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project opennms by OpenNMS.

the class AlarmDetailController method removeStickyMemo.

public ModelAndView removeStickyMemo(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    int alarmId;
    String alarmIdString = "";
    // Try to parse alarm ID from string to integer
    try {
        alarmIdString = httpServletRequest.getParameter("alarmId");
        alarmId = Integer.parseInt(alarmIdString);
        m_webAlarmRepository.removeStickyMemo(alarmId);
        return new ModelAndView(new RedirectView("detail.htm", true), "id", alarmId);
    } catch (NumberFormatException e) {
        logger.error("Could not parse alarm ID '{}' to integer.", httpServletRequest.getParameter("alarmId"));
        throw new ServletException("Could not parse alarm ID " + httpServletRequest.getParameter("alarmId") + " to integer.");
    }
}
Also used : ServletException(javax.servlet.ServletException) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 94 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project opennms by OpenNMS.

the class ThresholdController method finishThresholdFilterEdit.

private ModelAndView finishThresholdFilterEdit(HttpServletRequest request, Basethresholddef threshold) throws ServletException {
    boolean isExpression = threshold instanceof Expression;
    int thresholdIndex;
    if (isExpression) {
        thresholdIndex = WebSecurityUtils.safeParseInt(request.getParameter("expressionIndex"));
    } else {
        thresholdIndex = WebSecurityUtils.safeParseInt(request.getParameter("thresholdIndex"));
    }
    ModelAndView modelAndView;
    if (isExpression) {
        modelAndView = new ModelAndView("admin/thresholds/editExpression");
    } else {
        modelAndView = new ModelAndView("admin/thresholds/editThreshold");
    }
    List<ResourceFilter> saved = getFilterList(request, true);
    if (saved == null || saved.size() == 0) {
        saved = new ArrayList<ResourceFilter>(threshold.getResourceFilters());
        setFilterList(request, saved);
    }
    String stringIndex = request.getParameter("filterSelected");
    int filterIndex = stringIndex != null && !stringIndex.equals("") ? WebSecurityUtils.safeParseInt(stringIndex) - 1 : 0;
    /*
         * Save Threshold Filters on HTTP Session in order to restore the original list if user clicks on "Cancel"
         */
    String submitAction = request.getParameter("submitAction");
    if (ADDFILTER_BUTTON_TITLE.equals(submitAction)) {
        String field = request.getParameter("filterField");
        String content = request.getParameter("filterRegexp");
        if (field != null && !field.equals("") && content != null && !content.equals("")) {
            ResourceFilter filter = new ResourceFilter();
            filter.setField(field);
            filter.setContent(content);
            threshold.addResourceFilter(filter);
        }
    } else if (DELETE_BUTTON_TITLE.equals(submitAction)) {
        threshold.getResourceFilters().remove(filterIndex);
    } else if (EDIT_BUTTON_TITLE.equals(submitAction)) {
        modelAndView.addObject("filterSelected", request.getParameter("filterSelected"));
    } else if (UPDATE_BUTTON_TITLE.equals(submitAction)) {
        ResourceFilter filter = (ResourceFilter) threshold.getResourceFilters().get(filterIndex);
        filter.setField(request.getParameter("updateFilterField"));
        filter.setContent(request.getParameter("updateFilterRegexp"));
    } else if (MOVEUP_BUTTON_TITLE.equals(submitAction)) {
        moveThresholdFilter(threshold, filterIndex, filterIndex - 1);
    } else if (MOVEDOWN_BUTTON_TITLE.equals(submitAction)) {
        moveThresholdFilter(threshold, filterIndex, filterIndex + 1);
    }
    commonFinishEdit(request, threshold);
    if (isExpression) {
        ((Expression) threshold).setExpression(request.getParameter("expression"));
    } else {
        ((Threshold) threshold).setDsName(request.getParameter("dsName"));
    }
    String isNew = request.getParameter("isNew");
    if ("true".equals(isNew)) {
        modelAndView.addObject("isNew", true);
    }
    if (isExpression) {
        modelAndView.addObject("expression", threshold);
        modelAndView.addObject("expressionIndex", thresholdIndex);
    } else {
        modelAndView.addObject("threshold", threshold);
        modelAndView.addObject("thresholdIndex", thresholdIndex);
    }
    modelAndView.addObject("groupName", request.getParameter("groupName"));
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : ResourceFilter(org.opennms.netmgt.config.threshd.ResourceFilter) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) Threshold(org.opennms.netmgt.config.threshd.Threshold)

Example 95 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project opennms by OpenNMS.

the class ThresholdController method gotoEditExpression.

private ModelAndView gotoEditExpression(String expressionIndexString, String groupName) throws ServletException {
    ThresholdingConfigFactory configFactory = ThresholdingConfigFactory.getInstance();
    ModelAndView modelAndView;
    if (expressionIndexString == null) {
        throw new ServletException("expressionIndex parameter required to edit a threshold");
    }
    int expressionIndex = WebSecurityUtils.safeParseInt(expressionIndexString);
    Expression expression = configFactory.getGroup(groupName).getExpressions().get(expressionIndex);
    modelAndView = new ModelAndView("admin/thresholds/editExpression");
    modelAndView.addObject("expression", expression);
    modelAndView.addObject("expressionIndex", expressionIndex);
    modelAndView.addObject("groupName", groupName);
    modelAndView.addObject("isNew", false);
    addStandardEditingBits(modelAndView);
    return modelAndView;
}
Also used : ServletException(javax.servlet.ServletException) Expression(org.opennms.netmgt.config.threshd.Expression) ModelAndView(org.springframework.web.servlet.ModelAndView) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory)

Aggregations

ModelAndView (org.springframework.web.servlet.ModelAndView)1576 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)669 Test (org.junit.jupiter.api.Test)195 Test (org.junit.Test)188 HashMap (java.util.HashMap)166 ArrayList (java.util.ArrayList)140 RedirectView (org.springframework.web.servlet.view.RedirectView)90 Map (java.util.Map)85 List (java.util.List)69 IOException (java.io.IOException)62 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)60 Date (java.util.Date)57 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)49 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)49 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)47 GetMapping (org.springframework.web.bind.annotation.GetMapping)45 HandlerMethod (org.springframework.web.method.HandlerMethod)45 IPerson (org.apereo.portal.security.IPerson)43 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)35