rewrite using lambdas

This commit is contained in:
Athou
2014-12-12 10:06:23 +01:00
parent 2e475c35cc
commit 504e4eab3e
15 changed files with 44 additions and 150 deletions

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.dao;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -12,7 +13,6 @@ import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.QFeedCategory; import com.commafeed.backend.model.QFeedCategory;
import com.commafeed.backend.model.QUser; import com.commafeed.backend.model.QUser;
import com.commafeed.backend.model.User; import com.commafeed.backend.model.User;
import com.google.common.collect.Lists;
import com.mysema.query.types.Predicate; import com.mysema.query.types.Predicate;
@Singleton @Singleton
@@ -54,14 +54,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
} }
public List<FeedCategory> findAllChildrenCategories(User user, FeedCategory parent) { public List<FeedCategory> findAllChildrenCategories(User user, FeedCategory parent) {
List<FeedCategory> list = Lists.newArrayList(); return findAll(user).stream().filter(c -> isChild(c, parent)).collect(Collectors.toList());
List<FeedCategory> all = findAll(user);
for (FeedCategory cat : all) {
if (isChild(cat, parent)) {
list.add(cat);
}
}
return list;
} }
private boolean isChild(FeedCategory child, FeedCategory parent) { private boolean isChild(FeedCategory child, FeedCategory parent) {

View File

@@ -1,6 +1,7 @@
package com.commafeed.backend.dao; package com.commafeed.backend.dao;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -15,7 +16,6 @@ import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedEntry; import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.QFeedEntry; import com.commafeed.backend.model.QFeedEntry;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.mysema.query.Tuple; import com.mysema.query.Tuple;
import com.mysema.query.types.expr.NumberExpression; import com.mysema.query.types.expr.NumberExpression;
@@ -36,13 +36,9 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
} }
public List<FeedCapacity> findFeedsExceedingCapacity(long maxCapacity, long max) { public List<FeedCapacity> findFeedsExceedingCapacity(long maxCapacity, long max) {
List<FeedCapacity> list = Lists.newArrayList();
NumberExpression<Long> count = entry.id.countDistinct(); NumberExpression<Long> count = entry.id.countDistinct();
List<Tuple> tuples = newQuery().from(entry).groupBy(entry.feed).having(count.gt(maxCapacity)).limit(max).list(entry.feed.id, count); List<Tuple> tuples = newQuery().from(entry).groupBy(entry.feed).having(count.gt(maxCapacity)).limit(max).list(entry.feed.id, count);
for (Tuple tuple : tuples) { return tuples.stream().map(t -> new FeedCapacity(t.get(entry.feed.id), t.get(count))).collect(Collectors.toList());
list.add(new FeedCapacity(tuple.get(entry.feed.id), tuple.get(count)));
}
return list;
} }
public int deleteOldEntries(Long feedId, long max) { public int deleteOldEntries(Long feedId, long max) {

View File

@@ -1,6 +1,8 @@
package com.commafeed.backend.dao; package com.commafeed.backend.dao;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -13,9 +15,7 @@ import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.Models; import com.commafeed.backend.model.Models;
import com.commafeed.backend.model.QFeedSubscription; import com.commafeed.backend.model.QFeedSubscription;
import com.commafeed.backend.model.User; import com.commafeed.backend.model.User;
import com.google.common.base.Function;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.mysema.query.jpa.hibernate.HibernateQuery; import com.mysema.query.jpa.hibernate.HibernateQuery;
@Singleton @Singleton
@@ -60,26 +60,13 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
} }
public List<FeedSubscription> findByCategories(User user, List<FeedCategory> categories) { public List<FeedSubscription> findByCategories(User user, List<FeedCategory> categories) {
List<Long> categoryIds = Lists.transform(categories, new Function<FeedCategory, Long>() { Set<Long> categoryIds = categories.stream().map(c -> c.getId()).collect(Collectors.toSet());
@Override return findAll(user).stream().filter(s -> s.getCategory() != null && categoryIds.contains(s.getCategory().getId()))
public Long apply(FeedCategory input) { .collect(Collectors.toList());
return input.getId();
}
});
List<FeedSubscription> subscriptions = Lists.newArrayList();
for (FeedSubscription sub : findAll(user)) {
if (sub.getCategory() != null && categoryIds.contains(sub.getCategory().getId())) {
subscriptions.add(sub);
}
}
return subscriptions;
} }
private List<FeedSubscription> initRelations(List<FeedSubscription> list) { private List<FeedSubscription> initRelations(List<FeedSubscription> list) {
for (FeedSubscription sub : list) { list.forEach(s -> initRelations(s));
initRelations(sub);
}
return list; return list;
} }

