mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
import OPML
This commit is contained in:
@@ -3,15 +3,45 @@ package com.commafeed.backend.dao;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedCategoryService extends GenericDAO<FeedCategory, Long> {
|
||||
|
||||
public List<FeedCategory> findAll(User user) {
|
||||
return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user);
|
||||
}
|
||||
|
||||
public FeedCategory findById(User user, Long id) {
|
||||
EasyCriteria<FeedCategory> criteria = createCriteria();
|
||||
criteria.andEquals(MF.i(proxy().getUser()), user);
|
||||
criteria.andEquals(MF.i(proxy().getId()), id);
|
||||
return Iterables.getFirst(criteria.getResultList(), null);
|
||||
}
|
||||
|
||||
public FeedCategory findByName(User user, String name, FeedCategory parent) {
|
||||
EasyCriteria<FeedCategory> criteria = createCriteria();
|
||||
criteria.andEquals(MF.i(proxy().getUser()), user);
|
||||
criteria.andEquals(MF.i(proxy().getName()), name);
|
||||
if (parent == null) {
|
||||
criteria.andIsNull(MF.i(proxy().getParent()));
|
||||
} else {
|
||||
criteria.andEquals(MF.i(proxy().getParent()), parent);
|
||||
}
|
||||
|
||||
FeedCategory category = null;
|
||||
try {
|
||||
category = criteria.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
category = null;
|
||||
}
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedEntryService extends GenericDAO<FeedEntry, Long> {
|
||||
|
||||
@Inject
|
||||
@@ -34,6 +35,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry, Long> {
|
||||
}
|
||||
}
|
||||
feed.setLastUpdated(Calendar.getInstance().getTime());
|
||||
feed.setMessage(null);
|
||||
em.merge(feed);
|
||||
}
|
||||
|
||||
@@ -45,7 +47,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry, Long> {
|
||||
typedQuery.setParameter("user", user);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
public List<FeedEntry> getAllEntries(Feed feed) {
|
||||
String query = "select e from FeedEntry e where e.feed=:feed";
|
||||
TypedQuery<FeedEntry> typedQuery = em.createQuery(query,
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.uaihebert.factory.EasyCriteriaFactory;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus, Long> {
|
||||
|
||||
public FeedEntryStatus getStatus(User user, FeedEntry entry) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedService extends GenericDAO<Feed, Long> {
|
||||
|
||||
public Feed findByUrl(String url) {
|
||||
|
||||
@@ -8,20 +8,37 @@ import javax.persistence.TypedQuery;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.uaihebert.factory.EasyCriteriaFactory;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long> {
|
||||
|
||||
@Inject
|
||||
FeedCategoryService feedCategoryService;
|
||||
|
||||
public FeedSubscription findById(User user, Long id) {
|
||||
EasyCriteria<FeedSubscription> criteria = createCriteria();
|
||||
criteria.andEquals(MF.i(proxy().getUser()), user);
|
||||
criteria.andEquals(MF.i(proxy().getId()), id);
|
||||
return Iterables.getFirst(criteria.getResultList(), null);
|
||||
}
|
||||
|
||||
public FeedSubscription findByFeed(User user, Feed feed) {
|
||||
EasyCriteria<FeedSubscription> criteria = createCriteria();
|
||||
criteria.andEquals(MF.i(proxy().getUser()), user);
|
||||
criteria.andEquals(MF.i(proxy().getFeed()), feed);
|
||||
return Iterables.getFirst(criteria.getResultList(), null);
|
||||
}
|
||||
|
||||
public List<FeedSubscription> findAll(User user) {
|
||||
return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user);
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@ public abstract class GenericDAO<T, K> implements
|
||||
protected Class<T> getType() {
|
||||
return (Class<T>) type.getRawType();
|
||||
}
|
||||
|
||||
public EasyCriteria<T> createCriteria(){
|
||||
return EasyCriteriaFactory.createQueryCriteria(em, getType());
|
||||
}
|
||||
|
||||
protected T proxy() {
|
||||
return MF.p(getType());
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class UserService extends GenericDAO<User, Long> {
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.uaihebert.factory.EasyCriteriaFactory;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class UserSettingsService extends GenericDAO<UserSettings, Long> {
|
||||
|
||||
public UserSettings findByUser(User user) {
|
||||
|
||||
Reference in New Issue
Block a user