Search in sources :

Example 1 with Post

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();
    }
}
Also used : Post(models.Post) Date(java.util.Date)

Example 2 with Post

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);
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) UnexpectedException(play.exceptions.UnexpectedException) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Post(models.Post) ArrayList(java.util.ArrayList) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) UnexpectedException(play.exceptions.UnexpectedException)

Aggregations

Post (models.Post)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)1 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 UnexpectedException (play.exceptions.UnexpectedException)1