Files
Athou_commafeed/src/main/java/com/commafeed/frontend/model/Subscription.java

80 lines
2.7 KiB
Java
Raw Normal View History

2013-03-23 16:17:19 +01:00
package com.commafeed.frontend.model;
2013-03-22 09:29:30 +01:00
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
2013-05-26 15:36:55 +02:00
import com.commafeed.backend.feeds.FeedUtils;
2013-05-22 16:10:50 +02:00
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedSubscription;
2013-04-17 13:26:14 +02:00
import com.wordnik.swagger.annotations.ApiClass;
import com.wordnik.swagger.annotations.ApiProperty;
2013-03-25 12:24:00 +01:00
@SuppressWarnings("serial")
2013-04-17 13:26:14 +02:00
@ApiClass("User information")
@Data
public class Subscription implements Serializable {
public static Subscription build(FeedSubscription subscription, String publicUrl, UnreadCount unreadCount) {
Date now = new Date();
FeedCategory category = subscription.getCategory();
2013-05-22 16:10:50 +02:00
Feed feed = subscription.getFeed();
Subscription sub = new Subscription();
sub.setId(subscription.getId());
sub.setName(subscription.getTitle());
sub.setPosition(subscription.getPosition());
2013-05-22 16:10:50 +02:00
sub.setMessage(feed.getMessage());
sub.setErrorCount(feed.getErrorCount());
sub.setFeedUrl(feed.getUrl());
sub.setFeedLink(feed.getLink());
sub.setIconUrl(FeedUtils.getFaviconUrl(subscription, publicUrl));
2013-05-22 16:10:50 +02:00
sub.setLastRefresh(feed.getLastUpdated());
2013-07-25 09:17:33 +02:00
sub.setNextRefresh((feed.getDisabledUntil() != null && feed.getDisabledUntil().before(now)) ? null : feed.getDisabledUntil());
sub.setUnread(unreadCount.getUnreadCount());
sub.setNewestItemTime(unreadCount.getNewestItemTime());
2013-07-25 09:17:33 +02:00
sub.setCategoryId(category == null ? null : String.valueOf(category.getId()));
return sub;
}
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "subscription id", required = true)
2013-03-22 09:29:30 +01:00
private Long id;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "subscription name", required = true)
2013-03-22 09:29:30 +01:00
private String name;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "error message while fetching the feed", required = true)
2013-03-25 12:24:00 +01:00
private String message;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "error count", required = true)
2013-04-09 10:39:02 +02:00
private int errorCount;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "last time the feed was refreshed", required = true)
private Date lastRefresh;
2013-05-24 11:48:20 +02:00
@ApiProperty(value = "next time the feed refresh is planned, null if refresh is already queued", required = true)
2013-05-22 16:10:50 +02:00
private Date nextRefresh;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "this subscription's feed url", required = true)
2013-04-03 15:53:57 +02:00
private String feedUrl;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "this subscription's website url", required = true)
private String feedLink;
2013-05-26 15:36:55 +02:00
@ApiProperty(value = "The favicon url to use for this feed")
private String iconUrl;
2013-04-17 13:26:14 +02:00
@ApiProperty(value = "unread count", required = true)
2013-04-06 17:21:48 +02:00
private long unread;
2013-03-22 09:29:30 +01:00
@ApiProperty(value = "category id")
private String categoryId;
@ApiProperty("position of the subscription's in the list")
private Integer position;
@ApiProperty("date of the newest item")
private Date newestItemTime;
2013-03-22 09:29:30 +01:00
}