use of org.mamute.dto.KarmaByContextHistory in project mamute by caelum.
the class ReputationEventDAO method karmaByContext.
@SuppressWarnings("unchecked")
private KarmaByContextHistory karmaByContext(User user, DateTime after, Integer maxResult) {
String hql = "select e.context.class, e.context.id, sum(e.karmaReward), " + "e.date " + "from ReputationEvent e " + "where e.user = :user and e.date > :after " + "group by e.context.class, e.context.id, e.date " + "order by e.date desc";
// get aggregate list
Query query = session.createQuery(hql).setParameter("user", user).setParameter("after", after);
if (maxResult != null) {
query.setMaxResults(maxResult);
}
return new KarmaByContextHistory(fetchContextData(query.list()));
}
use of org.mamute.dto.KarmaByContextHistory in project mamute by caelum.
the class ReputationEventDAOTest method should_ignore_events_of_deleted_questions.
@Test
public void should_ignore_events_of_deleted_questions() {
session.save(new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved1, author));
session.delete(questionInvolved1);
KarmaByContextHistory karmaByQuestion = reputationEvents.karmaWonByQuestion(author, new DateTime(0));
assertNotNull(karmaByQuestion);
assertNotNull(karmaByQuestion.getHistory());
assertTrue(karmaByQuestion.getHistory().isEmpty());
}
use of org.mamute.dto.KarmaByContextHistory in project mamute by caelum.
the class ReputationEventDAOTest method should_group_reputation_karma_reward_by_post.
@Test
public void should_group_reputation_karma_reward_by_post() throws Exception {
ReputationEvent event1Question1 = event30MinAgo(EventType.ANSWER_DOWNVOTE);
ReputationEvent event2Question1 = event30MinAgo(EventType.QUESTION_DOWNVOTE);
Integer question1Karma = event1Question1.getKarmaReward() + event2Question1.getKarmaReward();
ReputationEvent event1Question2 = new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved2, author);
ReputationEvent event2Question2 = new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved2, author);
Integer question2Karma = event1Question2.getKarmaReward() + event2Question2.getKarmaReward();
ReputationEvent eventOut = TimeMachine.goTo(new DateTime().minusHours(2)).andExecute(new Block<ReputationEvent>() {
@Override
public ReputationEvent run() {
return new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved3, author);
}
});
session.save(eventOut);
session.save(event1Question1);
session.save(event1Question2);
session.save(event2Question1);
session.save(event2Question2);
KarmaByContextHistory karmaByQuestion = reputationEvents.karmaWonByQuestion(author, new DateTime().minusHours(1));
List<KarmaAndContext> history = karmaByQuestion.getHistory();
assertEquals(2, history.size());
KarmaAndContext ck1 = Iterables.find(history, contextOf(questionInvolved1), null);
assertNotNull(ck1);
KarmaAndContext ck2 = Iterables.find(history, contextOf(questionInvolved2), null);
assertNotNull(ck2);
assertEquals(question1Karma.longValue(), ck1.getKarma().longValue());
assertEquals(question2Karma.longValue(), ck2.getKarma().longValue());
}
use of org.mamute.dto.KarmaByContextHistory in project mamute by caelum.
the class ReputationEventDAO method karmaWonByQuestion.
@SuppressWarnings("unchecked")
public KarmaByContextHistory karmaWonByQuestion(User user) {
String hql = "select e.context, sum(e.karmaReward), e.date from ReputationEvent e " + "where e.user=:user " + "group by e.context, day(e.date) " + "order by e.date desc";
Query query = session.createQuery(hql).setParameter("user", user);
return new KarmaByContextHistory(query.list());
}
use of org.mamute.dto.KarmaByContextHistory in project mamute by caelum.
the class ReputationEventDAOTest method should_group_reputation_karma_reward_by_date.
@Test
public void should_group_reputation_karma_reward_by_date() throws Exception {
ReputationEvent event1 = TimeMachine.goTo(new DateTime().minusDays(1)).andExecute(new Block<ReputationEvent>() {
@Override
public ReputationEvent run() {
return new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved1, author);
}
});
ReputationEvent event2 = new ReputationEvent(EventType.ANSWER_DOWNVOTE, questionInvolved1, author);
session.save(event2);
session.save(event1);
KarmaByContextHistory karmaByQuestion = reputationEvents.karmaWonByQuestion(author, new DateTime().minusDays(2));
List<KarmaAndContext> history = karmaByQuestion.getHistory();
assertEquals(2, history.size());
assertEquals(questionInvolved1, history.get(1).getContext());
assertEquals(event1.getKarmaReward().longValue(), history.get(1).getKarma().longValue());
assertEquals(questionInvolved1, history.get(0).getContext());
assertEquals(event2.getKarmaReward().longValue(), history.get(0).getKarma().longValue());
}
Aggregations