forked from Archives/Athou_commafeed
major classes refactoring
This commit is contained in:
@@ -11,11 +11,11 @@ import javax.inject.Inject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.ApplicationSettingsService;
|
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||||
import com.commafeed.backend.dao.FeedCategoryService;
|
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||||
import com.commafeed.backend.dao.FeedService;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
import com.commafeed.backend.dao.UserService;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.feeds.FeedRefreshWorker;
|
import com.commafeed.backend.feeds.FeedRefreshWorker;
|
||||||
import com.commafeed.backend.model.ApplicationSettings;
|
import com.commafeed.backend.model.ApplicationSettings;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
@@ -23,7 +23,8 @@ 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.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
import com.commafeed.backend.security.PasswordEncryptionService;
|
import com.commafeed.backend.services.PasswordEncryptionService;
|
||||||
|
import com.commafeed.backend.services.UserService;
|
||||||
|
|
||||||
@Startup
|
@Startup
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -33,13 +34,16 @@ public class StartupBean {
|
|||||||
public static final String ADMIN_NAME = "admin";
|
public static final String ADMIN_NAME = "admin";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedCategoryService feedCategoryService;
|
FeedCategoryDAO feedCategoryDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedSubscriptionService feedSubscriptionService;
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
UserDAO userDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserService userService;
|
UserService userService;
|
||||||
@@ -48,7 +52,7 @@ public class StartupBean {
|
|||||||
PasswordEncryptionService encryptionService;
|
PasswordEncryptionService encryptionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsDAO applicationSettingsDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedRefreshWorker worker;
|
FeedRefreshWorker worker;
|
||||||
@@ -58,7 +62,7 @@ public class StartupBean {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init() {
|
private void init() {
|
||||||
startupTime = Calendar.getInstance().getTimeInMillis();
|
startupTime = Calendar.getInstance().getTimeInMillis();
|
||||||
if (userService.getCount() == 0) {
|
if (userDAO.getCount() == 0) {
|
||||||
initialData();
|
initialData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,57 +76,57 @@ public class StartupBean {
|
|||||||
private void initialData() {
|
private void initialData() {
|
||||||
log.info("Populating database with default values");
|
log.info("Populating database with default values");
|
||||||
|
|
||||||
applicationSettingsService.save(new ApplicationSettings());
|
applicationSettingsDAO.save(new ApplicationSettings());
|
||||||
|
|
||||||
User user = userService.register(ADMIN_NAME, "admin",
|
User user = userService.register(ADMIN_NAME, "admin",
|
||||||
Arrays.asList(Role.ADMIN, Role.USER));
|
Arrays.asList(Role.ADMIN, Role.USER));
|
||||||
userService.register("test", "test", Arrays.asList(Role.USER));
|
userService.register("test", "test", Arrays.asList(Role.USER));
|
||||||
|
|
||||||
Feed dilbert = new Feed("http://feed.dilbert.com/dilbert/daily_strip");
|
Feed dilbert = new Feed("http://feed.dilbert.com/dilbert/daily_strip");
|
||||||
feedService.save(dilbert);
|
feedDAO.save(dilbert);
|
||||||
|
|
||||||
Feed engadget = new Feed("http://www.engadget.com/rss.xml");
|
Feed engadget = new Feed("http://www.engadget.com/rss.xml");
|
||||||
feedService.save(engadget);
|
feedDAO.save(engadget);
|
||||||
|
|
||||||
Feed frandroid = new Feed("http://feeds.feedburner.com/frandroid");
|
Feed frandroid = new Feed("http://feeds.feedburner.com/frandroid");
|
||||||
feedService.save(frandroid);
|
feedDAO.save(frandroid);
|
||||||
|
|
||||||
FeedCategory newsCategory = new FeedCategory();
|
FeedCategory newsCategory = new FeedCategory();
|
||||||
newsCategory.setName("News");
|
newsCategory.setName("News");
|
||||||
newsCategory.setUser(user);
|
newsCategory.setUser(user);
|
||||||
feedCategoryService.save(newsCategory);
|
feedCategoryDAO.save(newsCategory);
|
||||||
|
|
||||||
FeedCategory comicsCategory = new FeedCategory();
|
FeedCategory comicsCategory = new FeedCategory();
|
||||||
comicsCategory.setName("Comics");
|
comicsCategory.setName("Comics");
|
||||||
comicsCategory.setUser(user);
|
comicsCategory.setUser(user);
|
||||||
comicsCategory.setParent(newsCategory);
|
comicsCategory.setParent(newsCategory);
|
||||||
feedCategoryService.save(comicsCategory);
|
feedCategoryDAO.save(comicsCategory);
|
||||||
|
|
||||||
FeedCategory techCategory = new FeedCategory();
|
FeedCategory techCategory = new FeedCategory();
|
||||||
techCategory.setName("Tech");
|
techCategory.setName("Tech");
|
||||||
techCategory.setUser(user);
|
techCategory.setUser(user);
|
||||||
techCategory.setParent(newsCategory);
|
techCategory.setParent(newsCategory);
|
||||||
feedCategoryService.save(techCategory);
|
feedCategoryDAO.save(techCategory);
|
||||||
|
|
||||||
FeedSubscription sub = new FeedSubscription();
|
FeedSubscription sub = new FeedSubscription();
|
||||||
sub.setCategory(comicsCategory);
|
sub.setCategory(comicsCategory);
|
||||||
sub.setFeed(dilbert);
|
sub.setFeed(dilbert);
|
||||||
sub.setTitle("Dilbert - Strips");
|
sub.setTitle("Dilbert - Strips");
|
||||||
sub.setUser(user);
|
sub.setUser(user);
|
||||||
feedSubscriptionService.save(sub);
|
feedSubscriptionDAO.save(sub);
|
||||||
|
|
||||||
FeedSubscription sub2 = new FeedSubscription();
|
FeedSubscription sub2 = new FeedSubscription();
|
||||||
sub2.setCategory(techCategory);
|
sub2.setCategory(techCategory);
|
||||||
sub2.setFeed(engadget);
|
sub2.setFeed(engadget);
|
||||||
sub2.setTitle("Engadget");
|
sub2.setTitle("Engadget");
|
||||||
sub2.setUser(user);
|
sub2.setUser(user);
|
||||||
feedSubscriptionService.save(sub2);
|
feedSubscriptionDAO.save(sub2);
|
||||||
|
|
||||||
FeedSubscription sub3 = new FeedSubscription();
|
FeedSubscription sub3 = new FeedSubscription();
|
||||||
sub3.setFeed(frandroid);
|
sub3.setFeed(frandroid);
|
||||||
sub3.setTitle("Frandroid");
|
sub3.setTitle("Frandroid");
|
||||||
sub3.setUser(user);
|
sub3.setUser(user);
|
||||||
feedSubscriptionService.save(sub3);
|
feedSubscriptionDAO.save(sub3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartupTime() {
|
public long getStartupTime() {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import com.uaihebert.factory.EasyCriteriaFactory;
|
|||||||
import com.uaihebert.model.EasyCriteria;
|
import com.uaihebert.model.EasyCriteria;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
public class ApplicationSettingsService {
|
public class ApplicationSettingsDAO {
|
||||||
|
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
protected EntityManager em;
|
protected EntityManager em;
|
||||||
@@ -16,7 +16,7 @@ import com.uaihebert.model.EasyCriteria;
|
|||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FeedCategoryService extends GenericDAO<FeedCategory> {
|
public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||||
|
|
||||||
public List<FeedCategory> findAll(User user) {
|
public List<FeedCategory> findAll(User user) {
|
||||||
EasyCriteria<FeedCategory> criteria = createCriteria();
|
EasyCriteria<FeedCategory> criteria = createCriteria();
|
||||||
@@ -20,7 +20,7 @@ import com.uaihebert.model.EasyCriteria;
|
|||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FeedService extends GenericDAO<Feed> {
|
public class FeedDAO extends GenericDAO<Feed> {
|
||||||
|
|
||||||
public List<Feed> findNextUpdatable(int count) {
|
public List<Feed> findNextUpdatable(int count) {
|
||||||
CriteriaQuery<Feed> query = builder.createQuery(getType());
|
CriteriaQuery<Feed> query = builder.createQuery(getType());
|
||||||
@@ -56,7 +56,7 @@ public class FeedService extends GenericDAO<Feed> {
|
|||||||
return Iterables.getFirst(feeds, null);
|
return Iterables.getFirst(feeds, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed getByIdWithEntries(Long feedId, int offset, int limit) {
|
public Feed findByIdWithEntries(Long feedId, int offset, int limit) {
|
||||||
EasyCriteria<Feed> criteria = createCriteria();
|
EasyCriteria<Feed> criteria = createCriteria();
|
||||||
criteria.andEquals(MF.i(proxy().getId()), feedId);
|
criteria.andEquals(MF.i(proxy().getId()), feedId);
|
||||||
criteria.leftJoinFetch(MF.i(proxy().getEntries()));
|
criteria.leftJoinFetch(MF.i(proxy().getEntries()));
|
||||||
38
src/main/java/com/commafeed/backend/dao/FeedEntryDAO.java
Normal file
38
src/main/java/com/commafeed/backend/dao/FeedEntryDAO.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
import com.commafeed.backend.model.Feed;
|
||||||
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
|
import com.commafeed.backend.model.FeedEntry_;
|
||||||
|
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||||
|
import com.uaihebert.model.EasyCriteria;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
||||||
|
|
||||||
|
public List<FeedEntry> findByGuids(List<String> guids) {
|
||||||
|
EasyCriteria<FeedEntry> criteria = createCriteria();
|
||||||
|
criteria.setDistinctTrue();
|
||||||
|
criteria.andStringIn(MF.i(proxy().getGuid()), guids);
|
||||||
|
criteria.leftJoinFetch(MF.i(proxy().getFeeds()));
|
||||||
|
return criteria.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FeedEntry> findByFeed(Feed feed, int offset, int limit) {
|
||||||
|
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
||||||
|
Root<FeedEntry> root = query.from(getType());
|
||||||
|
query.where(builder.isMember(feed, root.get(FeedEntry_.feeds)));
|
||||||
|
query.orderBy(builder.desc(root.get(FeedEntry_.updated)));
|
||||||
|
TypedQuery<FeedEntry> q = em.createQuery(query);
|
||||||
|
q.setFirstResult(offset);
|
||||||
|
q.setMaxResults(limit);
|
||||||
|
return q.getResultList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
@@ -33,10 +32,7 @@ import com.uaihebert.model.EasyCriteria;
|
|||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedCategoryService feedCategoryService;
|
|
||||||
|
|
||||||
public FeedEntryStatus findById(User user, Long id) {
|
public FeedEntryStatus findById(User user, Long id) {
|
||||||
|
|
||||||
@@ -58,7 +54,7 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatusesByKeywords(User user,
|
public List<FeedEntryStatus> findByKeywords(User user,
|
||||||
String keywords, int offset, int limit, boolean includeContent) {
|
String keywords, int offset, int limit, boolean includeContent) {
|
||||||
|
|
||||||
String joinedKeywords = StringUtils.join(
|
String joinedKeywords = StringUtils.join(
|
||||||
@@ -93,12 +89,12 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
|||||||
return q.getResultList();
|
return q.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatuses(User user, boolean unreadOnly,
|
public List<FeedEntryStatus> findAll(User user, boolean unreadOnly,
|
||||||
ReadingOrder order, boolean includeContent) {
|
ReadingOrder order, boolean includeContent) {
|
||||||
return getStatuses(user, unreadOnly, -1, -1, order, includeContent);
|
return findAll(user, unreadOnly, -1, -1, order, includeContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatuses(User user, boolean unreadOnly,
|
public List<FeedEntryStatus> findAll(User user, boolean unreadOnly,
|
||||||
int offset, int limit, ReadingOrder order, boolean includeContent) {
|
int offset, int limit, ReadingOrder order, boolean includeContent) {
|
||||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||||
Root<FeedEntryStatus> root = query.from(getType());
|
Root<FeedEntryStatus> root = query.from(getType());
|
||||||
@@ -138,13 +134,13 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatuses(Feed feed, User user,
|
public List<FeedEntryStatus> findByFeed(Feed feed, User user,
|
||||||
boolean unreadOnly, ReadingOrder order, boolean includeContent) {
|
boolean unreadOnly, ReadingOrder order, boolean includeContent) {
|
||||||
return getStatuses(feed, user, unreadOnly, -1, -1, order,
|
return findByFeed(feed, user, unreadOnly, -1, -1, order,
|
||||||
includeContent);
|
includeContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatuses(Feed feed, User user,
|
public List<FeedEntryStatus> findByFeed(Feed feed, User user,
|
||||||
boolean unreadOnly, int offset, int limit, ReadingOrder order,
|
boolean unreadOnly, int offset, int limit, ReadingOrder order,
|
||||||
boolean includeContent) {
|
boolean includeContent) {
|
||||||
|
|
||||||
@@ -173,14 +169,14 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
|||||||
return q.getResultList();
|
return q.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatuses(List<FeedCategory> categories,
|
public List<FeedEntryStatus> findByCategories(List<FeedCategory> categories,
|
||||||
User user, boolean unreadOnly, ReadingOrder order,
|
User user, boolean unreadOnly, ReadingOrder order,
|
||||||
boolean includeContent) {
|
boolean includeContent) {
|
||||||
return getStatuses(categories, user, unreadOnly, -1, -1, order,
|
return findByCategories(categories, user, unreadOnly, -1, -1, order,
|
||||||
includeContent);
|
includeContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> getStatuses(List<FeedCategory> categories,
|
public List<FeedEntryStatus> findByCategories(List<FeedCategory> categories,
|
||||||
User user, boolean unreadOnly, int offset, int limit,
|
User user, boolean unreadOnly, int offset, int limit,
|
||||||
ReadingOrder order, boolean includeContent) {
|
ReadingOrder order, boolean includeContent) {
|
||||||
|
|
||||||
@@ -209,15 +205,6 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
|||||||
return q.getResultList();
|
return q.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limit(TypedQuery<FeedEntryStatus> query, int offset, int limit) {
|
|
||||||
if (offset > -1) {
|
|
||||||
query.setFirstResult(offset);
|
|
||||||
}
|
|
||||||
if (limit > -1) {
|
|
||||||
query.setMaxResults(limit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void orderBy(CriteriaQuery<FeedEntryStatus> query,
|
private void orderBy(CriteriaQuery<FeedEntryStatus> query,
|
||||||
Root<FeedEntryStatus> root, ReadingOrder order) {
|
Root<FeedEntryStatus> root, ReadingOrder order) {
|
||||||
Path<Date> orderPath = root.get(FeedEntryStatus_.entry).get(
|
Path<Date> orderPath = root.get(FeedEntryStatus_.entry).get(
|
||||||
@@ -231,20 +218,20 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void markFeedEntries(User user, Feed feed, Date olderThan) {
|
public void markFeedEntries(User user, Feed feed, Date olderThan) {
|
||||||
List<FeedEntryStatus> statuses = getStatuses(feed, user, true,
|
List<FeedEntryStatus> statuses = findByFeed(feed, user, true,
|
||||||
ReadingOrder.desc, false);
|
ReadingOrder.desc, false);
|
||||||
update(markList(statuses, olderThan));
|
update(markList(statuses, olderThan));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markCategoryEntries(User user, List<FeedCategory> categories,
|
public void markCategoryEntries(User user, List<FeedCategory> categories,
|
||||||
Date olderThan) {
|
Date olderThan) {
|
||||||
List<FeedEntryStatus> statuses = getStatuses(categories, user, true,
|
List<FeedEntryStatus> statuses = findByCategories(categories, user, true,
|
||||||
ReadingOrder.desc, false);
|
ReadingOrder.desc, false);
|
||||||
update(markList(statuses, olderThan));
|
update(markList(statuses, olderThan));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAllEntries(User user, Date olderThan) {
|
public void markAllEntries(User user, Date olderThan) {
|
||||||
List<FeedEntryStatus> statuses = getStatuses(user, true,
|
List<FeedEntryStatus> statuses = findAll(user, true,
|
||||||
ReadingOrder.desc, false);
|
ReadingOrder.desc, false);
|
||||||
update(markList(statuses, olderThan));
|
update(markList(statuses, olderThan));
|
||||||
}
|
}
|
||||||
@@ -3,72 +3,21 @@ package com.commafeed.backend.dao;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
|
||||||
import com.commafeed.backend.model.FeedEntryStatus;
|
|
||||||
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.commafeed.frontend.utils.ModelFactory.MF;
|
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||||
import com.google.api.client.util.Lists;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.uaihebert.factory.EasyCriteriaFactory;
|
import com.uaihebert.factory.EasyCriteriaFactory;
|
||||||
import com.uaihebert.model.EasyCriteria;
|
import com.uaihebert.model.EasyCriteria;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FeedSubscriptionService extends GenericDAO<FeedSubscription> {
|
public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedCategoryService feedCategoryService;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedService feedService;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedEntryService feedEntryService;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
FeedEntryStatusService feedEntryStatusService;
|
|
||||||
|
|
||||||
public void subscribe(User user, String url, String title,
|
|
||||||
FeedCategory category) {
|
|
||||||
|
|
||||||
Feed feed = feedService.findByUrl(url);
|
|
||||||
if (feed == null) {
|
|
||||||
feed = new Feed();
|
|
||||||
feed.setUrl(url);
|
|
||||||
feedService.save(feed);
|
|
||||||
}
|
|
||||||
|
|
||||||
FeedSubscription sub = findByFeed(user, feed);
|
|
||||||
boolean newSubscription = false;
|
|
||||||
if (sub == null) {
|
|
||||||
sub = new FeedSubscription();
|
|
||||||
sub.setFeed(feed);
|
|
||||||
sub.setUser(user);
|
|
||||||
newSubscription = true;
|
|
||||||
}
|
|
||||||
sub.setCategory(category);
|
|
||||||
sub.setTitle(title);
|
|
||||||
saveOrUpdate(sub);
|
|
||||||
|
|
||||||
if (newSubscription) {
|
|
||||||
List<FeedEntryStatus> statuses = Lists.newArrayList();
|
|
||||||
List<FeedEntry> allEntries = feedEntryService.findByFeed(feed, 0,
|
|
||||||
10);
|
|
||||||
for (FeedEntry entry : allEntries) {
|
|
||||||
FeedEntryStatus status = new FeedEntryStatus();
|
|
||||||
status.setEntry(entry);
|
|
||||||
status.setRead(true);
|
|
||||||
status.setSubscription(sub);
|
|
||||||
statuses.add(status);
|
|
||||||
}
|
|
||||||
feedEntryStatusService.save(statuses);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FeedSubscription findById(User user, Long id) {
|
public FeedSubscription findById(User user, Long id) {
|
||||||
EasyCriteria<FeedSubscription> criteria = createCriteria();
|
EasyCriteria<FeedSubscription> criteria = createCriteria();
|
||||||
@@ -7,11 +7,13 @@ import java.util.List;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import com.commafeed.backend.model.AbstractModel;
|
import com.commafeed.backend.model.AbstractModel;
|
||||||
|
import com.commafeed.backend.model.FeedEntryStatus;
|
||||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.uaihebert.factory.EasyCriteriaFactory;
|
import com.uaihebert.factory.EasyCriteriaFactory;
|
||||||
@@ -128,6 +130,16 @@ public abstract class GenericDAO<T extends AbstractModel> implements
|
|||||||
return criteria.getResultList();
|
return criteria.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void limit(TypedQuery<FeedEntryStatus> query, int offset,
|
||||||
|
int limit) {
|
||||||
|
if (offset > -1) {
|
||||||
|
query.setFirstResult(offset);
|
||||||
|
}
|
||||||
|
if (limit > -1) {
|
||||||
|
query.setMaxResults(limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected Class<T> getType() {
|
protected Class<T> getType() {
|
||||||
return (Class<T>) type.getRawType();
|
return (Class<T>) type.getRawType();
|
||||||
|
|||||||
31
src/main/java/com/commafeed/backend/dao/UserDAO.java
Normal file
31
src/main/java/com/commafeed/backend/dao/UserDAO.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
|
import com.commafeed.backend.model.User;
|
||||||
|
import com.commafeed.backend.services.PasswordEncryptionService;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class UserDAO extends GenericDAO<User> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PasswordEncryptionService encryptionService;
|
||||||
|
|
||||||
|
public User findByName(String name) {
|
||||||
|
TypedQuery<User> query = em.createNamedQuery("User.byName", User.class);
|
||||||
|
query.setParameter("name", name.toLowerCase());
|
||||||
|
|
||||||
|
User user = null;
|
||||||
|
try {
|
||||||
|
user = query.getSingleResult();
|
||||||
|
} catch (NoResultException e) {
|
||||||
|
user = null;
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,13 +13,13 @@ import com.google.common.collect.Sets;
|
|||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Stateless
|
@Stateless
|
||||||
public class UserRoleService extends GenericDAO<UserRole> {
|
public class UserRoleDAO extends GenericDAO<UserRole> {
|
||||||
|
|
||||||
public List<UserRole> findAll(User user) {
|
public List<UserRole> findAll(User user) {
|
||||||
return findByField(MF.i(MF.p(UserRole.class).getUser()), user);
|
return findByField(MF.i(MF.p(UserRole.class).getUser()), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Role> getRoles(User user) {
|
public Set<Role> findRoles(User user) {
|
||||||
Set<Role> list = Sets.newHashSet();
|
Set<Role> list = Sets.newHashSet();
|
||||||
for (UserRole role : findByField(MF.i(proxy().getUser()), user)) {
|
for (UserRole role : findByField(MF.i(proxy().getUser()), user)) {
|
||||||
list.add(role.getRole());
|
list.add(role.getRole());
|
||||||
@@ -11,7 +11,7 @@ import com.uaihebert.model.EasyCriteria;
|
|||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class UserSettingsService extends GenericDAO<UserSettings> {
|
public class UserSettingsDAO extends GenericDAO<UserSettings> {
|
||||||
|
|
||||||
public UserSettings findByUser(User user) {
|
public UserSettings findByUser(User user) {
|
||||||
|
|
||||||
@@ -22,9 +22,10 @@ import org.apache.commons.lang.time.DateUtils;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedEntryService;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
import com.commafeed.backend.dao.FeedService;
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
|
import com.commafeed.backend.services.FeedUpdateService;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@@ -40,10 +41,13 @@ public class FeedRefreshWorker {
|
|||||||
FeedFetcher fetcher;
|
FeedFetcher fetcher;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedEntryService feedEntryService;
|
FeedEntryDAO feedEntryDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedUpdateService feedUpdateService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserTransaction transaction;
|
private UserTransaction transaction;
|
||||||
@@ -102,13 +106,13 @@ public class FeedRefreshWorker {
|
|||||||
transaction.begin();
|
transaction.begin();
|
||||||
|
|
||||||
if (fetchedFeed != null) {
|
if (fetchedFeed != null) {
|
||||||
feedEntryService.updateEntries(feed.getUrl(),
|
feedUpdateService.updateEntries(feed.getUrl(),
|
||||||
fetchedFeed.getEntries());
|
fetchedFeed.getEntries());
|
||||||
if (feed.getLink() == null) {
|
if (feed.getLink() == null) {
|
||||||
feed.setLink(fetchedFeed.getLink());
|
feed.setLink(fetchedFeed.getLink());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feedService.update(feed);
|
feedDAO.update(feed);
|
||||||
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
|
||||||
@@ -121,10 +125,10 @@ public class FeedRefreshWorker {
|
|||||||
Feed feed = null;
|
Feed feed = null;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
feed = Iterables.getFirst(feedService.findNextUpdatable(1), null);
|
feed = Iterables.getFirst(feedDAO.findNextUpdatable(1), null);
|
||||||
if (feed != null) {
|
if (feed != null) {
|
||||||
feed.setLastUpdated(Calendar.getInstance().getTime());
|
feed.setLastUpdated(Calendar.getInstance().getTime());
|
||||||
feedService.update(feed);
|
feedDAO.update(feed);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedCategoryService;
|
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||||
import com.commafeed.backend.dao.FeedService;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
|
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||||
import com.sun.syndication.feed.opml.Opml;
|
import com.sun.syndication.feed.opml.Opml;
|
||||||
import com.sun.syndication.feed.opml.Outline;
|
import com.sun.syndication.feed.opml.Outline;
|
||||||
import com.sun.syndication.io.FeedException;
|
import com.sun.syndication.io.FeedException;
|
||||||
@@ -20,13 +20,13 @@ import com.sun.syndication.io.WireFeedInput;
|
|||||||
public class OPMLImporter {
|
public class OPMLImporter {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedSubscriptionService feedSubscriptionService;
|
FeedSubscriptionService feedSubscriptionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedCategoryService feedCategoryService;
|
FeedCategoryDAO feedCategoryDAO;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void importOpml(User user, String xml) throws FeedException {
|
public void importOpml(User user, String xml) throws FeedException {
|
||||||
@@ -43,14 +43,14 @@ public class OPMLImporter {
|
|||||||
private void handleOutline(User user, Outline outline, FeedCategory parent) {
|
private void handleOutline(User user, Outline outline, FeedCategory parent) {
|
||||||
|
|
||||||
if (StringUtils.isEmpty(outline.getType())) {
|
if (StringUtils.isEmpty(outline.getType())) {
|
||||||
FeedCategory category = feedCategoryService.findByName(user,
|
FeedCategory category = feedCategoryDAO.findByName(user,
|
||||||
outline.getText(), parent);
|
outline.getText(), parent);
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
category = new FeedCategory();
|
category = new FeedCategory();
|
||||||
category.setName(outline.getText());
|
category.setName(outline.getText());
|
||||||
category.setParent(parent);
|
category.setParent(parent);
|
||||||
category.setUser(user);
|
category.setUser(user);
|
||||||
feedCategoryService.save(category);
|
feedCategoryDAO.save(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Outline> children = outline.getChildren();
|
List<Outline> children = outline.getChildren();
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.commafeed.backend.services;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
|
import com.commafeed.backend.model.Feed;
|
||||||
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
|
import com.commafeed.backend.model.FeedEntryStatus;
|
||||||
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
|
import com.commafeed.backend.model.User;
|
||||||
|
import com.google.api.client.util.Lists;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
|
public class FeedSubscriptionService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedCategoryDAO feedCategoryDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedEntryDAO feedEntryDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
|
public void subscribe(User user, String url, String title,
|
||||||
|
FeedCategory category) {
|
||||||
|
|
||||||
|
Feed feed = feedDAO.findByUrl(url);
|
||||||
|
if (feed == null) {
|
||||||
|
feed = new Feed();
|
||||||
|
feed.setUrl(url);
|
||||||
|
feedDAO.save(feed);
|
||||||
|
}
|
||||||
|
|
||||||
|
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, feed);
|
||||||
|
boolean newSubscription = false;
|
||||||
|
if (sub == null) {
|
||||||
|
sub = new FeedSubscription();
|
||||||
|
sub.setFeed(feed);
|
||||||
|
sub.setUser(user);
|
||||||
|
newSubscription = true;
|
||||||
|
}
|
||||||
|
sub.setCategory(category);
|
||||||
|
sub.setTitle(title);
|
||||||
|
feedSubscriptionDAO.saveOrUpdate(sub);
|
||||||
|
|
||||||
|
if (newSubscription) {
|
||||||
|
List<FeedEntryStatus> statuses = Lists.newArrayList();
|
||||||
|
List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0,
|
||||||
|
10);
|
||||||
|
for (FeedEntry entry : allEntries) {
|
||||||
|
FeedEntryStatus status = new FeedEntryStatus();
|
||||||
|
status.setEntry(entry);
|
||||||
|
status.setRead(true);
|
||||||
|
status.setSubscription(sub);
|
||||||
|
statuses.add(status);
|
||||||
|
}
|
||||||
|
feedEntryStatusDAO.save(statuses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.services;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -7,41 +7,44 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.TypedQuery;
|
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
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.FeedEntryStatus;
|
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.frontend.utils.ModelFactory.MF;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.uaihebert.model.EasyCriteria;
|
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
public class FeedUpdateService {
|
||||||
public class FeedEntryService extends GenericDAO<FeedEntry> {
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedSubscriptionService feedSubscriptionService;
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedEntryDAO feedEntryDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||||
|
|
||||||
public void updateEntries(String url, Collection<FeedEntry> entries) {
|
public void updateEntries(String url, Collection<FeedEntry> entries) {
|
||||||
Feed feed = feedService.findByUrl(url);
|
Feed feed = feedDAO.findByUrl(url);
|
||||||
List<String> guids = Lists.newArrayList();
|
List<String> guids = Lists.newArrayList();
|
||||||
for (FeedEntry entry : entries) {
|
for (FeedEntry entry : entries) {
|
||||||
guids.add(entry.getGuid());
|
guids.add(entry.getGuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FeedEntry> existingEntries = guids.isEmpty() ? new ArrayList<FeedEntry>()
|
List<FeedEntry> existingEntries = guids.isEmpty() ? new ArrayList<FeedEntry>()
|
||||||
: findByGuids(guids);
|
: feedEntryDAO.findByGuids(guids);
|
||||||
for (FeedEntry entry : entries) {
|
for (FeedEntry entry : entries) {
|
||||||
FeedEntry foundEntry = null;
|
FeedEntry foundEntry = null;
|
||||||
for (FeedEntry existingEntry : existingEntries) {
|
for (FeedEntry existingEntry : existingEntries) {
|
||||||
@@ -72,34 +75,15 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
|||||||
|
|
||||||
private void addFeedToEntry(FeedEntry entry, Feed feed) {
|
private void addFeedToEntry(FeedEntry entry, Feed feed) {
|
||||||
entry.getFeeds().add(feed);
|
entry.getFeeds().add(feed);
|
||||||
saveOrUpdate(entry);
|
feedEntryDAO.saveOrUpdate(entry);
|
||||||
List<FeedSubscription> subscriptions = feedSubscriptionService
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||||
.findByFeed(feed);
|
.findByFeed(feed);
|
||||||
for (FeedSubscription sub : subscriptions) {
|
for (FeedSubscription sub : subscriptions) {
|
||||||
FeedEntryStatus status = new FeedEntryStatus();
|
FeedEntryStatus status = new FeedEntryStatus();
|
||||||
status.setEntry(entry);
|
status.setEntry(entry);
|
||||||
status.setSubscription(sub);
|
status.setSubscription(sub);
|
||||||
em.persist(status);
|
feedEntryStatusDAO.save(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntry> findByGuids(List<String> guids) {
|
|
||||||
EasyCriteria<FeedEntry> criteria = createCriteria();
|
|
||||||
criteria.setDistinctTrue();
|
|
||||||
criteria.andStringIn(MF.i(proxy().getGuid()), guids);
|
|
||||||
criteria.leftJoinFetch(MF.i(proxy().getFeeds()));
|
|
||||||
return criteria.getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FeedEntry> findByFeed(Feed feed, int offset, int limit) {
|
|
||||||
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
|
||||||
Root<FeedEntry> root = query.from(getType());
|
|
||||||
query.where(builder.isMember(feed, root.get(FeedEntry_.feeds)));
|
|
||||||
query.orderBy(builder.desc(root.get(FeedEntry_.updated)));
|
|
||||||
TypedQuery<FeedEntry> q = em.createQuery(query);
|
|
||||||
q.setFirstResult(offset);
|
|
||||||
q.setMaxResults(limit);
|
|
||||||
return q.getResultList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.commafeed.backend.security;
|
package com.commafeed.backend.services;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
@@ -13,14 +13,14 @@ import javax.ejb.Singleton;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.UserService;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
|
|
||||||
// http://www.javacodegeeks.com/2012/05/secure-password-storage-donts-dos-and.html
|
// http://www.javacodegeeks.com/2012/05/secure-password-storage-donts-dos-and.html
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PasswordEncryptionService {
|
public class PasswordEncryptionService {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(UserService.class);
|
.getLogger(UserDAO.class);
|
||||||
|
|
||||||
public boolean authenticate(String attemptedPassword,
|
public boolean authenticate(String attemptedPassword,
|
||||||
byte[] encryptedPassword, byte[] salt) {
|
byte[] encryptedPassword, byte[] salt) {
|
||||||
@@ -1,39 +1,26 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.services;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.NoResultException;
|
|
||||||
import javax.persistence.TypedQuery;
|
|
||||||
|
|
||||||
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
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.commafeed.backend.security.PasswordEncryptionService;
|
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@SuppressWarnings("serial")
|
public class UserService {
|
||||||
public class UserService extends GenericDAO<User> {
|
|
||||||
|
@Inject
|
||||||
|
UserDAO userDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PasswordEncryptionService encryptionService;
|
PasswordEncryptionService encryptionService;
|
||||||
|
|
||||||
public User findByName(String name) {
|
|
||||||
TypedQuery<User> query = em.createNamedQuery("User.byName", User.class);
|
|
||||||
query.setParameter("name", name.toLowerCase());
|
|
||||||
|
|
||||||
User user = null;
|
|
||||||
try {
|
|
||||||
user = query.getSingleResult();
|
|
||||||
} catch (NoResultException e) {
|
|
||||||
user = null;
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User login(String name, String password) {
|
public User login(String name, String password) {
|
||||||
User user = findByName(name);
|
User user = userDAO.findByName(name);
|
||||||
if (user != null && !user.isDisabled()) {
|
if (user != null && !user.isDisabled()) {
|
||||||
boolean authenticated = encryptionService.authenticate(password,
|
boolean authenticated = encryptionService.authenticate(password,
|
||||||
user.getPassword(), user.getSalt());
|
user.getPassword(), user.getSalt());
|
||||||
@@ -51,7 +38,7 @@ public class UserService extends GenericDAO<User> {
|
|||||||
|
|
||||||
public User register(String name, String password, String email,
|
public User register(String name, String password, String email,
|
||||||
Collection<Role> roles) {
|
Collection<Role> roles) {
|
||||||
if (findByName(name) != null) {
|
if (userDAO.findByName(name) != null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
User user = new User();
|
User user = new User();
|
||||||
@@ -65,7 +52,7 @@ public class UserService extends GenericDAO<User> {
|
|||||||
user.getRoles().add(new UserRole(user, role));
|
user.getRoles().add(new UserRole(user, role));
|
||||||
user.getRoles().add(new UserRole(user, role));
|
user.getRoles().add(new UserRole(user, role));
|
||||||
}
|
}
|
||||||
save(user);
|
userDAO.save(user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@ import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
|
|||||||
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
|
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
|
||||||
import org.apache.wicket.request.Request;
|
import org.apache.wicket.request.Request;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.UserRoleService;
|
import com.commafeed.backend.dao.UserRoleDAO;
|
||||||
import com.commafeed.backend.dao.UserService;
|
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
|
import com.commafeed.backend.services.UserService;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@@ -22,7 +22,7 @@ public class CommaFeedSession extends AuthenticatedWebSession {
|
|||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserRoleService userRoleService;
|
UserRoleDAO userRoleDAO;
|
||||||
|
|
||||||
private User user;
|
private User user;
|
||||||
private Roles roles = new Roles();
|
private Roles roles = new Roles();
|
||||||
@@ -57,7 +57,7 @@ public class CommaFeedSession extends AuthenticatedWebSession {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
Set<String> roleSet = Sets.newHashSet();
|
Set<String> roleSet = Sets.newHashSet();
|
||||||
for (Role role : userRoleService.getRoles(user)) {
|
for (Role role : userRoleDAO.findRoles(user)) {
|
||||||
roleSet.add(role.name());
|
roleSet.add(role.name());
|
||||||
}
|
}
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import javax.inject.Inject;
|
|||||||
import org.apache.wicket.markup.head.IHeaderResponse;
|
import org.apache.wicket.markup.head.IHeaderResponse;
|
||||||
import org.apache.wicket.markup.html.WebPage;
|
import org.apache.wicket.markup.html.WebPage;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedCategoryService;
|
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryService;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryStatusService;
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
import com.commafeed.backend.dao.FeedService;
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
import com.commafeed.backend.dao.UserRoleService;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.dao.UserService;
|
import com.commafeed.backend.dao.UserRoleDAO;
|
||||||
import com.commafeed.backend.dao.UserSettingsService;
|
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||||
|
|
||||||
import de.agilecoders.wicket.Bootstrap;
|
import de.agilecoders.wicket.Bootstrap;
|
||||||
|
|
||||||
@@ -20,28 +20,28 @@ import de.agilecoders.wicket.Bootstrap;
|
|||||||
public class BasePage extends WebPage {
|
public class BasePage extends WebPage {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FeedService feedService;
|
protected FeedDAO feedDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FeedSubscriptionService feedSubscriptionService;
|
protected FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FeedCategoryService feedCategoryService;
|
protected FeedCategoryDAO feedCategoryDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FeedEntryService feedEntryService;
|
protected FeedEntryDAO feedEntryDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected FeedEntryStatusService feedEntryStatusService;
|
protected FeedEntryStatusDAO feedEntryStatusDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected UserService userService;
|
protected UserDAO userDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected UserSettingsService userSettingsService;
|
protected UserSettingsDAO userSettingsDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected UserRoleService userRoleService;
|
protected UserRoleDAO userRoleDAO;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderHead(IHeaderResponse response) {
|
public void renderHead(IHeaderResponse response) {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import org.apache.wicket.request.UrlRenderer;
|
|||||||
import org.apache.wicket.request.cycle.RequestCycle;
|
import org.apache.wicket.request.cycle.RequestCycle;
|
||||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.ApplicationSettingsService;
|
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||||
import com.commafeed.backend.dao.UserService;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.feeds.OPMLImporter;
|
import com.commafeed.backend.feeds.OPMLImporter;
|
||||||
import com.commafeed.backend.model.ApplicationSettings;
|
import com.commafeed.backend.model.ApplicationSettings;
|
||||||
import com.commafeed.frontend.utils.WicketUtils;
|
import com.commafeed.frontend.utils.WicketUtils;
|
||||||
@@ -33,13 +33,13 @@ public class GoogleImportCallbackPage extends WebPage {
|
|||||||
private static final String EXPORT_URL = "https://www.google.com/reader/subscriptions/export";
|
private static final String EXPORT_URL = "https://www.google.com/reader/subscriptions/export";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsDAO applicationSettingsDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OPMLImporter importer;
|
OPMLImporter importer;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserService userService;
|
UserDAO userDAO;
|
||||||
|
|
||||||
public static String getCallbackUrl() {
|
public static String getCallbackUrl() {
|
||||||
RequestCycle cycle = RequestCycle.get();
|
RequestCycle cycle = RequestCycle.get();
|
||||||
@@ -65,7 +65,7 @@ public class GoogleImportCallbackPage extends WebPage {
|
|||||||
} else if (code == null) {
|
} else if (code == null) {
|
||||||
throw new DisplayException("Missing authorization code");
|
throw new DisplayException("Missing authorization code");
|
||||||
} else {
|
} else {
|
||||||
ApplicationSettings settings = applicationSettingsService.get();
|
ApplicationSettings settings = applicationSettingsDAO.get();
|
||||||
String redirectUri = getCallbackUrl();
|
String redirectUri = getCallbackUrl();
|
||||||
String clientId = settings.getGoogleClientId();
|
String clientId = settings.getGoogleClientId();
|
||||||
String clientSecret = settings.getGoogleClientSecret();
|
String clientSecret = settings.getGoogleClientSecret();
|
||||||
@@ -90,7 +90,7 @@ public class GoogleImportCallbackPage extends WebPage {
|
|||||||
httpRequest, accessToken);
|
httpRequest, accessToken);
|
||||||
String opml = httpRequest.execute().parseAsString();
|
String opml = httpRequest.execute().parseAsString();
|
||||||
String state = responseUrl.getState();
|
String state = responseUrl.getState();
|
||||||
importer.importOpml(userService.findById(Long.valueOf(state)),
|
importer.importOpml(userDAO.findById(Long.valueOf(state)),
|
||||||
opml);
|
opml);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DisplayException(e);
|
throw new DisplayException(e);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.apache.wicket.markup.html.WebPage;
|
|||||||
import org.apache.wicket.request.flow.RedirectToUrlException;
|
import org.apache.wicket.request.flow.RedirectToUrlException;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.ApplicationSettingsService;
|
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||||
import com.commafeed.backend.model.ApplicationSettings;
|
import com.commafeed.backend.model.ApplicationSettings;
|
||||||
import com.commafeed.frontend.CommaFeedSession;
|
import com.commafeed.frontend.CommaFeedSession;
|
||||||
|
|
||||||
@@ -23,11 +23,11 @@ public class GoogleImportRedirectPage extends WebPage {
|
|||||||
private static final String AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
|
private static final String AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsDAO applicationSettingsDAO;
|
||||||
|
|
||||||
public GoogleImportRedirectPage() {
|
public GoogleImportRedirectPage() {
|
||||||
|
|
||||||
ApplicationSettings settings = applicationSettingsService.get();
|
ApplicationSettings settings = applicationSettingsDAO.get();
|
||||||
|
|
||||||
String clientId = settings.getGoogleClientId();
|
String clientId = settings.getGoogleClientId();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.apache.wicket.markup.head.IHeaderResponse;
|
|||||||
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
|
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
|
||||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.UserSettingsService;
|
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
import com.commafeed.backend.model.UserSettings;
|
import com.commafeed.backend.model.UserSettings;
|
||||||
import com.commafeed.frontend.CommaFeedSession;
|
import com.commafeed.frontend.CommaFeedSession;
|
||||||
@@ -34,7 +34,7 @@ import de.agilecoders.wicket.markup.html.bootstrap.extensions.icon.OpenWebIconsC
|
|||||||
public class HomePage extends BasePage {
|
public class HomePage extends BasePage {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserSettingsService settingsService;
|
UserSettingsDAO userSettingsDAO;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderHead(IHeaderResponse response) {
|
public void renderHead(IHeaderResponse response) {
|
||||||
@@ -67,7 +67,7 @@ public class HomePage extends BasePage {
|
|||||||
new UserCustomCssReference() {
|
new UserCustomCssReference() {
|
||||||
@Override
|
@Override
|
||||||
protected String getCss() {
|
protected String getCss() {
|
||||||
UserSettings settings = settingsService
|
UserSettings settings = userSettingsDAO
|
||||||
.findByUser(CommaFeedSession.get().getUser());
|
.findByUser(CommaFeedSession.get().getUser());
|
||||||
return settings == null ? null : settings
|
return settings == null ? null : settings
|
||||||
.getCustomCss();
|
.getCustomCss();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import org.apache.wicket.markup.head.IHeaderResponse;
|
import org.apache.wicket.markup.head.IHeaderResponse;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.ApplicationSettingsService;
|
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||||
import com.commafeed.frontend.pages.components.LoginPanel;
|
import com.commafeed.frontend.pages.components.LoginPanel;
|
||||||
import com.commafeed.frontend.pages.components.RegisterPanel;
|
import com.commafeed.frontend.pages.components.RegisterPanel;
|
||||||
import com.commafeed.frontend.utils.WicketUtils;
|
import com.commafeed.frontend.utils.WicketUtils;
|
||||||
@@ -13,7 +13,7 @@ import com.commafeed.frontend.utils.WicketUtils;
|
|||||||
public class WelcomePage extends BasePage {
|
public class WelcomePage extends BasePage {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsDAO applicationSettingsDAO;
|
||||||
|
|
||||||
public WelcomePage() {
|
public WelcomePage() {
|
||||||
add(new LoginPanel("login"));
|
add(new LoginPanel("login"));
|
||||||
@@ -21,7 +21,7 @@ public class WelcomePage extends BasePage {
|
|||||||
@Override
|
@Override
|
||||||
protected void onConfigure() {
|
protected void onConfigure() {
|
||||||
super.onConfigure();
|
super.onConfigure();
|
||||||
setVisibilityAllowed(applicationSettingsService.get()
|
setVisibilityAllowed(applicationSettingsDAO.get()
|
||||||
.isAllowRegistrations());
|
.isAllowRegistrations());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ import org.apache.wicket.validation.IValidator;
|
|||||||
import org.apache.wicket.validation.ValidationError;
|
import org.apache.wicket.validation.ValidationError;
|
||||||
import org.apache.wicket.validation.validator.StringValidator;
|
import org.apache.wicket.validation.validator.StringValidator;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.ApplicationSettingsService;
|
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||||
import com.commafeed.backend.dao.UserService;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
|
import com.commafeed.backend.services.UserService;
|
||||||
import com.commafeed.frontend.CommaFeedSession;
|
import com.commafeed.frontend.CommaFeedSession;
|
||||||
import com.commafeed.frontend.model.RegistrationRequest;
|
import com.commafeed.frontend.model.RegistrationRequest;
|
||||||
import com.commafeed.frontend.pages.GoogleImportRedirectPage;
|
import com.commafeed.frontend.pages.GoogleImportRedirectPage;
|
||||||
@@ -32,11 +33,14 @@ import com.commafeed.frontend.utils.ModelFactory.MF;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class RegisterPanel extends Panel {
|
public class RegisterPanel extends Panel {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
UserDAO userDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsDAO applicationSettingsDAO;
|
||||||
|
|
||||||
public RegisterPanel(String markupId) {
|
public RegisterPanel(String markupId) {
|
||||||
super(markupId);
|
super(markupId);
|
||||||
@@ -47,7 +51,7 @@ public class RegisterPanel extends Panel {
|
|||||||
"form", model) {
|
"form", model) {
|
||||||
@Override
|
@Override
|
||||||
protected void onSubmit() {
|
protected void onSubmit() {
|
||||||
if (applicationSettingsService.get().isAllowRegistrations()) {
|
if (applicationSettingsDAO.get().isAllowRegistrations()) {
|
||||||
RegistrationRequest req = getModelObject();
|
RegistrationRequest req = getModelObject();
|
||||||
userService.register(req.getName(), req.getPassword(),
|
userService.register(req.getName(), req.getPassword(),
|
||||||
Arrays.asList(Role.USER));
|
Arrays.asList(Role.USER));
|
||||||
@@ -79,7 +83,7 @@ public class RegisterPanel extends Panel {
|
|||||||
public void validate(
|
public void validate(
|
||||||
IValidatable<String> validatable) {
|
IValidatable<String> validatable) {
|
||||||
String name = validatable.getValue();
|
String name = validatable.getValue();
|
||||||
User user = userService.findByName(name);
|
User user = userDAO.findByName(name);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
validatable.error(new ValidationError(
|
validatable.error(new ValidationError(
|
||||||
"Name is already taken."));
|
"Name is already taken."));
|
||||||
|
|||||||
@@ -23,19 +23,21 @@ import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
|
|||||||
import org.apache.wicket.protocol.http.servlet.ServletWebResponse;
|
import org.apache.wicket.protocol.http.servlet.ServletWebResponse;
|
||||||
import org.apache.wicket.request.cycle.RequestCycle;
|
import org.apache.wicket.request.cycle.RequestCycle;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedCategoryService;
|
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryService;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryStatusService;
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
import com.commafeed.backend.dao.FeedService;
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
import com.commafeed.backend.dao.UserRoleService;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.dao.UserService;
|
import com.commafeed.backend.dao.UserRoleDAO;
|
||||||
import com.commafeed.backend.dao.UserSettingsService;
|
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||||
import com.commafeed.backend.feeds.FeedFetcher;
|
import com.commafeed.backend.feeds.FeedFetcher;
|
||||||
import com.commafeed.backend.feeds.OPMLImporter;
|
import com.commafeed.backend.feeds.OPMLImporter;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
import com.commafeed.backend.security.PasswordEncryptionService;
|
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||||
|
import com.commafeed.backend.services.PasswordEncryptionService;
|
||||||
|
import com.commafeed.backend.services.UserService;
|
||||||
import com.commafeed.frontend.CommaFeedApplication;
|
import com.commafeed.frontend.CommaFeedApplication;
|
||||||
import com.commafeed.frontend.CommaFeedSession;
|
import com.commafeed.frontend.CommaFeedSession;
|
||||||
import com.commafeed.frontend.SecurityCheck;
|
import com.commafeed.frontend.SecurityCheck;
|
||||||
@@ -52,28 +54,34 @@ public abstract class AbstractREST {
|
|||||||
HttpServletResponse response;
|
HttpServletResponse response;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedSubscriptionService feedSubscriptionService;
|
FeedSubscriptionService feedSubscriptionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedCategoryService feedCategoryService;
|
FeedCategoryDAO feedCategoryDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedEntryService feedEntryService;
|
FeedEntryDAO feedEntryDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedEntryStatusService feedEntryStatusService;
|
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
UserDAO userDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserSettingsService userSettingsService;
|
UserSettingsDAO userSettingsDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
UserRoleService userRoleService;
|
UserRoleDAO userRoleDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OPMLImporter opmlImporter;
|
OPMLImporter opmlImporter;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import javax.ws.rs.POST;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.ApplicationSettingsService;
|
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||||
import com.commafeed.backend.model.ApplicationSettings;
|
import com.commafeed.backend.model.ApplicationSettings;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
import com.commafeed.frontend.SecurityCheck;
|
import com.commafeed.frontend.SecurityCheck;
|
||||||
@@ -16,18 +16,18 @@ import com.commafeed.frontend.SecurityCheck;
|
|||||||
public class AdminSettingsREST {
|
public class AdminSettingsREST {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsDAO applicationSettingsDAO;
|
||||||
|
|
||||||
@Path("get")
|
@Path("get")
|
||||||
@GET
|
@GET
|
||||||
public ApplicationSettings get() {
|
public ApplicationSettings get() {
|
||||||
return applicationSettingsService.get();
|
return applicationSettingsDAO.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("save")
|
@Path("save")
|
||||||
@POST
|
@POST
|
||||||
public Response save(ApplicationSettings settings) {
|
public Response save(ApplicationSettings settings) {
|
||||||
applicationSettingsService.save(settings);
|
applicationSettingsDAO.save(settings);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
.entity("User already exists.").build();
|
.entity("User already exists.").build();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
User user = userService.findById(id);
|
User user = userDAO.findById(id);
|
||||||
if (StartupBean.ADMIN_NAME.equals(user.getName())
|
if (StartupBean.ADMIN_NAME.equals(user.getName())
|
||||||
&& !userModel.isEnabled()) {
|
&& !userModel.isEnabled()) {
|
||||||
return Response.status(Status.FORBIDDEN)
|
return Response.status(Status.FORBIDDEN)
|
||||||
@@ -62,11 +62,11 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
userModel.getPassword(), user.getSalt()));
|
userModel.getPassword(), user.getSalt()));
|
||||||
}
|
}
|
||||||
user.setDisabled(!userModel.isEnabled());
|
user.setDisabled(!userModel.isEnabled());
|
||||||
userService.update(user);
|
userDAO.update(user);
|
||||||
|
|
||||||
Set<Role> roles = userRoleService.getRoles(user);
|
Set<Role> roles = userRoleDAO.findRoles(user);
|
||||||
if (userModel.isAdmin() && !roles.contains(Role.ADMIN)) {
|
if (userModel.isAdmin() && !roles.contains(Role.ADMIN)) {
|
||||||
userRoleService.save(new UserRole(user, Role.ADMIN));
|
userRoleDAO.save(new UserRole(user, Role.ADMIN));
|
||||||
} else if (!userModel.isAdmin() && roles.contains(Role.ADMIN)) {
|
} else if (!userModel.isAdmin() && roles.contains(Role.ADMIN)) {
|
||||||
if (StartupBean.ADMIN_NAME.equals(user.getName())) {
|
if (StartupBean.ADMIN_NAME.equals(user.getName())) {
|
||||||
return Response
|
return Response
|
||||||
@@ -74,9 +74,9 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
.entity("You cannot remove the admin role from the admin user.")
|
.entity("You cannot remove the admin role from the admin user.")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
for (UserRole userRole : userRoleService.findAll(user)) {
|
for (UserRole userRole : userRoleDAO.findAll(user)) {
|
||||||
if (userRole.getRole() == Role.ADMIN) {
|
if (userRole.getRole() == Role.ADMIN) {
|
||||||
userRoleService.delete(userRole);
|
userRoleDAO.delete(userRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,12 +89,12 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
@Path("get")
|
@Path("get")
|
||||||
@GET
|
@GET
|
||||||
public UserModel getUser(@QueryParam("id") Long id) {
|
public UserModel getUser(@QueryParam("id") Long id) {
|
||||||
User user = userService.findById(id);
|
User user = userDAO.findById(id);
|
||||||
UserModel userModel = new UserModel();
|
UserModel userModel = new UserModel();
|
||||||
userModel.setId(user.getId());
|
userModel.setId(user.getId());
|
||||||
userModel.setName(user.getName());
|
userModel.setName(user.getName());
|
||||||
userModel.setEnabled(!user.isDisabled());
|
userModel.setEnabled(!user.isDisabled());
|
||||||
for (UserRole role : userRoleService.findAll(user)) {
|
for (UserRole role : userRoleDAO.findAll(user)) {
|
||||||
if (role.getRole() == Role.ADMIN) {
|
if (role.getRole() == Role.ADMIN) {
|
||||||
userModel.setAdmin(true);
|
userModel.setAdmin(true);
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
@GET
|
@GET
|
||||||
public Collection<UserModel> getUsers() {
|
public Collection<UserModel> getUsers() {
|
||||||
Map<Long, UserModel> users = Maps.newHashMap();
|
Map<Long, UserModel> users = Maps.newHashMap();
|
||||||
for (UserRole role : userRoleService.findAll()) {
|
for (UserRole role : userRoleDAO.findAll()) {
|
||||||
User user = role.getUser();
|
User user = role.getUser();
|
||||||
Long key = user.getId();
|
Long key = user.getId();
|
||||||
UserModel userModel = users.get(key);
|
UserModel userModel = users.get(key);
|
||||||
@@ -127,7 +127,7 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
@Path("delete")
|
@Path("delete")
|
||||||
@GET
|
@GET
|
||||||
public Response delete(@QueryParam("id") Long id) {
|
public Response delete(@QueryParam("id") Long id) {
|
||||||
User user = userService.findById(id);
|
User user = userDAO.findById(id);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return Response.status(Status.NOT_FOUND).build();
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
@@ -135,13 +135,13 @@ public class AdminUsersREST extends AbstractREST {
|
|||||||
return Response.status(Status.FORBIDDEN)
|
return Response.status(Status.FORBIDDEN)
|
||||||
.entity("You cannot delete the admin user.").build();
|
.entity("You cannot delete the admin user.").build();
|
||||||
}
|
}
|
||||||
feedEntryStatusService.delete(feedEntryStatusService.getStatuses(user,
|
feedEntryStatusDAO.delete(feedEntryStatusDAO.findAll(user,
|
||||||
false, ReadingOrder.desc, false));
|
false, ReadingOrder.desc, false));
|
||||||
feedSubscriptionService.delete(feedSubscriptionService.findAll(user));
|
feedSubscriptionDAO.delete(feedSubscriptionDAO.findAll(user));
|
||||||
feedCategoryService.delete(feedCategoryService.findAll(user));
|
feedCategoryDAO.delete(feedCategoryDAO.findAll(user));
|
||||||
userSettingsService.delete(userSettingsService.findByUser(user));
|
userSettingsDAO.delete(userSettingsDAO.findByUser(user));
|
||||||
userRoleService.delete(userRoleService.findAll(user));
|
userRoleDAO.delete(userRoleDAO.findAll(user));
|
||||||
userService.delete(user);
|
userDAO.delete(user);
|
||||||
|
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,15 +54,15 @@ public class EntriesREST extends AbstractREST {
|
|||||||
boolean unreadOnly = readType == ReadType.unread;
|
boolean unreadOnly = readType == ReadType.unread;
|
||||||
|
|
||||||
if (type == Type.feed) {
|
if (type == Type.feed) {
|
||||||
FeedSubscription subscription = feedSubscriptionService.findById(
|
FeedSubscription subscription = feedSubscriptionDAO.findById(
|
||||||
getUser(), Long.valueOf(id));
|
getUser(), Long.valueOf(id));
|
||||||
if (subscription != null) {
|
if (subscription != null) {
|
||||||
entries.setName(subscription.getTitle());
|
entries.setName(subscription.getTitle());
|
||||||
entries.setMessage(subscription.getFeed().getMessage());
|
entries.setMessage(subscription.getFeed().getMessage());
|
||||||
entries.setErrorCount(subscription.getFeed().getErrorCount());
|
entries.setErrorCount(subscription.getFeed().getErrorCount());
|
||||||
|
|
||||||
List<FeedEntryStatus> unreadEntries = feedEntryStatusService
|
List<FeedEntryStatus> unreadEntries = feedEntryStatusDAO
|
||||||
.getStatuses(subscription.getFeed(), getUser(),
|
.findByFeed(subscription.getFeed(), getUser(),
|
||||||
unreadOnly, offset, limit, order, true);
|
unreadOnly, offset, limit, order, true);
|
||||||
for (FeedEntryStatus status : unreadEntries) {
|
for (FeedEntryStatus status : unreadEntries) {
|
||||||
entries.getEntries().add(buildEntry(status));
|
entries.getEntries().add(buildEntry(status));
|
||||||
@@ -73,21 +73,21 @@ public class EntriesREST extends AbstractREST {
|
|||||||
|
|
||||||
if (ALL.equals(id)) {
|
if (ALL.equals(id)) {
|
||||||
entries.setName("All");
|
entries.setName("All");
|
||||||
List<FeedEntryStatus> unreadEntries = feedEntryStatusService
|
List<FeedEntryStatus> unreadEntries = feedEntryStatusDAO
|
||||||
.getStatuses(getUser(), unreadOnly, offset, limit,
|
.findAll(getUser(), unreadOnly, offset, limit,
|
||||||
order, true);
|
order, true);
|
||||||
for (FeedEntryStatus status : unreadEntries) {
|
for (FeedEntryStatus status : unreadEntries) {
|
||||||
entries.getEntries().add(buildEntry(status));
|
entries.getEntries().add(buildEntry(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
FeedCategory feedCategory = feedCategoryService.findById(
|
FeedCategory feedCategory = feedCategoryDAO.findById(
|
||||||
getUser(), Long.valueOf(id));
|
getUser(), Long.valueOf(id));
|
||||||
if (feedCategory != null) {
|
if (feedCategory != null) {
|
||||||
List<FeedCategory> childrenCategories = feedCategoryService
|
List<FeedCategory> childrenCategories = feedCategoryDAO
|
||||||
.findAllChildrenCategories(getUser(), feedCategory);
|
.findAllChildrenCategories(getUser(), feedCategory);
|
||||||
List<FeedEntryStatus> unreadEntries = feedEntryStatusService
|
List<FeedEntryStatus> unreadEntries = feedEntryStatusDAO
|
||||||
.getStatuses(childrenCategories, getUser(),
|
.findByCategories(childrenCategories, getUser(),
|
||||||
unreadOnly, offset, limit, order, true);
|
unreadOnly, offset, limit, order, true);
|
||||||
for (FeedEntryStatus status : unreadEntries) {
|
for (FeedEntryStatus status : unreadEntries) {
|
||||||
entries.getEntries().add(buildEntry(status));
|
entries.getEntries().add(buildEntry(status));
|
||||||
@@ -136,15 +136,15 @@ public class EntriesREST extends AbstractREST {
|
|||||||
olderThanTimestamp);
|
olderThanTimestamp);
|
||||||
|
|
||||||
if (type == Type.entry) {
|
if (type == Type.entry) {
|
||||||
FeedEntryStatus status = feedEntryStatusService.findById(getUser(),
|
FeedEntryStatus status = feedEntryStatusDAO.findById(getUser(),
|
||||||
Long.valueOf(id));
|
Long.valueOf(id));
|
||||||
status.setRead(read);
|
status.setRead(read);
|
||||||
feedEntryStatusService.update(status);
|
feedEntryStatusDAO.update(status);
|
||||||
} else if (type == Type.feed) {
|
} else if (type == Type.feed) {
|
||||||
if (read) {
|
if (read) {
|
||||||
FeedSubscription subscription = feedSubscriptionService
|
FeedSubscription subscription = feedSubscriptionDAO
|
||||||
.findById(getUser(), Long.valueOf(id));
|
.findById(getUser(), Long.valueOf(id));
|
||||||
feedEntryStatusService.markFeedEntries(getUser(),
|
feedEntryStatusDAO.markFeedEntries(getUser(),
|
||||||
subscription.getFeed(), olderThan);
|
subscription.getFeed(), olderThan);
|
||||||
} else {
|
} else {
|
||||||
throw new WebApplicationException(Response.status(
|
throw new WebApplicationException(Response.status(
|
||||||
@@ -153,13 +153,13 @@ public class EntriesREST extends AbstractREST {
|
|||||||
} else if (type == Type.category) {
|
} else if (type == Type.category) {
|
||||||
if (read) {
|
if (read) {
|
||||||
if (ALL.equals(id)) {
|
if (ALL.equals(id)) {
|
||||||
feedEntryStatusService.markAllEntries(getUser(), olderThan);
|
feedEntryStatusDAO.markAllEntries(getUser(), olderThan);
|
||||||
} else {
|
} else {
|
||||||
List<FeedCategory> categories = feedCategoryService
|
List<FeedCategory> categories = feedCategoryDAO
|
||||||
.findAllChildrenCategories(getUser(),
|
.findAllChildrenCategories(getUser(),
|
||||||
feedCategoryService.findById(getUser(),
|
feedCategoryDAO.findById(getUser(),
|
||||||
Long.valueOf(id)));
|
Long.valueOf(id)));
|
||||||
feedEntryStatusService.markCategoryEntries(getUser(),
|
feedEntryStatusDAO.markCategoryEntries(getUser(),
|
||||||
categories, olderThan);
|
categories, olderThan);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -180,8 +180,8 @@ public class EntriesREST extends AbstractREST {
|
|||||||
Entries entries = new Entries();
|
Entries entries = new Entries();
|
||||||
|
|
||||||
List<Entry> list = Lists.newArrayList();
|
List<Entry> list = Lists.newArrayList();
|
||||||
List<FeedEntryStatus> entriesStatus = feedEntryStatusService
|
List<FeedEntryStatus> entriesStatus = feedEntryStatusDAO
|
||||||
.getStatusesByKeywords(getUser(), keywords, offset, limit, true);
|
.findByKeywords(getUser(), keywords, offset, limit, true);
|
||||||
for (FeedEntryStatus status : entriesStatus) {
|
for (FeedEntryStatus status : entriesStatus) {
|
||||||
list.add(buildEntry(status));
|
list.add(buildEntry(status));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class SessionREST extends AbstractREST {
|
|||||||
userModel.setId(user.getId());
|
userModel.setId(user.getId());
|
||||||
userModel.setName(user.getName());
|
userModel.setName(user.getName());
|
||||||
userModel.setEnabled(!user.isDisabled());
|
userModel.setEnabled(!user.isDisabled());
|
||||||
for (UserRole role : userRoleService.findAll(user)) {
|
for (UserRole role : userRoleDAO.findAll(user)) {
|
||||||
if (role.getRole() == Role.ADMIN) {
|
if (role.getRole() == Role.ADMIN) {
|
||||||
userModel.setAdmin(true);
|
userModel.setAdmin(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class SettingsREST extends AbstractREST {
|
|||||||
@GET
|
@GET
|
||||||
public Settings get() {
|
public Settings get() {
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
UserSettings settings = userSettingsService.findByUser(getUser());
|
UserSettings settings = userSettingsDAO.findByUser(getUser());
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
s.setReadingMode(settings.getReadingMode().name());
|
s.setReadingMode(settings.getReadingMode().name());
|
||||||
s.setReadingOrder(settings.getReadingOrder().name());
|
s.setReadingOrder(settings.getReadingOrder().name());
|
||||||
@@ -36,7 +36,7 @@ public class SettingsREST extends AbstractREST {
|
|||||||
public Response save(Settings settings) {
|
public Response save(Settings settings) {
|
||||||
Preconditions.checkNotNull(settings);
|
Preconditions.checkNotNull(settings);
|
||||||
|
|
||||||
UserSettings s = userSettingsService.findByUser(getUser());
|
UserSettings s = userSettingsDAO.findByUser(getUser());
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
s = new UserSettings();
|
s = new UserSettings();
|
||||||
s.setUser(getUser());
|
s.setUser(getUser());
|
||||||
@@ -44,7 +44,7 @@ public class SettingsREST extends AbstractREST {
|
|||||||
s.setReadingMode(ReadingMode.valueOf(settings.getReadingMode()));
|
s.setReadingMode(ReadingMode.valueOf(settings.getReadingMode()));
|
||||||
s.setReadingOrder(ReadingOrder.valueOf(settings.getReadingOrder()));
|
s.setReadingOrder(ReadingOrder.valueOf(settings.getReadingOrder()));
|
||||||
s.setCustomCss(settings.getCustomCss());
|
s.setCustomCss(settings.getCustomCss());
|
||||||
userSettingsService.saveOrUpdate(s);
|
userSettingsDAO.saveOrUpdate(s);
|
||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
String url = prependHttp(req.getUrl());
|
String url = prependHttp(req.getUrl());
|
||||||
|
|
||||||
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
|
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
|
||||||
: feedCategoryService
|
: feedCategoryDAO
|
||||||
.findById(Long.valueOf(req.getCategoryId()));
|
.findById(Long.valueOf(req.getCategoryId()));
|
||||||
Feed fetchedFeed = fetchFeed(url);
|
Feed fetchedFeed = fetchFeed(url);
|
||||||
feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(),
|
feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(),
|
||||||
@@ -80,10 +80,10 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
@GET
|
@GET
|
||||||
@Path("unsubscribe")
|
@Path("unsubscribe")
|
||||||
public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
|
public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
|
||||||
FeedSubscription sub = feedSubscriptionService.findById(getUser(),
|
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(),
|
||||||
subscriptionId);
|
subscriptionId);
|
||||||
if (sub != null) {
|
if (sub != null) {
|
||||||
feedSubscriptionService.delete(sub);
|
feedSubscriptionDAO.delete(sub);
|
||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Status.NOT_FOUND).build();
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
@@ -95,14 +95,14 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
public Response rename(@QueryParam("type") Type type,
|
public Response rename(@QueryParam("type") Type type,
|
||||||
@QueryParam("id") Long id, @QueryParam("name") String name) {
|
@QueryParam("id") Long id, @QueryParam("name") String name) {
|
||||||
if (type == Type.feed) {
|
if (type == Type.feed) {
|
||||||
FeedSubscription subscription = feedSubscriptionService.findById(
|
FeedSubscription subscription = feedSubscriptionDAO.findById(
|
||||||
getUser(), id);
|
getUser(), id);
|
||||||
subscription.setTitle(name);
|
subscription.setTitle(name);
|
||||||
feedSubscriptionService.update(subscription);
|
feedSubscriptionDAO.update(subscription);
|
||||||
} else if (type == Type.category) {
|
} else if (type == Type.category) {
|
||||||
FeedCategory category = feedCategoryService.findById(getUser(), id);
|
FeedCategory category = feedCategoryDAO.findById(getUser(), id);
|
||||||
category.setName(name);
|
category.setName(name);
|
||||||
feedCategoryService.update(category);
|
feedCategoryDAO.update(category);
|
||||||
}
|
}
|
||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
}
|
}
|
||||||
@@ -113,10 +113,10 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
@QueryParam("collapse") boolean collapse) {
|
@QueryParam("collapse") boolean collapse) {
|
||||||
Preconditions.checkNotNull(id);
|
Preconditions.checkNotNull(id);
|
||||||
if (!EntriesREST.ALL.equals(id)) {
|
if (!EntriesREST.ALL.equals(id)) {
|
||||||
FeedCategory category = feedCategoryService.findById(getUser(),
|
FeedCategory category = feedCategoryDAO.findById(getUser(),
|
||||||
Long.valueOf(id));
|
Long.valueOf(id));
|
||||||
category.setCollapsed(collapse);
|
category.setCollapsed(collapse);
|
||||||
feedCategoryService.update(category);
|
feedCategoryDAO.update(category);
|
||||||
}
|
}
|
||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
}
|
}
|
||||||
@@ -135,22 +135,22 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
parent.setId(Long.valueOf(parentId));
|
parent.setId(Long.valueOf(parentId));
|
||||||
cat.setParent(parent);
|
cat.setParent(parent);
|
||||||
}
|
}
|
||||||
feedCategoryService.save(cat);
|
feedCategoryDAO.save(cat);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("deleteCategory")
|
@Path("deleteCategory")
|
||||||
public Response deleteCategory(@QueryParam("id") Long id) {
|
public Response deleteCategory(@QueryParam("id") Long id) {
|
||||||
FeedCategory cat = feedCategoryService.findById(getUser(), id);
|
FeedCategory cat = feedCategoryDAO.findById(getUser(), id);
|
||||||
if (cat != null) {
|
if (cat != null) {
|
||||||
List<FeedSubscription> subs = feedSubscriptionService
|
List<FeedSubscription> subs = feedSubscriptionDAO
|
||||||
.findByCategory(getUser(), cat);
|
.findByCategory(getUser(), cat);
|
||||||
for (FeedSubscription sub : subs) {
|
for (FeedSubscription sub : subs) {
|
||||||
sub.setCategory(null);
|
sub.setCategory(null);
|
||||||
}
|
}
|
||||||
feedSubscriptionService.update(subs);
|
feedSubscriptionDAO.update(subs);
|
||||||
feedCategoryService.delete(cat);
|
feedCategoryDAO.delete(cat);
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Status.NOT_FOUND).build();
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
@@ -182,10 +182,10 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
@GET
|
@GET
|
||||||
public Category getSubscriptions() {
|
public Category getSubscriptions() {
|
||||||
|
|
||||||
List<FeedCategory> categories = feedCategoryService.findAll(getUser());
|
List<FeedCategory> categories = feedCategoryDAO.findAll(getUser());
|
||||||
List<FeedSubscription> subscriptions = feedSubscriptionService
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||||
.findAll(getUser());
|
.findAll(getUser());
|
||||||
Map<Long, Long> unreadCount = feedEntryStatusService
|
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
||||||
.getUnreadCount(getUser());
|
.getUnreadCount(getUser());
|
||||||
|
|
||||||
Category root = buildCategory(null, categories, subscriptions,
|
Category root = buildCategory(null, categories, subscriptions,
|
||||||
|
|||||||
Reference in New Issue
Block a user