import OPML

This commit is contained in:
Jeremie Panzer
2013-03-25 12:24:00 +01:00
parent fa18c80e84
commit f0c4733b76
30 changed files with 307 additions and 24 deletions

View File

@@ -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;
}
}

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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());

View File

@@ -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

View File

@@ -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) {