forked from Archives/Athou_commafeed
Merge pull request #318 from Athou/perfs
statuses are not needed anymore for older entries
This commit is contained in:
@@ -7,16 +7,23 @@ import java.util.Map;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.Tuple;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.criteria.Selection;
|
||||
import javax.persistence.criteria.SetJoin;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryContent;
|
||||
@@ -26,14 +33,20 @@ import com.commafeed.backend.model.FeedEntryStatus_;
|
||||
import com.commafeed.backend.model.FeedEntry_;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.FeedSubscription_;
|
||||
import com.commafeed.backend.model.Feed_;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||
import com.google.api.client.util.Lists;
|
||||
import com.google.api.client.util.Maps;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@Stateless
|
||||
public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
|
||||
protected static Logger log = LoggerFactory
|
||||
.getLogger(FeedEntryStatusDAO.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public FeedEntryStatus findById(User user, Long id) {
|
||||
|
||||
@@ -57,6 +70,60 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return status;
|
||||
}
|
||||
|
||||
public FeedEntryStatus findByEntry(FeedEntry entry, FeedSubscription sub) {
|
||||
|
||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||
Root<FeedEntryStatus> root = query.from(getType());
|
||||
|
||||
Predicate p1 = builder.equal(root.get(FeedEntryStatus_.entry), entry);
|
||||
Predicate p2 = builder.equal(root.get(FeedEntryStatus_.subscription),
|
||||
sub);
|
||||
|
||||
query.where(p1, p2);
|
||||
|
||||
List<FeedEntryStatus> statuses = em.createQuery(query).getResultList();
|
||||
return Iterables.getFirst(statuses, null);
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findByEntries(List<FeedEntry> entries,
|
||||
FeedSubscription sub) {
|
||||
List<FeedEntryStatus> results = Lists.newArrayList();
|
||||
|
||||
if (CollectionUtils.isEmpty(entries)) {
|
||||
return results;
|
||||
}
|
||||
|
||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||
Root<FeedEntryStatus> root = query.from(getType());
|
||||
|
||||
Predicate p1 = root.get(FeedEntryStatus_.entry).in(entries);
|
||||
Predicate p2 = builder.equal(root.get(FeedEntryStatus_.subscription),
|
||||
sub);
|
||||
|
||||
query.where(p1, p2);
|
||||
|
||||
Map<Long, FeedEntryStatus> existing = Maps.uniqueIndex(
|
||||
em.createQuery(query).getResultList(),
|
||||
new Function<FeedEntryStatus, Long>() {
|
||||
@Override
|
||||
public Long apply(FeedEntryStatus input) {
|
||||
return input.getEntry().getId();
|
||||
}
|
||||
});
|
||||
|
||||
for (FeedEntry entry : entries) {
|
||||
FeedEntryStatus s = existing.get(entry.getId());
|
||||
if (s == null) {
|
||||
s = new FeedEntryStatus();
|
||||
s.setEntry(entry);
|
||||
s.setSubscription(sub);
|
||||
s.setRead(true);
|
||||
}
|
||||
results.add(s);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findByKeywords(User user, String keywords,
|
||||
int offset, int limit) {
|
||||
|
||||
@@ -135,14 +202,63 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return lazyLoadContent(includeContent, q.getResultList());
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findAll(User user, boolean unreadOnly,
|
||||
ReadingOrder order, boolean includeContent) {
|
||||
return findAll(user, unreadOnly, null, -1, -1, order, includeContent);
|
||||
public List<FeedEntryStatus> findAll(User user, Date newerThan, int offset,
|
||||
int limit, ReadingOrder order, boolean includeContent) {
|
||||
|
||||
CriteriaQuery<Tuple> query = builder.createTupleQuery();
|
||||
Root<FeedEntry> root = query.from(FeedEntry.class);
|
||||
|
||||
SetJoin<FeedEntry, Feed> feedJoin = root.join(FeedEntry_.feeds);
|
||||
SetJoin<Feed, FeedSubscription> subJoin = feedJoin
|
||||
.join(Feed_.subscriptions);
|
||||
|
||||
Selection<FeedEntry> entryAlias = root.alias("entry");
|
||||
Selection<FeedSubscription> subAlias = subJoin.alias("subscription");
|
||||
query.multiselect(entryAlias, subAlias);
|
||||
|
||||
List<Predicate> predicates = Lists.newArrayList();
|
||||
|
||||
predicates
|
||||
.add(builder.equal(subJoin.get(FeedSubscription_.user), user));
|
||||
|
||||
if (newerThan != null) {
|
||||
predicates.add(builder.greaterThanOrEqualTo(
|
||||
root.get(FeedEntry_.inserted), newerThan));
|
||||
}
|
||||
|
||||
query.where(predicates.toArray(new Predicate[0]));
|
||||
orderBy(query, root, order);
|
||||
|
||||
TypedQuery<Tuple> q = em.createQuery(query);
|
||||
limit(q, offset, limit);
|
||||
setTimeout(q);
|
||||
|
||||
List<Tuple> list = q.getResultList();
|
||||
List<FeedEntryStatus> results = Lists.newArrayList();
|
||||
for (Tuple tuple : list) {
|
||||
FeedEntry entry = tuple.get(entryAlias);
|
||||
FeedSubscription subscription = tuple.get(subAlias);
|
||||
|
||||
FeedEntryStatus status = findByEntry(entry, subscription);
|
||||
if (status == null) {
|
||||
status = new FeedEntryStatus();
|
||||
status.setEntry(entry);
|
||||
status.setRead(true);
|
||||
status.setSubscription(subscription);
|
||||
}
|
||||
results.add(status);
|
||||
}
|
||||
|
||||
return lazyLoadContent(includeContent, results);
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findAll(User user, boolean unreadOnly,
|
||||
Date newerThan, int offset, int limit, ReadingOrder order,
|
||||
public List<FeedEntryStatus> findAllUnread(User user, ReadingOrder order,
|
||||
boolean includeContent) {
|
||||
return findAllUnread(user, null, -1, -1, order, includeContent);
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findAllUnread(User user, Date newerThan,
|
||||
int offset, int limit, ReadingOrder order, boolean includeContent) {
|
||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||
Root<FeedEntryStatus> root = query.from(getType());
|
||||
|
||||
@@ -155,9 +271,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
|
||||
predicates
|
||||
.add(builder.equal(subJoin.get(FeedSubscription_.user), user));
|
||||
if (unreadOnly) {
|
||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
||||
}
|
||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
||||
|
||||
if (newerThan != null) {
|
||||
predicates.add(builder.greaterThanOrEqualTo(
|
||||
@@ -174,15 +288,48 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findBySubscription(
|
||||
FeedSubscription subscription, boolean unreadOnly,
|
||||
ReadingOrder order, boolean includeContent) {
|
||||
return findBySubscription(subscription, unreadOnly, null, -1, -1,
|
||||
order, includeContent);
|
||||
FeedSubscription subscription, Date newerThan, int offset,
|
||||
int limit, ReadingOrder order, boolean includeContent) {
|
||||
|
||||
CriteriaQuery<FeedEntry> query = builder.createQuery(FeedEntry.class);
|
||||
Root<FeedEntry> root = query.from(FeedEntry.class);
|
||||
|
||||
SetJoin<FeedEntry, Feed> feedJoin = root.join(FeedEntry_.feeds);
|
||||
SetJoin<Feed, FeedSubscription> subJoin = feedJoin
|
||||
.join(Feed_.subscriptions);
|
||||
|
||||
List<Predicate> predicates = Lists.newArrayList();
|
||||
|
||||
predicates.add(builder.equal(subJoin.get(FeedSubscription_.id),
|
||||
subscription.getId()));
|
||||
|
||||
if (newerThan != null) {
|
||||
predicates.add(builder.greaterThanOrEqualTo(
|
||||
root.get(FeedEntry_.inserted), newerThan));
|
||||
}
|
||||
|
||||
query.where(predicates.toArray(new Predicate[0]));
|
||||
orderBy(query, root, order);
|
||||
|
||||
TypedQuery<FeedEntry> q = em.createQuery(query);
|
||||
limit(q, offset, limit);
|
||||
setTimeout(q);
|
||||
|
||||
List<FeedEntry> list = q.getResultList();
|
||||
return lazyLoadContent(includeContent,
|
||||
findByEntries(list, subscription));
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findBySubscription(
|
||||
FeedSubscription subscription, boolean unreadOnly, Date newerThan,
|
||||
int offset, int limit, ReadingOrder order, boolean includeContent) {
|
||||
public List<FeedEntryStatus> findUnreadBySubscription(
|
||||
FeedSubscription subscription, ReadingOrder order,
|
||||
boolean includeContent) {
|
||||
return findUnreadBySubscription(subscription, null, -1, -1, order,
|
||||
includeContent);
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findUnreadBySubscription(
|
||||
FeedSubscription subscription, Date newerThan, int offset,
|
||||
int limit, ReadingOrder order, boolean includeContent) {
|
||||
|
||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||
Root<FeedEntryStatus> root = query.from(getType());
|
||||
@@ -194,9 +341,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
|
||||
predicates.add(builder.equal(root.get(FeedEntryStatus_.subscription),
|
||||
subscription));
|
||||
if (unreadOnly) {
|
||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
||||
}
|
||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
||||
|
||||
if (newerThan != null) {
|
||||
predicates.add(builder.greaterThanOrEqualTo(
|
||||
@@ -214,16 +359,73 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findByCategories(
|
||||
List<FeedCategory> categories, User user, boolean unreadOnly,
|
||||
ReadingOrder order, boolean includeContent) {
|
||||
return findByCategories(categories, user, unreadOnly, null, -1, -1,
|
||||
order, includeContent);
|
||||
List<FeedCategory> categories, Date newerThan, int offset,
|
||||
int limit, ReadingOrder order, boolean includeContent) {
|
||||
|
||||
CriteriaQuery<Tuple> query = builder.createTupleQuery();
|
||||
Root<FeedEntry> root = query.from(FeedEntry.class);
|
||||
|
||||
SetJoin<FeedEntry, Feed> feedJoin = root.join(FeedEntry_.feeds);
|
||||
SetJoin<Feed, FeedSubscription> subJoin = feedJoin
|
||||
.join(Feed_.subscriptions);
|
||||
|
||||
Selection<FeedEntry> entryAlias = root.alias("entry");
|
||||
Selection<FeedSubscription> subAlias = subJoin.alias("subscription");
|
||||
query.multiselect(entryAlias, subAlias);
|
||||
|
||||
List<Predicate> predicates = Lists.newArrayList();
|
||||
|
||||
if (categories.size() == 1) {
|
||||
predicates.add(builder.equal(subJoin
|
||||
.get(FeedSubscription_.category), categories.iterator()
|
||||
.next()));
|
||||
} else {
|
||||
predicates.add(subJoin.get(FeedSubscription_.category).in(
|
||||
categories));
|
||||
}
|
||||
|
||||
if (newerThan != null) {
|
||||
predicates.add(builder.greaterThanOrEqualTo(
|
||||
root.get(FeedEntry_.inserted), newerThan));
|
||||
}
|
||||
|
||||
query.where(predicates.toArray(new Predicate[0]));
|
||||
orderBy(query, root, order);
|
||||
|
||||
TypedQuery<Tuple> q = em.createQuery(query);
|
||||
limit(q, offset, limit);
|
||||
setTimeout(q);
|
||||
|
||||
List<Tuple> list = q.getResultList();
|
||||
List<FeedEntryStatus> results = Lists.newArrayList();
|
||||
for (Tuple tuple : list) {
|
||||
FeedEntry entry = tuple.get(entryAlias);
|
||||
FeedSubscription subscription = tuple.get(subAlias);
|
||||
|
||||
FeedEntryStatus status = findByEntry(entry, subscription);
|
||||
if (status == null) {
|
||||
status = new FeedEntryStatus();
|
||||
status.setEntry(entry);
|
||||
status.setSubscription(subscription);
|
||||
status.setRead(true);
|
||||
}
|
||||
results.add(status);
|
||||
}
|
||||
|
||||
return lazyLoadContent(includeContent, results);
|
||||
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findByCategories(
|
||||
List<FeedCategory> categories, User user, boolean unreadOnly,
|
||||
Date newerThan, int offset, int limit, ReadingOrder order,
|
||||
public List<FeedEntryStatus> findUnreadByCategories(
|
||||
List<FeedCategory> categories, ReadingOrder order,
|
||||
boolean includeContent) {
|
||||
return findUnreadByCategories(categories, null, -1, -1, order,
|
||||
includeContent);
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findUnreadByCategories(
|
||||
List<FeedCategory> categories, Date newerThan, int offset,
|
||||
int limit, ReadingOrder order, boolean includeContent) {
|
||||
|
||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||
Root<FeedEntryStatus> root = query.from(getType());
|
||||
@@ -235,9 +437,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
Join<FeedEntryStatus, FeedSubscription> subJoin = root
|
||||
.join(FeedEntryStatus_.subscription);
|
||||
|
||||
predicates
|
||||
.add(builder.equal(subJoin.get(FeedSubscription_.user), user));
|
||||
|
||||
if (categories.size() == 1) {
|
||||
predicates.add(builder.equal(subJoin
|
||||
.get(FeedSubscription_.category), categories.iterator()
|
||||
@@ -247,9 +446,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
categories));
|
||||
}
|
||||
|
||||
if (unreadOnly) {
|
||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
||||
}
|
||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
||||
|
||||
if (newerThan != null) {
|
||||
predicates.add(builder.greaterThanOrEqualTo(
|
||||
@@ -293,8 +490,8 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return results;
|
||||
}
|
||||
|
||||
private void orderBy(CriteriaQuery<FeedEntryStatus> query,
|
||||
Join<FeedEntryStatus, FeedEntry> entryJoin, ReadingOrder order) {
|
||||
private void orderBy(CriteriaQuery<?> query, Path<FeedEntry> entryJoin,
|
||||
ReadingOrder order) {
|
||||
if (order != null) {
|
||||
Path<Date> orderPath = entryJoin.get(FeedEntry_.updated);
|
||||
if (order == ReadingOrder.asc) {
|
||||
@@ -311,41 +508,46 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
|
||||
public void markSubscriptionEntries(FeedSubscription subscription,
|
||||
Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findBySubscription(subscription, true,
|
||||
List<FeedEntryStatus> statuses = findUnreadBySubscription(subscription,
|
||||
null, false);
|
||||
saveOrUpdate(markList(statuses, olderThan));
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
public void markCategoryEntries(User user, List<FeedCategory> categories,
|
||||
Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findByCategories(categories, user,
|
||||
true, null, false);
|
||||
saveOrUpdate(markList(statuses, olderThan));
|
||||
List<FeedEntryStatus> statuses = findUnreadByCategories(categories,
|
||||
null, false);
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
public void markStarredEntries(User user, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findStarred(user, null, false);
|
||||
saveOrUpdate(markList(statuses, olderThan));
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
public void markAllEntries(User user, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findAll(user, true, null, false);
|
||||
saveOrUpdate(markList(statuses, olderThan));
|
||||
List<FeedEntryStatus> statuses = findAllUnread(user, null, false);
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
private List<FeedEntryStatus> markList(List<FeedEntryStatus> statuses,
|
||||
Date olderThan) {
|
||||
private void markList(List<FeedEntryStatus> statuses, Date olderThan) {
|
||||
List<FeedEntryStatus> list = Lists.newArrayList();
|
||||
for (FeedEntryStatus status : statuses) {
|
||||
if (!status.isRead()) {
|
||||
Date inserted = status.getEntry().getInserted();
|
||||
if (olderThan == null || inserted == null
|
||||
|| olderThan.after(inserted)) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
if (status.isStarred()) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
} else {
|
||||
delete(status);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
saveOrUpdate(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
|
||||
@Stateless
|
||||
@@ -13,18 +16,74 @@ public class FeedEntryService {
|
||||
@Inject
|
||||
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||
|
||||
public void markEntry(User user, Long entryId, boolean read) {
|
||||
FeedEntryStatus status = feedEntryStatusDAO.findById(user, entryId);
|
||||
if (status != null) {
|
||||
status.setRead(read);
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
public void markEntry(User user, Long entryId, Long subscriptionId,
|
||||
boolean read) {
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(user,
|
||||
subscriptionId);
|
||||
if (sub == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FeedEntry entry = new FeedEntry();
|
||||
entry.setId(entryId);
|
||||
|
||||
FeedEntryStatus status = feedEntryStatusDAO.findByEntry(entry, sub);
|
||||
|
||||
if (read) {
|
||||
if (status != null) {
|
||||
if (status.isStarred()) {
|
||||
status.setRead(true);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
} else {
|
||||
feedEntryStatusDAO.delete(status);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (status == null) {
|
||||
status = new FeedEntryStatus();
|
||||
status.setEntry(entry);
|
||||
status.setSubscription(sub);
|
||||
}
|
||||
status.setRead(false);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void starEntry(User user, Long entryId, boolean starred) {
|
||||
FeedEntryStatus status = feedEntryStatusDAO.findById(user, entryId);
|
||||
if (status != null) {
|
||||
status.setStarred(starred);
|
||||
public void starEntry(User user, Long entryId, Long subscriptionId,
|
||||
boolean starred) {
|
||||
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(user,
|
||||
subscriptionId);
|
||||
if (sub == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
FeedEntry entry = new FeedEntry();
|
||||
entry.setId(entryId);
|
||||
|
||||
FeedEntryStatus status = feedEntryStatusDAO.findByEntry(entry, sub);
|
||||
|
||||
if (!starred) {
|
||||
if (status != null) {
|
||||
if (!status.isRead()) {
|
||||
status.setStarred(false);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
} else {
|
||||
feedEntryStatusDAO.delete(status);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (status == null) {
|
||||
status = new FeedEntryStatus();
|
||||
status.setEntry(entry);
|
||||
status.setSubscription(sub);
|
||||
status.setRead(true);
|
||||
}
|
||||
status.setStarred(true);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import com.commafeed.backend.feeds.FeedUtils;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.sun.syndication.feed.synd.SyndContentImpl;
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.feed.synd.SyndEntryImpl;
|
||||
@@ -27,28 +28,28 @@ public class Entry implements Serializable {
|
||||
Entry entry = new Entry();
|
||||
|
||||
FeedEntry feedEntry = status.getEntry();
|
||||
entry.setId(String.valueOf(status.getId()));
|
||||
FeedSubscription sub = status.getSubscription();
|
||||
|
||||
entry.setRead(status.isRead());
|
||||
entry.setStarred(status.isStarred());
|
||||
|
||||
entry.setId(String.valueOf(feedEntry.getId()));
|
||||
entry.setGuid(feedEntry.getGuid());
|
||||
entry.setTitle(feedEntry.getContent().getTitle());
|
||||
entry.setContent(feedEntry.getContent().getContent());
|
||||
entry.setRtl(FeedUtils.isRTL(feedEntry));
|
||||
entry.setAuthor(feedEntry.getAuthor());
|
||||
entry.setEnclosureUrl(status.getEntry().getContent().getEnclosureUrl());
|
||||
entry.setEnclosureType(status.getEntry().getContent()
|
||||
.getEnclosureType());
|
||||
entry.setEnclosureUrl(feedEntry.getContent().getEnclosureUrl());
|
||||
entry.setEnclosureType(feedEntry.getContent().getEnclosureType());
|
||||
entry.setDate(feedEntry.getUpdated());
|
||||
entry.setInsertedDate(feedEntry.getInserted());
|
||||
entry.setUrl(feedEntry.getUrl());
|
||||
|
||||
entry.setRead(status.isRead());
|
||||
entry.setStarred(status.isStarred());
|
||||
|
||||
entry.setFeedName(status.getSubscription().getTitle());
|
||||
entry.setFeedId(String.valueOf(status.getSubscription().getId()));
|
||||
entry.setFeedUrl(status.getSubscription().getFeed().getUrl());
|
||||
entry.setFeedLink(status.getSubscription().getFeed().getLink());
|
||||
entry.setIconUrl(FeedUtils.getFaviconUrl(status.getSubscription(),
|
||||
publicUrl));
|
||||
entry.setFeedName(sub.getTitle());
|
||||
entry.setFeedId(String.valueOf(sub.getId()));
|
||||
entry.setFeedUrl(sub.getFeed().getUrl());
|
||||
entry.setFeedLink(sub.getFeed().getLink());
|
||||
entry.setIconUrl(FeedUtils.getFaviconUrl(sub, publicUrl));
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,12 @@ import com.wordnik.swagger.annotations.ApiProperty;
|
||||
@ApiClass("Mark Request")
|
||||
public class MarkRequest implements Serializable {
|
||||
|
||||
@ApiProperty(value = "id", required = true)
|
||||
@ApiProperty(value = "entry id, category id, 'all' or 'starred'", required = true)
|
||||
private String id;
|
||||
|
||||
@ApiProperty(value = "feed id, only required when marking an entry")
|
||||
private Long feedId;
|
||||
|
||||
@ApiProperty(value = "mark as read or unread")
|
||||
private boolean read;
|
||||
|
||||
@@ -48,4 +51,12 @@ public class MarkRequest implements Serializable {
|
||||
this.olderThan = olderThan;
|
||||
}
|
||||
|
||||
public Long getFeedId() {
|
||||
return feedId;
|
||||
}
|
||||
|
||||
public void setFeedId(Long feedId) {
|
||||
this.feedId = feedId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ public class StarRequest implements Serializable {
|
||||
@ApiProperty(value = "id", required = true)
|
||||
private String id;
|
||||
|
||||
@ApiProperty(value = "feed id", required = true)
|
||||
private Long feedId;
|
||||
|
||||
@ApiProperty(value = "starred or not")
|
||||
private boolean starred;
|
||||
|
||||
@@ -37,4 +40,12 @@ public class StarRequest implements Serializable {
|
||||
this.starred = starred;
|
||||
}
|
||||
|
||||
public Long getFeedId() {
|
||||
return feedId;
|
||||
}
|
||||
|
||||
public void setFeedId(Long feedId) {
|
||||
this.feedId = feedId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class NextUnreadRedirectPage extends WebPage {
|
||||
List<FeedEntryStatus> statuses = null;
|
||||
if (StringUtils.isBlank(categoryId)
|
||||
|| CategoryREST.ALL.equals(categoryId)) {
|
||||
statuses = feedEntryStatusDAO.findAll(user, true, null, 0, 1,
|
||||
statuses = feedEntryStatusDAO.findAllUnread(user, null, 0, 1,
|
||||
ReadingOrder.desc, true);
|
||||
} else {
|
||||
FeedCategory category = feedCategoryDAO.findById(user,
|
||||
@@ -49,8 +49,8 @@ public class NextUnreadRedirectPage extends WebPage {
|
||||
if (category != null) {
|
||||
List<FeedCategory> children = feedCategoryDAO
|
||||
.findAllChildrenCategories(user, category);
|
||||
statuses = feedEntryStatusDAO.findByCategories(children, user,
|
||||
true, null, 0, 1, ReadingOrder.desc, false);
|
||||
statuses = feedEntryStatusDAO.findUnreadByCategories(children,
|
||||
null, 0, 1, ReadingOrder.desc, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,16 +79,21 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
if (StringUtils.isBlank(id)) {
|
||||
id = ALL;
|
||||
}
|
||||
|
||||
|
||||
Date newerThanDate = newerThan == null ? null : new Date(
|
||||
Long.valueOf(newerThan));
|
||||
|
||||
if (ALL.equals(id)) {
|
||||
entries.setName("All");
|
||||
List<FeedEntryStatus> unreadEntries = feedEntryStatusDAO.findAll(
|
||||
getUser(), unreadOnly, newerThanDate, offset, limit + 1, order,
|
||||
true);
|
||||
for (FeedEntryStatus status : unreadEntries) {
|
||||
List<FeedEntryStatus> list = null;
|
||||
if (unreadOnly) {
|
||||
list = feedEntryStatusDAO.findAllUnread(getUser(),
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
} else {
|
||||
list = feedEntryStatusDAO.findAll(getUser(), newerThanDate,
|
||||
offset, limit + 1, order, true);
|
||||
}
|
||||
for (FeedEntryStatus status : list) {
|
||||
entries.getEntries().add(
|
||||
Entry.build(status, applicationSettingsService.get()
|
||||
.getPublicUrl()));
|
||||
@@ -109,11 +114,17 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
if (feedCategory != null) {
|
||||
List<FeedCategory> childrenCategories = feedCategoryDAO
|
||||
.findAllChildrenCategories(getUser(), feedCategory);
|
||||
List<FeedEntryStatus> unreadEntries = feedEntryStatusDAO
|
||||
.findByCategories(childrenCategories, getUser(),
|
||||
unreadOnly, newerThanDate, offset, limit + 1,
|
||||
order, true);
|
||||
for (FeedEntryStatus status : unreadEntries) {
|
||||
List<FeedEntryStatus> list = null;
|
||||
if (unreadOnly) {
|
||||
list = feedEntryStatusDAO.findUnreadByCategories(
|
||||
childrenCategories, newerThanDate, offset,
|
||||
limit + 1, order, true);
|
||||
} else {
|
||||
list = feedEntryStatusDAO.findByCategories(
|
||||
childrenCategories, newerThanDate, offset,
|
||||
limit + 1, order, true);
|
||||
}
|
||||
for (FeedEntryStatus status : list) {
|
||||
entries.getEntries().add(
|
||||
Entry.build(status, applicationSettingsService
|
||||
.get().getPublicUrl()));
|
||||
|
||||
@@ -34,9 +34,10 @@ public class EntryREST extends AbstractResourceREST {
|
||||
@ApiParam(value = "Mark Request", required = true) MarkRequest req) {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getId());
|
||||
Preconditions.checkNotNull(req.getFeedId());
|
||||
|
||||
feedEntryService.markEntry(getUser(), Long.valueOf(req.getId()),
|
||||
req.isRead());
|
||||
req.getFeedId(), req.isRead());
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
@@ -48,9 +49,10 @@ public class EntryREST extends AbstractResourceREST {
|
||||
@ApiParam(value = "Star Request", required = true) StarRequest req) {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getId());
|
||||
Preconditions.checkNotNull(req.getFeedId());
|
||||
|
||||
feedEntryService.starEntry(getUser(), Long.valueOf(req.getId()),
|
||||
req.isStarred());
|
||||
req.getFeedId(), req.isStarred());
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -100,10 +100,17 @@ public class FeedREST extends AbstractResourceREST {
|
||||
entries.setMessage(subscription.getFeed().getMessage());
|
||||
entries.setErrorCount(subscription.getFeed().getErrorCount());
|
||||
|
||||
List<FeedEntryStatus> unreadEntries = feedEntryStatusDAO
|
||||
.findBySubscription(subscription, unreadOnly,
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
for (FeedEntryStatus status : unreadEntries) {
|
||||
List<FeedEntryStatus> list = null;
|
||||
if (unreadOnly) {
|
||||
list = feedEntryStatusDAO.findUnreadBySubscription(
|
||||
subscription, newerThanDate, offset, limit + 1, order,
|
||||
true);
|
||||
} else {
|
||||
list = feedEntryStatusDAO.findBySubscription(subscription,
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
}
|
||||
|
||||
for (FeedEntryStatus status : list) {
|
||||
entries.getEntries().add(
|
||||
Entry.build(status, applicationSettingsService.get()
|
||||
.getPublicUrl()));
|
||||
@@ -202,16 +209,20 @@ public class FeedREST extends AbstractResourceREST {
|
||||
@POST
|
||||
@ApiOperation(value = "Queue a feed for refresh", notes = "Manually add a feed to the refresh queue")
|
||||
public Response queueForRefresh(@ApiParam(value = "Feed id") IDRequest req) {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getId());
|
||||
// TODO evaluate if this is needed
|
||||
|
||||
// Preconditions.checkNotNull(req);
|
||||
// Preconditions.checkNotNull(req.getId());
|
||||
//
|
||||
// FeedSubscription sub = feedSubscriptionDAO.findById(getUser(),
|
||||
// req.getId());
|
||||
// if (sub != null) {
|
||||
// taskGiver.add(sub.getFeed());
|
||||
// return Response.ok(Status.OK).build();
|
||||
// }
|
||||
// return Response.ok(Status.NOT_FOUND).build();
|
||||
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(),
|
||||
req.getId());
|
||||
if (sub != null) {
|
||||
taskGiver.add(sub.getFeed());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
return Response.ok(Status.NOT_FOUND).build();
|
||||
return Response.ok("Disabled for now").build();
|
||||
}
|
||||
|
||||
@Path("/mark")
|
||||
|
||||
@@ -731,6 +731,7 @@ function($scope, $stateParams, $http, $route, $window, EntryService, SettingsSer
|
||||
});
|
||||
EntryService.mark({
|
||||
id : entry.id,
|
||||
feedId : entry.feedId,
|
||||
read : read
|
||||
});
|
||||
}
|
||||
@@ -759,6 +760,7 @@ function($scope, $stateParams, $http, $route, $window, EntryService, SettingsSer
|
||||
entry.starred = star;
|
||||
EntryService.star({
|
||||
id : entry.id,
|
||||
feedId : entry.feedId,
|
||||
starred : star
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user