Search in sources :

Example 81 with Question

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);
    }
}
Also used : Function(com.google.common.base.Function) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 82 with Question

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);
}
Also used : User(org.mamute.model.User) Watcher(org.mamute.model.watch.Watcher) Question(org.mamute.model.Question)

Example 83 with 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);
        }
    }
}
Also used : User(org.mamute.model.User) Email(org.apache.commons.mail.Email) News(org.mamute.model.News) Question(org.mamute.model.Question) LinkToHelper(org.mamute.notification.NotificationMailer.LinkToHelper) DateTime(org.joda.time.DateTime)

Example 84 with Question

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;
}
Also used : Comment(org.mamute.model.Comment) ReputationEventContext(org.mamute.model.ReputationEventContext) Question(org.mamute.model.Question)

Example 85 with Question

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());
}
Also used : User(org.mamute.model.User) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) Question(org.mamute.model.Question) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

Question (org.mamute.model.Question)96 Test (org.junit.Test)74 User (org.mamute.model.User)28 Answer (org.mamute.model.Answer)24 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)15 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)15 Tag (org.mamute.model.Tag)9 ArrayList (java.util.ArrayList)8 QuestionBuilder (org.mamute.builder.QuestionBuilder)7 QuestionInformation (org.mamute.model.QuestionInformation)7 DateTime (org.joda.time.DateTime)6 LoggedUser (org.mamute.model.LoggedUser)5 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)5 Elements (org.jsoup.select.Elements)4 AnswerAndVotes (org.mamute.model.AnswerAndVotes)4 Comment (org.mamute.model.Comment)4 Get (br.com.caelum.vraptor.Get)3 Before (org.junit.Before)3 DaoManager (org.mamute.integration.util.DaoManager)3 AnswerInformation (org.mamute.model.AnswerInformation)3