View File

@@ -24,9 +24,7 @@ public abstract class GenericDAO<T extends AbstractModel> extends AbstractDAO<T>
} }
public void saveOrUpdate(Collection<T> models) { public void saveOrUpdate(Collection<T> models) {
for (T model : models) { models.forEach(m -> persist(m));
persist(model);
}
} }
public void merge(T model) { public void merge(T model) {
@@ -34,9 +32,7 @@ public abstract class GenericDAO<T extends AbstractModel> extends AbstractDAO<T>
} }
public void merge(Collection<T> models) { public void merge(Collection<T> models) {
for (T model : models) { models.forEach(m -> merge(m));
merge(model);
}
} }
public T findById(Long id) { public T findById(Long id) {
@@ -50,9 +46,7 @@ public abstract class GenericDAO<T extends AbstractModel> extends AbstractDAO<T>
} }
public int delete(Collection<T> objects) { public int delete(Collection<T> objects) {
for (T object : objects) { objects.forEach(o -> delete(o));
delete(object);
}
return objects.size(); return objects.size();
} }

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.dao;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -12,7 +13,6 @@ import com.commafeed.backend.model.QUserRole;
import com.commafeed.backend.model.User; import com.commafeed.backend.model.User;
import com.commafeed.backend.model.UserRole; import com.commafeed.backend.model.UserRole;
import com.commafeed.backend.model.UserRole.Role; import com.commafeed.backend.model.UserRole.Role;
import com.google.common.collect.Sets;
@Singleton @Singleton
public class UserRoleDAO extends GenericDAO<UserRole> { public class UserRoleDAO extends GenericDAO<UserRole> {
@@ -33,10 +33,6 @@ public class UserRoleDAO extends GenericDAO<UserRole> {
} }
public Set<Role> findRoles(User user) { public Set<Role> findRoles(User user) {
Set<Role> list = Sets.newHashSet(); return findAll(user).stream().map(r -> r.getRole()).collect(Collectors.toSet());
for (UserRole role : findAll(user)) {
list.add(role.getRole());
}
return list;
} }
} }

View File

@@ -4,6 +4,7 @@ import java.io.StringReader;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -19,10 +20,7 @@ import org.xml.sax.InputSource;
import com.commafeed.backend.model.Feed; import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedEntry; import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryContent; import com.commafeed.backend.model.FeedEntryContent;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndEnclosure; import com.rometools.rome.feed.synd.SyndEnclosure;
import com.rometools.rome.feed.synd.SyndEntry; import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.feed.synd.SyndFeed;
@@ -42,13 +40,6 @@ public class FeedParser {
private static final Date START = new Date(86400000); private static final Date START = new Date(86400000);
private static final Date END = new Date(1000l * Integer.MAX_VALUE - 86400000); private static final Date END = new Date(1000l * Integer.MAX_VALUE - 86400000);
private static final Function<SyndContent, String> CONTENT_TO_STRING = new Function<SyndContent, String>() {
@Override
public String apply(SyndContent content) {
return content.getValue();
}
};
public FetchedFeed parse(String feedUrl, byte[] xml) throws FeedException { public FetchedFeed parse(String feedUrl, byte[] xml) throws FeedException {
FetchedFeed fetchedFeed = new FetchedFeed(); FetchedFeed fetchedFeed = new FetchedFeed();
Feed feed = fetchedFeed.getFeed(); Feed feed = fetchedFeed.getFeed();
@@ -172,7 +163,7 @@ public class FeedParser {
if (item.getContents().isEmpty()) { if (item.getContents().isEmpty()) {
content = item.getDescription() == null ? null : item.getDescription().getValue(); content = item.getDescription() == null ? null : item.getDescription().getValue();
} else { } else {
content = StringUtils.join(Collections2.transform(item.getContents(), CONTENT_TO_STRING), System.lineSeparator()); content = item.getContents().stream().map(c -> c.getValue()).collect(Collectors.joining(System.lineSeparator()));
} }
return StringUtils.trimToNull(content); return StringUtils.trimToNull(content);
} }

View File

@@ -8,6 +8,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -138,10 +139,7 @@ public class FeedRefreshUpdater implements Managed {
} }
if (CollectionUtils.isNotEmpty(subscriptions)) { if (CollectionUtils.isNotEmpty(subscriptions)) {
List<User> users = Lists.newArrayList(); List<User> users = subscriptions.stream().map(s -> s.getUser()).collect(Collectors.toList());
for (FeedSubscription sub : subscriptions) {
users.add(sub.getUser());
}
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0])); cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
cache.invalidateUserRootCategory(users.toArray(new User[0])); cache.invalidateUserRootCategory(users.toArray(new User[0]));
} }

