mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
@@ -51,6 +51,13 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
return category;
|
||||
}
|
||||
|
||||
public List<FeedCategory> findByParent(User user, FeedCategory parent) {
|
||||
EasyCriteria<FeedCategory> criteria = createCriteria();
|
||||
criteria.andEquals(FeedCategory_.user.getName(), user);
|
||||
criteria.andEquals(FeedCategory_.parent.getName(), parent);
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
public List<FeedCategory> findAllChildrenCategories(User user,
|
||||
FeedCategory parent) {
|
||||
List<FeedCategory> list = Lists.newArrayList();
|
||||
@@ -77,4 +84,5 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
}
|
||||
return isChild;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ public class FeedCategory extends AbstractModel {
|
||||
|
||||
private boolean collapsed;
|
||||
|
||||
private Integer position;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -86,4 +88,12 @@ public class FeedCategory extends AbstractModel {
|
||||
this.collapsed = collapsed;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ public class FeedSubscription extends AbstractModel {
|
||||
@OneToMany(mappedBy = "subscription", cascade = CascadeType.REMOVE)
|
||||
private Set<FeedEntryStatus> statuses;
|
||||
|
||||
private Integer position;
|
||||
|
||||
public Feed getFeed() {
|
||||
return feed;
|
||||
}
|
||||
@@ -73,4 +75,12 @@ public class FeedSubscription extends AbstractModel {
|
||||
this.statuses = statuses;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.List;
|
||||
import javax.ejb.ApplicationException;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
@@ -50,7 +52,7 @@ public class FeedSubscriptionService {
|
||||
FeedCategory category) {
|
||||
|
||||
final String pubUrl = applicationSettingsService.get().getPublicUrl();
|
||||
if (pubUrl == null) {
|
||||
if (StringUtils.isBlank(pubUrl)) {
|
||||
throw new FeedSubscriptionException(
|
||||
"Public URL of this CommaFeed instance is not set");
|
||||
}
|
||||
|
||||
@@ -8,19 +8,36 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.wordnik.swagger.annotations.ApiClass;
|
||||
import com.wordnik.swagger.annotations.ApiProperty;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@ApiClass("Entry details")
|
||||
public class Category implements Serializable {
|
||||
|
||||
@ApiProperty("category id")
|
||||
private String id;
|
||||
|
||||
@ApiProperty("parent category id")
|
||||
private String parentId;
|
||||
|
||||
@ApiProperty("category id")
|
||||
private String name;
|
||||
|
||||
@ApiProperty("category children categories")
|
||||
private List<Category> children = Lists.newArrayList();
|
||||
|
||||
@ApiProperty("category feeds")
|
||||
private List<Subscription> feeds = Lists.newArrayList();
|
||||
|
||||
@ApiProperty("wether the category is expanded or collapsed")
|
||||
private boolean expanded;
|
||||
|
||||
@ApiProperty("position of the category in the list")
|
||||
private Integer position;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -68,4 +85,13 @@ public class Category implements Serializable {
|
||||
public void setExpanded(boolean expanded) {
|
||||
this.expanded = expanded;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class Subscription implements Serializable {
|
||||
Subscription sub = new Subscription();
|
||||
sub.setId(subscription.getId());
|
||||
sub.setName(subscription.getTitle());
|
||||
sub.setPosition(subscription.getPosition());
|
||||
sub.setMessage(feed.getMessage());
|
||||
sub.setErrorCount(feed.getErrorCount());
|
||||
sub.setFeedUrl(feed.getUrl());
|
||||
@@ -77,6 +78,9 @@ public class Subscription implements Serializable {
|
||||
@ApiProperty(value = "category id")
|
||||
private String categoryId;
|
||||
|
||||
@ApiProperty("position of the subscription's in the list")
|
||||
private Integer position;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -165,4 +169,12 @@ public class Subscription implements Serializable {
|
||||
this.iconUrl = iconUrl;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,9 @@ public class CategoryModificationRequest implements Serializable {
|
||||
@ApiProperty(value = "new parent category id")
|
||||
private String parentId;
|
||||
|
||||
@ApiProperty(value = "new display position, null if not changed")
|
||||
private Integer position;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -48,4 +51,12 @@ public class CategoryModificationRequest implements Serializable {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ public class FeedModificationRequest implements Serializable {
|
||||
@ApiProperty(value = "new parent category id")
|
||||
private String categoryId;
|
||||
|
||||
@ApiProperty(value = "new display position, null if not changed")
|
||||
private Integer position;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -48,4 +51,12 @@ public class FeedModificationRequest implements Serializable {
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -266,6 +266,31 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
Long.valueOf(req.getParentId()));
|
||||
}
|
||||
category.setParent(parent);
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
List<FeedCategory> categories = feedCategoryDAO.findByParent(
|
||||
getUser(), parent);
|
||||
int existingIndex = -1;
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
if (ObjectUtils.equals(categories.get(i).getId(),
|
||||
category.getId())) {
|
||||
existingIndex = i;
|
||||
}
|
||||
}
|
||||
if (existingIndex != -1) {
|
||||
categories.remove(existingIndex);
|
||||
}
|
||||
|
||||
categories.add(Math.min(req.getPosition(), categories.size()),
|
||||
category);
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
categories.get(i).setPosition(i);
|
||||
}
|
||||
feedCategoryDAO.update(categories);
|
||||
} else {
|
||||
feedCategoryDAO.update(category);
|
||||
}
|
||||
|
||||
feedCategoryDAO.update(category);
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
@@ -289,6 +314,19 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/unreadCount")
|
||||
@ApiOperation(value = "Get unread count for feed subscriptions", responseClass = "List[com.commafeed.frontend.model.UnreadCount]")
|
||||
public Response getUnreadCount() {
|
||||
List<UnreadCount> list = Lists.newArrayList();
|
||||
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
||||
.getUnreadCount(getUser());
|
||||
for (Map.Entry<Long, Long> e : unreadCount.entrySet()) {
|
||||
list.add(new UnreadCount(e.getKey(), e.getValue()));
|
||||
}
|
||||
return Response.ok(list).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/get")
|
||||
@ApiOperation(value = "Get feed categories", notes = "Get all categories and subscriptions of the user", responseClass = "com.commafeed.frontend.model.Category")
|
||||
@@ -308,19 +346,6 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/unreadCount")
|
||||
@ApiOperation(value = "Get unread count for feed subscriptions", responseClass = "List[com.commafeed.frontend.model.UnreadCount]")
|
||||
public Response getUnreadCount() {
|
||||
List<UnreadCount> list = Lists.newArrayList();
|
||||
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
||||
.getUnreadCount(getUser());
|
||||
for (Map.Entry<Long, Long> e : unreadCount.entrySet()) {
|
||||
list.add(new UnreadCount(e.getKey(), e.getValue()));
|
||||
}
|
||||
return Response.ok(list).build();
|
||||
}
|
||||
|
||||
private Category buildCategory(Long id, List<FeedCategory> categories,
|
||||
List<FeedSubscription> subscriptions, Map<Long, Long> unreadCount) {
|
||||
Category category = new Category();
|
||||
@@ -335,6 +360,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
subscriptions, unreadCount);
|
||||
child.setId(String.valueOf(c.getId()));
|
||||
child.setName(c.getName());
|
||||
child.setPosition(c.getPosition());
|
||||
if (c.getParent() != null && c.getParent().getId() != null) {
|
||||
child.setParentId(String.valueOf(c.getParent().getId()));
|
||||
}
|
||||
@@ -345,7 +371,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
Collections.sort(category.getChildren(), new Comparator<Category>() {
|
||||
@Override
|
||||
public int compare(Category o1, Category o2) {
|
||||
return ObjectUtils.compare(o1.getName(), o2.getName());
|
||||
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -364,7 +390,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
Collections.sort(category.getFeeds(), new Comparator<Subscription>() {
|
||||
@Override
|
||||
public int compare(Subscription o1, Subscription o2) {
|
||||
return ObjectUtils.compare(o1.getName(), o2.getName());
|
||||
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
|
||||
}
|
||||
});
|
||||
return category;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -327,7 +328,29 @@ public class FeedREST extends AbstractResourceREST {
|
||||
Long.valueOf(req.getCategoryId()));
|
||||
}
|
||||
subscription.setCategory(parent);
|
||||
feedSubscriptionDAO.update(subscription);
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
|
||||
getUser(), parent);
|
||||
int existingIndex = -1;
|
||||
for (int i = 0; i < subs.size(); i++) {
|
||||
if (ObjectUtils.equals(subs.get(i).getId(),
|
||||
subscription.getId())) {
|
||||
existingIndex = i;
|
||||
}
|
||||
}
|
||||
if (existingIndex != -1) {
|
||||
subs.remove(existingIndex);
|
||||
}
|
||||
|
||||
subs.add(Math.min(req.getPosition(), subs.size()), subscription);
|
||||
for (int i = 0; i < subs.size(); i++) {
|
||||
subs.get(i).setPosition(i);
|
||||
}
|
||||
feedSubscriptionDAO.update(subs);
|
||||
} else {
|
||||
feedSubscriptionDAO.update(subscription);
|
||||
}
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user