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