Search in sources :

Example 6 with News

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

the class NewsBuilder method build.

public News build() {
    if (loggedUser == null) {
        loggedUser = new LoggedUser(author, null);
    }
    NewsInformation newsInformation = new NewsInformation(title, description, loggedUser, comment);
    News news = new News(newsInformation, author);
    setId(news, id);
    return news;
}
Also used : News(org.mamute.model.News) NewsInformation(org.mamute.model.NewsInformation) LoggedUser(org.mamute.model.LoggedUser)

Example 7 with News

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

the class NewsController method showNews.

@Get
public void showNews(@Load News news, String sluggedTitle) {
    User current = currentUser.getCurrent();
    news.checkVisibilityFor(currentUser);
    redirectToRightUrl(news, sluggedTitle);
    viewCounter.ping(news);
    boolean isWatching = watchers.ping(news, current);
    result.include("commentsWithVotes", votes.previousVotesForComments(news, current));
    result.include("currentVote", votes.previousVoteFor(news.getId(), current, News.class));
    result.include("news", news);
    result.include("isWatching", isWatching);
    result.include("userMediumPhoto", true);
    result.include("newsActive", true);
    result.include("noDefaultActive", true);
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) News(org.mamute.model.News) Get(br.com.caelum.vraptor.Get)

Example 8 with News

use of org.mamute.model.News 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 9 with News

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

the class NewsDAOTest method saveNews.

private News saveNews(User newsAuthor, boolean approved) {
    NewsInformation newsInformation = newsInformation(newsAuthor);
    News news = new News(newsInformation, newsAuthor);
    if (approved)
        news.approved();
    session.save(newsInformation);
    session.save(news);
    return news;
}
Also used : News(org.mamute.model.News) NewsInformation(org.mamute.model.NewsInformation)

Example 10 with News

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

the class NewsDAOTest method should_get_the_last_5_news_ordered_by_date.

@Test
public void should_get_the_last_5_news_ordered_by_date() {
    News thirdNews = saveApprovedNews(newsAuthor);
    News secondNews = createNewsAt(new DateTime().plusDays(1));
    News firstNews = createNewsAt(new DateTime().plusDays(2));
    List<News> newses = newsForModerator.hotNews();
    assertEquals(firstNews.getId(), newses.get(0).getId());
    assertEquals(secondNews.getId(), newses.get(1).getId());
    assertEquals(thirdNews.getId(), newses.get(2).getId());
}
Also used : News(org.mamute.model.News) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

News (org.mamute.model.News)12 Test (org.junit.Test)7 LoggedUser (org.mamute.model.LoggedUser)3 NewsInformation (org.mamute.model.NewsInformation)3 User (org.mamute.model.User)3 DateTime (org.joda.time.DateTime)2 NewsBuilder (org.mamute.builder.NewsBuilder)2 Question (org.mamute.model.Question)2 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 Post (br.com.caelum.vraptor.Post)1 Email (org.apache.commons.mail.Email)1 QuestionBuilder (org.mamute.builder.QuestionBuilder)1 ReputationEventContext (org.mamute.model.ReputationEventContext)1 LinkToHelper (org.mamute.notification.NotificationMailer.LinkToHelper)1