use of org.mamute.model.ReputationEvent in project mamute by caelum.
the class MassiveVoteRevertEvent method reputationEvent.
public ReputationEvent reputationEvent() {
EventType massiveVoteReverted = EventType.MASSIVE_VOTE_REVERTED;
massiveVoteReverted.setKarma(karma);
return new ReputationEvent(massiveVoteReverted, null, target);
}
use of org.mamute.model.ReputationEvent in project mamute by caelum.
the class HistoryController method publish.
@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.MODERATE_EDITS)
@Post
public void publish(Long moderatableId, String moderatableType, Long aprovedInformationId, String aprovedInformationType) {
Class<?> moderatableClass = urlMapping.getClassFor(moderatableType);
Information approved = informations.getById(aprovedInformationId, aprovedInformationType);
Moderatable moderatable = moderatables.getById(moderatableId, moderatableClass);
List<Information> pending = informations.pendingFor(moderatableId, moderatableClass);
if (!approved.isPending()) {
result.use(Results.http()).sendError(403);
return;
}
User approvedAuthor = approved.getAuthor();
refusePending(aprovedInformationId, pending);
currentUser.getCurrent().approve(moderatable, approved, environmentKarma);
ReputationEvent editAppoved = new ReputationEvent(EventType.EDIT_APPROVED, moderatable.getQuestion(), approvedAuthor);
int karma = calculator.karmaFor(editAppoved);
approvedAuthor.increaseKarma(karma);
reputationEvents.save(editAppoved);
result.redirectTo(this).history();
}
use of org.mamute.model.ReputationEvent in project mamute by caelum.
the class VotingMachine method register.
public void register(Votable votable, Vote current, Class<?> votableType) {
User voter = current.getAuthor();
User votableAuthor = votable.getAuthor();
ReputationEventContext eventContext = votes.contextOf(votable);
if (votable.getAuthor().getId().equals(voter.getId())) {
throw new IllegalArgumentException("an author can't vote its own votable");
}
Vote previous = votes.previousVoteFor(votable.getId(), voter, votableType);
boolean shouldCountKarma = voteChecker.shouldCountKarma(voter, votableAuthor, current);
if (previous != null) {
ReputationEvent receivedVote = new ReceivedVoteEvent(previous.getType(), votable, eventContext, shouldCountKarma).reputationEvent();
votableAuthor.descreaseKarma(karmaCalculator.karmaFor(receivedVote));
ReputationEvent votedAtSomething = new VotedAtSomethingEvent(previous, eventContext).reputationEvent();
voter.descreaseKarma(karmaCalculator.karmaFor(votedAtSomething));
reputationEvents.delete(receivedVote);
reputationEvents.delete(votedAtSomething);
}
votable.substitute(previous, current);
ReputationEvent receivedVote = new ReceivedVoteEvent(current.getType(), votable, eventContext, shouldCountKarma).reputationEvent();
votableAuthor.increaseKarma(karmaCalculator.karmaFor(receivedVote));
ReputationEvent votedAtSomething = new VotedAtSomethingEvent(current, eventContext).reputationEvent();
voter.increaseKarma(karmaCalculator.karmaFor(votedAtSomething));
reputationEvents.save(receivedVote);
reputationEvents.save(votedAtSomething);
if (votable.getVoteCount() <= -5) {
votable.getQuestion().remove();
retrieveDownvote.retrieveKarma(votable.getVotes());
}
}
use of org.mamute.model.ReputationEvent 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());
}
use of org.mamute.model.ReputationEvent in project mamute by caelum.
the class ReputationEventDAOTest method should_delete_event.
@SuppressWarnings("rawtypes")
@Test
public void should_delete_event() {
ReputationEvent toDelete = new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved1, author);
ReputationEvent other = new ReputationEvent(EventType.ANSWER_UPVOTE, questionInvolved1, author);
session.save(toDelete);
session.save(other);
reputationEvents.delete(toDelete);
List list = session.createCriteria(ReputationEvent.class).list();
assertEquals(1, list.size());
assertTrue(list.contains(other));
}
Aggregations