apply formatter

This commit is contained in:
Athou
2013-07-25 09:17:33 +02:00
parent 02f1090fe7
commit 8845c54d0c
82 changed files with 626 additions and 1116 deletions

View File

@@ -29,7 +29,7 @@ public class DatabaseCleaner {
@Inject
FeedSubscriptionDAO feedSubscriptionDAO;
@Inject
FeedEntryContentDAO feedEntryContentDAO;

View File

@@ -33,18 +33,14 @@ public class DatabaseUpdater {
try {
Thread currentThread = Thread.currentThread();
ClassLoader classLoader = currentThread.getContextClassLoader();
ResourceAccessor accessor = new ClassLoaderResourceAccessor(
classLoader);
ResourceAccessor accessor = new ClassLoaderResourceAccessor(classLoader);
context = new InitialContext();
DataSource dataSource = (DataSource) context
.lookup(datasourceName);
DataSource dataSource = (DataSource) context.lookup(datasourceName);
connection = dataSource.getConnection();
JdbcConnection jdbcConnection = new JdbcConnection(connection);
Database database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(
jdbcConnection);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcConnection);
if (database instanceof PostgresDatabase) {
database = new PostgresDatabase() {
@@ -56,9 +52,7 @@ public class DatabaseUpdater {
database.setConnection(jdbcConnection);
}
Liquibase liq = new Liquibase(
"changelogs/db.changelog-master.xml", accessor,
database);
Liquibase liq = new Liquibase("changelogs/db.changelog-master.xml", accessor, database);
liq.update("prod");
} finally {
if (context != null) {

View File

@@ -56,9 +56,7 @@ public class HttpGetter {
static {
try {
SSL_CONTEXT = SSLContext.getInstance("TLS");
SSL_CONTEXT.init(new KeyManager[0],
new TrustManager[] { new DefaultTrustManager() },
new SecureRandom());
SSL_CONTEXT.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
} catch (Exception e) {
log.error("Could not configure ssl context");
}
@@ -66,8 +64,7 @@ public class HttpGetter {
private static final X509HostnameVerifier VERIFIER = new DefaultHostnameVerifier();
public HttpResult getBinary(String url, int timeout) throws ClientProtocolException,
IOException, NotModifiedException {
public HttpResult getBinary(String url, int timeout) throws ClientProtocolException, IOException, NotModifiedException {
return getBinary(url, null, null, timeout);
}
@@ -85,8 +82,8 @@ public class HttpGetter {
* @throws NotModifiedException
* if the url hasn't changed since we asked for it last time
*/
public HttpResult getBinary(String url, String lastModified, String eTag, int timeout)
throws ClientProtocolException, IOException, NotModifiedException {
public HttpResult getBinary(String url, String lastModified, String eTag, int timeout) throws ClientProtocolException, IOException,
NotModifiedException {
HttpResult result = null;
long start = System.currentTimeMillis();
@@ -112,8 +109,7 @@ public class HttpGetter {
if (code == HttpStatus.SC_NOT_MODIFIED) {
throw new NotModifiedException("304 http code");
} else if (code >= 300) {
throw new HttpResponseException(code,
"Server returned HTTP error code " + code);
throw new HttpResponseException(code, "Server returned HTTP error code " + code);
}
} catch (HttpResponseException e) {
@@ -123,14 +119,11 @@ public class HttpGetter {
throw e;
}
}
Header lastModifiedHeader = response
.getFirstHeader(HttpHeaders.LAST_MODIFIED);
Header lastModifiedHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED);
Header eTagHeader = response.getFirstHeader(HttpHeaders.ETAG);
String lastModifiedResponse = lastModifiedHeader == null ? null
: StringUtils.trimToNull(lastModifiedHeader.getValue());
if (lastModified != null
&& StringUtils.equals(lastModified, lastModifiedResponse)) {
String lastModifiedResponse = lastModifiedHeader == null ? null : StringUtils.trimToNull(lastModifiedHeader.getValue());
if (lastModified != null && StringUtils.equals(lastModified, lastModifiedResponse)) {
throw new NotModifiedException("lastModifiedHeader is the same");
}
@@ -147,10 +140,8 @@ public class HttpGetter {
long duration = System.currentTimeMillis() - start;
Header contentType = entity.getContentType();
result = new HttpResult(content, contentType == null ? null
: contentType.getValue(), lastModifiedHeader == null ? null
: lastModifiedHeader.getValue(), eTagHeader == null ? null
: eTagHeader.getValue(), duration);
result = new HttpResult(content, contentType == null ? null : contentType.getValue(), lastModifiedHeader == null ? null
: lastModifiedHeader.getValue(), eTagHeader == null ? null : eTagHeader.getValue(), duration);
} finally {
client.getConnectionManager().shutdown();
}
@@ -165,8 +156,7 @@ public class HttpGetter {
private String eTag;
private long duration;
public HttpResult(byte[] content, String contentType,
String lastModifiedSince, String eTag, long duration) {
public HttpResult(byte[] content, String contentType, String lastModifiedSince, String eTag, long duration) {
this.content = content;
this.contentType = contentType;
this.lastModifiedSince = lastModifiedSince;
@@ -209,8 +199,7 @@ public class HttpGetter {
HttpProtocolParams.setContentCharset(params, UTF8);
HttpConnectionParams.setConnectionTimeout(params, timeout);
HttpConnectionParams.setSoTimeout(params, timeout);
client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0,
false));
client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return new DecompressingHttpClient(client);
}
@@ -225,13 +214,11 @@ public class HttpGetter {
private static class DefaultTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
@Override
@@ -240,21 +227,18 @@ public class HttpGetter {
}
}
private static class DefaultHostnameVerifier implements
X509HostnameVerifier {
private static class DefaultHostnameVerifier implements X509HostnameVerifier {
@Override
public void verify(String string, SSLSocket ssls) throws IOException {
}
@Override
public void verify(String string, X509Certificate xc)
throws SSLException {
public void verify(String string, X509Certificate xc) throws SSLException {
}
@Override
public void verify(String string, String[] strings, String[] strings1)
throws SSLException {
public void verify(String string, String[] strings, String[] strings1) throws SSLException {
}
@Override

View File

@@ -79,8 +79,7 @@ public class StartupBean {
IOUtils.closeQuietly(is);
}
for (Object key : props.keySet()) {
supportedLanguages.put(key.toString(),
props.getProperty(key.toString()));
supportedLanguages.put(key.toString(), props.getProperty(key.toString()));
}
}
@@ -92,11 +91,8 @@ public class StartupBean {
applicationSettingsService.save(settings);
try {
userService.register(USERNAME_ADMIN, "admin",
"admin@commafeed.com",
Arrays.asList(Role.ADMIN, Role.USER), true);
userService.register(USERNAME_DEMO, "demo", "demo@commafeed.com",
Arrays.asList(Role.USER), true);
userService.register(USERNAME_ADMIN, "admin", "admin@commafeed.com", Arrays.asList(Role.ADMIN, Role.USER), true);
userService.register(USERNAME_DEMO, "demo", "demo@commafeed.com", Arrays.asList(Role.USER), true);
} catch (Exception e) {
log.error(e.getMessage(), e);
}

View File

@@ -17,14 +17,13 @@ public abstract class CacheService {
public abstract void setLastEntries(Feed feed, List<String> entries);
public String buildUniqueEntryKey(Feed feed, FeedEntry entry) {
return DigestUtils.sha1Hex(entry.getGuid() +
entry.getUrl());
return DigestUtils.sha1Hex(entry.getGuid() + entry.getUrl());
}
public abstract Category getRootCategory(User user);
public abstract void setRootCategory(User user, Category category);
public abstract Map<Long, Long> getUnreadCounts(User user);
public abstract void setUnreadCounts(User user, Map<Long, Long> map);

View File

@@ -29,8 +29,7 @@ import com.google.api.client.util.Lists;
@ApplicationScoped
public class RedisCacheService extends CacheService {
private static final Logger log = LoggerFactory
.getLogger(RedisCacheService.class);
private static final Logger log = LoggerFactory.getLogger(RedisCacheService.class);
private JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
private ObjectMapper mapper = new ObjectMapper();
@@ -113,8 +112,7 @@ public class RedisCacheService extends CacheService {
String key = buildRedisUnreadCountKey(user);
String json = jedis.get(key);
if (json != null) {
MapType type = mapper.getTypeFactory().constructMapType(
Map.class, Long.class, Long.class);
MapType type = mapper.getTypeFactory().constructMapType(Map.class, Long.class, Long.class);
map = mapper.readValue(json, type);
}
} catch (Exception e) {

View File

@@ -26,8 +26,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
CriteriaQuery<FeedCategory> query = builder.createQuery(getType());
Root<FeedCategory> root = query.from(getType());
Join<FeedCategory, User> userJoin = (Join<FeedCategory, User>) root
.fetch(FeedCategory_.user);
Join<FeedCategory, User> userJoin = (Join<FeedCategory, User>) root.fetch(FeedCategory_.user);
query.where(builder.equal(userJoin.get(User_.id), user.getId()));
@@ -38,14 +37,12 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
CriteriaQuery<FeedCategory> query = builder.createQuery(getType());
Root<FeedCategory> root = query.from(getType());
Predicate p1 = builder.equal(
root.get(FeedCategory_.user).get(User_.id), user.getId());
Predicate p1 = builder.equal(root.get(FeedCategory_.user).get(User_.id), user.getId());
Predicate p2 = builder.equal(root.get(FeedCategory_.id), id);
query.where(p1, p2);
return Iterables.getFirst(cache(em.createQuery(query)).getResultList(),
null);
return Iterables.getFirst(cache(em.createQuery(query)).getResultList(), null);
}
public FeedCategory findByName(User user, String name, FeedCategory parent) {
@@ -60,8 +57,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
if (parent == null) {
predicates.add(builder.isNull(root.get(FeedCategory_.parent)));
} else {
predicates
.add(builder.equal(root.get(FeedCategory_.parent), parent));
predicates.add(builder.equal(root.get(FeedCategory_.parent), parent));
}
query.where(predicates.toArray(new Predicate[0]));
@@ -85,8 +81,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
if (parent == null) {
predicates.add(builder.isNull(root.get(FeedCategory_.parent)));
} else {
predicates
.add(builder.equal(root.get(FeedCategory_.parent), parent));
predicates.add(builder.equal(root.get(FeedCategory_.parent), parent));
}
query.where(predicates.toArray(new Predicate[0]));
@@ -94,8 +89,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
return em.createQuery(query).getResultList();
}
public List<FeedCategory> findAllChildrenCategories(User user,
FeedCategory parent) {
public List<FeedCategory> findAllChildrenCategories(User user, FeedCategory parent) {
List<FeedCategory> list = Lists.newArrayList();
List<FeedCategory> all = findAll(user);
for (FeedCategory cat : all) {

View File

@@ -39,23 +39,17 @@ public class FeedDAO extends GenericDAO<Feed> {
public List<Feed> feeds;
}
private List<Predicate> getUpdatablePredicates(Root<Feed> root,
Date threshold) {
private List<Predicate> getUpdatablePredicates(Root<Feed> root, Date threshold) {
Predicate hasSubscriptions = builder.isNotEmpty(root
.get(Feed_.subscriptions));
Predicate hasSubscriptions = builder.isNotEmpty(root.get(Feed_.subscriptions));
Predicate neverUpdated = builder.isNull(root.get(Feed_.lastUpdated));
Predicate updatedBeforeThreshold = builder.lessThan(
root.get(Feed_.lastUpdated), threshold);
Predicate updatedBeforeThreshold = builder.lessThan(root.get(Feed_.lastUpdated), threshold);
Predicate disabledDateIsNull = builder.isNull(root
.get(Feed_.disabledUntil));
Predicate disabledDateIsInPast = builder.lessThan(
root.get(Feed_.disabledUntil), new Date());
Predicate disabledDateIsNull = builder.isNull(root.get(Feed_.disabledUntil));
Predicate disabledDateIsInPast = builder.lessThan(root.get(Feed_.disabledUntil), new Date());
return Lists.newArrayList(hasSubscriptions,
builder.or(neverUpdated, updatedBeforeThreshold),
return Lists.newArrayList(hasSubscriptions, builder.or(neverUpdated, updatedBeforeThreshold),
builder.or(disabledDateIsNull, disabledDateIsInPast));
}
@@ -64,8 +58,7 @@ public class FeedDAO extends GenericDAO<Feed> {
Root<Feed> root = query.from(getType());
query.select(builder.count(root));
query.where(getUpdatablePredicates(root, threshold).toArray(
new Predicate[0]));
query.where(getUpdatablePredicates(root, threshold).toArray(new Predicate[0]));
TypedQuery<Long> q = em.createQuery(query);
return q.getSingleResult();
@@ -75,8 +68,7 @@ public class FeedDAO extends GenericDAO<Feed> {
CriteriaQuery<Feed> query = builder.createQuery(getType());
Root<Feed> root = query.from(getType());
query.where(getUpdatablePredicates(root, threshold).toArray(
new Predicate[0]));
query.where(getUpdatablePredicates(root, threshold).toArray(new Predicate[0]));
query.orderBy(builder.asc(root.get(Feed_.lastUpdated)));
@@ -94,11 +86,9 @@ public class FeedDAO extends GenericDAO<Feed> {
}
String normalized = FeedUtils.normalizeURL(url);
feeds = findByField(Feed_.normalizedUrlHash,
DigestUtils.sha1Hex(normalized));
feeds = findByField(Feed_.normalizedUrlHash, DigestUtils.sha1Hex(normalized));
feed = Iterables.getFirst(feeds, null);
if (feed != null
&& StringUtils.equals(normalized, feed.getNormalizedUrl())) {
if (feed != null && StringUtils.equals(normalized, feed.getNormalizedUrl())) {
return feed;
}
@@ -110,8 +100,7 @@ public class FeedDAO extends GenericDAO<Feed> {
}
public void deleteRelationships(Feed feed) {
Query relationshipDeleteQuery = em
.createNamedQuery("Feed.deleteEntryRelationships");
Query relationshipDeleteQuery = em.createNamedQuery("Feed.deleteEntryRelationships");
relationshipDeleteQuery.setParameter("feedId", feed.getId());
relationshipDeleteQuery.executeUpdate();
}
@@ -120,8 +109,7 @@ public class FeedDAO extends GenericDAO<Feed> {
CriteriaQuery<Feed> query = builder.createQuery(getType());
Root<Feed> root = query.from(getType());
SetJoin<Feed, FeedSubscription> join = root.join(Feed_.subscriptions,
JoinType.LEFT);
SetJoin<Feed, FeedSubscription> join = root.join(Feed_.subscriptions, JoinType.LEFT);
query.where(builder.isNull(join.get(FeedSubscription_.id)));
TypedQuery<Feed> q = em.createQuery(query);
q.setMaxResults(max);
@@ -138,8 +126,7 @@ public class FeedDAO extends GenericDAO<Feed> {
}
public static enum DuplicateMode {
NORMALIZED_URL(Feed_.normalizedUrlHash), LAST_CONTENT(
Feed_.lastContentHash), PUSH_TOPIC(Feed_.pushTopicHash);
NORMALIZED_URL(Feed_.normalizedUrlHash), LAST_CONTENT(Feed_.lastContentHash), PUSH_TOPIC(Feed_.pushTopicHash);
private SingularAttribute<Feed, String> path;
private DuplicateMode(SingularAttribute<Feed, String> path) {
@@ -151,8 +138,7 @@ public class FeedDAO extends GenericDAO<Feed> {
}
}
public List<FeedCount> findDuplicates(DuplicateMode mode, int offset,
int limit, long minCount) {
public List<FeedCount> findDuplicates(DuplicateMode mode, int offset, int limit, long minCount) {
CriteriaQuery<String> query = builder.createQuery(String.class);
Root<Feed> root = query.from(getType());

View File

@@ -24,22 +24,19 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
CriteriaQuery<FeedEntryContent> query = builder.createQuery(getType());
Root<FeedEntryContent> root = query.from(getType());
Predicate p1 = builder.equal(root.get(FeedEntryContent_.contentHash),
DigestUtils.sha1Hex(content.getContent()));
Predicate p1 = builder.equal(root.get(FeedEntryContent_.contentHash), DigestUtils.sha1Hex(content.getContent()));
Predicate p2 = null;
if (content.getTitle() == null) {
p2 = builder.isNull(root.get(FeedEntryContent_.title));
} else {
p2 = builder.equal(root.get(FeedEntryContent_.title),
content.getTitle());
p2 = builder.equal(root.get(FeedEntryContent_.title), content.getTitle());
}
Predicate p3 = null;
if (content.getAuthor() == null) {
p3 = builder.isNull(root.get(FeedEntryContent_.author));
} else {
p3 = builder.equal(root.get(FeedEntryContent_.author),
content.getAuthor());
p3 = builder.equal(root.get(FeedEntryContent_.author), content.getAuthor());
}
query.where(p1, p2, p3);
@@ -52,8 +49,7 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
CriteriaQuery<FeedEntryContent> query = builder.createQuery(getType());
Root<FeedEntryContent> root = query.from(getType());
Join<FeedEntryContent, FeedEntry> join = root.join(
FeedEntryContent_.entries, JoinType.LEFT);
Join<FeedEntryContent, FeedEntry> join = root.join(FeedEntryContent_.entries, JoinType.LEFT);
query.where(builder.isNull(join.get(FeedEntry_.id)));
TypedQuery<FeedEntryContent> q = em.createQuery(query);
q.setMaxResults(max);

View File

@@ -26,19 +26,16 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
@Inject
ApplicationSettingsService applicationSettingsService;
protected static final Logger log = LoggerFactory
.getLogger(FeedEntryDAO.class);
protected static final Logger log = LoggerFactory.getLogger(FeedEntryDAO.class);
public FeedEntry findExisting(String guid, String url, Long feedId) {
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
Root<FeedEntry> root = query.from(getType());
Predicate p1 = builder.equal(root.get(FeedEntry_.guidHash),
DigestUtils.sha1Hex(guid));
Predicate p1 = builder.equal(root.get(FeedEntry_.guidHash), DigestUtils.sha1Hex(guid));
Predicate p2 = builder.equal(root.get(FeedEntry_.url), url);
Predicate p3 = builder.equal(root.get(FeedEntry_.feed).get(Feed_.id),
feedId);
Predicate p3 = builder.equal(root.get(FeedEntry_.feed).get(Feed_.id), feedId);
query.where(p1, p2, p3);

View File

@@ -45,8 +45,7 @@ import com.google.common.collect.Lists;
@Stateless
public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
protected static Logger log = LoggerFactory
.getLogger(FeedEntryStatusDAO.class);
protected static Logger log = LoggerFactory.getLogger(FeedEntryStatusDAO.class);
private static final String ALIAS_STATUS = "status";
private static final String ALIAS_ENTRY = "entry";
@@ -54,16 +53,14 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
private static final Comparator<FeedEntryStatus> STATUS_COMPARATOR_DESC = new Comparator<FeedEntryStatus>() {
@Override
public int compare(FeedEntryStatus o1, FeedEntryStatus o2) {
return ObjectUtils.compare(o2.getEntryUpdated(),
o1.getEntryUpdated());
return ObjectUtils.compare(o2.getEntryUpdated(), o1.getEntryUpdated());
};
};
private static final Comparator<FeedEntryStatus> STATUS_COMPARATOR_ASC = new Comparator<FeedEntryStatus>() {
@Override
public int compare(FeedEntryStatus o1, FeedEntryStatus o2) {
return ObjectUtils.compare(o1.getEntryUpdated(),
o2.getEntryUpdated());
return ObjectUtils.compare(o1.getEntryUpdated(), o2.getEntryUpdated());
};
};
@@ -76,8 +73,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
Root<FeedEntryStatus> root = query.from(getType());
Predicate p1 = builder.equal(root.get(FeedEntryStatus_.entry), entry);
Predicate p2 = builder.equal(root.get(FeedEntryStatus_.subscription),
sub);
Predicate p2 = builder.equal(root.get(FeedEntryStatus_.subscription), sub);
query.where(p1, p2);
@@ -87,12 +83,10 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return handleStatus(status, sub, entry);
}
private FeedEntryStatus handleStatus(FeedEntryStatus status,
FeedSubscription sub, FeedEntry entry) {
private FeedEntryStatus handleStatus(FeedEntryStatus status, FeedSubscription sub, FeedEntry entry) {
if (status == null) {
Date unreadThreshold = applicationSettingsService.get().getUnreadThreshold();
boolean read = unreadThreshold == null ? false : entry.getUpdated()
.before(unreadThreshold);
boolean read = unreadThreshold == null ? false : entry.getUpdated().before(unreadThreshold);
status = new FeedEntryStatus(sub.getUser(), sub, entry);
status.setRead(read);
status.setMarkable(!read);
@@ -102,8 +96,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return status;
}
public List<FeedEntryStatus> findStarred(User user, Date newerThan,
int offset, int limit, ReadingOrder order, boolean includeContent) {
public List<FeedEntryStatus> findStarred(User user, Date newerThan, int offset, int limit, ReadingOrder order, boolean includeContent) {
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
Root<FeedEntryStatus> root = query.from(getType());
@@ -115,8 +108,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
query.where(predicates.toArray(new Predicate[0]));
if (newerThan != null) {
predicates.add(builder.greaterThanOrEqualTo(
root.get(FeedEntryStatus_.entryInserted), newerThan));
predicates.add(builder.greaterThanOrEqualTo(root.get(FeedEntryStatus_.entryInserted), newerThan));
}
orderStatusesBy(query, root, order);
@@ -126,37 +118,28 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
setTimeout(q);
List<FeedEntryStatus> statuses = q.getResultList();
for (FeedEntryStatus status : statuses) {
status = handleStatus(status, status.getSubscription(),
status.getEntry());
status = handleStatus(status, status.getSubscription(), status.getEntry());
}
return lazyLoadContent(includeContent, statuses);
}
private Criteria buildSearchCriteria(FeedSubscription sub,
boolean unreadOnly, String keywords, Date newerThan, int offset,
int limit, ReadingOrder order, boolean includeContent, Date last) {
Criteria criteria = getSession().createCriteria(FeedEntry.class,
ALIAS_ENTRY);
private Criteria buildSearchCriteria(FeedSubscription sub, boolean unreadOnly, String keywords, Date newerThan, int offset, int limit,
ReadingOrder order, boolean includeContent, Date last) {
Criteria criteria = getSession().createCriteria(FeedEntry.class, ALIAS_ENTRY);
criteria.add(Restrictions.eq(FeedEntry_.feed.getName(), sub.getFeed()));
if (keywords != null) {
Criteria contentJoin = criteria.createCriteria(
FeedEntry_.content.getName(), "content",
JoinType.INNER_JOIN);
Criteria contentJoin = criteria.createCriteria(FeedEntry_.content.getName(), "content", JoinType.INNER_JOIN);
for (String keyword : keywords.split(" ")) {
Disjunction or = Restrictions.disjunction();
or.add(Restrictions.ilike(FeedEntryContent_.content.getName(),
keyword, MatchMode.ANYWHERE));
or.add(Restrictions.ilike(FeedEntryContent_.title.getName(),
keyword, MatchMode.ANYWHERE));
or.add(Restrictions.ilike(FeedEntryContent_.content.getName(), keyword, MatchMode.ANYWHERE));
or.add(Restrictions.ilike(FeedEntryContent_.title.getName(), keyword, MatchMode.ANYWHERE));
contentJoin.add(or);
}
}
Criteria statusJoin = criteria.createCriteria(
FeedEntry_.statuses.getName(), ALIAS_STATUS,
JoinType.LEFT_OUTER_JOIN,
Criteria statusJoin = criteria.createCriteria(FeedEntry_.statuses.getName(), ALIAS_STATUS, JoinType.LEFT_OUTER_JOIN,
Restrictions.eq(FeedEntryStatus_.subscription.getName(), sub));
if (unreadOnly) {
@@ -168,14 +151,12 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
Date unreadThreshold = applicationSettingsService.get().getUnreadThreshold();
if (unreadThreshold != null) {
criteria.add(Restrictions.ge(FeedEntry_.updated.getName(),
unreadThreshold));
criteria.add(Restrictions.ge(FeedEntry_.updated.getName(), unreadThreshold));
}
}
if (newerThan != null) {
criteria.add(Restrictions.ge(FeedEntry_.inserted.getName(),
newerThan));
criteria.add(Restrictions.ge(FeedEntry_.inserted.getName(), newerThan));
}
if (last != null) {
@@ -209,26 +190,19 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
}
@SuppressWarnings("unchecked")
public List<FeedEntryStatus> findBySubscriptions(
List<FeedSubscription> subscriptions, boolean unreadOnly,
String keywords, Date newerThan, int offset, int limit,
ReadingOrder order, boolean includeContent) {
public List<FeedEntryStatus> findBySubscriptions(List<FeedSubscription> subscriptions, boolean unreadOnly, String keywords,
Date newerThan, int offset, int limit, ReadingOrder order, boolean includeContent) {
int capacity = offset + limit;
Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC
: STATUS_COMPARATOR_ASC;
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(
capacity, comparator);
Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC : STATUS_COMPARATOR_ASC;
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(capacity, comparator);
for (FeedSubscription sub : subscriptions) {
Date last = (order != null && set.isFull()) ? set.last()
.getEntryUpdated() : null;
Criteria criteria = buildSearchCriteria(sub, unreadOnly, keywords,
newerThan, -1, capacity, order, includeContent, last);
Date last = (order != null && set.isFull()) ? set.last().getEntryUpdated() : null;
Criteria criteria = buildSearchCriteria(sub, unreadOnly, keywords, newerThan, -1, capacity, order, includeContent, last);
criteria.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
List<Map<String, Object>> list = criteria.list();
for (Map<String, Object> map : list) {
FeedEntryStatus status = (FeedEntryStatus) map
.get(ALIAS_STATUS);
FeedEntryStatus status = (FeedEntryStatus) map.get(ALIAS_STATUS);
FeedEntry entry = (FeedEntry) map.get(ALIAS_ENTRY);
entry.setSubscription(sub);
@@ -252,8 +226,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
@SuppressWarnings("unchecked")
public Long getUnreadCount(FeedSubscription subscription) {
Long count = null;
Criteria criteria = buildSearchCriteria(subscription, true, null, null,
-1, -1, null, false, null);
Criteria criteria = buildSearchCriteria(subscription, true, null, null, -1, -1, null, false, null);
ProjectionList projection = Projections.projectionList();
projection.add(Projections.rowCount(), "count");
criteria.setProjection(projection);
@@ -265,8 +238,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return count;
}
private List<FeedEntryStatus> lazyLoadContent(boolean includeContent,
List<FeedEntryStatus> results) {
private List<FeedEntryStatus> lazyLoadContent(boolean includeContent, List<FeedEntryStatus> results) {
if (includeContent) {
for (FeedEntryStatus status : results) {
Models.initialize(status.getSubscription().getFeed());
@@ -276,13 +248,11 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return results;
}
private void orderStatusesBy(CriteriaQuery<?> query,
Path<FeedEntryStatus> statusJoin, ReadingOrder order) {
private void orderStatusesBy(CriteriaQuery<?> query, Path<FeedEntryStatus> statusJoin, ReadingOrder order) {
orderBy(query, statusJoin.get(FeedEntryStatus_.entryUpdated), order);
}
private void orderBy(CriteriaQuery<?> query, Path<Date> date,
ReadingOrder order) {
private void orderBy(CriteriaQuery<?> query, Path<Date> date, ReadingOrder order) {
if (order != null) {
if (order == ReadingOrder.asc) {
query.orderBy(builder.asc(date));
@@ -296,16 +266,13 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
setTimeout(query, applicationSettingsService.get().getQueryTimeout());
}
public void markSubscriptionEntries(List<FeedSubscription> subscriptions,
Date olderThan) {
List<FeedEntryStatus> statuses = findBySubscriptions(subscriptions,
true, null, null, -1, -1, null, false);
public void markSubscriptionEntries(List<FeedSubscription> subscriptions, Date olderThan) {
List<FeedEntryStatus> statuses = findBySubscriptions(subscriptions, true, null, null, -1, -1, null, false);
markList(statuses, olderThan);
}
public void markStarredEntries(User user, Date olderThan) {
List<FeedEntryStatus> statuses = findStarred(user, null, -1, -1, null,
false);
List<FeedEntryStatus> statuses = findStarred(user, null, -1, -1, null, false);
markList(statuses, olderThan);
}
@@ -314,8 +281,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
for (FeedEntryStatus status : statuses) {
if (!status.isRead()) {
Date inserted = status.getEntry().getInserted();
if (olderThan == null || inserted == null
|| olderThan.after(inserted)) {
if (olderThan == null || inserted == null || olderThan.after(inserted)) {
status.setRead(true);
list.add(status);
}

View File

@@ -28,8 +28,7 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
CriteriaQuery<FeedSubscription> query = builder.createQuery(getType());
Root<FeedSubscription> root = query.from(getType());
Predicate p1 = builder.equal(
root.get(FeedSubscription_.user).get(User_.id), user.getId());
Predicate p1 = builder.equal(root.get(FeedSubscription_.user).get(User_.id), user.getId());
Predicate p2 = builder.equal(root.get(FeedSubscription_.id), id);
root.fetch(FeedSubscription_.feed, JoinType.LEFT);
@@ -37,8 +36,7 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
query.where(p1, p2);
FeedSubscription sub = Iterables.getFirst(cache(em.createQuery(query))
.getResultList(), null);
FeedSubscription sub = Iterables.getFirst(cache(em.createQuery(query)).getResultList(), null);
initRelations(sub);
return sub;
}
@@ -47,10 +45,8 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
CriteriaQuery<FeedSubscription> query = builder.createQuery(getType());
Root<FeedSubscription> root = query.from(getType());
query.where(builder.equal(root.get(FeedSubscription_.feed)
.get(Feed_.id), feed.getId()));
List<FeedSubscription> list = cache(em.createQuery(query))
.getResultList();
query.where(builder.equal(root.get(FeedSubscription_.feed).get(Feed_.id), feed.getId()));
List<FeedSubscription> list = cache(em.createQuery(query)).getResultList();
initRelations(list);
return list;
}
@@ -60,18 +56,15 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
CriteriaQuery<FeedSubscription> query = builder.createQuery(getType());
Root<FeedSubscription> root = query.from(getType());
Predicate p1 = builder.equal(
root.get(FeedSubscription_.user).get(User_.id), user.getId());
Predicate p2 = builder.equal(
root.get(FeedSubscription_.feed).get(Feed_.id), feed.getId());
Predicate p1 = builder.equal(root.get(FeedSubscription_.user).get(User_.id), user.getId());
Predicate p2 = builder.equal(root.get(FeedSubscription_.feed).get(Feed_.id), feed.getId());
root.fetch(FeedSubscription_.feed, JoinType.LEFT);
root.fetch(FeedSubscription_.category, JoinType.LEFT);
query.where(p1, p2);
FeedSubscription sub = Iterables.getFirst(cache(em.createQuery(query))
.getResultList(), null);
FeedSubscription sub = Iterables.getFirst(cache(em.createQuery(query)).getResultList(), null);
initRelations(sub);
return sub;
}
@@ -84,57 +77,46 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
root.fetch(FeedSubscription_.feed, JoinType.LEFT);
root.fetch(FeedSubscription_.category, JoinType.LEFT);
query.where(builder.equal(root.get(FeedSubscription_.user)
.get(User_.id), user.getId()));
query.where(builder.equal(root.get(FeedSubscription_.user).get(User_.id), user.getId()));
List<FeedSubscription> list = cache(em.createQuery(query))
.getResultList();
List<FeedSubscription> list = cache(em.createQuery(query)).getResultList();
initRelations(list);
return list;
}
public List<FeedSubscription> findByCategory(User user,
FeedCategory category) {
public List<FeedSubscription> findByCategory(User user, FeedCategory category) {
CriteriaQuery<FeedSubscription> query = builder.createQuery(getType());
Root<FeedSubscription> root = query.from(getType());
Predicate p1 = builder.equal(
root.get(FeedSubscription_.user).get(User_.id), user.getId());
Predicate p1 = builder.equal(root.get(FeedSubscription_.user).get(User_.id), user.getId());
Predicate p2 = null;
if (category == null) {
p2 = builder.isNull(
root.get(FeedSubscription_.category));
p2 = builder.isNull(root.get(FeedSubscription_.category));
} else {
p2 = builder.equal(
root.get(FeedSubscription_.category).get(FeedCategory_.id),
category.getId());
p2 = builder.equal(root.get(FeedSubscription_.category).get(FeedCategory_.id), category.getId());
}
query.where(p1, p2);
List<FeedSubscription> list = cache(em.createQuery(query))
.getResultList();
List<FeedSubscription> list = cache(em.createQuery(query)).getResultList();
initRelations(list);
return list;
}
public List<FeedSubscription> findByCategories(User user,
List<FeedCategory> categories) {
List<Long> categoryIds = Lists.transform(categories,
new Function<FeedCategory, Long>() {
@Override
public Long apply(FeedCategory input) {
return input.getId();
}
});
public List<FeedSubscription> findByCategories(User user, List<FeedCategory> categories) {
List<Long> categoryIds = Lists.transform(categories, new Function<FeedCategory, Long>() {
@Override
public Long apply(FeedCategory input) {
return input.getId();
}
});
List<FeedSubscription> subscriptions = Lists.newArrayList();
for (FeedSubscription sub : findAll(user)) {
if (sub.getCategory() != null
&& categoryIds.contains(sub.getCategory().getId())) {
if (sub.getCategory() != null && categoryIds.contains(sub.getCategory().getId())) {
subscriptions.add(sub);
}
}

View File

@@ -96,8 +96,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
return q.getResultList();
}
public List<T> findAll(int startIndex, int count, String orderBy,
boolean asc) {
public List<T> findAll(int startIndex, int count, String orderBy, boolean asc) {
CriteriaQuery<T> query = builder.createQuery(getType());
Root<T> root = query.from(getType());
@@ -126,8 +125,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
return findByField(field, value, false);
}
protected <V> List<T> findByField(Attribute<T, V> field, V value,
boolean cache) {
protected <V> List<T> findByField(Attribute<T, V> field, V value, boolean cache) {
CriteriaQuery<T> query = builder.createQuery(getType());
Root<T> root = query.from(getType());

View File

@@ -18,11 +18,10 @@ public class UserDAO extends GenericDAO<User> {
CriteriaQuery<User> query = builder.createQuery(getType());
Root<User> root = query.from(getType());
query.where(builder.equal(builder.lower(root.get(User_.name)),
name.toLowerCase()));
query.where(builder.equal(builder.lower(root.get(User_.name)), name.toLowerCase()));
TypedQuery<User> q = em.createQuery(query);
cache(q);
User user = null;
try {
user = q.getSingleResult();
@@ -38,7 +37,7 @@ public class UserDAO extends GenericDAO<User> {
query.where(builder.equal(root.get(User_.apiKey), key));
TypedQuery<User> q = em.createQuery(query);
cache(q);
User user = null;
try {
user = q.getSingleResult();

View File

@@ -33,8 +33,7 @@ public class UserRoleDAO extends GenericDAO<UserRole> {
CriteriaQuery<UserRole> query = builder.createQuery(getType());
Root<UserRole> root = query.from(getType());
query.where(builder.equal(root.get(UserRole_.user).get(User_.id),
user.getId()));
query.where(builder.equal(root.get(UserRole_.user).get(User_.id), user.getId()));
return cache(em.createQuery(query)).getResultList();
}

View File

@@ -18,8 +18,7 @@ public class UserSettingsDAO extends GenericDAO<UserSettings> {
CriteriaQuery<UserSettings> query = builder.createQuery(getType());
Root<UserSettings> root = query.from(getType());
query.where(builder.equal(root.get(UserSettings_.user).get(User_.id),
user.getId()));
query.where(builder.equal(root.get(UserSettings_.user).get(User_.id), user.getId()));
UserSettings settings = null;
try {

View File

@@ -27,12 +27,9 @@ public class FaviconFetcher {
private static long MAX_ICON_LENGTH = 20000;
private static int TIMEOUT = 4000;
protected static List<String> ICON_MIMETYPES = Arrays.asList(
"image/x-icon", "image/vnd.microsoft.icon", "image/ico",
"image/icon", "text/ico", "application/ico", "image/x-ms-bmp",
"image/x-bmp", "image/gif", "image/png", "image/jpeg");
private static List<String> ICON_MIMETYPE_BLACKLIST = Arrays.asList(
"application/xml", "text/html");
protected static List<String> ICON_MIMETYPES = Arrays.asList("image/x-icon", "image/vnd.microsoft.icon", "image/ico", "image/icon",
"text/ico", "application/ico", "image/x-ms-bmp", "image/x-bmp", "image/gif", "image/png", "image/jpeg");
private static List<String> ICON_MIMETYPE_BLACKLIST = Arrays.asList("application/xml", "text/html");
@Inject
HttpGetter getter;
@@ -101,14 +98,12 @@ public class FaviconFetcher {
}
if (length < MIN_ICON_LENGTH) {
log.debug("Length {} below MIN_ICON_LENGTH {}", length,
MIN_ICON_LENGTH);
log.debug("Length {} below MIN_ICON_LENGTH {}", length, MIN_ICON_LENGTH);
return false;
}
if (length > MAX_ICON_LENGTH) {
log.debug("Length {} greater than MAX_ICON_LENGTH {}", length,
MAX_ICON_LENGTH);
log.debug("Length {} greater than MAX_ICON_LENGTH {}", length, MAX_ICON_LENGTH);
return false;
}
@@ -126,8 +121,7 @@ public class FaviconFetcher {
return null;
}
Elements icons = doc
.select("link[rel~=(?i)^(shortcut|icon|shortcut icon)$]");
Elements icons = doc.select("link[rel~=(?i)^(shortcut|icon|shortcut icon)$]");
if (icons.isEmpty()) {
log.debug("No icon found in page {}", url);

View File

@@ -30,18 +30,15 @@ public class FeedFetcher {
@Inject
HttpGetter getter;
public FetchedFeed fetch(String feedUrl, boolean extractFeedUrlFromHtml,
String lastModified, String eTag, Date lastPublishedDate,
String lastContentHash) throws FeedException,
ClientProtocolException, IOException, NotModifiedException {
public FetchedFeed fetch(String feedUrl, boolean extractFeedUrlFromHtml, String lastModified, String eTag, Date lastPublishedDate,
String lastContentHash) throws FeedException, ClientProtocolException, IOException, NotModifiedException {
log.debug("Fetching feed {}", feedUrl);
FetchedFeed fetchedFeed = null;
int timeout = 20000;
HttpResult result = getter.getBinary(feedUrl, lastModified, eTag, timeout);
if (extractFeedUrlFromHtml) {
String extractedUrl = extractFeedUrl(
StringUtils.newStringUtf8(result.getContent()), feedUrl);
String extractedUrl = extractFeedUrl(StringUtils.newStringUtf8(result.getContent()), feedUrl);
if (org.apache.commons.lang.StringUtils.isNotBlank(extractedUrl)) {
result = getter.getBinary(extractedUrl, lastModified, eTag, timeout);
feedUrl = extractedUrl;
@@ -54,18 +51,15 @@ public class FeedFetcher {
}
String hash = DigestUtils.sha1Hex(content);
if (lastContentHash != null && hash != null
&& lastContentHash.equals(hash)) {
if (lastContentHash != null && hash != null && lastContentHash.equals(hash)) {
log.debug("content hash not modified: {}", feedUrl);
throw new NotModifiedException("content hash not modified");
}
fetchedFeed = parser.parse(feedUrl, content);
if (lastPublishedDate != null
&& fetchedFeed.getFeed().getLastPublishedDate() != null
&& lastPublishedDate.getTime() == fetchedFeed.getFeed()
.getLastPublishedDate().getTime()) {
if (lastPublishedDate != null && fetchedFeed.getFeed().getLastPublishedDate() != null
&& lastPublishedDate.getTime() == fetchedFeed.getFeed().getLastPublishedDate().getTime()) {
log.debug("publishedDate not modified: {}", feedUrl);
throw new NotModifiedException("publishedDate not modified");
}

View File

@@ -33,12 +33,10 @@ public class FeedParser {
private static Logger log = LoggerFactory.getLogger(FeedParser.class);
private static final String ATOM_10_URI = "http://www.w3.org/2005/Atom";
private static final Namespace ATOM_10_NS = Namespace
.getNamespace(ATOM_10_URI);
private static final Namespace ATOM_10_NS = Namespace.getNamespace(ATOM_10_URI);
private static final Date START = new Date(86400000);
private static final Date END = new Date(
1000l * Integer.MAX_VALUE - 86400000);
private static final Date END = new Date(1000l * Integer.MAX_VALUE - 86400000);
private static final Function<SyndContent, String> CONTENT_TO_STRING = new Function<SyndContent, String>() {
public String apply(SyndContent content) {
@@ -55,11 +53,9 @@ public class FeedParser {
try {
String encoding = FeedUtils.guessEncoding(xml);
String xmlString = FeedUtils.trimInvalidXmlCharacters(new String(
xml, encoding));
String xmlString = FeedUtils.trimInvalidXmlCharacters(new String(xml, encoding));
if (xmlString == null) {
throw new FeedException("Input string is null for url "
+ feedUrl);
throw new FeedException("Input string is null for url " + feedUrl);
}
InputSource source = new InputSource(new StringReader(xmlString));
SyndFeed rss = new SyndFeedInput().build(source);
@@ -88,20 +84,16 @@ public class FeedParser {
continue;
}
entry.setGuid(FeedUtils.truncate(guid, 2048));
entry.setUrl(FeedUtils.truncate(
FeedUtils.toAbsoluteUrl(item.getLink(), feed.getLink()),
2048));
entry.setUrl(FeedUtils.truncate(FeedUtils.toAbsoluteUrl(item.getLink(), feed.getLink()), 2048));
entry.setUpdated(validateDate(getEntryUpdateDate(item), true));
FeedEntryContent content = new FeedEntryContent();
content.setContent(getContent(item));
content.setTitle(getTitle(item));
content.setAuthor(item.getAuthor());
SyndEnclosure enclosure = (SyndEnclosure) Iterables.getFirst(
item.getEnclosures(), null);
SyndEnclosure enclosure = (SyndEnclosure) Iterables.getFirst(item.getEnclosures(), null);
if (enclosure != null) {
content.setEnclosureUrl(FeedUtils.truncate(
enclosure.getUrl(), 2048));
content.setEnclosureUrl(FeedUtils.truncate(enclosure.getUrl(), 2048));
content.setEnclosureType(enclosure.getType());
}
entry.setContent(content);
@@ -111,21 +103,17 @@ public class FeedParser {
Date lastEntryDate = null;
Date publishedDate = validateDate(rss.getPublishedDate(), false);
if (!entries.isEmpty()) {
List<Long> sortedTimestamps = FeedUtils
.getSortedTimestamps(entries);
List<Long> sortedTimestamps = FeedUtils.getSortedTimestamps(entries);
Long timestamp = sortedTimestamps.get(0);
lastEntryDate = new Date(timestamp);
publishedDate = getFeedPublishedDate(publishedDate, entries);
}
feed.setLastPublishedDate(validateDate(publishedDate, true));
feed.setAverageEntryInterval(FeedUtils
.averageTimeBetweenEntries(entries));
feed.setAverageEntryInterval(FeedUtils.averageTimeBetweenEntries(entries));
feed.setLastEntryDate(lastEntryDate);
} catch (Exception e) {
throw new FeedException(String.format(
"Could not parse feed from %s : %s", feedUrl,
e.getMessage()), e);
throw new FeedException(String.format("Could not parse feed from %s : %s", feedUrl, e.getMessage()), e);
}
return fetchedFeed;
}
@@ -144,8 +132,7 @@ public class FeedParser {
for (Object object : elements) {
if (object instanceof Element) {
Element element = (Element) object;
if ("link".equals(element.getName())
&& ATOM_10_NS.equals(element.getNamespace())) {
if ("link".equals(element.getName()) && ATOM_10_NS.equals(element.getNamespace())) {
SyndLink link = new SyndLinkImpl();
link.setRel(element.getAttributeValue("rel"));
link.setHref(element.getAttributeValue("href"));
@@ -156,8 +143,7 @@ public class FeedParser {
}
}
private Date getFeedPublishedDate(Date publishedDate,
List<FeedEntry> entries) {
private Date getFeedPublishedDate(Date publishedDate, List<FeedEntry> entries) {
for (FeedEntry entry : entries) {
if (publishedDate == null || entry.getUpdated().getTime() > publishedDate.getTime()) {
@@ -197,12 +183,9 @@ public class FeedParser {
private String getContent(SyndEntry item) {
String content = null;
if (item.getContents().isEmpty()) {
content = item.getDescription() == null ? null : item
.getDescription().getValue();
content = item.getDescription() == null ? null : item.getDescription().getValue();
} else {
content = StringUtils.join(Collections2.transform(
item.getContents(), CONTENT_TO_STRING),
SystemUtils.LINE_SEPARATOR);
content = StringUtils.join(Collections2.transform(item.getContents(), CONTENT_TO_STRING), SystemUtils.LINE_SEPARATOR);
}
return StringUtils.trimToEmpty(content);
}
@@ -224,8 +207,7 @@ public class FeedParser {
private String findHub(SyndFeed feed) {
for (SyndLink l : (List<SyndLink>) feed.getLinks()) {
if ("hub".equalsIgnoreCase(l.getRel())) {
log.debug("found hub {} for feed {}", l.getHref(),
feed.getLink());
log.debug("found hub {} for feed {}", l.getHref(), feed.getLink());
return l.getHref();
}
}
@@ -236,8 +218,7 @@ public class FeedParser {
private String findSelf(SyndFeed feed) {
for (SyndLink l : (List<SyndLink>) feed.getLinks()) {
if ("self".equalsIgnoreCase(l.getRel())) {
log.debug("found self {} for feed {}", l.getHref(),
feed.getLink());
log.debug("found self {} for feed {}", l.getHref(), feed.getLink());
return l.getHref();
}
}

View File

@@ -12,32 +12,28 @@ import org.slf4j.LoggerFactory;
public class FeedRefreshExecutor {
private static Logger log = LoggerFactory
.getLogger(FeedRefreshExecutor.class);
private static Logger log = LoggerFactory.getLogger(FeedRefreshExecutor.class);
private String poolName;
private ThreadPoolExecutor pool;
private LinkedBlockingDeque<Runnable> queue;
public FeedRefreshExecutor(final String poolName, int threads,
int queueCapacity) {
public FeedRefreshExecutor(final String poolName, int threads, int queueCapacity) {
log.info("Creating pool {} with {} threads", poolName, threads);
this.poolName = poolName;
pool = new ThreadPoolExecutor(threads, threads, 0,
TimeUnit.MILLISECONDS,
queue = new LinkedBlockingDeque<Runnable>(queueCapacity) {
private static final long serialVersionUID = 1L;
pool = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, queue = new LinkedBlockingDeque<Runnable>(queueCapacity) {
private static final long serialVersionUID = 1L;
@Override
public boolean offer(Runnable r) {
Task task = (Task) r;
if (task.isUrgent()) {
return offerFirst(r);
} else {
return offerLast(r);
}
}
});
@Override
public boolean offer(Runnable r) {
Task task = (Task) r;
if (task.isUrgent()) {
return offerFirst(r);
} else {
return offerLast(r);
}
}
});
pool.setRejectedExecutionHandler(new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
@@ -50,8 +46,7 @@ public class FeedRefreshExecutor {
queue.put(r);
}
} catch (InterruptedException e1) {
log.error(poolName
+ " interrupted while waiting for queue.", e1);
log.error(poolName + " interrupted while waiting for queue.", e1);
}
}
});
@@ -80,13 +75,11 @@ public class FeedRefreshExecutor {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
log.error(
"{} interrupted while waiting for threads to finish.",
poolName);
log.error("{} interrupted while waiting for threads to finish.", poolName);
}
}
}
private static class NamedThreadFactory implements ThreadFactory {
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
@@ -94,15 +87,12 @@ public class FeedRefreshExecutor {
private NamedThreadFactory(String poolName) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
namePrefix = poolName + "-thread-";
}
public Thread newThread(Runnable r) {
Thread t = new Thread(group, r,
namePrefix + threadNumber.getAndIncrement(),
0);
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
if (t.isDaemon())
t.setDaemon(false);
if (t.getPriority() != Thread.NORM_PRIORITY)

View File

@@ -52,8 +52,7 @@ public class FeedRefreshTaskGiver {
@PostConstruct
public void init() {
backgroundThreads = applicationSettingsService.get()
.getBackgroundThreads();
backgroundThreads = applicationSettingsService.get().getBackgroundThreads();
executor = Executors.newFixedThreadPool(1);
}
@@ -125,8 +124,7 @@ public class FeedRefreshTaskGiver {
public void add(Feed feed) {
Date threshold = getThreshold();
if (feed.getLastUpdated() == null
|| feed.getLastUpdated().before(threshold)) {
if (feed.getLastUpdated() == null || feed.getLastUpdated().before(threshold)) {
addQueue.add(feed);
}
}

View File

@@ -38,8 +38,7 @@ import com.google.common.util.concurrent.Striped;
@ApplicationScoped
public class FeedRefreshUpdater {
protected static Logger log = LoggerFactory
.getLogger(FeedRefreshUpdater.class);
protected static Logger log = LoggerFactory.getLogger(FeedRefreshUpdater.class);
@Inject
FeedUpdateService feedUpdateService;
@@ -75,8 +74,7 @@ public class FeedRefreshUpdater {
public void init() {
ApplicationSettings settings = applicationSettingsService.get();
int threads = Math.max(settings.getDatabaseUpdateThreads(), 1);
pool = new FeedRefreshExecutor("feed-refresh-updater", threads,
500 * threads);
pool = new FeedRefreshExecutor("feed-refresh-updater", threads, 500 * threads);
locks = Striped.lazyWeakLock(threads * 100000);
}
@@ -113,8 +111,7 @@ public class FeedRefreshUpdater {
if (!lastEntries.contains(cacheKey)) {
log.debug("cache miss for {}", entry.getUrl());
if (subscriptions == null) {
subscriptions = feedSubscriptionDAO
.findByFeed(feed);
subscriptions = feedSubscriptionDAO.findByFeed(feed);
}
ok &= addEntry(feed, entry, subscriptions);
metricsBean.entryCacheMiss();
@@ -143,8 +140,7 @@ public class FeedRefreshUpdater {
}
}
private boolean addEntry(final Feed feed, final FeedEntry entry,
final List<FeedSubscription> subscriptions) {
private boolean addEntry(final Feed feed, final FeedEntry entry, final List<FeedSubscription> subscriptions) {
boolean success = false;
// lock on feed, make sure we are not updating the same feed twice at
@@ -155,8 +151,7 @@ public class FeedRefreshUpdater {
// twice at the same time
String key2 = DigestUtils.sha1Hex(entry.getContent().getContent());
Iterator<Lock> iterator = locks.bulkGet(Arrays.asList(key1, key2))
.iterator();
Iterator<Lock> iterator = locks.bulkGet(Arrays.asList(key1, key2)).iterator();
Lock lock1 = iterator.next();
Lock lock2 = iterator.next();
boolean locked1 = false;
@@ -171,8 +166,7 @@ public class FeedRefreshUpdater {
log.error("lock timeout for " + feed.getUrl() + " - " + key1);
}
} catch (InterruptedException e) {
log.error("interrupted while waiting for lock for " + feed.getUrl()
+ " : " + e.getMessage(), e);
log.error("interrupted while waiting for lock for " + feed.getUrl() + " : " + e.getMessage(), e);
} finally {
if (locked1) {
lock1.unlock();

View File

@@ -25,8 +25,7 @@ import com.sun.syndication.io.FeedException;
@ApplicationScoped
public class FeedRefreshWorker {
private static Logger log = LoggerFactory
.getLogger(FeedRefreshWorker.class);
private static Logger log = LoggerFactory.getLogger(FeedRefreshWorker.class);
@Inject
FeedRefreshUpdater feedRefreshUpdater;
@@ -52,8 +51,7 @@ public class FeedRefreshWorker {
private void init() {
ApplicationSettings settings = applicationSettingsService.get();
int threads = settings.getBackgroundThreads();
pool = new FeedRefreshExecutor("feed-refresh-worker", threads,
20 * threads);
pool = new FeedRefreshExecutor("feed-refresh-worker", threads, 20 * threads);
}
@PreDestroy
@@ -95,8 +93,7 @@ public class FeedRefreshWorker {
private void update(Feed feed) {
Date now = new Date();
try {
FetchedFeed fetchedFeed = fetcher.fetch(feed.getUrl(), false,
feed.getLastModifiedHeader(), feed.getEtagHeader(),
FetchedFeed fetchedFeed = fetcher.fetch(feed.getUrl(), false, feed.getLastModifiedHeader(), feed.getEtagHeader(),
feed.getLastPublishedDate(), feed.getLastContentHash());
// stops here if NotModifiedException or any other exception is
// thrown
@@ -104,21 +101,17 @@ public class FeedRefreshWorker {
Date disabledUntil = null;
if (applicationSettingsService.get().isHeavyLoad()) {
disabledUntil = FeedUtils.buildDisabledUntil(fetchedFeed
.getFeed().getLastEntryDate(), fetchedFeed.getFeed()
disabledUntil = FeedUtils.buildDisabledUntil(fetchedFeed.getFeed().getLastEntryDate(), fetchedFeed.getFeed()
.getAverageEntryInterval());
}
feed.setLastUpdateSuccess(now);
feed.setLink(fetchedFeed.getFeed().getLink());
feed.setLastModifiedHeader(fetchedFeed.getFeed()
.getLastModifiedHeader());
feed.setLastModifiedHeader(fetchedFeed.getFeed().getLastModifiedHeader());
feed.setEtagHeader(fetchedFeed.getFeed().getEtagHeader());
feed.setLastContentHash(fetchedFeed.getFeed().getLastContentHash());
feed.setLastPublishedDate(fetchedFeed.getFeed()
.getLastPublishedDate());
feed.setAverageEntryInterval(fetchedFeed.getFeed()
.getAverageEntryInterval());
feed.setLastPublishedDate(fetchedFeed.getFeed().getLastPublishedDate());
feed.setAverageEntryInterval(fetchedFeed.getFeed().getAverageEntryInterval());
feed.setLastEntryDate(fetchedFeed.getFeed().getLastEntryDate());
feed.setErrorCount(0);
@@ -129,14 +122,11 @@ public class FeedRefreshWorker {
feedRefreshUpdater.updateFeed(feed, entries);
} catch (NotModifiedException e) {
log.debug("Feed not modified : {} - {}", feed.getUrl(),
e.getMessage());
log.debug("Feed not modified : {} - {}", feed.getUrl(), e.getMessage());
Date disabledUntil = null;
if (applicationSettingsService.get().isHeavyLoad()) {
disabledUntil = FeedUtils
.buildDisabledUntil(feed.getLastEntryDate(),
feed.getAverageEntryInterval());
disabledUntil = FeedUtils.buildDisabledUntil(feed.getLastEntryDate(), feed.getAverageEntryInterval());
}
feed.setErrorCount(0);
feed.setMessage(null);
@@ -144,8 +134,7 @@ public class FeedRefreshWorker {
taskGiver.giveBack(feed);
} catch (Exception e) {
String message = "Unable to refresh feed " + feed.getUrl() + " : "
+ e.getMessage();
String message = "Unable to refresh feed " + feed.getUrl() + " : " + e.getMessage();
if (e instanceof FeedException) {
log.debug(e.getClass().getName() + " " + message, e);
} else {
@@ -154,8 +143,7 @@ public class FeedRefreshWorker {
feed.setErrorCount(feed.getErrorCount() + 1);
feed.setMessage(message);
feed.setDisabledUntil(FeedUtils.buildDisabledUntil(feed
.getErrorCount()));
feed.setDisabledUntil(FeedUtils.buildDisabledUntil(feed.getErrorCount()));
taskGiver.giveBack(feed);
}

View File

@@ -41,10 +41,8 @@ public class FeedUtils {
protected static Logger log = LoggerFactory.getLogger(FeedUtils.class);
private static final String ESCAPED_QUESTION_MARK = Pattern.quote("?");
private static final List<String> ALLOWED_IFRAME_CSS_RULES = Arrays.asList(
"height", "width", "border");
private static final char[] DISALLOWED_IFRAME_CSS_RULE_CHARACTERS = new char[] {
'(', ')' };
private static final List<String> ALLOWED_IFRAME_CSS_RULES = Arrays.asList("height", "width", "border");
private static final char[] DISALLOWED_IFRAME_CSS_RULE_CHARACTERS = new char[] { '(', ')' };
public static String truncate(String string, int length) {
if (string != null) {
@@ -54,8 +52,8 @@ public class FeedUtils {
}
/**
* Detect feed encoding by using the declared encoding in the xml processing
* instruction and by detecting the characters used in the feed
* Detect feed encoding by using the declared encoding in the xml processing instruction and by detecting the characters used in the
* feed
*
*/
public static String guessEncoding(byte[] bytes) {
@@ -87,8 +85,7 @@ public class FeedUtils {
}
/**
* Normalize the url. The resulting url is not meant to be fetched but
* rather used as a mean to identify a feed and avoid duplicates
* Normalize the url. The resulting url is not meant to be fetched but rather used as a mean to identify a feed and avoid duplicates
*/
public static String normalizeURL(String url) {
if (url == null) {
@@ -113,13 +110,11 @@ public class FeedUtils {
normalized = normalized.replace("//www.", "//");
// feedproxy redirects to feedburner
normalized = normalized.replace("feedproxy.google.com",
"feeds.feedburner.com");
normalized = normalized.replace("feedproxy.google.com", "feeds.feedburner.com");
// feedburner feeds have a special treatment
if (normalized.split(ESCAPED_QUESTION_MARK)[0].contains("feedburner.com")) {
normalized = normalized.replace("feeds2.feedburner.com",
"feeds.feedburner.com");
normalized = normalized.replace("feeds2.feedburner.com", "feeds.feedburner.com");
normalized = normalized.split(ESCAPED_QUESTION_MARK)[0];
normalized = StringUtils.removeEnd(normalized, "/");
}
@@ -146,17 +141,13 @@ public class FeedUtils {
return encoding;
}
public static String handleContent(String content, String baseUri,
boolean keepTextOnly) {
public static String handleContent(String content, String baseUri, boolean keepTextOnly) {
if (StringUtils.isNotBlank(content)) {
baseUri = StringUtils.trimToEmpty(baseUri);
Whitelist whitelist = new Whitelist();
whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite",
"code", "col", "colgroup", "dd", "div", "dl", "dt", "em",
"h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe", "img",
"li", "ol", "p", "pre", "q", "small", "strike", "strong",
"sub", "sup", "table", "tbody", "td", "tfoot", "th",
"thead", "tr", "u", "ul");
whitelist.addTags("a", "b", "blockquote", "br", "caption", "cite", "code", "col", "colgroup", "dd", "div", "dl", "dt", "em",
"h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe", "img", "li", "ol", "p", "pre", "q", "small", "strike", "strong",
"sub", "sup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "u", "ul");
whitelist.addAttributes("div", "dir");
whitelist.addAttributes("pre", "dir");
@@ -167,22 +158,16 @@ public class FeedUtils {
whitelist.addAttributes("blockquote", "cite");
whitelist.addAttributes("col", "span", "width");
whitelist.addAttributes("colgroup", "span", "width");
whitelist.addAttributes("iframe", "src", "height", "width",
"allowfullscreen", "frameborder", "style");
whitelist.addAttributes("img", "align", "alt", "height", "src",
"title", "width");
whitelist.addAttributes("iframe", "src", "height", "width", "allowfullscreen", "frameborder", "style");
whitelist.addAttributes("img", "align", "alt", "height", "src", "title", "width");
whitelist.addAttributes("ol", "start", "type");
whitelist.addAttributes("q", "cite");
whitelist.addAttributes("table", "border", "bordercolor",
"summary", "width");
whitelist.addAttributes("td", "border", "bordercolor", "abbr",
"axis", "colspan", "rowspan", "width");
whitelist.addAttributes("th", "border", "bordercolor", "abbr",
"axis", "colspan", "rowspan", "scope", "width");
whitelist.addAttributes("table", "border", "bordercolor", "summary", "width");
whitelist.addAttributes("td", "border", "bordercolor", "abbr", "axis", "colspan", "rowspan", "width");
whitelist.addAttributes("th", "border", "bordercolor", "abbr", "axis", "colspan", "rowspan", "scope", "width");
whitelist.addAttributes("ul", "type");
whitelist.addProtocols("a", "href", "ftp", "http", "https",
"mailto");
whitelist.addProtocols("a", "href", "ftp", "http", "https", "mailto");
whitelist.addProtocols("blockquote", "cite", "http", "https");
whitelist.addProtocols("img", "src", "http", "https");
whitelist.addProtocols("q", "cite", "http", "https");
@@ -199,8 +184,7 @@ public class FeedUtils {
e.attr("style", escaped);
}
clean.outputSettings(new OutputSettings().escapeMode(
EscapeMode.base).prettyPrint(false));
clean.outputSettings(new OutputSettings().escapeMode(EscapeMode.base).prettyPrint(false));
Element body = clean.body();
if (keepTextOnly) {
content = body.text();
@@ -215,9 +199,7 @@ public class FeedUtils {
List<String> rules = Lists.newArrayList();
CSSOMParser parser = new CSSOMParser();
try {
CSSStyleDeclaration decl = parser
.parseStyleDeclaration(new InputSource(new StringReader(
orig)));
CSSStyleDeclaration decl = parser.parseStyleDeclaration(new InputSource(new StringReader(orig)));
for (int i = 0; i < decl.getLength(); i++) {
String property = decl.item(i);
@@ -226,11 +208,8 @@ public class FeedUtils {
continue;
}
if (ALLOWED_IFRAME_CSS_RULES.contains(property)
&& StringUtils.containsNone(value,
DISALLOWED_IFRAME_CSS_RULE_CHARACTERS)) {
rules.add(property + ":" + decl.getPropertyValue(property)
+ ";");
if (ALLOWED_IFRAME_CSS_RULES.contains(property) && StringUtils.containsNone(value, DISALLOWED_IFRAME_CSS_RULE_CHARACTERS)) {
rules.add(property + ":" + decl.getPropertyValue(property) + ";");
}
}
} catch (IOException e) {
@@ -278,8 +257,7 @@ public class FeedUtils {
}
if (c >= 32 || c == 9 || c == 10 || c == 13) {
if (!Character.isHighSurrogate(c)
&& !Character.isLowSurrogate(c)) {
if (!Character.isHighSurrogate(c) && !Character.isLowSurrogate(c)) {
sb.append(c);
}
}
@@ -306,8 +284,7 @@ public class FeedUtils {
/**
* When the feed was refreshed successfully
*/
public static Date buildDisabledUntil(Date publishedDate,
Long averageEntryInterval) {
public static Date buildDisabledUntil(Date publishedDate, Long averageEntryInterval) {
Date now = new Date();
if (publishedDate == null) {
@@ -325,8 +302,7 @@ public class FeedUtils {
} else if (averageEntryInterval != null) {
// use average time between entries to decide when to refresh next
int factor = 2;
return new Date(Math.min(DateUtils.addHours(now, 6).getTime(),
now.getTime() + averageEntryInterval / factor));
return new Date(Math.min(DateUtils.addHours(now, 6).getTime(), now.getTime() + averageEntryInterval / factor));
} else {
// unknown case, recheck in 24 hours
return DateUtils.addHours(now, 24);
@@ -378,14 +354,11 @@ public class FeedUtils {
return baseUrl + url;
}
public static String getFaviconUrl(FeedSubscription subscription,
String publicUrl) {
return removeTrailingSlash(publicUrl) + "/rest/feed/favicon/"
+ subscription.getId();
public static String getFaviconUrl(FeedSubscription subscription, String publicUrl) {
return removeTrailingSlash(publicUrl) + "/rest/feed/favicon/" + subscription.getId();
}
public static String proxyImages(String content, String publicUrl,
boolean proxyImages) {
public static String proxyImages(String content, String publicUrl, boolean proxyImages) {
if (!proxyImages) {
return content;
}
@@ -398,8 +371,7 @@ public class FeedUtils {
for (Element element : elements) {
String href = element.attr("src");
if (href != null) {
String proxy = removeTrailingSlash(publicUrl)
+ "/rest/server/proxy?u=" + imageProxyEncoder(href);
String proxy = removeTrailingSlash(publicUrl) + "/rest/server/proxy?u=" + imageProxyEncoder(href);
element.attr("src", proxy);
}
}

View File

@@ -28,13 +28,11 @@ public class OPMLExporter {
public Opml export(User user) {
Opml opml = new Opml();
opml.setFeedType("opml_1.1");
opml.setTitle(String.format("%s subscriptions in CommaFeed",
user.getName()));
opml.setTitle(String.format("%s subscriptions in CommaFeed", user.getName()));
opml.setCreated(new Date());
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findAll(user);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(user);
for (FeedCategory cat : categories) {
opml.getOutlines().add(buildCategoryOutline(cat, subscriptions));
@@ -50,20 +48,17 @@ public class OPMLExporter {
}
@SuppressWarnings("unchecked")
private Outline buildCategoryOutline(FeedCategory cat,
List<FeedSubscription> subscriptions) {
private Outline buildCategoryOutline(FeedCategory cat, List<FeedSubscription> subscriptions) {
Outline outline = new Outline();
outline.setText(cat.getName());
outline.setTitle(cat.getName());
for (FeedCategory child : cat.getChildren()) {
outline.getChildren().add(
buildCategoryOutline(child, subscriptions));
outline.getChildren().add(buildCategoryOutline(child, subscriptions));
}
for (FeedSubscription sub : subscriptions) {
if (sub.getCategory() != null
&& sub.getCategory().getId().equals(cat.getId())) {
if (sub.getCategory() != null && sub.getCategory().getId().equals(cat.getId())) {
outline.getChildren().add(buildSubscriptionOutline(sub));
}
}
@@ -76,11 +71,9 @@ public class OPMLExporter {
outline.setText(sub.getTitle());
outline.setTitle(sub.getTitle());
outline.setType("rss");
outline.getAttributes().add(
new Attribute("xmlUrl", sub.getFeed().getUrl()));
outline.getAttributes().add(new Attribute("xmlUrl", sub.getFeed().getUrl()));
if (sub.getFeed().getLink() != null) {
outline.getAttributes().add(
new Attribute("htmlUrl", sub.getFeed().getLink()));
outline.getAttributes().add(new Attribute("htmlUrl", sub.getFeed().getLink()));
}
return outline;
}

View File

@@ -63,13 +63,12 @@ public class OPMLImporter {
if (name == null) {
name = FeedUtils.truncate(outline.getTitle(), 128);
}
FeedCategory category = feedCategoryDAO.findByName(user, name,
parent);
FeedCategory category = feedCategoryDAO.findByName(user, name, parent);
if (category == null) {
if (StringUtils.isBlank(name)) {
name = "Unnamed category";
}
category = new FeedCategory();
category.setName(name);
category.setParent(parent);
@@ -91,13 +90,11 @@ public class OPMLImporter {
}
// make sure we continue with the import process even a feed failed
try {
feedSubscriptionService.subscribe(user, outline.getXmlUrl(),
name, parent);
feedSubscriptionService.subscribe(user, outline.getXmlUrl(), name, parent);
} catch (FeedSubscriptionException e) {
throw e;
} catch (Exception e) {
log.error("error while importing {}: {}", outline.getXmlUrl(),
e.getMessage());
log.error("error while importing {}: {}", outline.getXmlUrl(), e.getMessage());
}
}
cache.invalidateUserData(user);

View File

@@ -14,7 +14,12 @@ public abstract class AbstractModel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "gen")
@TableGenerator(name = "gen", table = "hibernate_sequences", pkColumnName = "sequence_name", valueColumnName = "sequence_next_hi_value", allocationSize = 1000)
@TableGenerator(
name = "gen",
table = "hibernate_sequences",
pkColumnName = "sequence_name",
valueColumnName = "sequence_next_hi_value",
allocationSize = 1000)
private Long id;
public Long getId() {

View File

@@ -136,8 +136,7 @@ public class Feed extends AbstractModel {
private Date pushLastPing;
/**
* Denotes a feed that needs to be refreshed before others. Currently used
* when a feed is queued manually for refresh. Not persisted.
* Denotes a feed that needs to be refreshed before others. Currently used when a feed is queued manually for refresh. Not persisted.
*/
@Transient
private boolean urgent;

View File

@@ -56,8 +56,7 @@ public class FeedEntryStatus extends AbstractModel {
}
public FeedEntryStatus(User user, FeedSubscription subscription,
FeedEntry entry) {
public FeedEntryStatus(User user, FeedSubscription subscription, FeedEntry entry) {
setUser(user);
setSubscription(subscription);
setEntry(entry);

View File

@@ -55,8 +55,7 @@ public class User extends AbstractModel {
@Temporal(TemporalType.TIMESTAMP)
private Date recoverPasswordTokenDate;
@OneToMany(mappedBy = "user", cascade = { CascadeType.PERSIST,
CascadeType.REMOVE })
@OneToMany(mappedBy = "user", cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
private Set<UserRole> roles = Sets.newHashSet();
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)

View File

@@ -26,8 +26,7 @@ import com.google.common.collect.Lists;
public class SubscriptionHandler {
private static Logger log = LoggerFactory
.getLogger(SubscriptionHandler.class);
private static Logger log = LoggerFactory.getLogger(SubscriptionHandler.class);
@Inject
ApplicationSettingsService applicationSettingsService;
@@ -47,16 +46,13 @@ public class SubscriptionHandler {
String hub = feed.getPushHub();
String topic = feed.getPushTopic();
String publicUrl = FeedUtils
.removeTrailingSlash(applicationSettingsService.get()
.getPublicUrl());
String publicUrl = FeedUtils.removeTrailingSlash(applicationSettingsService.get().getPublicUrl());
log.debug("sending new pubsub subscription to {} for {}", hub, topic);
HttpPost post = new HttpPost(hub);
List<NameValuePair> nvp = Lists.newArrayList();
nvp.add(new BasicNameValuePair("hub.callback", publicUrl
+ "/rest/push/callback"));
nvp.add(new BasicNameValuePair("hub.callback", publicUrl + "/rest/push/callback"));
nvp.add(new BasicNameValuePair("hub.topic", topic));
nvp.add(new BasicNameValuePair("hub.mode", "subscribe"));
nvp.add(new BasicNameValuePair("hub.verify", "async"));
@@ -65,8 +61,7 @@ public class SubscriptionHandler {
nvp.add(new BasicNameValuePair("hub.lease_seconds", ""));
post.setHeader(HttpHeaders.USER_AGENT, "CommaFeed");
post.setHeader(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_FORM_URLENCODED);
post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
HttpClient client = HttpGetter.newClient(20000);
try {
@@ -77,23 +72,19 @@ public class SubscriptionHandler {
if (code != 204 && code != 202 && code != 200) {
String message = EntityUtils.toString(response.getEntity());
String pushpressError = " is value is not allowed. You may only subscribe to";
if (code == 400
&& StringUtils.contains(message, pushpressError)) {
if (code == 400 && StringUtils.contains(message, pushpressError)) {
String[] tokens = message.split(" ");
feed.setPushTopic(tokens[tokens.length - 1]);
taskGiver.giveBack(feed);
log.debug("handled pushpress subfeed {} : {}", topic,
feed.getPushTopic());
log.debug("handled pushpress subfeed {} : {}", topic, feed.getPushTopic());
} else {
throw new Exception("Unexpected response code: " + code
+ " " + response.getStatusLine().getReasonPhrase()
+ " - " + message);
throw new Exception("Unexpected response code: " + code + " " + response.getStatusLine().getReasonPhrase() + " - "
+ message);
}
}
log.debug("subscribed to {} for {}", hub, topic);
} catch (Exception e) {
log.error("Could not subscribe to {} for {} : " + e.getMessage(),
hub, topic);
log.error("Could not subscribe to {} for {} : " + e.getMessage(), hub, topic);
} finally {
client.getConnectionManager().shutdown();
}

View File

@@ -4,8 +4,7 @@ import org.jdom.Element;
import com.sun.syndication.feed.opml.Opml;
public class OPML11Generator extends
com.sun.syndication.io.impl.OPML10Generator {
public class OPML11Generator extends com.sun.syndication.io.impl.OPML10Generator {
public OPML11Generator() {
super("opml_1.1");

View File

@@ -6,20 +6,17 @@ import org.jdom.Element;
import com.sun.syndication.io.impl.OPML10Parser;
public class OPML11Parser extends OPML10Parser {
public OPML11Parser() {
super("opml_1.1");
}
public OPML11Parser() {
super("opml_1.1");
}
@Override
public boolean isMyType(Document document) {
Element e = document.getRootElement();
if (e.getName().equals("opml")
&& (e.getChild("head") == null || e.getChild("head").getChild(
"docs") == null)
&& (e.getAttributeValue("version") == null || e
.getAttributeValue("version").equals("1.1"))) {
if (e.getName().equals("opml") && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null)
&& (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.1"))) {
return true;
}

View File

@@ -26,8 +26,7 @@ public class RSSRDF10Parser extends RSS10Parser {
Element rssRoot = document.getRootElement();
Namespace defaultNS = rssRoot.getNamespace();
List additionalNSs = Lists.newArrayList(rssRoot
.getAdditionalNamespaces());
List additionalNSs = Lists.newArrayList(rssRoot.getAdditionalNamespaces());
List<Element> children = rssRoot.getChildren();
if (CollectionUtils.isNotEmpty(children)) {
Element child = children.get(0);

View File

@@ -29,8 +29,7 @@ public class ApplicationSettingsService {
public ApplicationSettings get() {
if (settings == null) {
settings = Iterables.getFirst(applicationSettingsDAO.findAll(),
null);
settings = Iterables.getFirst(applicationSettingsDAO.findAll(), null);
}
return settings;
}

View File

@@ -16,20 +16,14 @@ public class FeedEntryContentService {
/**
* this is NOT thread-safe
*/
public FeedEntryContent findOrCreate(FeedEntryContent content,
String baseUrl) {
public FeedEntryContent findOrCreate(FeedEntryContent content, String baseUrl) {
FeedEntryContent existing = feedEntryContentDAO.findExisting(content);
if (existing == null) {
content.setAuthor(FeedUtils.truncate(
FeedUtils.handleContent(content.getAuthor(), baseUrl, true),
128));
content.setTitle(FeedUtils.truncate(
FeedUtils.handleContent(content.getTitle(), baseUrl, true),
2048));
content.setAuthor(FeedUtils.truncate(FeedUtils.handleContent(content.getAuthor(), baseUrl, true), 128));
content.setTitle(FeedUtils.truncate(FeedUtils.handleContent(content.getTitle(), baseUrl, true), 2048));
content.setContentHash(DigestUtils.sha1Hex(content.getContent()));
content.setContent(FeedUtils.handleContent(content.getContent(),
baseUrl, false));
content.setContent(FeedUtils.handleContent(content.getContent(), baseUrl, false));
existing = content;
feedEntryContentDAO.saveOrUpdate(existing);
}

View File

@@ -23,10 +23,8 @@ public class FeedEntryService {
@Inject
FeedEntryDAO feedEntryDAO;
public void markEntry(User user, Long entryId, Long subscriptionId,
boolean read) {
FeedSubscription sub = feedSubscriptionDAO.findById(user,
subscriptionId);
public void markEntry(User user, Long entryId, Long subscriptionId, boolean read) {
FeedSubscription sub = feedSubscriptionDAO.findById(user, subscriptionId);
if (sub == null) {
return;
}
@@ -43,11 +41,9 @@ public class FeedEntryService {
}
}
public void starEntry(User user, Long entryId, Long subscriptionId,
boolean starred) {
public void starEntry(User user, Long entryId, Long subscriptionId, boolean starred) {
FeedSubscription sub = feedSubscriptionDAO.findById(user,
subscriptionId);
FeedSubscription sub = feedSubscriptionDAO.findById(user, subscriptionId);
if (sub == null) {
return;
}

View File

@@ -25,8 +25,7 @@ import com.google.api.client.util.Maps;
public class FeedSubscriptionService {
private static Logger log = LoggerFactory
.getLogger(FeedSubscriptionService.class);
private static Logger log = LoggerFactory.getLogger(FeedSubscriptionService.class);
@SuppressWarnings("serial")
@ApplicationException
@@ -57,17 +56,14 @@ public class FeedSubscriptionService {
@Inject
CacheService cache;
public Feed subscribe(User user, String url, String title,
FeedCategory category) {
public Feed subscribe(User user, String url, String title, FeedCategory category) {
final String pubUrl = applicationSettingsService.get().getPublicUrl();
if (StringUtils.isBlank(pubUrl)) {
throw new FeedSubscriptionException(
"Public URL of this CommaFeed instance is not set");
throw new FeedSubscriptionException("Public URL of this CommaFeed instance is not set");
}
if (url.startsWith(pubUrl)) {
throw new FeedSubscriptionException(
"Could not subscribe to a feed from this CommaFeed instance");
throw new FeedSubscriptionException("Could not subscribe to a feed from this CommaFeed instance");
}
Feed feed = feedService.findOrCreate(url);

View File

@@ -24,7 +24,7 @@ import com.google.common.collect.Lists;
@Stateless
public class FeedUpdateService {
@PersistenceContext
protected EntityManager em;
@@ -42,24 +42,21 @@ public class FeedUpdateService {
@Inject
CacheService cache;
@Inject
FeedEntryContentService feedEntryContentService;
/**
* this is NOT thread-safe
*/
public void updateEntry(Feed feed, FeedEntry entry,
List<FeedSubscription> subscriptions) {
public void updateEntry(Feed feed, FeedEntry entry, List<FeedSubscription> subscriptions) {
FeedEntry existing = feedEntryDAO.findExisting(entry.getGuid(),
entry.getUrl(), feed.getId());
FeedEntry existing = feedEntryDAO.findExisting(entry.getGuid(), entry.getUrl(), feed.getId());
if (existing != null) {
return;
}
FeedEntryContent content = feedEntryContentService.findOrCreate(
entry.getContent(), feed.getLink());
FeedEntryContent content = feedEntryContentService.findOrCreate(entry.getContent(), feed.getLink());
entry.setGuidHash(DigestUtils.sha1Hex(entry.getGuid()));
entry.setContent(content);
entry.setInserted(new Date());

View File

@@ -26,8 +26,7 @@ public class MailService implements Serializable {
@Inject
ApplicationSettingsService applicationSettingsService;
public void sendMail(User user, String subject, String content)
throws Exception {
public void sendMail(User user, String subject, String content) throws Exception {
ApplicationSettings settings = applicationSettingsService.get();
@@ -50,8 +49,7 @@ public class MailService implements Serializable {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username, "CommaFeed"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(dest));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(dest));
message.setSubject("CommaFeed - " + subject);
message.setContent(content, "text/html; charset=utf-8");

View File

@@ -53,8 +53,7 @@ public class PasswordEncryptionService implements Serializable {
// http://blog.crackpassword.com/2010/09/smartphone-forensics-cracking-blackberry-backup-passwords/
int iterations = 20000;
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations,
derivedKeyLength);
KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, iterations, derivedKeyLength);
byte[] bytes = null;
try {

View File

@@ -48,15 +48,13 @@ public class UserService {
User user = userDAO.findByName(name);
if (user != null && !user.isDisabled()) {
boolean authenticated = encryptionService.authenticate(password,
user.getPassword(), user.getSalt());
boolean authenticated = encryptionService.authenticate(password, user.getPassword(), user.getSalt());
if (authenticated) {
Date lastLogin = user.getLastLogin();
Date now = new Date();
// only update lastLogin field every hour in order to not
// invalidate the cache everytime someone logs in
if (lastLogin == null
|| lastLogin.before(DateUtils.addHours(now, -1))) {
if (lastLogin == null || lastLogin.before(DateUtils.addHours(now, -1))) {
user.setLastLogin(now);
userDAO.saveOrUpdate(user);
}
@@ -66,39 +64,30 @@ public class UserService {
return null;
}
public User register(String name, String password, String email,
Collection<Role> roles) {
public User register(String name, String password, String email, Collection<Role> roles) {
return register(name, password, email, roles, false);
}
public User register(String name, String password, String email,
Collection<Role> roles, boolean forceRegistration) {
public User register(String name, String password, String email, Collection<Role> roles, boolean forceRegistration) {
Preconditions.checkNotNull(name);
Preconditions.checkArgument(StringUtils.length(name) <= 32,
"Name too long (32 characters maximum)");
Preconditions.checkArgument(StringUtils.length(name) <= 32, "Name too long (32 characters maximum)");
Preconditions.checkNotNull(password);
if (!forceRegistration) {
Preconditions.checkState(applicationSettingsService.get()
.isAllowRegistrations(),
Preconditions.checkState(applicationSettingsService.get().isAllowRegistrations(),
"Registrations are closed on this CommaFeed instance");
Preconditions.checkNotNull(email);
Preconditions.checkArgument(StringUtils.length(name) >= 3,
"Name too short (3 characters minimum)");
Preconditions.checkArgument(
forceRegistration || StringUtils.length(password) >= 6,
"Password too short (6 characters maximum)");
Preconditions.checkArgument(StringUtils.contains(email, "@"),
"Invalid email address");
Preconditions.checkArgument(StringUtils.length(name) >= 3, "Name too short (3 characters minimum)");
Preconditions
.checkArgument(forceRegistration || StringUtils.length(password) >= 6, "Password too short (6 characters maximum)");
Preconditions.checkArgument(StringUtils.contains(email, "@"), "Invalid email address");
}
Preconditions.checkArgument(userDAO.findByName(name) == null,
"Name already taken");
Preconditions.checkArgument(userDAO.findByName(name) == null, "Name already taken");
if (StringUtils.isNotBlank(email)) {
Preconditions.checkArgument(userDAO.findByEmail(email) == null,
"Email already taken");
Preconditions.checkArgument(userDAO.findByEmail(email) == null, "Email already taken");
}
User user = new User();
@@ -122,8 +111,7 @@ public class UserService {
}
public String generateApiKey(User user) {
byte[] key = encryptionService.getEncryptedPassword(UUID.randomUUID()
.toString(), user.getSalt());
byte[] key = encryptionService.getEncryptedPassword(UUID.randomUUID().toString(), user.getSalt());
return DigestUtils.sha1Hex(key);
}
}

View File

@@ -49,15 +49,12 @@ import com.commafeed.frontend.utils.exception.DisplayExceptionPage;
public class CommaFeedApplication extends AuthenticatedWebApplication {
private static Logger log = LoggerFactory
.getLogger(CommaFeedApplication.class);
private static Logger log = LoggerFactory.getLogger(CommaFeedApplication.class);
public CommaFeedApplication() {
super();
String prod = ResourceBundle.getBundle("application").getString(
"production");
setConfigurationType(Boolean.valueOf(prod) ? RuntimeConfigurationType.DEPLOYMENT
: RuntimeConfigurationType.DEVELOPMENT);
String prod = ResourceBundle.getBundle("application").getString("production");
setConfigurationType(Boolean.valueOf(prod) ? RuntimeConfigurationType.DEPLOYMENT : RuntimeConfigurationType.DEVELOPMENT);
}
@Override
@@ -66,16 +63,16 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
mountPage("welcome", WelcomePage.class);
mountPage("demo", DemoLoginPage.class);
mountPage("recover", PasswordRecoveryPage.class);
mountPage("recover2", PasswordRecoveryCallbackPage.class);
mountPage("logout", LogoutPage.class);
mountPage("error", DisplayExceptionPage.class);
// mountPage("google/import/redirect", GoogleImportRedirectPage.class);
// mountPage(GoogleImportCallbackPage.PAGE_PATH,
// GoogleImportCallbackPage.class);
// mountPage("google/import/redirect", GoogleImportRedirectPage.class);
// mountPage(GoogleImportCallbackPage.PAGE_PATH,
// GoogleImportCallbackPage.class);
mountPage("next", NextUnreadRedirectPage.class);
@@ -89,8 +86,7 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
setHeaderResponseDecorator(new IHeaderResponseDecorator() {
@Override
public IHeaderResponse decorate(IHeaderResponse response) {
return new JavaScriptFilteredIntoFooterHeaderResponse(response,
"footer-container");
return new JavaScriptFilteredIntoFooterHeaderResponse(response, "footer-container");
}
});
@@ -100,61 +96,52 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
AjaxRequestTarget target = cycle.find(AjaxRequestTarget.class);
// redirect to the error page if ajax request, render error on
// current page otherwise
RedirectPolicy policy = target == null ? RedirectPolicy.NEVER_REDIRECT
: RedirectPolicy.AUTO_REDIRECT;
return new RenderPageRequestHandler(new PageProvider(
new DisplayExceptionPage(ex)), policy);
RedirectPolicy policy = target == null ? RedirectPolicy.NEVER_REDIRECT : RedirectPolicy.AUTO_REDIRECT;
return new RenderPageRequestHandler(new PageProvider(new DisplayExceptionPage(ex)), policy);
}
});
}
private void setupSecurity() {
getSecuritySettings().setAuthenticationStrategy(
new DefaultAuthenticationStrategy("LoggedIn") {
getSecuritySettings().setAuthenticationStrategy(new DefaultAuthenticationStrategy("LoggedIn") {
private CookieUtils cookieUtils = null;
private CookieUtils cookieUtils = null;
@Override
protected CookieUtils getCookieUtils() {
@Override
protected CookieUtils getCookieUtils() {
if (cookieUtils == null) {
cookieUtils = new CookieUtils() {
@Override
protected void initializeCookie(Cookie cookie) {
super.initializeCookie(cookie);
cookie.setHttpOnly(true);
}
};
if (cookieUtils == null) {
cookieUtils = new CookieUtils() {
@Override
protected void initializeCookie(Cookie cookie) {
super.initializeCookie(cookie);
cookie.setHttpOnly(true);
}
return cookieUtils;
}
});
getSecuritySettings().setAuthorizationStrategy(
new IAuthorizationStrategy() {
};
}
return cookieUtils;
}
});
getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy() {
@Override
public <T extends IRequestableComponent> boolean isInstantiationAuthorized(
Class<T> componentClass) {
boolean authorized = true;
@Override
public <T extends IRequestableComponent> boolean isInstantiationAuthorized(Class<T> componentClass) {
boolean authorized = true;
boolean restricted = componentClass
.isAnnotationPresent(SecurityCheck.class);
if (restricted) {
SecurityCheck annotation = componentClass
.getAnnotation(SecurityCheck.class);
Roles roles = CommaFeedSession.get().getRoles();
authorized = roles.hasAnyRole(new Roles(annotation
.value().name()));
}
return authorized;
}
boolean restricted = componentClass.isAnnotationPresent(SecurityCheck.class);
if (restricted) {
SecurityCheck annotation = componentClass.getAnnotation(SecurityCheck.class);
Roles roles = CommaFeedSession.get().getRoles();
authorized = roles.hasAnyRole(new Roles(annotation.value().name()));
}
return authorized;
}
@Override
public boolean isActionAuthorized(Component component,
Action action) {
return true;
}
});
@Override
public boolean isActionAuthorized(Component component, Action action) {
return true;
}
});
}
@Override
@@ -164,10 +151,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
protected void setupInjection() {
try {
BeanManager beanManager = (BeanManager) new InitialContext()
.lookup("java:comp/BeanManager");
new CdiConfiguration(beanManager).setPropagation(
ConversationPropagation.NONE).configure(this);
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
new CdiConfiguration(beanManager).setPropagation(ConversationPropagation.NONE).configure(this);
} catch (NamingException e) {
log.warn("Could not locate bean manager. CDI is disabled.");
}

View File

@@ -24,8 +24,7 @@ import com.wordnik.swagger.annotations.ApiProperty;
@ApiClass("Entry details")
public class Entry implements Serializable {
public static Entry build(FeedEntryStatus status, String publicUrl,
boolean proxyImages) {
public static Entry build(FeedEntryStatus status, String publicUrl, boolean proxyImages) {
Entry entry = new Entry();
FeedEntry feedEntry = status.getEntry();
@@ -38,8 +37,7 @@ public class Entry implements Serializable {
entry.setId(String.valueOf(feedEntry.getId()));
entry.setGuid(feedEntry.getGuid());
entry.setTitle(feedEntry.getContent().getTitle());
entry.setContent(FeedUtils.proxyImages(feedEntry.getContent()
.getContent(), publicUrl, proxyImages));
entry.setContent(FeedUtils.proxyImages(feedEntry.getContent().getContent(), publicUrl, proxyImages));
entry.setRtl(FeedUtils.isRTL(feedEntry));
entry.setAuthor(feedEntry.getContent().getAuthor());
entry.setEnclosureUrl(feedEntry.getContent().getEnclosureUrl());

View File

@@ -20,8 +20,7 @@ import com.wordnik.swagger.annotations.ApiProperty;
@ApiClass("User information")
public class Subscription implements Serializable {
public static Subscription build(FeedSubscription subscription,
String publicUrl, long unreadCount) {
public static Subscription build(FeedSubscription subscription, String publicUrl, long unreadCount) {
Date now = new Date();
FeedCategory category = subscription.getCategory();
Feed feed = subscription.getFeed();
@@ -35,12 +34,9 @@ public class Subscription implements Serializable {
sub.setFeedLink(feed.getLink());
sub.setIconUrl(FeedUtils.getFaviconUrl(subscription, publicUrl));
sub.setLastRefresh(feed.getLastUpdated());
sub.setNextRefresh((feed.getDisabledUntil() != null && feed
.getDisabledUntil().before(now)) ? null : feed
.getDisabledUntil());
sub.setNextRefresh((feed.getDisabledUntil() != null && feed.getDisabledUntil().before(now)) ? null : feed.getDisabledUntil());
sub.setUnread(unreadCount);
sub.setCategoryId(category == null ? null : String.valueOf(category
.getId()));
sub.setCategoryId(category == null ? null : String.valueOf(category.getId()));
return sub;
}

View File

@@ -14,7 +14,7 @@ import com.wordnik.swagger.annotations.ApiProperty;
@XmlAccessorType(XmlAccessType.FIELD)
@ApiClass("Feed information request")
public class FeedInfoRequest implements Serializable {
@ApiProperty(value = "feed url", required = true)
private String url;
@@ -25,7 +25,5 @@ public class FeedInfoRequest implements Serializable {
public void setUrl(String url) {
this.url = url;
}
}

View File

@@ -24,7 +24,9 @@ public class MarkRequest implements Serializable {
@ApiProperty(value = "mark as read or unread")
private boolean read;
@ApiProperty(value = "only entries older than this, pass the timestamp you got from the entry list to prevent marking an entry that was not retrieved", required = false)
@ApiProperty(
value = "only entries older than this, pass the timestamp you got from the entry list to prevent marking an entry that was not retrieved",
required = false)
private Long olderThan;
public String getId() {

View File

@@ -79,15 +79,12 @@ public abstract class BasePage extends WebPage {
if (user != null) {
UserSettings settings = userSettingsDAO.findByUser(user);
if (settings != null) {
lang = settings.getLanguage() == null ? "en" : settings
.getLanguage();
theme = settings.getTheme() == null ? "default" : settings
.getTheme();
lang = settings.getLanguage() == null ? "en" : settings.getLanguage();
theme = settings.getTheme() == null ? "default" : settings.getTheme();
}
}
add(new TransparentWebMarkupContainer("html").setMarkupId(
"theme-" + theme).add(new AttributeModifier("lang", lang)));
add(new TransparentWebMarkupContainer("html").setMarkupId("theme-" + theme).add(new AttributeModifier("lang", lang)));
settings = applicationSettingsService.get();
add(new HeaderResponseContainer("footer-container", "footer-container"));
@@ -107,8 +104,7 @@ public abstract class BasePage extends WebPage {
if (getApplication().getConfigurationType() == RuntimeConfigurationType.DEPLOYMENT) {
long startupTime = startupBean.getStartupTime();
String suffix = "?" + startupTime;
response.render(JavaScriptHeaderItem.forUrl("static/all.js"
+ suffix));
response.render(JavaScriptHeaderItem.forUrl("static/all.js" + suffix));
response.render(CssHeaderItem.forUrl("static/all.css" + suffix));
} else {
response.render(JavaScriptHeaderItem.forUrl("wro/lib.js"));

View File

@@ -16,8 +16,7 @@ public class DemoLoginPage extends WebPage {
UserService userService;
public DemoLoginPage() {
CommaFeedSession.get().authenticate(StartupBean.USERNAME_DEMO,
StartupBean.USERNAME_DEMO);
CommaFeedSession.get().authenticate(StartupBean.USERNAME_DEMO, StartupBean.USERNAME_DEMO);
setResponsePage(getApplication().getHomePage());
}
}

View File

@@ -55,8 +55,7 @@ public class GoogleImportCallbackPage extends WebPage {
if (request.getQueryString() != null) {
urlBuffer.append('?').append(request.getQueryString());
}
AuthorizationCodeResponseUrl responseUrl = new AuthorizationCodeResponseUrl(
urlBuffer.toString());
AuthorizationCodeResponseUrl responseUrl = new AuthorizationCodeResponseUrl(urlBuffer.toString());
String code = responseUrl.getCode();
if (responseUrl.getError() != null) {
@@ -73,8 +72,8 @@ public class GoogleImportCallbackPage extends WebPage {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
AuthorizationCodeTokenRequest tokenRequest = new AuthorizationCodeTokenRequest(
httpTransport, jsonFactory, new GenericUrl(TOKEN_URL), code);
AuthorizationCodeTokenRequest tokenRequest = new AuthorizationCodeTokenRequest(httpTransport, jsonFactory, new GenericUrl(
TOKEN_URL), code);
tokenRequest.setRedirectUri(redirectUri);
tokenRequest.put("client_id", clientId);
tokenRequest.put("client_secret", clientSecret);
@@ -87,16 +86,13 @@ public class GoogleImportCallbackPage extends WebPage {
TokenResponse tokenResponse = tokenRequest.execute();
String accessToken = tokenResponse.getAccessToken();
HttpRequest httpRequest = httpTransport.createRequestFactory()
.buildGetRequest(new GenericUrl(EXPORT_URL));
BearerToken.authorizationHeaderAccessMethod().intercept(
httpRequest, accessToken);
HttpRequest httpRequest = httpTransport.createRequestFactory().buildGetRequest(new GenericUrl(EXPORT_URL));
BearerToken.authorizationHeaderAccessMethod().intercept(httpRequest, accessToken);
String opml = httpRequest.execute().parseAsString();
User user = CommaFeedSession.get().getUser();
if (user != null) {
if (StartupBean.USERNAME_DEMO.equals(user.getName())) {
throw new DisplayException(
"Import is disabled for the demo account");
throw new DisplayException("Import is disabled for the demo account");
}
importer.importOpml(CommaFeedSession.get().getUser(), opml);
}

View File

@@ -15,8 +15,7 @@ import com.commafeed.backend.services.ApplicationSettingsService;
@SuppressWarnings("serial")
public class GoogleImportRedirectPage extends WebPage {
private static Logger log = Logger
.getLogger(GoogleImportRedirectPage.class);
private static Logger log = Logger.getLogger(GoogleImportRedirectPage.class);
private static final String SCOPE = "https://www.google.com/reader/subscriptions/export email profile";
private static final String AUTH_URL = "https://accounts.google.com/o/oauth2/auth";

View File

@@ -18,16 +18,12 @@ public class HomePage extends BasePage {
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(CssHeaderItem.forReference(
new UserCustomCssReference() {
@Override
protected String getCss() {
UserSettings settings = userSettingsDAO
.findByUser(CommaFeedSession.get().getUser());
return settings == null ? null : settings
.getCustomCss();
}
}, new PageParameters().add("_t", System.currentTimeMillis()),
null));
response.render(CssHeaderItem.forReference(new UserCustomCssReference() {
@Override
protected String getCss() {
UserSettings settings = userSettingsDAO.findByUser(CommaFeedSession.get().getUser());
return settings == null ? null : settings.getCustomCss();
}
}, new PageParameters().add("_t", System.currentTimeMillis()), null));
}
}

View File

@@ -52,21 +52,15 @@ public class NextUnreadRedirectPage extends WebPage {
}
List<FeedEntryStatus> statuses = null;
if (StringUtils.isBlank(categoryId)
|| CategoryREST.ALL.equals(categoryId)) {
if (StringUtils.isBlank(categoryId) || CategoryREST.ALL.equals(categoryId)) {
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
statuses = feedEntryStatusDAO.findBySubscriptions(subs, true, null,
null, 0, 1, order, true);
statuses = feedEntryStatusDAO.findBySubscriptions(subs, true, null, null, 0, 1, order, true);
} else {
FeedCategory category = feedCategoryDAO.findById(user,
Long.valueOf(categoryId));
FeedCategory category = feedCategoryDAO.findById(user, Long.valueOf(categoryId));
if (category != null) {
List<FeedCategory> children = feedCategoryDAO
.findAllChildrenCategories(user, category);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findByCategories(user, children);
statuses = feedEntryStatusDAO.findBySubscriptions(
subscriptions, true, null, null, 0, 1, order, true);
List<FeedCategory> children = feedCategoryDAO.findAllChildrenCategories(user, category);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user, children);
statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions, true, null, null, 0, 1, order, true);
}
}

View File

@@ -40,12 +40,10 @@ public class PasswordRecoveryCallbackPage extends BasePage {
if (user == null) {
throw new DisplayException("email not found");
}
if (user.getRecoverPasswordToken() == null
|| !user.getRecoverPasswordToken().equals(token)) {
if (user.getRecoverPasswordToken() == null || !user.getRecoverPasswordToken().equals(token)) {
throw new DisplayException("invalid token");
}
if (user.getRecoverPasswordTokenDate().before(
DateUtils.addDays(new Date(), -2))) {
if (user.getRecoverPasswordTokenDate().before(DateUtils.addDays(new Date(), -2))) {
throw new DisplayException("token expired");
}
@@ -57,8 +55,7 @@ public class PasswordRecoveryCallbackPage extends BasePage {
protected void onSubmit() {
String passwd = password.getObject();
if (StringUtils.equals(passwd, confirm.getObject())) {
byte[] password = encryptionService.getEncryptedPassword(
passwd, user.getSalt());
byte[] password = encryptionService.getEncryptedPassword(passwd, user.getSalt());
user.setPassword(password);
user.setApiKey(userService.generateApiKey(user));
user.setRecoverPasswordToken(null);
@@ -71,10 +68,8 @@ public class PasswordRecoveryCallbackPage extends BasePage {
}
};
add(form);
form.add(new PasswordTextField("password", password).setResetPassword(
true).add(StringValidator.minimumLength(6)));
form.add(new PasswordTextField("confirm", confirm).setResetPassword(
true).add(StringValidator.minimumLength(6)));
form.add(new PasswordTextField("password", password).setResetPassword(true).add(StringValidator.minimumLength(6)));
form.add(new PasswordTextField("confirm", confirm).setResetPassword(true).add(StringValidator.minimumLength(6)));
form.add(new BookmarkablePageLink<Void>("cancel", HomePage.class));

View File

@@ -21,8 +21,7 @@ import com.commafeed.frontend.pages.components.BootstrapFeedbackPanel;
@SuppressWarnings("serial")
public class PasswordRecoveryPage extends BasePage {
private static Logger log = LoggerFactory
.getLogger(PasswordRecoveryPage.class);
private static Logger log = LoggerFactory.getLogger(PasswordRecoveryPage.class);
public PasswordRecoveryPage() {
@@ -37,12 +36,10 @@ public class PasswordRecoveryPage extends BasePage {
error("Email not found.");
} else {
try {
user.setRecoverPasswordToken(DigestUtils.sha1Hex(UUID
.randomUUID().toString()));
user.setRecoverPasswordToken(DigestUtils.sha1Hex(UUID.randomUUID().toString()));
user.setRecoverPasswordTokenDate(new Date());
userDAO.saveOrUpdate(user);
mailService.sendMail(user, "Password recovery",
buildEmailContent(user));
mailService.sendMail(user, "Password recovery", buildEmailContent(user));
info("Email sent.");
} catch (Exception e) {
log.error(e.getMessage(), e);
@@ -67,9 +64,7 @@ public class PasswordRecoveryPage extends BasePage {
private String buildEmailContent(User user) throws Exception {
String publicUrl = FeedUtils
.removeTrailingSlash(applicationSettingsService.get()
.getPublicUrl());
String publicUrl = FeedUtils.removeTrailingSlash(applicationSettingsService.get().getPublicUrl());
publicUrl += "/recover2";
return String
@@ -78,11 +73,7 @@ public class PasswordRecoveryPage extends BasePage {
}
private String callbackUrl(User user, String publicUrl) throws Exception {
return new URIBuilder(publicUrl)
.addParameter(PasswordRecoveryCallbackPage.PARAM_EMAIL,
user.getEmail())
.addParameter(PasswordRecoveryCallbackPage.PARAM_TOKEN,
user.getRecoverPasswordToken()).build().toURL()
.toString();
return new URIBuilder(publicUrl).addParameter(PasswordRecoveryCallbackPage.PARAM_EMAIL, user.getEmail())
.addParameter(PasswordRecoveryCallbackPage.PARAM_TOKEN, user.getRecoverPasswordToken()).build().toURL().toString();
}
}

View File

@@ -53,8 +53,7 @@ public class TestRssPage extends WebPage {
} catch (InterruptedException e) {
// do nothing
}
getRequestCycle().scheduleRequestHandlerAfterCurrent(
new TextRequestHandler("text/xml", "UTF-8", writer.toString()));
getRequestCycle().scheduleRequestHandlerAfterCurrent(new TextRequestHandler("text/xml", "UTF-8", writer.toString()));
}
}

View File

@@ -15,16 +15,14 @@ public class WelcomePage extends BasePage {
ApplicationSettingsService applicationSettingsService;
public WelcomePage() {
add(new BookmarkablePageLink<Void>("logo-link", getApplication()
.getHomePage()));
add(new BookmarkablePageLink<Void>("logo-link", getApplication().getHomePage()));
add(new BookmarkablePageLink<Void>("demo-login", DemoLoginPage.class));
add(new LoginPanel("login"));
add(new RegisterPanel("register") {
@Override
protected void onConfigure() {
super.onConfigure();
setVisibilityAllowed(applicationSettingsService.get()
.isAllowRegistrations());
setVisibilityAllowed(applicationSettingsService.get().isAllowRegistrations());
}
});
}

View File

@@ -19,11 +19,9 @@ public class LoginPanel extends SignInPanel {
public LoginPanel(String id) {
super(id);
replace(new BootstrapFeedbackPanel("feedback",
new ContainerFeedbackMessageFilter(this)));
replace(new BootstrapFeedbackPanel("feedback", new ContainerFeedbackMessageFilter(this)));
Form<?> form = (Form<?>) get("signInForm");
form.add(new BookmarkablePageLink<Void>("recover",
PasswordRecoveryPage.class){
form.add(new BookmarkablePageLink<Void>("recover", PasswordRecoveryPage.class) {
@Override
protected void onConfigure() {
super.onConfigure();

View File

@@ -45,62 +45,51 @@ public class RegisterPanel extends Panel {
IModel<RegistrationRequest> model = Model.of(new RegistrationRequest());
Form<RegistrationRequest> form = new StatelessForm<RegistrationRequest>(
"form", model) {
Form<RegistrationRequest> form = new StatelessForm<RegistrationRequest>("form", model) {
@Override
protected void onSubmit() {
if (applicationSettingsService.get().isAllowRegistrations()) {
RegistrationRequest req = getModelObject();
userService.register(req.getName(), req.getPassword(),
req.getEmail(), Arrays.asList(Role.USER));
userService.register(req.getName(), req.getPassword(), req.getEmail(), Arrays.asList(Role.USER));
IAuthenticationStrategy strategy = getApplication()
.getSecuritySettings().getAuthenticationStrategy();
IAuthenticationStrategy strategy = getApplication().getSecuritySettings().getAuthenticationStrategy();
strategy.save(req.getName(), req.getPassword());
CommaFeedSession.get().signIn(req.getName(),
req.getPassword());
CommaFeedSession.get().signIn(req.getName(), req.getPassword());
}
setResponsePage(getApplication().getHomePage());
}
};
add(form);
add(new BootstrapFeedbackPanel("feedback",
new ContainerFeedbackMessageFilter(form)));
add(new BootstrapFeedbackPanel("feedback", new ContainerFeedbackMessageFilter(form)));
RegistrationRequest p = MF.p(RegistrationRequest.class);
form.add(new RequiredTextField<String>("name", MF.m(model, p.getName()))
.add(StringValidator.lengthBetween(3, 32)).add(
new IValidator<String>() {
@Override
public void validate(
IValidatable<String> validatable) {
String name = validatable.getValue();
User user = userDAO.findByName(name);
if (user != null) {
validatable.error(new ValidationError(
"Name is already taken."));
}
}
}));
form.add(new PasswordTextField("password", MF.m(model, p.getPassword()))
.setResetPassword(false).add(StringValidator.minimumLength(6)));
form.add(new RequiredTextField<String>("email", MF.m(model,
p.getEmail())) {
form.add(new RequiredTextField<String>("name", MF.m(model, p.getName())).add(StringValidator.lengthBetween(3, 32)).add(
new IValidator<String>() {
@Override
public void validate(IValidatable<String> validatable) {
String name = validatable.getValue();
User user = userDAO.findByName(name);
if (user != null) {
validatable.error(new ValidationError("Name is already taken."));
}
}
}));
form.add(new PasswordTextField("password", MF.m(model, p.getPassword())).setResetPassword(false).add(
StringValidator.minimumLength(6)));
form.add(new RequiredTextField<String>("email", MF.m(model, p.getEmail())) {
@Override
protected String getInputType() {
return "email";
}
}.add(RfcCompliantEmailAddressValidator.getInstance()).add(
new IValidator<String>() {
@Override
public void validate(IValidatable<String> validatable) {
String email = validatable.getValue();
User user = userDAO.findByEmail(email);
if (user != null) {
validatable.error(new ValidationError(
"Email is already taken."));
}
}
}));
}.add(RfcCompliantEmailAddressValidator.getInstance()).add(new IValidator<String>() {
@Override
public void validate(IValidatable<String> validatable) {
String email = validatable.getValue();
User user = userDAO.findByEmail(email);
if (user != null) {
validatable.error(new ValidationError("Email is already taken."));
}
}
}));
}
}

View File

@@ -12,8 +12,7 @@ import ro.isdc.wro.model.resource.processor.impl.css.CssImportPreProcessor;
public class SassImportProcessor extends CssImportPreProcessor {
@Override
protected String doTransform(String cssContent, List<Resource> foundImports)
throws IOException {
protected String doTransform(String cssContent, List<Resource> foundImports) throws IOException {
for (Resource resource : foundImports) {
String uri = resource.getUri();
int lastSlash = uri.lastIndexOf('/');

View File

@@ -15,10 +15,8 @@ import ro.isdc.wro.model.resource.SupportedResourceType;
public class SassOnlyProcessor extends RubySassCssProcessor {
@Override
public void process(Resource resource, Reader reader, Writer writer)
throws IOException {
if (resource.getUri().endsWith(".sass")
|| resource.getUri().endsWith(".scss")) {
public void process(Resource resource, Reader reader, Writer writer) throws IOException {
if (resource.getUri().endsWith(".sass") || resource.getUri().endsWith(".scss")) {
super.process(resource, reader, writer);
} else {
writer.write(IOUtils.toString(reader));

View File

@@ -17,8 +17,7 @@ public class TimestampProcessor implements ResourcePreProcessor {
private static final String NOW = "" + System.currentTimeMillis();
@Override
public void process(Resource resource, Reader reader, Writer writer)
throws IOException {
public void process(Resource resource, Reader reader, Writer writer) throws IOException {
String content = IOUtils.toString(reader);
content = content.replace("${timestamp}", NOW);
writer.write(content);

View File

@@ -24,10 +24,8 @@ public abstract class UserCustomCssReference extends ResourceReference {
resourceResponse.setTextEncoding("UTF-8");
resourceResponse.setWriteCallback(new WriteCallback() {
@Override
public void writeData(Attributes attributes)
throws IOException {
attributes.getResponse().write(
StringUtils.trimToEmpty(getCss()));
public void writeData(Attributes attributes) throws IOException {
attributes.getResponse().write(StringUtils.trimToEmpty(getCss()));
}
});
return resourceResponse;

View File

@@ -10,7 +10,7 @@ import com.google.api.client.util.Maps;
/**
* Build-time solution
*
*
*/
public class WroAdditionalProvider implements ProcessorProvider {

View File

@@ -7,7 +7,7 @@ import ro.isdc.wro.model.resource.processor.ResourcePreProcessor;
/**
* Runtime solution
*
*
*/
public class WroManagerFactory extends ConfigurableWroManagerFactory {

View File

@@ -1,6 +1,5 @@
package com.commafeed.frontend.rest;
public class Enums {
public enum Type {

View File

@@ -17,18 +17,14 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
public class JsonProvider extends JacksonJsonProvider {
@Override
public void writeTo(Object value, Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, mediaType.toString()
+ ";charset=UTF-8");
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, mediaType.toString() + ";charset=UTF-8");
httpHeaders.putSingle(HttpHeaders.CACHE_CONTROL, "no-cache");
httpHeaders.putSingle(HttpHeaders.PRAGMA, "no-cache");
super.writeTo(value, type, genericType, annotations, mediaType,
httpHeaders, entityStream);
super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
}

View File

@@ -51,8 +51,7 @@ public abstract class AbstractREST {
ServletWebResponse swresp = new ServletWebResponse(swreq, response);
RequestCycle cycle = app.createRequestCycle(swreq, swresp);
ThreadContext.setRequestCycle(cycle);
CommaFeedSession session = (CommaFeedSession) app
.fetchCreateAndSetSession(cycle);
CommaFeedSession session = (CommaFeedSession) app.fetchCreateAndSetSession(cycle);
if (session.getUser() == null) {
cookieLogin(app, session);
@@ -63,8 +62,7 @@ public abstract class AbstractREST {
}
private void cookieLogin(CommaFeedApplication app, CommaFeedSession session) {
IAuthenticationStrategy authenticationStrategy = app
.getSecuritySettings().getAuthenticationStrategy();
IAuthenticationStrategy authenticationStrategy = app.getSecuritySettings().getAuthenticationStrategy();
String[] data = authenticationStrategy.load();
if (data != null && data.length > 1) {
session.signIn(data[0], data[1]);
@@ -98,8 +96,7 @@ public abstract class AbstractREST {
boolean allowed = true;
User user = null;
Method method = context.getMethod();
SecurityCheck check = method.isAnnotationPresent(SecurityCheck.class) ? method
.getAnnotation(SecurityCheck.class) : method
SecurityCheck check = method.isAnnotationPresent(SecurityCheck.class) ? method.getAnnotation(SecurityCheck.class) : method
.getDeclaringClass().getAnnotation(SecurityCheck.class);
if (check != null) {
@@ -113,11 +110,9 @@ public abstract class AbstractREST {
}
if (!allowed) {
if (user == null) {
return Response.status(Status.UNAUTHORIZED)
.entity("You are not authorized to do this.").build();
return Response.status(Status.UNAUTHORIZED).entity("You are not authorized to do this.").build();
} else {
return Response.status(Status.FORBIDDEN)
.entity("You are not authorized to do this.").build();
return Response.status(Status.FORBIDDEN).entity("You are not authorized to do this.").build();
}
}

View File

@@ -33,40 +33,33 @@ public abstract class AbstractResourceREST extends AbstractREST {
@GET
@SecurityCheck(value = Role.NONE)
@ApiOperation(value = "Returns information about API parameters", responseClass = "com.wordnik.swagger.core.Documentation")
public Response getHelp(@Context Application app,
@Context HttpHeaders headers, @Context UriInfo uriInfo) {
public Response getHelp(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
TypeUtil.addAllowablePackage(Entries.class.getPackage().getName());
TypeUtil.addAllowablePackage(MarkRequest.class.getPackage().getName());
String apiVersion = ApiDocumentationREST.API_VERSION;
String swaggerVersion = SwaggerSpec.version();
String basePath = ApiDocumentationREST
.getBasePath(applicationSettingsService.get().getPublicUrl());
String basePath = ApiDocumentationREST.getBasePath(applicationSettingsService.get().getPublicUrl());
Class<?> resource = null;
String path = prependSlash(uriInfo.getPath());
for (Class<?> klass : app.getClasses()) {
Api api = klass.getAnnotation(Api.class);
if (api != null && api.value() != null
&& StringUtils.equals(prependSlash(api.value()), path)) {
if (api != null && api.value() != null && StringUtils.equals(prependSlash(api.value()), path)) {
resource = klass;
break;
}
}
if (resource == null) {
return Response
.status(Status.NOT_FOUND)
.entity("Api annotation not found on class "
+ getClass().getName()).build();
return Response.status(Status.NOT_FOUND).entity("Api annotation not found on class " + getClass().getName()).build();
}
Api api = resource.getAnnotation(Api.class);
String apiPath = api.value();
String apiListingPath = api.value();
Documentation doc = new HelpApi(null).filterDocs(JaxrsApiReader.read(
resource, apiVersion, swaggerVersion, basePath, apiPath),
Documentation doc = new HelpApi(null).filterDocs(JaxrsApiReader.read(resource, apiVersion, swaggerVersion, basePath, apiPath),
headers, uriInfo, apiListingPath, apiPath);
doc.setSwaggerVersion(swaggerVersion);

View File

@@ -102,24 +102,18 @@ public class AdminREST extends AbstractResourceREST {
roles.add(Role.ADMIN);
}
try {
userService.register(userModel.getName(),
userModel.getPassword(), userModel.getEmail(), roles,
true);
userService.register(userModel.getName(), userModel.getPassword(), userModel.getEmail(), roles, true);
} catch (Exception e) {
return Response.status(Status.CONFLICT).entity(e.getMessage())
.build();
return Response.status(Status.CONFLICT).entity(e.getMessage()).build();
}
} else {
User user = userDAO.findById(id);
if (StartupBean.USERNAME_ADMIN.equals(user.getName())
&& !userModel.isEnabled()) {
return Response.status(Status.FORBIDDEN)
.entity("You cannot disable the admin user.").build();
if (StartupBean.USERNAME_ADMIN.equals(user.getName()) && !userModel.isEnabled()) {
return Response.status(Status.FORBIDDEN).entity("You cannot disable the admin user.").build();
}
user.setName(userModel.getName());
if (StringUtils.isNotBlank(userModel.getPassword())) {
user.setPassword(encryptionService.getEncryptedPassword(
userModel.getPassword(), user.getSalt()));
user.setPassword(encryptionService.getEncryptedPassword(userModel.getPassword(), user.getSalt()));
}
user.setEmail(userModel.getEmail());
user.setDisabled(!userModel.isEnabled());
@@ -130,10 +124,7 @@ public class AdminREST extends AbstractResourceREST {
userRoleDAO.saveOrUpdate(new UserRole(user, Role.ADMIN));
} else if (!userModel.isAdmin() && roles.contains(Role.ADMIN)) {
if (StartupBean.USERNAME_ADMIN.equals(user.getName())) {
return Response
.status(Status.FORBIDDEN)
.entity("You cannot remove the admin role from the admin user.")
.build();
return Response.status(Status.FORBIDDEN).entity("You cannot remove the admin role from the admin user.").build();
}
for (UserRole userRole : userRoleDAO.findAll(user)) {
if (userRole.getRole() == Role.ADMIN) {
@@ -150,8 +141,7 @@ public class AdminREST extends AbstractResourceREST {
@Path("/user/get/{id}")
@GET
@ApiOperation(value = "Get user information", notes = "Get user information", responseClass = "com.commafeed.frontend.model.UserModel")
public Response getUser(
@ApiParam(value = "user id", required = true) @PathParam("id") Long id) {
public Response getUser(@ApiParam(value = "user id", required = true) @PathParam("id") Long id) {
Preconditions.checkNotNull(id);
User user = userDAO.findById(id);
UserModel userModel = new UserModel();
@@ -205,8 +195,7 @@ public class AdminREST extends AbstractResourceREST {
return Response.status(Status.NOT_FOUND).build();
}
if (StartupBean.USERNAME_ADMIN.equals(user.getName())) {
return Response.status(Status.FORBIDDEN)
.entity("You cannot delete the admin user.").build();
return Response.status(Status.FORBIDDEN).entity("You cannot delete the admin user.").build();
}
userService.unregister(user);
return Response.ok().build();
@@ -214,7 +203,10 @@ public class AdminREST extends AbstractResourceREST {
@Path("/settings")
@GET
@ApiOperation(value = "Retrieve application settings", notes = "Retrieve application settings", responseClass = "com.commafeed.backend.model.ApplicationSettings")
@ApiOperation(
value = "Retrieve application settings",
notes = "Retrieve application settings",
responseClass = "com.commafeed.backend.model.ApplicationSettings")
public Response getSettings() {
return Response.ok(applicationSettingsService.get()).build();
}
@@ -222,8 +214,7 @@ public class AdminREST extends AbstractResourceREST {
@Path("/settings")
@POST
@ApiOperation(value = "Save application settings", notes = "Save application settings")
public Response saveSettings(
@ApiParam(required = true) ApplicationSettings settings) {
public Response saveSettings(@ApiParam(required = true) ApplicationSettings settings) {
Preconditions.checkNotNull(settings);
applicationSettingsService.save(settings);
return Response.ok().build();
@@ -232,8 +223,7 @@ public class AdminREST extends AbstractResourceREST {
@Path("/metrics")
@GET
@ApiOperation(value = "Retrieve server metrics")
public Response getMetrics(
@QueryParam("backlog") @DefaultValue("false") boolean backlog) {
public Response getMetrics(@QueryParam("backlog") @DefaultValue("false") boolean backlog) {
Map<String, Object> map = Maps.newLinkedHashMap();
map.put("lastMinute", metricsBean.getLastMinute());
map.put("lastHour", metricsBean.getLastHour());
@@ -254,52 +244,44 @@ public class AdminREST extends AbstractResourceREST {
@ApiOperation(value = "Feeds cleanup", notes = "Delete feeds without subscriptions and entries without feeds")
public Response cleanupFeeds() {
Map<String, Long> map = Maps.newHashMap();
map.put("feeds_without_subscriptions",
cleaner.cleanFeedsWithoutSubscriptions());
map.put("feeds_without_subscriptions", cleaner.cleanFeedsWithoutSubscriptions());
return Response.ok(map).build();
}
@Path("/cleanup/content")
@GET
@ApiOperation(value = "Content cleanup", notes = "Delete contents without entries")
public Response cleanupContents() {
Map<String, Long> map = Maps.newHashMap();
map.put("contents_without_entries",
cleaner.cleanContentsWithoutEntries());
map.put("contents_without_entries", cleaner.cleanContentsWithoutEntries());
return Response.ok(map).build();
}
@Path("/cleanup/entries")
@GET
@ApiOperation(value = "Entries cleanup", notes = "Delete entries older than given date")
public Response cleanupEntries(
@QueryParam("days") @DefaultValue("30") int days) {
public Response cleanupEntries(@QueryParam("days") @DefaultValue("30") int days) {
Map<String, Long> map = Maps.newHashMap();
map.put("old entries",
cleaner.cleanEntriesOlderThan(days, TimeUnit.DAYS));
map.put("old entries", cleaner.cleanEntriesOlderThan(days, TimeUnit.DAYS));
return Response.ok(map).build();
}
@Path("/cleanup/findDuplicateFeeds")
@GET
@ApiOperation(value = "Find duplicate feeds")
public Response findDuplicateFeeds(@QueryParam("mode") DuplicateMode mode,
@QueryParam("page") int page, @QueryParam("limit") int limit,
@QueryParam("minCount") long minCount) {
List<FeedCount> list = feedDAO.findDuplicates(mode, limit * page,
limit, minCount);
public Response findDuplicateFeeds(@QueryParam("mode") DuplicateMode mode, @QueryParam("page") int page,
@QueryParam("limit") int limit, @QueryParam("minCount") long minCount) {
List<FeedCount> list = feedDAO.findDuplicates(mode, limit * page, limit, minCount);
return Response.ok(list).build();
}
@Path("/cleanup/merge")
@POST
@ApiOperation(value = "Merge feeds", notes = "Merge feeds together")
public Response mergeFeeds(
@ApiParam(required = true) FeedMergeRequest request) {
public Response mergeFeeds(@ApiParam(required = true) FeedMergeRequest request) {
Feed into = feedDAO.findById(request.getIntoFeedId());
if (into == null) {
return Response.status(Status.BAD_REQUEST)
.entity("'into feed' not found").build();
return Response.status(Status.BAD_REQUEST).entity("'into feed' not found").build();
}
List<Feed> feeds = Lists.newArrayList();
@@ -309,8 +291,7 @@ public class AdminREST extends AbstractResourceREST {
}
if (feeds.isEmpty()) {
return Response.status(Status.BAD_REQUEST)
.entity("'from feeds' empty").build();
return Response.status(Status.BAD_REQUEST).entity("'from feeds' empty").build();
}
cleaner.mergeFeeds(into, feeds);

View File

@@ -40,14 +40,12 @@ public class ApiDocumentationREST extends AbstractREST {
}
Api api = resource.getAnnotation(Api.class);
if (api != null) {
doc.addApi(new DocumentationEndPoint(api.value(), api
.description()));
doc.addApi(new DocumentationEndPoint(api.value(), api.description()));
}
}
doc.setSwaggerVersion(SwaggerSpec.version());
doc.setBasePath(getBasePath(applicationSettingsService.get()
.getPublicUrl()));
doc.setBasePath(getBasePath(applicationSettingsService.get().getPublicUrl()));
doc.setApiVersion(API_VERSION);
return Response.ok().entity(doc).build();

View File

@@ -82,14 +82,20 @@ public class CategoryREST extends AbstractResourceREST {
@Path("/entries")
@GET
@ApiOperation(value = "Get category entries", notes = "Get a list of category entries", responseClass = "com.commafeed.frontend.model.Entries")
@ApiOperation(
value = "Get category entries",
notes = "Get a list of category entries",
responseClass = "com.commafeed.frontend.model.Entries")
public Response getCategoryEntries(
@ApiParam(value = "id of the category, 'all' or 'starred'", required = true) @QueryParam("id") String id,
@ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @DefaultValue("unread") @QueryParam("readType") ReadType readType,
@ApiParam(value = "only entries newer than this") @QueryParam("newerThan") Long newerThan,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,
@ApiParam(value = "limit for paging, default 20, maximum 50") @DefaultValue("20") @QueryParam("limit") int limit,
@ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
@ApiParam(value = "id of the category, 'all' or 'starred'", required = true) @QueryParam("id") String id, @ApiParam(
value = "all entries or only unread ones",
allowableValues = "all,unread",
required = true) @DefaultValue("unread") @QueryParam("readType") ReadType readType, @ApiParam(
value = "only entries newer than this") @QueryParam("newerThan") Long newerThan,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(
value = "limit for paging, default 20, maximum 50") @DefaultValue("20") @QueryParam("limit") int limit, @ApiParam(
value = "date ordering",
allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
Preconditions.checkNotNull(readType);
limit = Math.min(limit, 50);
@@ -101,50 +107,38 @@ public class CategoryREST extends AbstractResourceREST {
id = ALL;
}
Date newerThanDate = newerThan == null ? null : new Date(
Long.valueOf(newerThan));
Date newerThanDate = newerThan == null ? null : new Date(Long.valueOf(newerThan));
if (ALL.equals(id)) {
entries.setName("All");
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findAll(getUser());
List<FeedEntryStatus> list = feedEntryStatusDAO
.findBySubscriptions(subscriptions, unreadOnly, null,
newerThanDate, offset, limit + 1, order, true);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
List<FeedEntryStatus> list = feedEntryStatusDAO.findBySubscriptions(subscriptions, unreadOnly, null, newerThanDate, offset,
limit + 1, order, true);
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get()
.getPublicUrl(), applicationSettingsService
.get().isImageProxyEnabled()));
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
.isImageProxyEnabled()));
}
} else if (STARRED.equals(id)) {
entries.setName("Starred");
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(
getUser(), newerThanDate, offset, limit + 1, order, true);
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(getUser(), newerThanDate, offset, limit + 1, order, true);
for (FeedEntryStatus status : starred) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get()
.getPublicUrl(), applicationSettingsService
.get().isImageProxyEnabled()));
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
.isImageProxyEnabled()));
}
} else {
FeedCategory parent = feedCategoryDAO.findById(getUser(),
Long.valueOf(id));
FeedCategory parent = feedCategoryDAO.findById(getUser(), Long.valueOf(id));
if (parent != null) {
List<FeedCategory> categories = feedCategoryDAO
.findAllChildrenCategories(getUser(), parent);
List<FeedSubscription> subs = feedSubscriptionDAO
.findByCategories(getUser(), categories);
List<FeedEntryStatus> list = feedEntryStatusDAO
.findBySubscriptions(subs, unreadOnly, null,
newerThanDate, offset, limit + 1, order, true);
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(getUser(), parent);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(getUser(), categories);
List<FeedEntryStatus> list = feedEntryStatusDAO.findBySubscriptions(subs, unreadOnly, null, newerThanDate, offset,
limit + 1, order, true);
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService
.get().getPublicUrl(),
applicationSettingsService.get()
.isImageProxyEnabled()));
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
.isImageProxyEnabled()));
}
entries.setName(parent.getName());
}
@@ -176,8 +170,7 @@ public class CategoryREST extends AbstractResourceREST {
int offset = 0;
int limit = 20;
Entries entries = (Entries) getCategoryEntries(id, readType, null,
offset, limit, order).getEntity();
Entries entries = (Entries) getCategoryEntries(id, readType, null, offset, limit, order).getEntity();
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
@@ -206,28 +199,21 @@ public class CategoryREST extends AbstractResourceREST {
@Path("/mark")
@POST
@ApiOperation(value = "Mark category entries", notes = "Mark feed entries of this category as read")
public Response markCategoryEntries(
@ApiParam(value = "category id, or 'all'", required = true) MarkRequest req) {
public Response markCategoryEntries(@ApiParam(value = "category id, or 'all'", required = true) MarkRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Date olderThan = req.getOlderThan() == null ? null : new Date(
req.getOlderThan());
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
if (ALL.equals(req.getId())) {
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findAll(getUser());
feedEntryStatusDAO
.markSubscriptionEntries(subscriptions, olderThan);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
feedEntryStatusDAO.markSubscriptionEntries(subscriptions, olderThan);
} else if (STARRED.equals(req.getId())) {
feedEntryStatusDAO.markStarredEntries(getUser(), olderThan);
} else {
FeedCategory parent = feedCategoryDAO.findById(getUser(),
Long.valueOf(req.getId()));
List<FeedCategory> categories = feedCategoryDAO
.findAllChildrenCategories(getUser(), parent);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(
getUser(), categories);
FeedCategory parent = feedCategoryDAO.findById(getUser(), Long.valueOf(req.getId()));
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(getUser(), parent);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(getUser(), categories);
feedEntryStatusDAO.markSubscriptionEntries(subs, olderThan);
}
cache.invalidateUserData(getUser());
@@ -237,8 +223,7 @@ public class CategoryREST extends AbstractResourceREST {
@Path("/add")
@POST
@ApiOperation(value = "Add a category", notes = "Add a new feed category")
public Response addCategory(
@ApiParam(required = true) AddCategoryRequest req) {
public Response addCategory(@ApiParam(required = true) AddCategoryRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getName());
@@ -267,17 +252,14 @@ public class CategoryREST extends AbstractResourceREST {
FeedCategory cat = feedCategoryDAO.findById(getUser(), req.getId());
if (cat != null) {
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
getUser(), cat);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(getUser(), cat);
for (FeedSubscription sub : subs) {
sub.setCategory(null);
}
feedSubscriptionDAO.saveOrUpdate(subs);
List<FeedCategory> categories = feedCategoryDAO
.findAllChildrenCategories(getUser(), cat);
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(getUser(), cat);
for (FeedCategory child : categories) {
if (!child.getId().equals(cat.getId())
&& child.getParent().getId().equals(cat.getId())) {
if (!child.getId().equals(cat.getId()) && child.getParent().getId().equals(cat.getId())) {
child.setParent(null);
}
}
@@ -294,43 +276,35 @@ public class CategoryREST extends AbstractResourceREST {
@POST
@Path("/modify")
@ApiOperation(value = "Rename a category", notes = "Rename an existing feed category")
public Response modifyCategory(
@ApiParam(required = true) CategoryModificationRequest req) {
public Response modifyCategory(@ApiParam(required = true) CategoryModificationRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
FeedCategory category = feedCategoryDAO
.findById(getUser(), req.getId());
FeedCategory category = feedCategoryDAO.findById(getUser(), req.getId());
if (StringUtils.isNotBlank(req.getName())) {
category.setName(req.getName());
}
FeedCategory parent = null;
if (req.getParentId() != null
&& !CategoryREST.ALL.equals(req.getParentId())
&& !StringUtils.equals(req.getParentId(),
String.valueOf(req.getId()))) {
parent = feedCategoryDAO.findById(getUser(),
Long.valueOf(req.getParentId()));
if (req.getParentId() != null && !CategoryREST.ALL.equals(req.getParentId())
&& !StringUtils.equals(req.getParentId(), String.valueOf(req.getId()))) {
parent = feedCategoryDAO.findById(getUser(), Long.valueOf(req.getParentId()));
}
category.setParent(parent);
if (req.getPosition() != null) {
List<FeedCategory> categories = feedCategoryDAO.findByParent(
getUser(), parent);
List<FeedCategory> categories = feedCategoryDAO.findByParent(getUser(), parent);
Collections.sort(categories, new Comparator<FeedCategory>() {
@Override
public int compare(FeedCategory o1, FeedCategory o2) {
return ObjectUtils.compare(o1.getPosition(),
o2.getPosition());
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
}
});
int existingIndex = -1;
for (int i = 0; i < categories.size(); i++) {
if (ObjectUtils.equals(categories.get(i).getId(),
category.getId())) {
if (ObjectUtils.equals(categories.get(i).getId(), category.getId())) {
existingIndex = i;
}
}
@@ -338,8 +312,7 @@ public class CategoryREST extends AbstractResourceREST {
categories.remove(existingIndex);
}
categories.add(Math.min(req.getPosition(), categories.size()),
category);
categories.add(Math.min(req.getPosition(), categories.size()), category);
for (int i = 0; i < categories.size(); i++) {
categories.get(i).setPosition(i);
}
@@ -360,8 +333,7 @@ public class CategoryREST extends AbstractResourceREST {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
FeedCategory category = feedCategoryDAO.findById(getUser(),
Long.valueOf(req.getId()));
FeedCategory category = feedCategoryDAO.findById(getUser(), Long.valueOf(req.getId()));
if (category == null) {
return Response.status(Status.NOT_FOUND).build();
}
@@ -376,8 +348,7 @@ public class CategoryREST extends AbstractResourceREST {
@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 = feedSubscriptionService
.getUnreadCount(getUser());
Map<Long, Long> unreadCount = feedSubscriptionService.getUnreadCount(getUser());
for (Map.Entry<Long, Long> e : unreadCount.entrySet()) {
list.add(new UnreadCount(e.getKey(), e.getValue()));
}
@@ -386,7 +357,10 @@ public class CategoryREST extends AbstractResourceREST {
@GET
@Path("/get")
@ApiOperation(value = "Get feed categories", notes = "Get all categories and subscriptions of the user", responseClass = "com.commafeed.frontend.model.Category")
@ApiOperation(
value = "Get feed categories",
notes = "Get all categories and subscriptions of the user",
responseClass = "com.commafeed.frontend.model.Category")
public Response getSubscriptions() {
User user = getUser();
@@ -394,10 +368,8 @@ public class CategoryREST extends AbstractResourceREST {
if (root == null) {
log.debug("root category cache miss for {}", user.getName());
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findAll(getUser());
Map<Long, Long> unreadCount = feedSubscriptionService
.getUnreadCount(getUser());
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
Map<Long, Long> unreadCount = feedSubscriptionService.getUnreadCount(getUser());
root = buildCategory(null, categories, subscriptions, unreadCount);
root.setId("all");
@@ -407,18 +379,14 @@ public class CategoryREST extends AbstractResourceREST {
return Response.ok(root).build();
}
private Category buildCategory(Long id, List<FeedCategory> categories,
List<FeedSubscription> subscriptions, Map<Long, Long> unreadCount) {
private Category buildCategory(Long id, List<FeedCategory> categories, List<FeedSubscription> subscriptions, Map<Long, Long> unreadCount) {
Category category = new Category();
category.setId(String.valueOf(id));
category.setExpanded(true);
for (FeedCategory c : categories) {
if ((id == null && c.getParent() == null)
|| (c.getParent() != null && ObjectUtils.equals(c
.getParent().getId(), id))) {
Category child = buildCategory(c.getId(), categories,
subscriptions, unreadCount);
if ((id == null && c.getParent() == null) || (c.getParent() != null && ObjectUtils.equals(c.getParent().getId(), id))) {
Category child = buildCategory(c.getId(), categories, subscriptions, unreadCount);
child.setId(String.valueOf(c.getId()));
child.setName(c.getName());
child.setPosition(c.getPosition());
@@ -438,13 +406,10 @@ public class CategoryREST extends AbstractResourceREST {
for (FeedSubscription subscription : subscriptions) {
if ((id == null && subscription.getCategory() == null)
|| (subscription.getCategory() != null && ObjectUtils
.equals(subscription.getCategory().getId(), id))) {
|| (subscription.getCategory() != null && ObjectUtils.equals(subscription.getCategory().getId(), id))) {
Long size = unreadCount.get(subscription.getId());
long unread = size == null ? 0 : size;
Subscription sub = Subscription
.build(subscription, applicationSettingsService.get()
.getPublicUrl(), unread);
Subscription sub = Subscription.build(subscription, applicationSettingsService.get().getPublicUrl(), unread);
category.getFeeds().add(sub);
}
}

View File

@@ -50,14 +50,12 @@ public class EntryREST extends AbstractResourceREST {
@Path("/mark")
@POST
@ApiOperation(value = "Mark a feed entry", notes = "Mark a feed entry as read/unread")
public Response markFeedEntry(
@ApiParam(value = "Mark Request", required = true) MarkRequest req) {
public Response markFeedEntry(@ApiParam(value = "Mark Request", required = true) MarkRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Preconditions.checkNotNull(req.getFeedId());
feedEntryService.markEntry(getUser(), Long.valueOf(req.getId()),
req.getFeedId(), req.isRead());
feedEntryService.markEntry(getUser(), Long.valueOf(req.getId()), req.getFeedId(), req.isRead());
cache.invalidateUserData(getUser());
return Response.ok(Status.OK).build();
}
@@ -65,8 +63,7 @@ public class EntryREST extends AbstractResourceREST {
@Path("/markMultiple")
@POST
@ApiOperation(value = "Mark multiple feed entries", notes = "Mark feed entries as read/unread")
public Response markFeedEntries(
@ApiParam(value = "Multiple Mark Request", required = true) MultipleMarkRequest req) {
public Response markFeedEntries(@ApiParam(value = "Multiple Mark Request", required = true) MultipleMarkRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getRequests());
@@ -80,25 +77,26 @@ public class EntryREST extends AbstractResourceREST {
@Path("/star")
@POST
@ApiOperation(value = "Mark a feed entry", notes = "Mark a feed entry as read/unread")
public Response starFeedEntry(
@ApiParam(value = "Star Request", required = true) StarRequest req) {
public Response starFeedEntry(@ApiParam(value = "Star Request", required = true) StarRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Preconditions.checkNotNull(req.getFeedId());
feedEntryService.starEntry(getUser(), Long.valueOf(req.getId()),
req.getFeedId(), req.isStarred());
feedEntryService.starEntry(getUser(), Long.valueOf(req.getId()), req.getFeedId(), req.isStarred());
return Response.ok(Status.OK).build();
}
@Path("/search")
@GET
@ApiOperation(value = "Search for entries", notes = "Look through title and content of entries by keywords", responseClass = "com.commafeed.frontend.model.Entries")
@ApiOperation(
value = "Search for entries",
notes = "Look through title and content of entries by keywords",
responseClass = "com.commafeed.frontend.model.Entries")
public Response searchEntries(
@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 = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit) {
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(
value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit) {
keywords = StringUtils.trimToEmpty(keywords);
limit = Math.min(limit, 50);
Preconditions.checkArgument(StringUtils.length(keywords) >= 3);
@@ -107,12 +105,10 @@ public class EntryREST extends AbstractResourceREST {
List<Entry> list = Lists.newArrayList();
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(getUser());
List<FeedEntryStatus> entriesStatus = feedEntryStatusDAO
.findBySubscriptions(subs, false, keywords, null, offset,
limit, ReadingOrder.desc, true);
List<FeedEntryStatus> entriesStatus = feedEntryStatusDAO.findBySubscriptions(subs, false, keywords, null, offset, limit,
ReadingOrder.desc, true);
for (FeedEntryStatus status : entriesStatus) {
list.add(Entry.build(status, applicationSettingsService.get()
.getPublicUrl(), applicationSettingsService.get()
list.add(Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
.isImageProxyEnabled()));
}

View File

@@ -124,13 +124,15 @@ public class FeedREST extends AbstractResourceREST {
@Path("/entries")
@GET
@ApiOperation(value = "Get feed entries", notes = "Get a list of feed entries", responseClass = "com.commafeed.frontend.model.Entries")
public Response getFeedEntries(
@ApiParam(value = "id of the feed", required = true) @QueryParam("id") String id,
@ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @DefaultValue("unread") @QueryParam("readType") ReadType readType,
@ApiParam(value = "only entries newer than this") @QueryParam("newerThan") Long newerThan,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,
@ApiParam(value = "limit for paging, default 20, maximum 50") @DefaultValue("20") @QueryParam("limit") int limit,
@ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
public Response getFeedEntries(@ApiParam(value = "id of the feed", required = true) @QueryParam("id") String id, @ApiParam(
value = "all entries or only unread ones",
allowableValues = "all,unread",
required = true) @DefaultValue("unread") @QueryParam("readType") ReadType readType, @ApiParam(
value = "only entries newer than this") @QueryParam("newerThan") Long newerThan,
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset, @ApiParam(
value = "limit for paging, default 20, maximum 50") @DefaultValue("20") @QueryParam("limit") int limit, @ApiParam(
value = "date ordering",
allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(readType);
@@ -141,27 +143,22 @@ public class FeedREST extends AbstractResourceREST {
Entries entries = new Entries();
boolean unreadOnly = readType == ReadType.unread;
Date newerThanDate = newerThan == null ? null : new Date(
Long.valueOf(newerThan));
Date newerThanDate = newerThan == null ? null : new Date(Long.valueOf(newerThan));
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(),
Long.valueOf(id));
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), Long.valueOf(id));
if (subscription != null) {
entries.setName(subscription.getTitle());
entries.setMessage(subscription.getFeed().getMessage());
entries.setErrorCount(subscription.getFeed().getErrorCount());
entries.setFeedLink(subscription.getFeed().getLink());
List<FeedEntryStatus> list = feedEntryStatusDAO
.findBySubscriptions(Arrays.asList(subscription),
unreadOnly, null, newerThanDate, offset, limit + 1,
order, true);
List<FeedEntryStatus> list = feedEntryStatusDAO.findBySubscriptions(Arrays.asList(subscription), unreadOnly, null,
newerThanDate, offset, limit + 1, order, true);
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get()
.getPublicUrl(), applicationSettingsService
.get().isImageProxyEnabled()));
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
.isImageProxyEnabled()));
}
boolean hasMore = entries.getEntries().size() > limit;
@@ -180,8 +177,7 @@ public class FeedREST extends AbstractResourceREST {
@ApiOperation(value = "Get feed entries as a feed", notes = "Get a feed of feed entries")
@Produces(MediaType.APPLICATION_XML)
@SecurityCheck(value = Role.USER, apiKeyAllowed = true)
public Response getFeedEntriesAsFeed(
@ApiParam(value = "id of the feed", required = true) @QueryParam("id") String id) {
public Response getFeedEntriesAsFeed(@ApiParam(value = "id of the feed", required = true) @QueryParam("id") String id) {
Preconditions.checkNotNull(id);
@@ -190,8 +186,7 @@ public class FeedREST extends AbstractResourceREST {
int offset = 0;
int limit = 20;
Entries entries = (Entries) getFeedEntries(id, readType, null, offset,
limit, order).getEntity();
Entries entries = (Entries) getFeedEntries(id, readType, null, offset, limit, order).getEntity();
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
@@ -222,16 +217,13 @@ public class FeedREST extends AbstractResourceREST {
url = StringUtils.trimToEmpty(url);
url = prependHttp(url);
try {
FetchedFeed feed = feedFetcher.fetch(url, true, null, null, null,
null);
FetchedFeed feed = feedFetcher.fetch(url, true, null, null, null, null);
info = new FeedInfo();
info.setUrl(feed.getFeed().getUrl());
info.setTitle(feed.getTitle());
} catch (Exception e) {
throw new WebApplicationException(e, Response
.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build());
throw new WebApplicationException(e, Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
}
return info;
}
@@ -239,8 +231,7 @@ public class FeedREST extends AbstractResourceREST {
@POST
@Path("/fetch")
@ApiOperation(value = "Fetch a feed", notes = "Fetch a feed by its url", responseClass = "com.commafeed.frontend.model.FeedInfo")
public Response fetchFeed(
@ApiParam(value = "feed url", required = true) FeedInfoRequest req) {
public Response fetchFeed(@ApiParam(value = "feed url", required = true) FeedInfoRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getUrl());
@@ -248,8 +239,7 @@ public class FeedREST extends AbstractResourceREST {
try {
info = fetchFeedInternal(req.getUrl());
} catch (Exception e) {
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build();
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
return Response.ok(info).build();
}
@@ -262,8 +252,7 @@ public class FeedREST extends AbstractResourceREST {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(),
req.getId());
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), req.getId());
if (sub != null) {
Feed feed = sub.getFeed();
feed.setUrgent(true);
@@ -277,19 +266,15 @@ public class FeedREST extends AbstractResourceREST {
@Path("/mark")
@POST
@ApiOperation(value = "Mark feed entries", notes = "Mark feed entries as read (unread is not supported)")
public Response markFeedEntries(
@ApiParam(value = "Mark request") MarkRequest req) {
public Response markFeedEntries(@ApiParam(value = "Mark request") MarkRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Date olderThan = req.getOlderThan() == null ? null : new Date(
req.getOlderThan());
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(),
Long.valueOf(req.getId()));
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), Long.valueOf(req.getId()));
if (subscription != null) {
feedEntryStatusDAO.markSubscriptionEntries(
Arrays.asList(subscription), olderThan);
feedEntryStatusDAO.markSubscriptionEntries(Arrays.asList(subscription), olderThan);
}
cache.invalidateUserData(getUser());
return Response.ok(Status.OK).build();
@@ -298,33 +283,27 @@ public class FeedREST extends AbstractResourceREST {
@GET
@Path("/get/{id}")
@ApiOperation(value = "", notes = "")
public Response get(
@ApiParam(value = "user id", required = true) @PathParam("id") Long id) {
public Response get(@ApiParam(value = "user id", required = true) @PathParam("id") Long id) {
Preconditions.checkNotNull(id);
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), id);
if (sub == null) {
return Response.status(Status.NOT_FOUND).build();
}
Long unreadCount = feedSubscriptionService.getUnreadCount(getUser())
.get(id);
Long unreadCount = feedSubscriptionService.getUnreadCount(getUser()).get(id);
if (unreadCount == null) {
unreadCount = new Long(0);
}
return Response.ok(
Subscription.build(sub, applicationSettingsService.get()
.getPublicUrl(), unreadCount)).build();
return Response.ok(Subscription.build(sub, applicationSettingsService.get().getPublicUrl(), unreadCount)).build();
}
@GET
@Path("/favicon/{id}")
@ApiOperation(value = "Fetch a feed's icon", notes = "Fetch a feed's icon")
public Response getFavicon(
@ApiParam(value = "subscription id") @PathParam("id") Long id) {
public Response getFavicon(@ApiParam(value = "subscription id") @PathParam("id") Long id) {
Preconditions.checkNotNull(id);
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(),
id);
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), id);
if (subscription == null) {
return Response.status(Status.NOT_FOUND).build();
}
@@ -334,11 +313,8 @@ public class FeedREST extends AbstractResourceREST {
ResponseBuilder builder = null;
if (icon == null) {
String baseUrl = FeedUtils
.removeTrailingSlash(applicationSettingsService.get()
.getPublicUrl());
builder = Response.status(Status.MOVED_PERMANENTLY).location(
URI.create(baseUrl + "/images/default_favicon.gif"));
String baseUrl = FeedUtils.removeTrailingSlash(applicationSettingsService.get().getPublicUrl());
builder = Response.status(Status.MOVED_PERMANENTLY).location(URI.create(baseUrl + "/images/default_favicon.gif"));
} else {
builder = Response.ok(icon, "image/x-icon");
}
@@ -360,8 +336,7 @@ public class FeedREST extends AbstractResourceREST {
@POST
@Path("/subscribe")
@ApiOperation(value = "Subscribe to a feed", notes = "Subscribe to a feed")
public Response subscribe(
@ApiParam(value = "subscription request", required = true) SubscribeRequest req) {
public Response subscribe(@ApiParam(value = "subscription request", required = true) SubscribeRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getTitle());
Preconditions.checkNotNull(req.getUrl());
@@ -370,18 +345,13 @@ public class FeedREST extends AbstractResourceREST {
try {
url = fetchFeedInternal(url).getUrl();
FeedCategory category = CategoryREST.ALL
.equals(req.getCategoryId()) ? null : feedCategoryDAO
.findById(Long.valueOf(req.getCategoryId()));
FeedCategory category = CategoryREST.ALL.equals(req.getCategoryId()) ? null : feedCategoryDAO.findById(Long.valueOf(req
.getCategoryId()));
FeedInfo info = fetchFeedInternal(url);
feedSubscriptionService.subscribe(getUser(), info.getUrl(),
req.getTitle(), category);
feedSubscriptionService.subscribe(getUser(), info.getUrl(), req.getTitle(), category);
} catch (Exception e) {
log.info("Failed to subscribe to URL {}: {}", url, e.getMessage());
return Response
.status(Status.SERVICE_UNAVAILABLE)
.entity("Failed to subscribe to URL " + url + ": "
+ e.getMessage()).build();
return Response.status(Status.SERVICE_UNAVAILABLE).entity("Failed to subscribe to URL " + url + ": " + e.getMessage()).build();
}
cache.invalidateUserData(getUser());
return Response.ok(Status.OK).build();
@@ -390,8 +360,7 @@ public class FeedREST extends AbstractResourceREST {
@GET
@Path("/subscribe")
@ApiOperation(value = "Subscribe to a feed", notes = "Subscribe to a feed")
public Response subscribe(
@ApiParam(value = "feed url", required = true) @QueryParam("url") String url) {
public Response subscribe(@ApiParam(value = "feed url", required = true) @QueryParam("url") String url) {
try {
Preconditions.checkNotNull(url);
@@ -400,14 +369,11 @@ public class FeedREST extends AbstractResourceREST {
url = fetchFeedInternal(url).getUrl();
FeedInfo info = fetchFeedInternal(url);
feedSubscriptionService.subscribe(getUser(), info.getUrl(),
info.getTitle(), null);
feedSubscriptionService.subscribe(getUser(), info.getUrl(), info.getTitle(), null);
} catch (Exception e) {
log.info("Could not subscribe to url {} : {}", url, e.getMessage());
}
return Response.temporaryRedirect(
URI.create(applicationSettingsService.get().getPublicUrl()))
.build();
return Response.temporaryRedirect(URI.create(applicationSettingsService.get().getPublicUrl())).build();
}
private String prependHttp(String url) {
@@ -424,8 +390,7 @@ public class FeedREST extends AbstractResourceREST {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(),
req.getId());
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), req.getId());
if (sub != null) {
feedSubscriptionDAO.delete(sub);
cache.invalidateUserData(getUser());
@@ -438,41 +403,34 @@ public class FeedREST extends AbstractResourceREST {
@POST
@Path("/modify")
@ApiOperation(value = "Modify a subscription", notes = "Modify a feed subscription")
public Response modify(
@ApiParam(value = "subscription id", required = true) FeedModificationRequest req) {
public Response modify(@ApiParam(value = "subscription id", required = true) FeedModificationRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(),
req.getId());
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), req.getId());
if (StringUtils.isNotBlank(req.getName())) {
subscription.setTitle(req.getName());
}
FeedCategory parent = null;
if (req.getCategoryId() != null
&& !CategoryREST.ALL.equals(req.getCategoryId())) {
parent = feedCategoryDAO.findById(getUser(),
Long.valueOf(req.getCategoryId()));
if (req.getCategoryId() != null && !CategoryREST.ALL.equals(req.getCategoryId())) {
parent = feedCategoryDAO.findById(getUser(), Long.valueOf(req.getCategoryId()));
}
subscription.setCategory(parent);
if (req.getPosition() != null) {
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
getUser(), parent);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(getUser(), parent);
Collections.sort(subs, new Comparator<FeedSubscription>() {
@Override
public int compare(FeedSubscription o1, FeedSubscription o2) {
return ObjectUtils.compare(o1.getPosition(),
o2.getPosition());
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
}
});
int existingIndex = -1;
for (int i = 0; i < subs.size(); i++) {
if (ObjectUtils.equals(subs.get(i).getId(),
subscription.getId())) {
if (ObjectUtils.equals(subs.get(i).getId(), subscription.getId())) {
existingIndex = i;
}
}
@@ -500,22 +458,19 @@ public class FeedREST extends AbstractResourceREST {
String publicUrl = applicationSettingsService.get().getPublicUrl();
if (StringUtils.isBlank(publicUrl)) {
throw new WebApplicationException(Response
.status(Status.INTERNAL_SERVER_ERROR)
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR)
.entity("Set the public URL in the admin section.").build());
}
if (StartupBean.USERNAME_DEMO.equals(getUser().getName())) {
return Response.status(Status.FORBIDDEN)
.entity("Import is disabled for the demo account").build();
return Response.status(Status.FORBIDDEN).entity("Import is disabled for the demo account").build();
}
try {
FileItemFactory factory = new DiskFileItemFactory(1000000, null);
ServletFileUpload upload = new ServletFileUpload(factory);
for (FileItem item : upload.parseRequest(request)) {
if ("file".equals(item.getFieldName())) {
String opml = IOUtils.toString(item.getInputStream(),
"UTF-8");
String opml = IOUtils.toString(item.getInputStream(), "UTF-8");
if (StringUtils.isNotBlank(opml)) {
opmlImporter.importOpml(getUser(), opml);
}
@@ -523,14 +478,10 @@ public class FeedREST extends AbstractResourceREST {
}
}
} catch (Exception e) {
throw new WebApplicationException(Response
.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build());
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
}
cache.invalidateUserData(getUser());
return Response.temporaryRedirect(
URI.create(applicationSettingsService.get().getPublicUrl()))
.build();
return Response.temporaryRedirect(URI.create(applicationSettingsService.get().getPublicUrl())).build();
}
@GET
@@ -544,8 +495,7 @@ public class FeedREST extends AbstractResourceREST {
try {
opmlString = output.outputString(opml);
} catch (Exception e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e)
.build();
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e).build();
}
return Response.ok(opmlString).build();
}

View File

@@ -33,8 +33,7 @@ import com.google.api.client.repackaged.com.google.common.base.Preconditions;
@Path("/push")
public class PubSubHubbubCallbackREST {
private static Logger log = LoggerFactory
.getLogger(PubSubHubbubCallbackREST.class);
private static Logger log = LoggerFactory.getLogger(PubSubHubbubCallbackREST.class);
@Context
HttpServletRequest request;
@@ -57,13 +56,10 @@ public class PubSubHubbubCallbackREST {
@Path("/callback")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response verify(@QueryParam("hub.mode") String mode,
@QueryParam("hub.topic") String topic,
@QueryParam("hub.challenge") String challenge,
@QueryParam("hub.lease_seconds") String leaseSeconds,
public Response verify(@QueryParam("hub.mode") String mode, @QueryParam("hub.topic") String topic,
@QueryParam("hub.challenge") String challenge, @QueryParam("hub.lease_seconds") String leaseSeconds,
@QueryParam("hub.verify_token") String verifyToken) {
if (!applicationSettingsService.get()
.isPubsubhubbub()) {
if (!applicationSettingsService.get().isPubsubhubbub()) {
return Response.status(Status.FORBIDDEN).entity("pubsubhubbub is disabled").build();
}
@@ -76,8 +72,7 @@ public class PubSubHubbubCallbackREST {
if (feeds.isEmpty() == false) {
for (Feed feed : feeds) {
log.debug("activated push notifications for {}",
feed.getPushTopic());
log.debug("activated push notifications for {}", feed.getPushTopic());
feed.setPushLastPing(new Date());
}
feedDAO.saveOrUpdate(feeds);
@@ -92,8 +87,7 @@ public class PubSubHubbubCallbackREST {
@POST
@Consumes({ MediaType.APPLICATION_ATOM_XML, "application/rss+xml" })
public Response callback() {
if (!applicationSettingsService.get()
.isPubsubhubbub()) {
if (!applicationSettingsService.get().isPubsubhubbub()) {
return Response.status(Status.FORBIDDEN).entity("pubsubhubbub is disabled").build();
}
try {

View File

@@ -34,10 +34,8 @@ public class ServerREST extends AbstractResourceREST {
ApplicationPropertiesService properties = ApplicationPropertiesService.get();
ServerInfo infos = new ServerInfo();
infos.setAnnouncement(applicationSettingsService.get()
.getAnnouncement());
infos.getSupportedLanguages().putAll(
startupBean.getSupportedLanguages());
infos.setAnnouncement(applicationSettingsService.get().getAnnouncement());
infos.getSupportedLanguages().putAll(startupBean.getSupportedLanguages());
infos.setVersion(properties.getVersion());
infos.setGitCommit(properties.getGitCommit());
return Response.ok(infos).build();
@@ -57,8 +55,7 @@ public class ServerREST extends AbstractResourceREST {
HttpResult result = httpGetter.getBinary(url, 20000);
return Response.ok(result.getContent()).build();
} catch (Exception e) {
return Response.status(Status.SERVICE_UNAVAILABLE)
.entity(e.getMessage()).build();
return Response.status(Status.SERVICE_UNAVAILABLE).entity(e.getMessage()).build();
}
}
}

View File

@@ -66,7 +66,10 @@ public class UserREST extends AbstractResourceREST {
@Path("/settings")
@GET
@ApiOperation(value = "Retrieve user settings", notes = "Retrieve user settings", responseClass = "com.commafeed.frontend.model.Settings")
@ApiOperation(
value = "Retrieve user settings",
notes = "Retrieve user settings",
responseClass = "com.commafeed.frontend.model.Settings")
public Response getSettings() {
Settings s = new Settings();
UserSettings settings = userSettingsDAO.findByUser(getUser());
@@ -149,16 +152,13 @@ public class UserREST extends AbstractResourceREST {
@Path("/profile")
@POST
@ApiOperation(value = "Save user's profile")
public Response save(
@ApiParam(required = true) ProfileModificationRequest request) {
public Response save(@ApiParam(required = true) ProfileModificationRequest request) {
User user = getUser();
Preconditions.checkArgument(StringUtils.isBlank(request.getPassword())
|| request.getPassword().length() >= 6);
Preconditions.checkArgument(StringUtils.isBlank(request.getPassword()) || request.getPassword().length() >= 6);
if (StringUtils.isNotBlank(request.getEmail())) {
User u = userDAO.findByEmail(request.getEmail());
Preconditions.checkArgument(u == null
|| user.getId().equals(u.getId()));
Preconditions.checkArgument(u == null || user.getId().equals(u.getId()));
}
if (StartupBean.USERNAME_DEMO.equals(user.getName())) {
@@ -167,8 +167,7 @@ public class UserREST extends AbstractResourceREST {
user.setEmail(StringUtils.trimToNull(request.getEmail()));
if (StringUtils.isNotBlank(request.getPassword())) {
byte[] password = encryptionService.getEncryptedPassword(
request.getPassword(), user.getSalt());
byte[] password = encryptionService.getEncryptedPassword(request.getPassword(), user.getSalt());
user.setPassword(password);
user.setApiKey(userService.generateApiKey(user));
}
@@ -185,12 +184,10 @@ public class UserREST extends AbstractResourceREST {
@SecurityCheck(Role.NONE)
public Response register(@ApiParam(required = true) RegistrationRequest req) {
try {
userService.register(req.getName(), req.getPassword(),
req.getEmail(), Arrays.asList(Role.USER));
userService.register(req.getName(), req.getPassword(), req.getEmail(), Arrays.asList(Role.USER));
return Response.ok().build();
} catch (Exception e) {
return Response.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build();
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
}
@@ -199,8 +196,7 @@ public class UserREST extends AbstractResourceREST {
@POST
@ApiOperation(value = "Delete the user account")
public Response delete() {
if (StartupBean.USERNAME_ADMIN.equals(getUser().getName())
|| StartupBean.USERNAME_DEMO.equals(getUser().getName())) {
if (StartupBean.USERNAME_ADMIN.equals(getUser().getName()) || StartupBean.USERNAME_DEMO.equals(getUser().getName())) {
return Response.status(Status.FORBIDDEN).build();
}
userService.unregister(getUser());

View File

@@ -29,14 +29,12 @@ import com.commafeed.backend.services.ApplicationPropertiesService;
import com.commafeed.frontend.CommaFeedSession;
/**
* Replace variables from templates on the fly in dev mode only. In production
* the substitution is done at build-time.
* Replace variables from templates on the fly in dev mode only. In production the substitution is done at build-time.
*
*/
public class InternationalizationDevelopmentFilter implements Filter {
private static Logger log = LoggerFactory
.getLogger(InternationalizationDevelopmentFilter.class);
private static Logger log = LoggerFactory.getLogger(InternationalizationDevelopmentFilter.class);
@Inject
UserSettingsDAO userSettingsDAO;
@@ -55,8 +53,7 @@ public class InternationalizationDevelopmentFilter implements Filter {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (production) {
chain.doFilter(request, response);
@@ -64,8 +61,7 @@ public class InternationalizationDevelopmentFilter implements Filter {
}
final ServletOutputStream wrapper = new ServletOutputStreamWrapper();
ServletResponse interceptor = new HttpServletResponseWrapper(
(HttpServletResponse) response) {
ServletResponse interceptor = new HttpServletResponseWrapper((HttpServletResponse) response) {
@Override
public ServletOutputStream getOutputStream() throws IOException {
@@ -74,10 +70,8 @@ public class InternationalizationDevelopmentFilter implements Filter {
};
chain.doFilter(request, interceptor);
UserSettings settings = userSettingsDAO.findByUser(CommaFeedSession
.get().getUser());
String lang = (settings == null || settings.getLanguage() == null) ? "en"
: settings.getLanguage();
UserSettings settings = userSettingsDAO.findByUser(CommaFeedSession.get().getUser());
String lang = (settings == null || settings.getLanguage() == null) ? "en" : settings.getLanguage();
byte[] bytes = translate(wrapper.toString(), lang).getBytes("UTF-8");
response.setContentLength(bytes.length);
@@ -91,8 +85,7 @@ public class InternationalizationDevelopmentFilter implements Filter {
Properties props = new Properties();
InputStream is = null;
try {
is = getClass()
.getResourceAsStream("/i18n/" + lang + ".properties");
is = getClass().getResourceAsStream("/i18n/" + lang + ".properties");
props.load(new InputStreamReader(is, "UTF-8"));
} catch (Exception e) {
log.error(e.getMessage(), e);
@@ -111,8 +104,7 @@ public class InternationalizationDevelopmentFilter implements Filter {
while (m.find()) {
String var = m.group(1);
Object replacement = props.get(var);
String replacementValue = replacement == null ? var : replacement
.toString().split("#")[0];
String replacementValue = replacement == null ? var : replacement.toString().split("#")[0];
m.appendReplacement(sb, replacementValue);
}
m.appendTail(sb);

View File

@@ -38,7 +38,7 @@ public class ModelFactory {
*
*/
public static class MF {
public static <T> String i(T proxiedValue) {
return ModelFactory.invokedProperty(proxiedValue);
}

View File

@@ -17,16 +17,12 @@ import org.apache.wicket.util.template.PackageTextTemplate;
public class WicketUtils {
public static void loadJS(IHeaderResponse response, Class<?> klass,
String fileName) {
HeaderItem result = JavaScriptHeaderItem
.forReference(new JavaScriptResourceReference(klass, fileName
+ ".js"));
public static void loadJS(IHeaderResponse response, Class<?> klass, String fileName) {
HeaderItem result = JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(klass, fileName + ".js"));
response.render(result);
}
public static void loadJS(IHeaderResponse response, Class<?> klass,
String fileName, Map<String, ? extends Object> variables) {
public static void loadJS(IHeaderResponse response, Class<?> klass, String fileName, Map<String, ? extends Object> variables) {
HeaderItem result = null;
PackageTextTemplate template = null;
try {
@@ -40,14 +36,12 @@ public class WicketUtils {
}
public static HttpServletRequest getHttpServletRequest() {
ServletWebRequest servletWebRequest = (ServletWebRequest) RequestCycle
.get().getRequest();
ServletWebRequest servletWebRequest = (ServletWebRequest) RequestCycle.get().getRequest();
return servletWebRequest.getContainerRequest();
}
public static HttpServletResponse getHttpServletResponse() {
WebResponse webResponse = (WebResponse) RequestCycle.get()
.getResponse();
WebResponse webResponse = (WebResponse) RequestCycle.get().getResponse();
return (HttpServletResponse) webResponse.getContainerResponse();
}
}

View File

@@ -20,8 +20,7 @@ public class DisplayExceptionPage extends BasePage {
add(new Label("message", t.getMessage()));
add(new BookmarkablePageLink<Void>("homepage", getApplication()
.getHomePage()));
add(new BookmarkablePageLink<Void>("homepage", getApplication().getHomePage()));
StringWriter stringWriter = new StringWriter();
t.printStackTrace(new PrintWriter(stringWriter));

View File

@@ -21,8 +21,7 @@ public class CDIBootstrap implements Extension {
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) {
}
void afterDeploymentValidation(@Observes AfterDeploymentValidation event,
BeanManager manager) {
void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager manager) {
}
@Produces