Search in sources :

Example 1 with FlaggableAndFlagCount

use of org.mamute.dto.FlaggableAndFlagCount in project mamute by caelum.

the class FlagController method topFlagged.

@CustomBrutauthRules(ModeratorOnlyRule.class)
@Get
public void topFlagged() {
    List<FlaggableAndFlagCount> flaggedQuestions = flaggables.flaggedButVisible(Question.class);
    List<FlaggableAndFlagCount> flaggedAnswers = flaggables.flaggedButVisible(Answer.class);
    List<FlaggableAndFlagCount> flaggedComments = flaggables.flaggedButVisible(Comment.class);
    List<Question> commentQuestions = new ArrayList<>();
    Iterator<FlaggableAndFlagCount> iterator = flaggedComments.iterator();
    while (iterator.hasNext()) {
        Comment comment = (Comment) iterator.next().getFlaggable();
        Question q = questions.fromCommentId(comment.getId());
        if (q != null) {
            commentQuestions.add(q);
            continue;
        }
        Answer answerFromComment = answers.fromCommentId(comment.getId());
        if (answerFromComment != null) {
            commentQuestions.add(answerFromComment.getQuestion());
            continue;
        }
        // some flags may be related to news (not questions nor answers)
        iterator.remove();
    }
    result.include("questions", flaggedQuestions);
    result.include("answers", flaggedAnswers);
    result.include("comments", flaggedComments);
    result.include("commentQuestions", commentQuestions);
}
Also used : Comment(org.mamute.model.Comment) Answer(org.mamute.model.Answer) FlaggableAndFlagCount(org.mamute.dto.FlaggableAndFlagCount) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Get(br.com.caelum.vraptor.Get)

Aggregations

CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 ArrayList (java.util.ArrayList)1 FlaggableAndFlagCount (org.mamute.dto.FlaggableAndFlagCount)1 Answer (org.mamute.model.Answer)1 Comment (org.mamute.model.Comment)1 Question (org.mamute.model.Question)1