Search in sources :

Example 6 with ReputationEvent

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);
}
Also used : EventType(org.mamute.model.EventType) ReputationEvent(org.mamute.model.ReputationEvent)

Example 7 with ReputationEvent

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();
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) ReputationEvent(org.mamute.model.ReputationEvent) QuestionInformation(org.mamute.model.QuestionInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Moderatable(org.mamute.model.interfaces.Moderatable) Post(br.com.caelum.vraptor.Post) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 8 with ReputationEvent

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());
    }
}
Also used : Vote(org.mamute.model.Vote) User(org.mamute.model.User) ReceivedVoteEvent(org.mamute.reputation.rules.ReceivedVoteEvent) VotedAtSomethingEvent(org.mamute.reputation.rules.VotedAtSomethingEvent) ReputationEventContext(org.mamute.model.ReputationEventContext) ReputationEvent(org.mamute.model.ReputationEvent)

Example 9 with ReputationEvent

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());
}
Also used : KarmaByContextHistory(org.mamute.dto.KarmaByContextHistory) KarmaAndContext(org.mamute.dto.KarmaAndContext) ReputationEvent(org.mamute.model.ReputationEvent) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 10 with ReputationEvent

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));
}
Also used : List(java.util.List) ReputationEvent(org.mamute.model.ReputationEvent) Test(org.junit.Test)

Aggregations

ReputationEvent (org.mamute.model.ReputationEvent)10 Test (org.junit.Test)6 User (org.mamute.model.User)5 DateTime (org.joda.time.DateTime)3 KarmaByContextHistory (org.mamute.dto.KarmaByContextHistory)3 LoggedUser (org.mamute.model.LoggedUser)3 KarmaAndContext (org.mamute.dto.KarmaAndContext)2 UserSummaryForTag (org.mamute.dto.UserSummaryForTag)2 Question (org.mamute.model.Question)2 ReputationEventContext (org.mamute.model.ReputationEventContext)2 Tag (org.mamute.model.Tag)2 Vote (org.mamute.model.Vote)2 ReceivedVoteEvent (org.mamute.reputation.rules.ReceivedVoteEvent)2 VotedAtSomethingEvent (org.mamute.reputation.rules.VotedAtSomethingEvent)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 Post (br.com.caelum.vraptor.Post)1 List (java.util.List)1 Answer (org.mamute.model.Answer)1 AnswerInformation (org.mamute.model.AnswerInformation)1 EventType (org.mamute.model.EventType)1