forked from Archives/Athou_commafeed
force a feed refresh when someone subscribes
This commit is contained in:
@@ -69,7 +69,16 @@ public class FeedRefreshWorker {
|
|||||||
}
|
}
|
||||||
return new AsyncResult<Void>(null);
|
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,
|
private void update(Feed feed) throws NotSupportedException,
|
||||||
SystemException, SecurityException, IllegalStateException,
|
SystemException, SecurityException, IllegalStateException,
|
||||||
RollbackException, HeuristicMixedException,
|
RollbackException, HeuristicMixedException,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class FeedSubscriptionService {
|
|||||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
public void subscribe(User user, String url, String title,
|
public Feed subscribe(User user, String url, String title,
|
||||||
FeedCategory category) {
|
FeedCategory category) {
|
||||||
|
|
||||||
Feed feed = feedDAO.findByUrl(url);
|
Feed feed = feedDAO.findByUrl(url);
|
||||||
@@ -72,5 +72,6 @@ public class FeedSubscriptionService {
|
|||||||
}
|
}
|
||||||
feedEntryStatusDAO.save(statuses);
|
feedEntryStatusDAO.save(statuses);
|
||||||
}
|
}
|
||||||
|
return feed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
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.io.IOUtils;
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
|
|
||||||
|
import com.commafeed.backend.feeds.FeedRefreshWorker;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
@@ -34,6 +36,9 @@ import com.google.common.base.Preconditions;
|
|||||||
@Path("subscriptions")
|
@Path("subscriptions")
|
||||||
public class SubscriptionsREST extends AbstractREST {
|
public class SubscriptionsREST extends AbstractREST {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedRefreshWorker worker;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("fetch")
|
@Path("fetch")
|
||||||
public Feed fetchFeed(@QueryParam("url") String url) {
|
public Feed fetchFeed(@QueryParam("url") String url) {
|
||||||
@@ -62,11 +67,11 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
url = fetchFeed(url).getUrl();
|
url = fetchFeed(url).getUrl();
|
||||||
|
|
||||||
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
|
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
|
||||||
: feedCategoryDAO
|
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
|
||||||
.findById(Long.valueOf(req.getCategoryId()));
|
|
||||||
Feed fetchedFeed = fetchFeed(url);
|
Feed fetchedFeed = fetchFeed(url);
|
||||||
feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(),
|
Feed feed = feedSubscriptionService.subscribe(getUser(),
|
||||||
req.getTitle(), category);
|
fetchedFeed.getUrl(), req.getTitle(), category);
|
||||||
|
worker.updateAsync(feed);
|
||||||
|
|
||||||
return Response.ok(Status.OK).build();
|
return Response.ok(Status.OK).build();
|
||||||
}
|
}
|
||||||
@@ -145,8 +150,8 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
public Response deleteCategory(@QueryParam("id") Long id) {
|
public Response deleteCategory(@QueryParam("id") Long id) {
|
||||||
FeedCategory cat = feedCategoryDAO.findById(getUser(), id);
|
FeedCategory cat = feedCategoryDAO.findById(getUser(), id);
|
||||||
if (cat != null) {
|
if (cat != null) {
|
||||||
List<FeedSubscription> subs = feedSubscriptionDAO
|
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
|
||||||
.findByCategory(getUser(), cat);
|
getUser(), cat);
|
||||||
for (FeedSubscription sub : subs) {
|
for (FeedSubscription sub : subs) {
|
||||||
sub.setCategory(null);
|
sub.setCategory(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user