Esempio n. 1
0
 @ModelAttribute("filters")
 public static List<TrackerFilterEnum> getFilter(HttpServletRequest request) {
   Template tmpl = Template.getTemplate(request);
   if (tmpl.isSessionAuthorized()) {
     return Arrays.asList(TrackerFilterEnum.values());
   } else {
     List<TrackerFilterEnum> trackerFilters = new ArrayList<>();
     for (TrackerFilterEnum trackerFilter : TrackerFilterEnum.values()) {
       if ("mine".equals(trackerFilter.getValue())) {
         continue;
       }
       trackerFilters.add(trackerFilter);
     }
     return trackerFilters;
   }
 }
Esempio n. 2
0
  @RequestMapping("/tracker")
  public ModelAndView tracker(
      @RequestParam(value = "filter", defaultValue = "all") String filterAction,
      @RequestParam(value = "offset", required = false) Integer offset,
      HttpServletRequest request)
      throws Exception {

    if (offset == null) {
      offset = 0;
    } else {
      if (offset < 0 || offset > 300) {
        throw new UserErrorException("Некорректное значение offset");
      }
    }

    TrackerFilterEnum trackerFilter = getFilterValue(filterAction);

    Map<String, Object> params = new HashMap<>();
    params.put("mine", trackerFilter == TrackerFilterEnum.MINE);
    params.put("offset", offset);
    params.put("filter", trackerFilter.getValue());

    if (trackerFilter != TrackerFilterEnum.ALL) {
      params.put("addition_query", "&amp;filter=" + trackerFilter.getValue());
    } else {
      params.put("addition_query", "");
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    if (trackerFilter == TrackerFilterEnum.MINE) {
      calendar.add(Calendar.MONTH, -6);
    } else {
      calendar.add(Calendar.HOUR, -24);
    }
    Timestamp dateLimit = new Timestamp(calendar.getTimeInMillis());

    Template tmpl = Template.getTemplate(request);
    int messages = tmpl.getProf().getMessages();
    int topics = tmpl.getProf().getTopics();

    params.put("topics", topics);

    User user = tmpl.getCurrentUser();

    if (trackerFilter == TrackerFilterEnum.MINE) {
      if (!tmpl.isSessionAuthorized()) {
        throw new UserErrorException("Not authorized");
      }
      params.put("title", "Последние сообщения (мои темы)");
    } else {
      params.put("title", "Последние сообщения");
    }
    params.put(
        "msgs", trackerDao.getTrackAll(trackerFilter, user, dateLimit, topics, offset, messages));

    if (tmpl.isModeratorSession() && trackerFilter != TrackerFilterEnum.MINE) {
      params.put("newUsers", userDao.getNewUsers());
      params.put("deleteStats", deleteInfoDao.getRecentStats());
    }

    return new ModelAndView("tracker", params);
  }
Esempio n. 3
0
 static {
   filterValues = new HashSet<>();
   for (TrackerFilterEnum eventFilter : TrackerFilterEnum.values()) {
     filterValues.add(eventFilter.getValue());
   }
 }