use of org.mamute.model.Question in project mamute by caelum.
the class SolrQuestionIndex method indexQuestionBatch.
@Override
public void indexQuestionBatch(Collection<Question> questions) {
try {
List<SolrInputDocument> docs = new ArrayList<>();
for (Question question : questions) {
docs.add(toDoc(question));
LOGGER.info("Question synced or updated(trying to): " + question);
}
server.add(docs);
server.commit();
LOGGER.info("Questions synced or updated with success");
} catch (IOException | SolrServerException e) {
List<Long> ids = Lists.transform(new ArrayList<Question>(questions), new Function<Question, Long>() {
public Long apply(Question input) {
return input.getId();
}
});
throw new IndexException("Could not index a Question in the following list: " + ids, e);
}
}
use of org.mamute.model.Question in project mamute by caelum.
the class SubscribeUsersToNewQuestion method subscribeUsers.
public void subscribeUsers(@Observes QuestionCreated questionCreated) {
Question question = questionCreated.getQuestion();
List<User> subscribed = users.findUsersSubscribedToAllQuestions();
for (User user : subscribed) {
watchers.add(question, new Watcher(user));
}
newQuestionMailer.send(subscribed, question);
}
use of org.mamute.model.Question in project mamute by caelum.
the class NewsletterMailer method sendTo.
public void sendTo(ScrollableResults results, boolean isTestNewsletter) {
DateTime pastWeek = new DateTime().minusWeeks(1);
DateTime twelveHoursAgo = new DateTime().minusHours(12);
List<News> hotNews = news.hotNews();
List<Question> hotQuestions = questions.hot(pastWeek, 8);
List<Question> unanswered = questions.randomUnanswered(pastWeek, twelveHoursAgo, 8);
LinkToHelper linkToHelper = new NotificationMailer.LinkToHelper(router, brutalEnv);
String siteName = bundle.getMessage("site.name");
String date = brutalDateFormat.getInstance("date.joda.newsletter.pattern").print(new DateTime());
String teste = isTestNewsletter ? bundle.getMessage("newsletter_mail_test") : "";
while (results.next()) {
User user = (User) results.get()[0];
try {
Email email = templates.template("newsletter_mail", date, siteName, teste).with("hotNews", hotNews).with("hotQuestions", hotQuestions).with("unansweredQuestions", unanswered).with("unsubscribeLink", linkToHelper.unsubscribeLink(user)).with("linkToHelper", linkToHelper).with("l10n", bundle).with("sanitizer", POLICY).with("siteName", siteName).with("date", date).with("logoUrl", env.get("mail_logo_url")).to(user.getName(), user.getEmail());
email.setCharset("utf-8");
mailer.send(email);
} catch (Exception e) {
LOG.error("could not send email", e);
}
}
}
use of org.mamute.model.Question in project mamute by caelum.
the class VoteDAO method contextOf.
// TODO: refactor?
public ReputationEventContext contextOf(Votable votable) {
boolean isNews = News.class.isAssignableFrom(votable.getClass());
if (isNews) {
return (ReputationEventContext) votable;
}
boolean isQuestionOrAnswer = !Comment.class.isAssignableFrom(votable.getClass());
if (isQuestionOrAnswer) {
return votable.getQuestion();
}
Question question = (Question) session.createQuery("select q from Question q join q.comments.comments c where c=:comment").setParameter("comment", votable).uniqueResult();
if (question != null) {
return question;
}
question = (Question) session.createQuery("select a.question from Answer a join a.comments.comments c where c=:comment").setParameter("comment", votable).uniqueResult();
if (question != null) {
return question;
}
ReputationEventContext ctx = (ReputationEventContext) session.createQuery("select news from News news join news.comments.comments c where c=:comment").setParameter("comment", votable).uniqueResult();
return ctx;
}
use of org.mamute.model.Question in project mamute by caelum.
the class AnswerQuestionTest method should_not_display_answer_form_when_already_answered.
@Test
public void should_not_display_answer_form_when_already_answered() {
Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
User karmaNigga = karmaNigga();
answerQuestionWithDao(karmaNigga, question, "Resposta da questao do teste de edicao", false);
UserFlow navigation = login(navigate(), karmaNigga.getEmail());
navigation = goToQuestionPage(navigation, question);
VRaptorTestResult questionPage = navigation.followRedirect().execute();
questionPage.wasStatus(200).isValid();
Elements answerForm = getElementsByClass(questionPage.getResponseBody(), "answer-form");
assertTrue(answerForm.isEmpty());
}
Aggregations