use of org.haiku.haikudepotserver.feed.model.SyndEntrySupplier in project haikudepotserver by haiku.
the class FeedController method createFeed.
private SyndFeed createFeed(FeedSpecification key) {
Preconditions.checkNotNull(key);
Locale locale = Locale.ENGLISH;
if (!Strings.isNullOrEmpty(key.getNaturalLanguageCode())) {
locale = new Locale(key.getNaturalLanguageCode());
}
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(key.getFeedType().getFeedType());
feed.setTitle(FEED_TITLE);
feed.setDescription(messageSource.getMessage("feed.description", new Object[] {}, locale));
feed.setLink(baseUrl);
feed.setPublishedDate(new java.util.Date());
SyndImage image = new SyndImageImpl();
image.setUrl(baseUrl + "/__img/haikudepot32.png");
image.setTitle(FEED_ICON_TITLE);
feed.setImage(image);
List<SyndEntry> entries = new ArrayList<>();
for (SyndEntrySupplier supplier : syndEntrySuppliers) {
entries.addAll(supplier.generate(key));
}
// sort the entries and then take the first number of them up to the limit.
entries.sort((o1, o2) -> -1 * o1.getPublishedDate().compareTo(o2.getPublishedDate()));
if (entries.size() > key.getLimit()) {
entries = entries.subList(0, key.getLimit());
}
feed.setEntries(entries);
return feed;
}
Aggregations