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);
}
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());
}
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());
}
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;
}
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());
}
Aggregations