View File

@@ -9,6 +9,7 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -388,13 +389,7 @@ public class FeedUtils {
} }
public static List<Long> getSortedTimestamps(List<FeedEntry> entries) { public static List<Long> getSortedTimestamps(List<FeedEntry> entries) {
List<Long> timestamps = Lists.newArrayList(); return entries.stream().map(t -> t.getUpdated().getTime()).sorted(Collections.reverseOrder()).collect(Collectors.toList());
for (FeedEntry entry : entries) {
timestamps.add(entry.getUpdated().getTime());
}
Collections.sort(timestamps);
Collections.reverse(timestamps);
return timestamps;
} }
public static String removeTrailingSlash(String url) { public static String removeTrailingSlash(String url) {

View File

@@ -71,12 +71,7 @@ public class User extends AbstractModel {
private Date lastFullRefresh; private Date lastFullRefresh;
public boolean hasRole(Role role) { public boolean hasRole(Role role) {
for (UserRole userRole : getRoles()) { return getRoles().stream().anyMatch(r -> r.getRole() == role);
if (userRole.getRole() == role) {
return true;
}
}
return false;
} }
public boolean shouldRefreshFeedsAt(Date when) { public boolean shouldRefreshFeedsAt(Date when) {

View File

@@ -13,7 +13,6 @@ import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.model.FeedCategory; import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedSubscription; import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.User; import com.commafeed.backend.model.User;
import com.google.common.base.Function;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import com.rometools.opml.feed.opml.Attribute; import com.rometools.opml.feed.opml.Attribute;
@@ -24,13 +23,7 @@ import com.rometools.opml.feed.opml.Outline;
@Singleton @Singleton
public class OPMLExporter { public class OPMLExporter {
private static Long ROOT_CATEGORY_ID = new Long(-1); private static Long ROOT_CATEGORY_ID = Long.valueOf(Long.MIN_VALUE);
private static final Function<FeedSubscription, Long> SUBSCRIPTION_TO_CATEGORYID = new Function<FeedSubscription, Long>() {
@Override
public Long apply(FeedSubscription sub) {
return sub.getCategory() == null ? ROOT_CATEGORY_ID : sub.getCategory().getId();
}
};
private final FeedCategoryDAO feedCategoryDAO; private final FeedCategoryDAO feedCategoryDAO;
private final FeedSubscriptionDAO feedSubscriptionDAO; private final FeedSubscriptionDAO feedSubscriptionDAO;
@@ -42,7 +35,8 @@ public class OPMLExporter {
opml.setCreated(new Date()); opml.setCreated(new Date());
List<FeedCategory> categories = feedCategoryDAO.findAll(user); List<FeedCategory> categories = feedCategoryDAO.findAll(user);
Multimap<Long, FeedSubscription> subscriptions = Multimaps.index(feedSubscriptionDAO.findAll(user), SUBSCRIPTION_TO_CATEGORYID); Multimap<Long, FeedSubscription> subscriptions = Multimaps.index(feedSubscriptionDAO.findAll(user),
sub -> sub.getCategory() == null ? ROOT_CATEGORY_ID : sub.getCategory().getId());
// export root categories // export root categories
for (FeedCategory cat : categories) { for (FeedCategory cat : categories) {

View File

@@ -1,7 +1,8 @@
package com.commafeed.backend.service; package com.commafeed.backend.service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -13,9 +14,6 @@ import com.commafeed.backend.dao.FeedEntryTagDAO;
import com.commafeed.backend.model.FeedEntry; import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryTag; import com.commafeed.backend.model.FeedEntryTag;
import com.commafeed.backend.model.User; import com.commafeed.backend.model.User;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@RequiredArgsConstructor(onConstructor = @__({ @Inject })) @RequiredArgsConstructor(onConstructor = @__({ @Inject }))
@Singleton @Singleton
@@ -30,29 +28,12 @@ public class FeedEntryTagService {
return; return;
} }
List<FeedEntryTag> tags = feedEntryTagDAO.findByEntry(user, entry); List<FeedEntryTag> existingTags = feedEntryTagDAO.findByEntry(user, entry);
Map<String, FeedEntryTag> tagMap = Maps.uniqueIndex(tags, new Function<FeedEntryTag, String>() { Set<String> existingTagNames = existingTags.stream().map(t -> t.getName()).collect(Collectors.toSet());
@Override
public String apply(FeedEntryTag input) {
return input.getName();
}
});
List<FeedEntryTag> addList = Lists.newArrayList(); List<FeedEntryTag> addList = tagNames.stream().filter(name -> !existingTagNames.contains(name))
List<FeedEntryTag> removeList = Lists.newArrayList(); .map(name -> new FeedEntryTag(user, entry, name)).collect(Collectors.toList());
List<FeedEntryTag> removeList = existingTags.stream().filter(tag -> !tagNames.contains(tag.getName())).collect(Collectors.toList());
for (String tagName : tagNames) {
FeedEntryTag tag = tagMap.get(tagName);
if (tag == null) {
addList.add(new FeedEntryTag(user, entry, tagName));
}
}
for (FeedEntryTag tag : tags) {
if (!tagNames.contains(tag.getName())) {
removeList.add(tag);
}
}
feedEntryTagDAO.saveOrUpdate(addList); feedEntryTagDAO.saveOrUpdate(addList);
feedEntryTagDAO.delete(removeList); feedEntryTagDAO.delete(removeList);

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -23,7 +24,6 @@ import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.Models; import com.commafeed.backend.model.Models;
import com.commafeed.backend.model.User; import com.commafeed.backend.model.User;
import com.commafeed.frontend.model.UnreadCount; import com.commafeed.frontend.model.UnreadCount;
import com.google.common.collect.Maps;
@Slf4j @Slf4j
@RequiredArgsConstructor(onConstructor = @__({ @Inject })) @RequiredArgsConstructor(onConstructor = @__({ @Inject }))
@@ -92,12 +92,7 @@ public class FeedSubscriptionService {
} }
public Map<Long, UnreadCount> getUnreadCount(User user) { public Map<Long, UnreadCount> getUnreadCount(User user) {
Map<Long, UnreadCount> map = Maps.newHashMap(); return feedSubscriptionDAO.findAll(user).stream().collect(Collectors.toMap(s -> s.getId(), s -> getUnreadCount(user, s)));
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
for (FeedSubscription sub : subs) {
map.put(sub.getId(), getUnreadCount(user, sub));
}
return map;
} }
private UnreadCount getUnreadCount(User user, FeedSubscription sub) { private UnreadCount getUnreadCount(User user, FeedSubscription sub) {

View File

@@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import lombok.Data; import lombok.Data;
@@ -11,9 +12,7 @@ import com.commafeed.backend.feed.FeedUtils;
import com.commafeed.backend.model.FeedEntry; import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryContent; import com.commafeed.backend.model.FeedEntryContent;
import com.commafeed.backend.model.FeedEntryStatus; import com.commafeed.backend.model.FeedEntryStatus;
import com.commafeed.backend.model.FeedEntryTag;
import com.commafeed.backend.model.FeedSubscription; import com.commafeed.backend.model.FeedSubscription;
import com.google.common.collect.Lists;
import com.rometools.rome.feed.synd.SyndContent; import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl; import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEnclosure; import com.rometools.rome.feed.synd.SyndEnclosure;
@@ -48,12 +47,7 @@ public class Entry implements Serializable {
entry.setFeedUrl(sub.getFeed().getUrl()); entry.setFeedUrl(sub.getFeed().getUrl());
entry.setFeedLink(sub.getFeed().getLink()); entry.setFeedLink(sub.getFeed().getLink());
entry.setIconUrl(FeedUtils.getFaviconUrl(sub, publicUrl)); entry.setIconUrl(FeedUtils.getFaviconUrl(sub, publicUrl));
entry.setTags(status.getTags().stream().map(t -> t.getName()).collect(Collectors.toList()));
List<String> tags = Lists.newArrayList();
for (FeedEntryTag tag : status.getTags()) {
tags.add(tag.getName());
}
entry.setTags(tags);
if (content != null) { if (content != null) {
entry.setRtl(FeedUtils.isRTL(feedEntry)); entry.setRtl(FeedUtils.isRTL(feedEntry));

View File

@@ -3,6 +3,7 @@ package com.commafeed.frontend.resource;
import io.dropwizard.hibernate.UnitOfWork; import io.dropwizard.hibernate.UnitOfWork;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
@@ -10,6 +11,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -60,7 +62,6 @@ import com.commafeed.frontend.model.request.MarkRequest;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl; import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.io.SyndFeedOutput; import com.rometools.rome.io.SyndFeedOutput;
@@ -127,10 +128,7 @@ public class CategoryREST {
List<Long> excludedIds = null; List<Long> excludedIds = null;
if (StringUtils.isNotEmpty(excludedSubscriptionIds)) { if (StringUtils.isNotEmpty(excludedSubscriptionIds)) {
excludedIds = Lists.newArrayList(); excludedIds = Arrays.stream(excludedSubscriptionIds.split(",")).map(Long::valueOf).collect(Collectors.toList());
for (String excludedId : excludedSubscriptionIds.split(",")) {
excludedIds.add(Long.valueOf(excludedId));
}
} }
if (ALL.equals(id)) { if (ALL.equals(id)) {
@@ -216,14 +214,8 @@ public class CategoryREST {
feed.setFeedType("rss_2.0"); feed.setFeedType("rss_2.0");
feed.setTitle("CommaFeed - " + entries.getName()); feed.setTitle("CommaFeed - " + entries.getName());
feed.setDescription("CommaFeed - " + entries.getName()); feed.setDescription("CommaFeed - " + entries.getName());
String publicUrl = config.getApplicationSettings().getPublicUrl(); feed.setLink(config.getApplicationSettings().getPublicUrl());
feed.setLink(publicUrl); feed.setEntries(entries.getEntries().stream().map(e -> e.asRss()).collect(Collectors.toList()));
List<SyndEntry> children = Lists.newArrayList();
for (Entry entry : entries.getEntries()) {
children.add(entry.asRss());
}
feed.setEntries(children);
SyndFeedOutput output = new SyndFeedOutput(); SyndFeedOutput output = new SyndFeedOutput();
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();

View File

@@ -12,6 +12,7 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -78,9 +79,7 @@ import com.commafeed.frontend.model.request.MarkRequest;
import com.commafeed.frontend.model.request.SubscribeRequest; import com.commafeed.frontend.model.request.SubscribeRequest;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.rometools.opml.feed.opml.Opml; import com.rometools.opml.feed.opml.Opml;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl; import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.io.SyndFeedOutput; import com.rometools.rome.io.SyndFeedOutput;
@@ -218,14 +217,8 @@ public class FeedREST {
feed.setFeedType("rss_2.0"); feed.setFeedType("rss_2.0");
feed.setTitle("CommaFeed - " + entries.getName()); feed.setTitle("CommaFeed - " + entries.getName());
feed.setDescription("CommaFeed - " + entries.getName()); feed.setDescription("CommaFeed - " + entries.getName());
String publicUrl = config.getApplicationSettings().getPublicUrl(); feed.setLink(config.getApplicationSettings().getPublicUrl());
feed.setLink(publicUrl); feed.setEntries(entries.getEntries().stream().map(e -> e.asRss()).collect(Collectors.toList()));
List<SyndEntry> children = Lists.newArrayList();
for (Entry entry : entries.getEntries()) {
children.add(entry.asRss());
}
feed.setEntries(children);
SyndFeedOutput output = new SyndFeedOutput(); SyndFeedOutput output = new SyndFeedOutput();
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();