Search in sources :

Example 1 with SortStyle

use of org.opennms.web.alarm.SortStyle in project opennms by OpenNMS.

the class AlarmFilterController method getSortStyle.

private SortStyle getSortStyle(HttpServletRequest request) {
    // handle the style sort parameter
    String sortStyleString = request.getParameter("sortby");
    SortStyle sortStyle = DEFAULT_SORT_STYLE;
    if (sortStyleString != null) {
        SortStyle temp = SortStyle.getSortStyle(sortStyleString);
        if (temp != null) {
            sortStyle = temp;
        }
    }
    return sortStyle;
}
Also used : SortStyle(org.opennms.web.alarm.SortStyle)

Example 2 with SortStyle

use of org.opennms.web.alarm.SortStyle in project opennms by OpenNMS.

the class NCSAlarmController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String display = request.getParameter("display");
    // handle the style sort parameter
    String sortStyleString = request.getParameter("sortby");
    SortStyle sortStyle = m_defaultSortStyle;
    if (sortStyleString != null) {
        SortStyle temp = SortStyle.getSortStyle(sortStyleString);
        if (temp != null) {
            sortStyle = temp;
        }
    }
    // handle the acknowledgment type parameter
    String ackTypeString = request.getParameter("acktype");
    AcknowledgeType ackType = m_defaultAcknowledgeType;
    if (ackTypeString != null) {
        AcknowledgeType temp = AcknowledgeType.getAcknowledgeType(ackTypeString);
        if (temp != null) {
            ackType = temp;
        }
    }
    // handle the filter parameters
    String[] filterStrings = request.getParameterValues("filter");
    List<Filter> filterList = new ArrayList<>();
    if (filterStrings != null) {
        for (int i = 0; i < filterStrings.length; i++) {
            Filter filter = AlarmUtil.getFilter(filterStrings[i], getServletContext());
            if (filter != null) {
                filterList.add(filter);
            }
        }
    } else {
        filterList.add(AlarmUtil.getFilter("parmmatchany=componentType=Service", getServletContext()));
    }
    // handle the optional limit parameter
    String limitString = request.getParameter("limit");
    int limit = "long".equals(display) ? getDefaultLongLimit() : getDefaultShortLimit();
    if (limitString != null) {
        try {
            int newlimit = WebSecurityUtils.safeParseInt(limitString);
            if (newlimit > 0) {
                limit = newlimit;
            }
        } catch (NumberFormatException e) {
        // do nothing, the default is already set
        }
    }
    // handle the optional multiple parameter
    String multipleString = request.getParameter("multiple");
    int multiple = DEFAULT_MULTIPLE;
    if (multipleString != null) {
        try {
            multiple = Math.max(0, WebSecurityUtils.safeParseInt(multipleString));
        } catch (NumberFormatException e) {
        }
    }
    // put the parameters in a convenient struct
    Filter[] filters = filterList.toArray(new Filter[0]);
    AlarmQueryParms parms = new AlarmQueryParms();
    parms.ackType = ackType;
    parms.display = display;
    parms.filters = filterList;
    parms.limit = limit;
    parms.multiple = multiple;
    parms.sortStyle = sortStyle;
    AlarmCriteria queryCriteria = new AlarmCriteria(filters, sortStyle, ackType, limit, limit * multiple);
    AlarmCriteria countCriteria = new AlarmCriteria(filters, ackType);
    OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(AlarmUtil.getOnmsCriteria(queryCriteria));
    // get the total alarm count
    int alarmCount = m_webAlarmRepository.countMatchingAlarms(AlarmUtil.getOnmsCriteria(countCriteria));
    ModelAndView modelAndView = new ModelAndView(getSuccessView());
    modelAndView.addObject("alarms", alarms);
    modelAndView.addObject("alarmCount", alarmCount);
    modelAndView.addObject("parms", parms);
    return modelAndView;
}
Also used : SortStyle(org.opennms.web.alarm.SortStyle) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) AlarmQueryParms(org.opennms.web.alarm.AlarmQueryParms) ModelAndView(org.springframework.web.servlet.ModelAndView) AcknowledgeType(org.opennms.web.alarm.AcknowledgeType) Filter(org.opennms.web.filter.Filter) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SortStyle (org.opennms.web.alarm.SortStyle)2 ArrayList (java.util.ArrayList)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 AcknowledgeType (org.opennms.web.alarm.AcknowledgeType)1 AlarmQueryParms (org.opennms.web.alarm.AlarmQueryParms)1 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)1 Filter (org.opennms.web.filter.Filter)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1