Search in sources :

Example 1 with SuspectMassiveVote

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

the class VoteDAO method suspectMassiveVote.

public List<SuspectMassiveVote> suspectMassiveVote(VoteType type, DateTime begin, DateTime end) {
    Query query = session.createQuery("select new " + SuspectMassiveVote.class.getCanonicalName() + "(av,count(av),aa) " + "from Answer a join a.author aa join a.votes v join v.author av " + "where v.type = :type and v.createdAt between :begin and :end " + "group by av,aa " + "order by count(av) desc");
    query.setParameter("type", type);
    query.setParameter("begin", begin);
    query.setParameter("end", end);
    return query.setMaxResults(10).list();
}
Also used : Query(org.hibernate.Query) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote)

Example 2 with SuspectMassiveVote

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

the class VoteDAOTest method testName.

@Test
public void testName() throws Exception {
    Question question = question(currentUser, tags);
    Answer answer = answer("answer answer answer answer answer", question, currentUser);
    Question question2 = question(currentUser, tags);
    Answer answer2 = answer("answer answer answer answer answer", question2, currentUser);
    Question question3 = question(currentUser, tags);
    Answer answer3 = answer("answer answer answer answer answer", question3, currentUser);
    session.save(question);
    session.save(question2);
    session.save(question3);
    session.save(answer);
    session.save(answer2);
    session.save(answer3);
    upvote(answer, otherUser);
    upvote(answer2, otherUser);
    upvote(answer3, otherUser);
    List<SuspectMassiveVote> answers = votes.suspectMassiveVote(VoteType.UP, new DateTime().minusHours(1), new DateTime());
    assertEquals(otherUser, answers.get(0).getVoteAuthor());
    assertEquals(currentUser, answers.get(0).getAnswerAuthor());
    assertEquals(3l, answers.get(0).getMassiveVoteCount().longValue());
}
Also used : Answer(org.mamute.model.Answer) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote) Question(org.mamute.model.Question) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)2 Query (org.hibernate.Query)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 Answer (org.mamute.model.Answer)1 Question (org.mamute.model.Question)1