use of models.Post in project play-cookbook by spinscale.
the class LoadDataJob method doJob.
// Create random posts
public void doJob() {
for (int i = 0; i < 100; i++) {
Post post = new Post();
post.author = "Alexander Reelsen";
post.title = RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(50));
post.content = RandomStringUtils.randomAlphabetic(RandomUtils.nextInt(500));
post.createdAt = new Date(new Date().getTime() + RandomUtils.nextInt(Integer.MAX_VALUE));
post.save();
}
}
use of models.Post in project play-cookbook by spinscale.
the class FeedResult method apply.
public void apply(Request request, Response response) {
try {
SyndFeed feed = new SyndFeedImpl();
feed.setAuthor(Play.configuration.getProperty("rss.author"));
feed.setTitle(Play.configuration.getProperty("rss.title"));
feed.setDescription(Play.configuration.getProperty("rss.description"));
feed.setLink(getFeedLink());
List<SyndEntry> entries = new ArrayList<SyndEntry>();
for (Post post : posts) {
String url = createUrl("Application.showPost", "id", post.id.toString());
SyndEntry entry = createEntry(post.title, url, post.content, post.createdAt);
entries.add(entry);
}
feed.setEntries(entries);
feed.setFeedType(getFeedType());
setContentType(response);
SyndFeedOutput output = new SyndFeedOutput();
String rss = output.outputString(feed);
response.out.write(rss.getBytes("utf-8"));
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
Aggregations