示例#1
0
 private void checkTopicTitleLength(Topic topic) {
   String title = topic.getTitle();
   if (title != null) {
     title = title.substring(0, Math.min(MAX_TITLE_LENGTH, title.length()));
     topic.setTitle(title);
   }
 }
示例#2
0
  @Override
  public Topic buildTopicFromComment(Comment comment, int projectId) {
    Topic topic = new Topic();
    topic.setCreated(comment.getCreated());
    topic.setExcerpt(comment.getContent());
    checkTopicExcerptLength(topic);
    topic.setLastUpdatorId(comment.getCreatorId());
    topic.setProjectId(projectId);
    topic.setRefId(comment.getAttachId());
    topic.setRefType(comment.getAttachType());

    Commentable commentable =
        (Commentable)
            identifiableManager.getIdentifiableByTypeAndId(
                comment.getAttachType(), comment.getAttachId());

    if (commentable == null) {
      return null;
    }

    topic.setTitle(commentable.getCommentSubject());
    topic.setUpdated(comment.getUpdated());
    topic.setDeleted(false);
    return topic;
  }
示例#3
0
 @Override
 public int getTopicCount(int projectId) {
   Topic topicExample = new Topic(false);
   topicExample.setProjectId(projectId);
   topicExample.setStick(true);
   return topicMapper.countByExample(new TopicExample(topicExample));
 }
示例#4
0
 private void checkTopicExcerptLength(Topic topic) {
   String excerpt = topic.getExcerpt();
   if (excerpt != null) {
     excerpt = excerpt.substring(0, Math.min(MAX_EXCERPT_LENGTH, excerpt.length()));
     topic.setExcerpt(excerpt);
   }
 }
示例#5
0
  @Override
  public List<Topic> getCollectedTopics(int projectId) {
    Topic topicExample = new Topic(false);
    topicExample.setProjectId(projectId);
    topicExample.setStick(true);

    return Lists.newArrayList(topicMapper.selectByExample(new TopicExample(topicExample)));
  }
示例#6
0
 @Override
 public Topic unstickTopic(int id) {
   Topic topicExample = new Topic(false);
   topicExample.setId(id);
   topicExample.setStick(false);
   topicMapper.updateByPrimaryKeySelective(topicExample);
   return topicMapper.selectByPrimaryKey(id);
 }
示例#7
0
  @Override
  public void recoverTopcicByTypeAndId(String type, int id) {
    Topic example = new Topic();
    example.setRefId(id);
    example.setRefType(type);

    Topic topic = new Topic(false);

    topicMapper.updateByExampleSelective(topic, new TopicExample(example));
  }
示例#8
0
 @Override
 public Topic createTopic(Topic topic) {
   // Date now = new Date();
   // topic.setCreated(now);
   // topic.setUpdated(now);
   topic.setStick(false);
   topic.setExcerpt(HtmlTextParser.getPlainText(topic.getExcerpt()));
   checkTopicTitleLength(topic);
   topicMapper.insert(topic);
   return topic;
 }
示例#9
0
 @Override
 public Topic buildTopicFromDiscussion(Discussion discussion) {
   Topic topic = new Topic();
   topic.setCreated(discussion.getCreated());
   topic.setExcerpt(discussion.getContent());
   checkTopicExcerptLength(topic);
   topic.setLastUpdatorId(discussion.getCreatorId());
   topic.setProjectId(discussion.getProjectId());
   topic.setRefId(discussion.getId());
   topic.setRefType(discussion.getType());
   topic.setTitle(discussion.getSubject());
   topic.setUpdated(discussion.getUpdated());
   topic.setDeleted(false);
   return topic;
 }
示例#10
0
  @Override
  public Topic createOrUpdateTopic(Topic topic) {

    if (topic == null) {
      return null;
    }

    Topic t = new Topic();
    t.setRefId(topic.getRefId());
    t.setRefType(topic.getRefType());
    TopicExample example = new TopicExample(t);

    List<Topic> topics = topicMapper.selectByExample(example);
    if (topics.size() == 0) {
      createTopic(topic);
      return topic;
    } else {
      topic.setId(topics.get(0).getId());
      topic.setCreated(null);
      updateTopic(topic);
      return topic;
    }
  }
示例#11
0
  @Override
  public Topic getTopicByTypeAndId(String type, int id) {
    Topic example = new Topic();
    example.setRefId(id);
    example.setRefType(type);

    List<Topic> topics = topicMapper.selectByExample(new TopicExample(example));
    if (topics != null && !topics.isEmpty()) {
      // 只可能有一个topic
      Topic topic = topics.get(0);
      if (topic.getLastUpdator() == null) {
        topic.setLastUpdator(userMapper.selectByPrimaryKey(topic.getLastUpdatorId()));
      }

      String a = topic.getExcerpt();
      String b = HtmlTextParser.getPlainText(a);

      topic.setExcerpt(HtmlTextParser.getPlainText(topic.getExcerpt()));

      BaseOperateItem identifiable =
          identifiableManager.getIdentifiableByTypeAndId(topic.getRefType(), topic.getRefId());
      if (identifiable != null) {
        topic.setTargetCreator(
            userMapper.selectByPrimaryKey(((BaseProjectItem) identifiable).getCreatorId()));
      }

      return topic;
    }

    return null;
  }
示例#12
0
  @Override
  public List<Topic> getTopicListByProjectId(int projectId, int start, int limit) {
    Topic topic = new Topic(false);
    topic.setProjectId(projectId);
    topic.setStick(false);
    TopicExample example = new TopicExample(topic);
    example.setLimit(start, limit);
    example.setOrderByClause("updated desc");

    List<Topic> topics = Lists.newArrayList();
    if (start == 0) {
      topics = getCollectedTopics(projectId);
    }
    topics.addAll(topicMapper.selectByExample(example));

    for (Topic t : topics) {
      t.setExcerpt(HtmlTextParser.getPlainText(t.getExcerpt()));
      t.setLastUpdator(userMapper.selectByPrimaryKey(t.getLastUpdatorId()));
      BaseOperateItem identifiable =
          identifiableManager.getIdentifiableByTypeAndId(t.getRefType(), t.getRefId());
      if (identifiable != null) {
        t.setTargetCreator(
            userMapper.selectByPrimaryKey(((BaseProjectItem) identifiable).getCreatorId()));
      }
    }
    return topics;
  }