Search in sources :

Example 1 with ModeratableAndPendingHistory

use of org.mamute.model.ModeratableAndPendingHistory in project mamute by caelum.

the class HistoryController method history.

@SimpleBrutauthRules({ EnvironmentKarmaRule.class })
@EnvironmentAccessLevel(PermissionRules.MODERATE_EDITS)
@Get
public void history() {
    ModeratableAndPendingHistory pendingQuestions = informations.pendingByUpdatables(Question.class);
    result.include("questions", pendingQuestions);
    ModeratableAndPendingHistory pendingAnswers = informations.pendingByUpdatables(Answer.class);
    result.include("answers", pendingAnswers);
}
Also used : ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) Get(br.com.caelum.vraptor.Get) SimpleBrutauthRules(br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)

Example 2 with ModeratableAndPendingHistory

use of org.mamute.model.ModeratableAndPendingHistory in project mamute by caelum.

the class UpdatablesAndPendingHistoryTest method should_build_group_informations_by_updatable.

@Test
public void should_build_group_informations_by_updatable() {
    List<Object[]> updatableAndInformations = new ArrayList<>();
    User author = user("name", "emaiil");
    QuestionInformationBuilder builder = new QuestionInformationBuilder().with(author);
    QuestionInformation info1 = builder.withTitle("title1").build();
    QuestionInformation info2 = builder.withTitle("title2").build();
    Question question1 = new Question(info1, author);
    question1.setId(1l);
    QuestionInformation info3 = builder.withTitle("title3").build();
    QuestionInformation info4 = builder.withTitle("title4").build();
    Question question2 = new Question(info3, author);
    question2.setId(2l);
    updatableAndInformations.add(new Object[] { question1, info1 });
    updatableAndInformations.add(new Object[] { question1, info2 });
    updatableAndInformations.add(new Object[] { question2, info3 });
    updatableAndInformations.add(new Object[] { question2, info4 });
    ModeratableAndPendingHistory updatablesAndPendingHistory = new ModeratableAndPendingHistory(updatableAndInformations);
    List<Information> pendingInfoForQ1 = updatablesAndPendingHistory.pendingInfoFor(question1);
    List<Information> pendingInfoForQ2 = updatablesAndPendingHistory.pendingInfoFor(question2);
    assertEquals(2, pendingInfoForQ1.size());
    assertEquals("title1", ((QuestionInformation) pendingInfoForQ1.get(0)).getTitle());
    assertEquals("title2", ((QuestionInformation) pendingInfoForQ1.get(1)).getTitle());
    assertEquals(2, pendingInfoForQ2.size());
    assertEquals("title3", ((QuestionInformation) pendingInfoForQ2.get(0)).getTitle());
    assertEquals("title4", ((QuestionInformation) pendingInfoForQ2.get(1)).getTitle());
}
Also used : User(org.mamute.model.User) ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) QuestionInformationBuilder(org.mamute.model.QuestionInformationBuilder) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) Information(org.mamute.model.Information) QuestionInformation(org.mamute.model.QuestionInformation) QuestionInformation(org.mamute.model.QuestionInformation) Test(org.junit.Test)

Example 3 with ModeratableAndPendingHistory

use of org.mamute.model.ModeratableAndPendingHistory in project mamute by caelum.

the class InformationDAOTest method should_get_pending_history.

@Test
public void should_get_pending_history() {
    newQuestion(author);
    Question question2 = newQuestion(author);
    newChangesWithStatus(question2, 2, PENDING);
    Question question3 = newQuestion(author);
    newChangesWithStatus(question3, 3, PENDING);
    ModeratableAndPendingHistory pending = informations.pendingByUpdatables(Question.class);
    List<Moderatable> questions = pending.moderatables();
    assertEquals(2, questions.size());
    assertEquals(question2.getId(), questions.get(0).getId());
    List<Information> pendingQuestion2 = pending.pendingInfoFor(questions.get(0));
    assertEquals(2, pendingQuestion2.size());
    List<Information> pendingQuestion3 = pending.pendingInfoFor(questions.get(1));
    assertEquals(3, pendingQuestion3.size());
}
Also used : ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) Question(org.mamute.model.Question) Moderatable(org.mamute.model.interfaces.Moderatable) QuestionInformation(org.mamute.model.QuestionInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Test(org.junit.Test)

Example 4 with ModeratableAndPendingHistory

use of org.mamute.model.ModeratableAndPendingHistory in project mamute by caelum.

the class InformationDAO method pendingByUpdatables.

@SuppressWarnings("unchecked")
public ModeratableAndPendingHistory pendingByUpdatables(Class<?> clazz) {
    String hql = "select updatable, info from " + clazz.getSimpleName() + " updatable " + "join updatable.history info " + "where info.status = :pending order by info.createdAt asc";
    Query query = session.createQuery(hql);
    query.setParameter("pending", UpdateStatus.PENDING);
    List<Object[]> results = query.list();
    ModeratableAndPendingHistory pending = new ModeratableAndPendingHistory(results);
    return pending;
}
Also used : Query(org.hibernate.Query) ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory)

Example 5 with ModeratableAndPendingHistory

use of org.mamute.model.ModeratableAndPendingHistory in project mamute by caelum.

the class InformationDAOTest method should_find_pending_answers_edits.

@Test
public void should_find_pending_answers_edits() {
    Answer answer = answer("info1 info1 info1 info1 info1 info1 info1 ", question, author);
    session.save(answer);
    newPendingChangesAnswer(answer, 2);
    ModeratableAndPendingHistory pendingByUpdatables = informations.pendingByUpdatables(Answer.class);
    List<Information> pendingInfoForAnswer = pendingByUpdatables.pendingInfoFor(answer);
    assertEquals(2, pendingInfoForAnswer.size());
}
Also used : Answer(org.mamute.model.Answer) ModeratableAndPendingHistory(org.mamute.model.ModeratableAndPendingHistory) QuestionInformation(org.mamute.model.QuestionInformation) Information(org.mamute.model.Information) AnswerInformation(org.mamute.model.AnswerInformation) Test(org.junit.Test)

Aggregations

ModeratableAndPendingHistory (org.mamute.model.ModeratableAndPendingHistory)5 Test (org.junit.Test)3 Information (org.mamute.model.Information)3 QuestionInformation (org.mamute.model.QuestionInformation)3 AnswerInformation (org.mamute.model.AnswerInformation)2 Question (org.mamute.model.Question)2 SimpleBrutauthRules (br.com.caelum.brutauth.auth.annotations.SimpleBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 ArrayList (java.util.ArrayList)1 Query (org.hibernate.Query)1 Answer (org.mamute.model.Answer)1 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)1 User (org.mamute.model.User)1 Moderatable (org.mamute.model.interfaces.Moderatable)1