Search in sources :

Example 11 with Item

use of com.rometools.rome.feed.rss.Item in project books by aidanwhiteley.

the class SiteRssFeed method createSiteRssFeed.

public Channel createSiteRssFeed() {
    PageRequest pageObj = PageRequest.of(0, booksFeedsMaxEntries);
    Page<Book> recentBooks = bookRepository.findAllByOrderByCreatedDateTimeDesc(pageObj);
    Channel channel = new Channel(FEED_TYPE_RSS_2_0);
    channel.setTitle(booksFeedsTitles);
    channel.setLink(booksFeedsDomain);
    channel.setDescription(booksFeedsDescription);
    channel.setPubDate(new Date());
    channel.setItems(recentBooks.stream().map(b -> {
        Item item = new Item();
        item.setTitle(b.getTitle() + " by " + b.getAuthor());
        item.setLink(booksFeedsDomain + "#/book/" + b.getId());
        Guid guid = new Guid();
        guid.setPermaLink(true);
        guid.setValue(booksFeedsDomain + "#/book/" + b.getId());
        item.setGuid(guid);
        ZonedDateTime zdt = b.getCreatedDateTime().atZone(ZoneId.systemDefault());
        item.setPubDate(Date.from(zdt.toInstant()));
        Content content = new Content();
        content.setType("text/html");
        content.setValue(b.getSummary() + "\r\n \r\nRating: " + b.getRating());
        item.setContent(content);
        return item;
    }).collect(Collectors.toList()));
    return channel;
}
Also used : Item(com.rometools.rome.feed.rss.Item) PageRequest(org.springframework.data.domain.PageRequest) ZonedDateTime(java.time.ZonedDateTime) Book(com.aidanwhiteley.books.domain.Book) Content(com.rometools.rome.feed.rss.Content) Channel(com.rometools.rome.feed.rss.Channel) Guid(com.rometools.rome.feed.rss.Guid) Date(java.util.Date)

Aggregations

Item (com.rometools.rome.feed.rss.Item)11 Channel (com.rometools.rome.feed.rss.Channel)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Test (org.junit.jupiter.api.Test)4 Description (com.rometools.rome.feed.rss.Description)3 Guid (com.rometools.rome.feed.rss.Guid)3 List (java.util.List)3 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)2 Book (com.aidanwhiteley.books.domain.Book)1 ImmutableList (com.google.common.collect.ImmutableList)1 Content (com.rometools.rome.feed.rss.Content)1 InputStream (java.io.InputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 PageRequest (org.springframework.data.domain.PageRequest)1 MediaType (org.springframework.http.MediaType)1 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)1