2013-04-18 12:50:44 +02:00
|
|
|
package com.commafeed.backend.services;
|
|
|
|
|
|
|
|
|
|
import javax.ejb.Stateless;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
|
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
2013-06-20 18:45:58 +02:00
|
|
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
|
|
|
|
import com.commafeed.backend.model.FeedEntry;
|
2013-04-18 12:50:44 +02:00
|
|
|
import com.commafeed.backend.model.FeedEntryStatus;
|
2013-06-20 18:45:58 +02:00
|
|
|
import com.commafeed.backend.model.FeedSubscription;
|
2013-04-18 12:50:44 +02:00
|
|
|
import com.commafeed.backend.model.User;
|
|
|
|
|
|
|
|
|
|
@Stateless
|
|
|
|
|
public class FeedEntryService {
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
FeedEntryStatusDAO feedEntryStatusDAO;
|
|
|
|
|
|
2013-06-20 18:45:58 +02:00
|
|
|
@Inject
|
|
|
|
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
|
|
|
|
|
|
|
|
|
public void markEntry(User user, Long entryId, Long subscriptionId,
|
|
|
|
|
boolean read) {
|
|
|
|
|
FeedSubscription sub = feedSubscriptionDAO.findById(user,
|
|
|
|
|
subscriptionId);
|
|
|
|
|
if (sub == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FeedEntry entry = new FeedEntry();
|
|
|
|
|
entry.setId(entryId);
|
|
|
|
|
|
|
|
|
|
FeedEntryStatus status = feedEntryStatusDAO.findByEntry(entry, sub);
|
|
|
|
|
|
|
|
|
|
if (read) {
|
|
|
|
|
if (status != null) {
|
|
|
|
|
if (status.isStarred()) {
|
|
|
|
|
status.setRead(true);
|
|
|
|
|
feedEntryStatusDAO.saveOrUpdate(status);
|
|
|
|
|
} else {
|
|
|
|
|
feedEntryStatusDAO.delete(status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (status == null) {
|
2013-07-14 05:48:47 +02:00
|
|
|
status = new FeedEntryStatus(user, sub, entry);
|
2013-06-20 18:45:58 +02:00
|
|
|
status.setSubscription(sub);
|
|
|
|
|
}
|
|
|
|
|
status.setRead(false);
|
2013-06-06 09:54:17 +02:00
|
|
|
feedEntryStatusDAO.saveOrUpdate(status);
|
2013-05-23 11:30:57 +02:00
|
|
|
}
|
2013-06-20 18:45:58 +02:00
|
|
|
|
2013-04-18 12:50:44 +02:00
|
|
|
}
|
2013-04-29 22:37:26 +02:00
|
|
|
|
2013-06-20 18:45:58 +02:00
|
|
|
public void starEntry(User user, Long entryId, Long subscriptionId,
|
|
|
|
|
boolean starred) {
|
|
|
|
|
|
|
|
|
|
FeedSubscription sub = feedSubscriptionDAO.findById(user,
|
|
|
|
|
subscriptionId);
|
|
|
|
|
if (sub == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FeedEntry entry = new FeedEntry();
|
|
|
|
|
entry.setId(entryId);
|
|
|
|
|
|
|
|
|
|
FeedEntryStatus status = feedEntryStatusDAO.findByEntry(entry, sub);
|
|
|
|
|
|
|
|
|
|
if (!starred) {
|
|
|
|
|
if (status != null) {
|
|
|
|
|
if (!status.isRead()) {
|
|
|
|
|
status.setStarred(false);
|
|
|
|
|
feedEntryStatusDAO.saveOrUpdate(status);
|
|
|
|
|
} else {
|
|
|
|
|
feedEntryStatusDAO.delete(status);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (status == null) {
|
2013-07-14 05:48:47 +02:00
|
|
|
status = new FeedEntryStatus(user, sub, entry);
|
2013-06-20 18:45:58 +02:00
|
|
|
status.setSubscription(sub);
|
|
|
|
|
status.setRead(true);
|
|
|
|
|
}
|
|
|
|
|
status.setStarred(true);
|
2013-06-06 09:54:17 +02:00
|
|
|
feedEntryStatusDAO.saveOrUpdate(status);
|
2013-05-23 11:30:57 +02:00
|
|
|
}
|
2013-04-29 22:37:26 +02:00
|
|
|
}
|
2013-04-18 12:50:44 +02:00
|
|
|
}
|