api tweak

This commit is contained in:
Athou
2013-04-16 10:42:34 +02:00
parent 43eafd51c7
commit 852f834377
3 changed files with 19 additions and 30 deletions

View File

@@ -69,15 +69,6 @@ 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,

View File

@@ -48,7 +48,7 @@ public class EntriesREST extends AbstractREST {
@ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @QueryParam("readType") ReadType readType, @ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @QueryParam("readType") ReadType readType,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,
@ApiParam(value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit, @ApiParam(value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit,
@ApiParam(value = "entry date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) { @ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
Preconditions.checkNotNull(id); Preconditions.checkNotNull(id);
Preconditions.checkNotNull(readType); Preconditions.checkNotNull(readType);
@@ -83,7 +83,7 @@ public class EntriesREST extends AbstractREST {
@ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @QueryParam("readType") ReadType readType, @ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @QueryParam("readType") ReadType readType,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,
@ApiParam(value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit, @ApiParam(value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit,
@ApiParam(value = "entry date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) { @ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
Preconditions.checkNotNull(id); Preconditions.checkNotNull(id);
Preconditions.checkNotNull(readType); Preconditions.checkNotNull(readType);
@@ -179,7 +179,7 @@ public class EntriesREST extends AbstractREST {
@Path("/category/mark") @Path("/category/mark")
@GET @GET
@ApiOperation(value = "Mark feed entries", notes = "Mark feed entries as read/unread") @ApiOperation(value = "Mark category entries", notes = "Mark feed entries as read/unread")
public Response markCategoryEntries( public Response markCategoryEntries(
@ApiParam(value = "category id, or 'all'", required = true) @QueryParam("id") String id, @ApiParam(value = "category id, or 'all'", required = true) @QueryParam("id") String id,
@ApiParam(value = "only entries older than this, prevent marking an entry that was not retrieved") @QueryParam("olderThan") Long olderThanTimestamp) { @ApiParam(value = "only entries older than this, prevent marking an entry that was not retrieved") @QueryParam("olderThan") Long olderThanTimestamp) {
@@ -205,7 +205,7 @@ public class EntriesREST extends AbstractREST {
@Path("/search") @Path("/search")
@GET @GET
@ApiOperation(value = "Search for entries", notes = "Look through title and content of entries by keywords") @ApiOperation(value = "Search for entries", notes = "Look through title and content of entries by keywords", responseClass = "com.commafeed.frontend.model.Entries")
public Entries searchEntries( public Entries searchEntries(
@ApiParam(value = "keywords separated by spaces, 3 characters minimum", required = true) @QueryParam("keywords") String keywords, @ApiParam(value = "keywords separated by spaces, 3 characters minimum", required = true) @QueryParam("keywords") String keywords,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,

View File

@@ -5,7 +5,6 @@ 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;
@@ -23,7 +22,6 @@ 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;
@@ -32,15 +30,16 @@ import com.commafeed.frontend.model.Subscription;
import com.commafeed.frontend.model.SubscriptionRequest; import com.commafeed.frontend.model.SubscriptionRequest;
import com.commafeed.frontend.rest.resources.EntriesREST.Type; import com.commafeed.frontend.rest.resources.EntriesREST.Type;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
@Path("subscriptions") @Path("/subscriptions")
@Api(value = "/subscriptions", description = "Operations about user feed subscriptions")
public class SubscriptionsREST extends AbstractREST { public class SubscriptionsREST extends AbstractREST {
@Inject
FeedRefreshWorker worker;
@GET @GET
@Path("fetch") @Path("/fetch")
@ApiOperation(value = "Search for entries", notes = "Look through title and content of entries by keywords", responseClass = "com.commafeed.frontend.model.Entries")
public Feed fetchFeed(@QueryParam("url") String url) { public Feed fetchFeed(@QueryParam("url") String url) {
Preconditions.checkNotNull(url); Preconditions.checkNotNull(url);
@@ -57,7 +56,7 @@ public class SubscriptionsREST extends AbstractREST {
} }
@POST @POST
@Path("subscribe") @Path("/subscribe")
public Response subscribe(SubscriptionRequest req) { public Response subscribe(SubscriptionRequest req) {
Preconditions.checkNotNull(req); Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getTitle()); Preconditions.checkNotNull(req.getTitle());
@@ -69,9 +68,8 @@ public class SubscriptionsREST extends AbstractREST {
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId())); : feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
Feed fetchedFeed = fetchFeed(url); Feed fetchedFeed = fetchFeed(url);
Feed feed = feedSubscriptionService.subscribe(getUser(), feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(),
fetchedFeed.getUrl(), req.getTitle(), category); req.getTitle(), category);
worker.updateAsync(feed);
return Response.ok(Status.OK).build(); return Response.ok(Status.OK).build();
} }
@@ -84,7 +82,7 @@ public class SubscriptionsREST extends AbstractREST {
} }
@GET @GET
@Path("unsubscribe") @Path("/unsubscribe")
public Response unsubscribe(@QueryParam("id") Long subscriptionId) { public Response unsubscribe(@QueryParam("id") Long subscriptionId) {
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), FeedSubscription sub = feedSubscriptionDAO.findById(getUser(),
subscriptionId); subscriptionId);
@@ -97,7 +95,7 @@ public class SubscriptionsREST extends AbstractREST {
} }
@GET @GET
@Path("rename") @Path("/rename")
public Response rename(@QueryParam("type") Type type, public Response rename(@QueryParam("type") Type type,
@QueryParam("id") Long id, @QueryParam("name") String name) { @QueryParam("id") Long id, @QueryParam("name") String name) {
if (type == Type.feed) { if (type == Type.feed) {
@@ -114,7 +112,7 @@ public class SubscriptionsREST extends AbstractREST {
} }
@GET @GET
@Path("collapse") @Path("/collapse")
public Response collapse(@QueryParam("id") String id, public Response collapse(@QueryParam("id") String id,
@QueryParam("collapse") boolean collapse) { @QueryParam("collapse") boolean collapse) {
Preconditions.checkNotNull(id); Preconditions.checkNotNull(id);
@@ -127,7 +125,7 @@ public class SubscriptionsREST extends AbstractREST {
return Response.ok(Status.OK).build(); return Response.ok(Status.OK).build();
} }
@Path("addCategory") @Path("/addCategory")
@GET @GET
public Response addCategory(@QueryParam("name") String name, public Response addCategory(@QueryParam("name") String name,
@QueryParam("parentId") String parentId) { @QueryParam("parentId") String parentId) {
@@ -146,7 +144,7 @@ public class SubscriptionsREST extends AbstractREST {
} }
@GET @GET
@Path("deleteCategory") @Path("/deleteCategory")
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) {
@@ -164,7 +162,7 @@ public class SubscriptionsREST extends AbstractREST {
} }
@POST @POST
@Path("import") @Path("/import")
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
public Response importOpml() { public Response importOpml() {
try { try {