Search in sources :

Example 1 with KarmaCalculator

use of org.mamute.reputation.rules.KarmaCalculator in project mamute by caelum.

the class RulesInterceptor method intercept.

@Override
public void intercept(InterceptorStack stack, ControllerMethod method, Object obj) throws InterceptionException {
    ClassController<KarmaCalculator> mirrorOnKarma = new Mirror().on(KarmaCalculator.class);
    List<Field> karmaCalculatorFields = mirrorOnKarma.reflectAll().fields();
    for (Field field : karmaCalculatorFields) {
        result.include(field.getName(), mirrorOnKarma.get().field(field));
    }
    PermissionRules[] rules = PermissionRules.values();
    for (PermissionRules rule : rules) {
        long karma = environmentKarma.get(rule);
        result.include(rule.name(), karma);
    }
    stack.next(method, obj);
}
Also used : Field(java.lang.reflect.Field) KarmaCalculator(org.mamute.reputation.rules.KarmaCalculator) Mirror(net.vidageek.mirror.dsl.Mirror) PermissionRules(org.mamute.auth.rules.PermissionRules)

Example 2 with KarmaCalculator

use of org.mamute.reputation.rules.KarmaCalculator in project mamute by caelum.

the class VoteDAOTest method beforeTest.

@Before
public void beforeTest() {
    votes = new VoteDAO(session);
    currentUser = user("Current User", "currentUser@email.com");
    otherUser = user("Other User", "otherUser@email.com");
    session.save(otherUser);
    session.save(currentUser);
    tags.add(tag("bla"));
    for (Tag tag : tags) {
        session.save(tag);
    }
    InvisibleForUsersRule invisibleRule = new InvisibleForUsersRule(new LoggedUser(currentUser, null));
    votingMachine = new VotingMachine(votes, new KarmaCalculator(), new ReputationEventDAO(session, invisibleRule), new MassiveVote(), new RetrieveKarmaDownvote());
}
Also used : VotingMachine(org.mamute.model.vote.VotingMachine) RetrieveKarmaDownvote(org.mamute.controllers.RetrieveKarmaDownvote) ReputationEventDAO(org.mamute.dao.ReputationEventDAO) KarmaCalculator(org.mamute.reputation.rules.KarmaCalculator) LoggedUser(org.mamute.model.LoggedUser) MassiveVote(org.mamute.model.vote.MassiveVote) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote) VoteDAO(org.mamute.dao.VoteDAO) Tag(org.mamute.model.Tag) InvisibleForUsersRule(org.mamute.dao.InvisibleForUsersRule) Before(org.junit.Before)

Example 3 with KarmaCalculator

use of org.mamute.reputation.rules.KarmaCalculator in project mamute by caelum.

the class VotingMachineTest method setUp.

@Before
public void setUp() {
    votes = mock(VoteDAO.class);
    ReputationEventDAO reputationEvents = mock(ReputationEventDAO.class);
    votingMachine = new VotingMachine(votes, new KarmaCalculator(), reputationEvents, new MassiveVote(), new RetrieveKarmaDownvote());
    voter = user("chico", "chico@brutal.com", 1l);
    author = user("author", "author@brutal.com", 2l);
    votable = question.withTitle("title").withDescription("description").withAuthor(author).build();
}
Also used : VotingMachine(org.mamute.model.vote.VotingMachine) RetrieveKarmaDownvote(org.mamute.controllers.RetrieveKarmaDownvote) ReputationEventDAO(org.mamute.dao.ReputationEventDAO) KarmaCalculator(org.mamute.reputation.rules.KarmaCalculator) MassiveVote(org.mamute.model.vote.MassiveVote) VoteDAO(org.mamute.dao.VoteDAO) Before(org.junit.Before)

Aggregations

KarmaCalculator (org.mamute.reputation.rules.KarmaCalculator)3 Before (org.junit.Before)2 RetrieveKarmaDownvote (org.mamute.controllers.RetrieveKarmaDownvote)2 ReputationEventDAO (org.mamute.dao.ReputationEventDAO)2 VoteDAO (org.mamute.dao.VoteDAO)2 MassiveVote (org.mamute.model.vote.MassiveVote)2 VotingMachine (org.mamute.model.vote.VotingMachine)2 Field (java.lang.reflect.Field)1 Mirror (net.vidageek.mirror.dsl.Mirror)1 PermissionRules (org.mamute.auth.rules.PermissionRules)1 InvisibleForUsersRule (org.mamute.dao.InvisibleForUsersRule)1 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)1 LoggedUser (org.mamute.model.LoggedUser)1 Tag (org.mamute.model.Tag)1