force a feed refresh when someone subscribes

This commit is contained in:
Athou
2013-04-16 07:26:24 +02:00
parent 7034031417
commit b9fbf0fdf3
3 changed files with 23 additions and 8 deletions

View File

@@ -69,7 +69,16 @@ public class FeedRefreshWorker {
}
return new AsyncResult<Void>(null);
}
@Asynchronous
public void updateAsync(Feed feed){
try {
update(feed);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
private void update(Feed feed) throws NotSupportedException,
SystemException, SecurityException, IllegalStateException,
RollbackException, HeuristicMixedException,

View File

@@ -37,7 +37,7 @@ public class FeedSubscriptionService {
FeedSubscriptionDAO feedSubscriptionDAO;
@Lock(LockType.WRITE)
public void subscribe(User user, String url, String title,
public Feed subscribe(User user, String url, String title,
FeedCategory category) {
Feed feed = feedDAO.findByUrl(url);
@@ -72,5 +72,6 @@ public class FeedSubscriptionService {
}
feedEntryStatusDAO.save(statuses);
}
return feed;
}
}

View File

@@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -22,6 +23,7 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ObjectUtils;
import com.commafeed.backend.feeds.FeedRefreshWorker;
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedSubscription;
@@ -34,6 +36,9 @@ import com.google.common.base.Preconditions;
@Path("subscriptions")
public class SubscriptionsREST extends AbstractREST {
@Inject
FeedRefreshWorker worker;
@GET
@Path("fetch")
public Feed fetchFeed(@QueryParam("url") String url) {
@@ -62,11 +67,11 @@ public class SubscriptionsREST extends AbstractREST {
url = fetchFeed(url).getUrl();
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
: feedCategoryDAO
.findById(Long.valueOf(req.getCategoryId()));
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
Feed fetchedFeed = fetchFeed(url);
feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(),
req.getTitle(), category);
Feed feed = feedSubscriptionService.subscribe(getUser(),
fetchedFeed.getUrl(), req.getTitle(), category);
worker.updateAsync(feed);
return Response.ok(Status.OK).build();
}
@@ -145,8 +150,8 @@ public class SubscriptionsREST extends AbstractREST {
public Response deleteCategory(@QueryParam("id") Long id) {
FeedCategory cat = feedCategoryDAO.findById(getUser(), id);
if (cat != null) {
List<FeedSubscription> subs = feedSubscriptionDAO
.findByCategory(getUser(), cat);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
getUser(), cat);
for (FeedSubscription sub : subs) {
sub.setCategory(null);
}