@RequestMapping("/server.jsp")
  public ModelAndView serverInfo() {
    List<User> moderators = userDao.getModerators();

    ModelAndView mv = new ModelAndView("server");
    mv.getModel().put("moderators", moderators);

    List<User> correctors = userDao.getCorrectors();

    mv.getModel().put("correctors", correctors);

    return mv;
  }
示例#2
0
  public void hideAnonymous(UserDao userDao, Set<Integer> hideSet)
      throws SQLException, UserNotFoundException {
    if (comment != null) {
      User commentAuthor = userDao.getUserCached(comment.getUserid());

      if (commentAuthor.isAnonymousScore()) {
        hideNode(hideSet);
      }
    }

    if (comment == null || !hideSet.contains(comment.getId())) {
      for (CommentNode child : childs) {
        child.hideAnonymous(userDao, hideSet);
      }
    }
  }
示例#3
0
  public SearchItem(
      SolrDocument doc,
      UserDao userDao,
      MsgbaseDao msgbaseDao,
      LorCodeService lorCodeService,
      boolean secure) {
    msgid = (String) doc.getFieldValue("id");
    title = (String) doc.getFieldValue("title");
    topicTitle = (String) doc.getFieldValue("topic_title");
    int userid = (Integer) doc.getFieldValue("user_id");
    Date postdate_dt = (Date) doc.getFieldValue("postdate");
    postdate = new Timestamp(postdate_dt.getTime());
    topic = (Integer) doc.getFieldValue("topic_id");
    section = (String) doc.getFieldValue("section");

    if (!"wiki".equals(section)) {
      virtualWiki = null;
      MessageText messageText = msgbaseDao.getMessageText(Integer.valueOf(msgid));
      String rawMessage = messageText.getText();
      if (messageText.isLorcode()) {
        message = lorCodeService.parseComment(rawMessage, secure);
      } else {
        message = rawMessage;
      }
    } else {
      // Wiki id like <virtual_wiki>-<topic_id>
      String[] msgIds = msgid.split("-");
      if (msgIds.length != 2) {
        throw new RuntimeException("Invalid wiki ID");
      }

      String content = msgbaseDao.getMessageTextFromWiki(Integer.valueOf(msgIds[1]));
      String msg = StringUtil.escapeHtml(content.substring(0, Math.min(1300, content.length())));
      if (Math.min(1300, content.length()) == 1300) {
        message = msg + "...";
      } else {
        message = msg;
      }
      virtualWiki = msgIds[0];
    }
    try {
      user = userDao.getUserCached(userid);
    } catch (UserNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
  public List<TrackerItem> getTrackAll(
      TrackerFilterEnum filter,
      User currentUser,
      Date startDate,
      int topics,
      int offset,
      final int messagesInPage) {

    MapSqlParameterSource parameter = new MapSqlParameterSource();
    parameter.addValue("interval", startDate);
    parameter.addValue("topics", topics);
    parameter.addValue("offset", offset);

    String partIgnored;

    if (currentUser != null) {
      partIgnored = queryPartIgnored + queryPartTagIgnored;
      parameter.addValue("userid", currentUser.getId());
    } else {
      partIgnored = "";
    }

    String partFilter;
    switch (filter) {
      case ALL:
        partFilter = "";
        break;
      case NOTALKS:
        partFilter = queryPartNoTalks;
        break;
      case MAIN:
        partFilter = queryPartMain;
        break;
      case TECH:
        partFilter = queryPartTech;
        break;
      default:
        partFilter = "";
    }

    boolean showUncommited =
        currentUser != null && (currentUser.isModerator() || currentUser.isCorrector());

    String partUncommited = showUncommited ? "" : noUncommited;

    String query;

    query =
        String.format(
            queryTrackerMain,
            partUncommited,
            partIgnored,
            partFilter,
            partUncommited,
            partIgnored,
            partFilter);

    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(query, parameter);

    List<TrackerItem> res = new ArrayList<>(topics);

    while (resultSet.next()) {
      User author = userDao.getUserCached(resultSet.getInt("author"));
      int msgid = resultSet.getInt("id");
      Timestamp lastmod = resultSet.getTimestamp("lastmod");
      int stat1 = resultSet.getInt("stat1");
      int groupId = resultSet.getInt("gid");
      String groupTitle = resultSet.getString("gtitle");
      String title = StringUtil.makeTitle(resultSet.getString("title"));
      int cid = resultSet.getInt("cid");
      User lastCommentBy;
      try {
        int id = resultSet.getInt("last_comment_by");

        if (id != 0) {
          lastCommentBy = userDao.getUserCached(id);
        } else {
          lastCommentBy = null;
        }
      } catch (UserNotFoundException e) {
        throw new RuntimeException(e);
      }
      boolean resolved = resultSet.getBoolean("resolved");
      int section = resultSet.getInt("section");
      String groupUrlName = resultSet.getString("urlname");
      Timestamp postdate = resultSet.getTimestamp("postdate");
      boolean uncommited = resultSet.getBoolean("smod") && !resultSet.getBoolean("moderate");
      int pages = Topic.getPageCount(stat1, messagesInPage);

      ImmutableList<String> tags;

      tags = topicTagService.getTagsForTitle(msgid);

      res.add(
          new TrackerItem(
              author,
              msgid,
              lastmod,
              stat1,
              groupId,
              groupTitle,
              title,
              cid,
              lastCommentBy,
              resolved,
              section,
              groupUrlName,
              postdate,
              uncommited,
              pages,
              tags));
    }

    return res;
  }
示例#5
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);
  }