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