diff --git a/src/main/app/js/controllers.js b/src/main/app/js/controllers.js index 7ae8d904..9eb1747d 100644 --- a/src/main/app/js/controllers.js +++ b/src/main/app/js/controllers.js @@ -322,17 +322,21 @@ module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedS $scope.save = function() { var sub = $scope.sub; + $scope.error = null; FeedService.modify({ id : sub.id, name : sub.name, position : sub.position, - categoryId : sub.categoryId + categoryId : sub.categoryId, + filter : sub.filter }, function() { CategoryService.init(); $state.transitionTo('feeds.view', { _id : 'all', _type : 'category' }); + }, function(e) { + $scope.error = e.data; }); }; }]); @@ -489,7 +493,7 @@ module.controller('ToolbarCtrl', [ type : $stateParams._type, id : $stateParams._id, olderThan : olderThan, - keywords: $location.search().q, + keywords : $location.search().q, read : true }); }; @@ -882,7 +886,7 @@ module.controller('FeedListCtrl', [ service.mark({ id : $scope.selectedId, olderThan : olderThan || $scope.timestamp, - keywords: $location.search().q, + keywords : $location.search().q, read : true }, function() { CategoryService.refresh(function() { diff --git a/src/main/app/templates/feeds.feed_details.html b/src/main/app/templates/feeds.feed_details.html index 699b25f9..3a173bd6 100644 --- a/src/main/app/templates/feeds.feed_details.html +++ b/src/main/app/templates/feeds.feed_details.html @@ -3,6 +3,7 @@

{{ 'details.feed_details' | translate }}

+
{{ error }}
@@ -69,6 +70,13 @@
+
+ +
+ +
+
+
diff --git a/src/main/java/com/commafeed/backend/feed/FeedEntryFilter.java b/src/main/java/com/commafeed/backend/feed/FeedEntryFilter.java index bc43e0a4..79ab69c8 100644 --- a/src/main/java/com/commafeed/backend/feed/FeedEntryFilter.java +++ b/src/main/java/com/commafeed/backend/feed/FeedEntryFilter.java @@ -56,6 +56,7 @@ public class FeedEntryFilter { }; JexlEngine engine = new JexlEngine(uberspect, null, null, null); + engine.setStrict(true); engine.setClassLoader(cl); return engine; } diff --git a/src/main/java/com/commafeed/backend/model/FeedSubscription.java b/src/main/java/com/commafeed/backend/model/FeedSubscription.java index 5ef2e711..92a08cec 100644 --- a/src/main/java/com/commafeed/backend/model/FeedSubscription.java +++ b/src/main/java/com/commafeed/backend/model/FeedSubscription.java @@ -41,6 +41,6 @@ public class FeedSubscription extends AbstractModel { private Integer position; @Column(length = 4096) - private String filter = "author.contains('a')"; + private String filter; } diff --git a/src/main/java/com/commafeed/frontend/model/Subscription.java b/src/main/java/com/commafeed/frontend/model/Subscription.java index a395b184..99e8d387 100644 --- a/src/main/java/com/commafeed/frontend/model/Subscription.java +++ b/src/main/java/com/commafeed/frontend/model/Subscription.java @@ -35,6 +35,7 @@ public class Subscription implements Serializable { sub.setUnread(unreadCount.getUnreadCount()); sub.setNewestItemTime(unreadCount.getNewestItemTime()); sub.setCategoryId(category == null ? null : String.valueOf(category.getId())); + sub.setFilter(subscription.getFilter()); return sub; } @@ -77,4 +78,7 @@ public class Subscription implements Serializable { @ApiModelProperty("date of the newest item") private Date newestItemTime; + @ApiModelProperty(value = "JEXL string evaluated on new entries to mark them as read if they do not match") + private String filter; + } \ No newline at end of file diff --git a/src/main/java/com/commafeed/frontend/model/request/FeedModificationRequest.java b/src/main/java/com/commafeed/frontend/model/request/FeedModificationRequest.java index c8b44876..595693e4 100644 --- a/src/main/java/com/commafeed/frontend/model/request/FeedModificationRequest.java +++ b/src/main/java/com/commafeed/frontend/model/request/FeedModificationRequest.java @@ -24,4 +24,7 @@ public class FeedModificationRequest implements Serializable { @ApiModelProperty(value = "new display position, null if not changed") private Integer position; + @ApiModelProperty(value = "JEXL string evaluated on new entries to mark them as read if they do not match") + private String filter; + } diff --git a/src/main/java/com/commafeed/frontend/resource/FeedREST.java b/src/main/java/com/commafeed/frontend/resource/FeedREST.java index cd29b06d..b16b349a 100644 --- a/src/main/java/com/commafeed/frontend/resource/FeedREST.java +++ b/src/main/java/com/commafeed/frontend/resource/FeedREST.java @@ -44,12 +44,15 @@ import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.dao.FeedEntryStatusDAO; import com.commafeed.backend.dao.FeedSubscriptionDAO; +import com.commafeed.backend.feed.FeedEntryFilter; import com.commafeed.backend.feed.FeedFetcher; import com.commafeed.backend.feed.FeedQueues; import com.commafeed.backend.feed.FeedUtils; import com.commafeed.backend.feed.FetchedFeed; import com.commafeed.backend.model.Feed; import com.commafeed.backend.model.FeedCategory; +import com.commafeed.backend.model.FeedEntry; +import com.commafeed.backend.model.FeedEntryContent; import com.commafeed.backend.model.FeedEntryStatus; import com.commafeed.backend.model.FeedSubscription; import com.commafeed.backend.model.User; @@ -93,6 +96,20 @@ import com.wordnik.swagger.annotations.ApiParam; @Singleton public class FeedREST { + private static final FeedEntry TEST_ENTRY = initTestEntry(); + + private static FeedEntry initTestEntry() { + FeedEntry entry = new FeedEntry(); + entry.setUrl("https://github.com/Athou/commafeed"); + + FeedEntryContent content = new FeedEntryContent(); + content.setAuthor("Athou"); + content.setTitle("Merge pull request #662 from Athou/dw8"); + content.setContent("Merge pull request #662 from Athou/dw8"); + entry.setContent(content); + return entry; + } + private final FeedSubscriptionDAO feedSubscriptionDAO; private final FeedCategoryDAO feedCategoryDAO; private final FeedEntryStatusDAO feedEntryStatusDAO; @@ -418,7 +435,15 @@ public class FeedREST { Preconditions.checkNotNull(req); Preconditions.checkNotNull(req.getId()); + try { + new FeedEntryFilter(req.getFilter()).matchesEntry(TEST_ENTRY); + } catch (Exception e) { + Throwable root = Throwables.getRootCause(e); + return Response.status(Status.BAD_REQUEST).entity(root.getMessage()).build(); + } + FeedSubscription subscription = feedSubscriptionDAO.findById(user, req.getId()); + subscription.setFilter(req.getFilter()); if (StringUtils.isNotBlank(req.getName())) { subscription.setTitle(req.getName());