use of org.mamute.reputation.rules.VotedAtSomethingEvent in project mamute by caelum.
the class VotedAtSomethingEventTest method should_calculate_karma_for_downvote.
@Test
public void should_calculate_karma_for_downvote() {
VotedAtSomethingEvent votedAtSomething = new VotedAtSomethingEvent(new Vote(null, VoteType.DOWN), null);
assertEquals(KarmaCalculator.DOWNVOTED_QUESTION_OR_ANSWER, votedAtSomething.reward());
}
use of org.mamute.reputation.rules.VotedAtSomethingEvent in project mamute by caelum.
the class VotedAtSomethingEventTest method should_calculate_karma_for_upvote.
@Test
public void should_calculate_karma_for_upvote() {
VotedAtSomethingEvent votedAtSomething = new VotedAtSomethingEvent(new Vote(null, VoteType.UP), null);
assertEquals(0, votedAtSomething.reward());
}
use of org.mamute.reputation.rules.VotedAtSomethingEvent in project mamute by caelum.
the class VotingMachine method unRegister.
public void unRegister(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 unvote its own votable since it can't even vote on it");
}
Vote previous = votes.previousVoteFor(votable.getId(), voter, votableType);
boolean shouldCountKarma = voteChecker.shouldCountKarma(voter, votableAuthor, current);
/* O previous vai sempre existir nessa caso !! ( o ideal :] ) */
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.remove(previous);
}
// 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.reputation.rules.VotedAtSomethingEvent 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());
}
}
Aggregations