forked from Archives/Athou_commafeed
apply intellij fixes
This commit is contained in:
@@ -88,30 +88,14 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
|
||||
|
||||
@Override
|
||||
public void initialize(Bootstrap<CommaFeedConfiguration> bootstrap) {
|
||||
bootstrap.setConfigurationFactoryFactory(new DefaultConfigurationFactoryFactory<CommaFeedConfiguration>() {
|
||||
@Override
|
||||
protected ObjectMapper configureObjectMapper(ObjectMapper objectMapper) {
|
||||
// disable case sensitivity because EnvironmentSubstitutor maps MYPROPERTY to myproperty and not to myProperty
|
||||
return objectMapper
|
||||
.setConfig(objectMapper.getDeserializationConfig().with(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
|
||||
}
|
||||
});
|
||||
|
||||
// enable config.yml string substitution
|
||||
// e.g. having a custom config.yml file with app.session.path=${SOME_ENV_VAR} will substitute SOME_ENV_VAR
|
||||
SubstitutingSourceProvider substitutingSourceProvider = new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
|
||||
new EnvironmentVariableSubstitutor(false));
|
||||
// enable config.yml properties override with env variables prefixed with CF_
|
||||
// e.g. setting CF_APP_ALLOWREGISTRATIONS=true will set app.allowRegistrations to true
|
||||
EnvironmentSubstitutor environmentSubstitutor = new EnvironmentSubstitutor("CF", substitutingSourceProvider);
|
||||
bootstrap.setConfigurationSourceProvider(environmentSubstitutor);
|
||||
configureEnvironmentSubstitutor(bootstrap);
|
||||
|
||||
bootstrap.getObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
|
||||
|
||||
bootstrap.addBundle(websocketBundle = new WebsocketBundle<>());
|
||||
bootstrap.addBundle(hibernateBundle = new HibernateBundle<CommaFeedConfiguration>(AbstractModel.class, Feed.class,
|
||||
FeedCategory.class, FeedEntry.class, FeedEntryContent.class, FeedEntryStatus.class, FeedEntryTag.class,
|
||||
FeedSubscription.class, User.class, UserRole.class, UserSettings.class) {
|
||||
bootstrap.addBundle(hibernateBundle = new HibernateBundle<>(AbstractModel.class, Feed.class, FeedCategory.class, FeedEntry.class,
|
||||
FeedEntryContent.class, FeedEntryStatus.class, FeedEntryTag.class, FeedSubscription.class, User.class, UserRole.class,
|
||||
UserSettings.class) {
|
||||
@Override
|
||||
public DataSourceFactory getDataSourceFactory(CommaFeedConfiguration configuration) {
|
||||
DataSourceFactory factory = configuration.getDataSourceFactory();
|
||||
@@ -126,7 +110,7 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
|
||||
}
|
||||
});
|
||||
|
||||
bootstrap.addBundle(new MigrationsBundle<CommaFeedConfiguration>() {
|
||||
bootstrap.addBundle(new MigrationsBundle<>() {
|
||||
@Override
|
||||
public DataSourceFactory getDataSourceFactory(CommaFeedConfiguration configuration) {
|
||||
return configuration.getDataSourceFactory();
|
||||
@@ -137,8 +121,32 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
|
||||
bootstrap.addBundle(new MultiPartBundle());
|
||||
}
|
||||
|
||||
private static void configureEnvironmentSubstitutor(Bootstrap<CommaFeedConfiguration> bootstrap) {
|
||||
bootstrap.setConfigurationFactoryFactory(new DefaultConfigurationFactoryFactory<>() {
|
||||
@Override
|
||||
protected ObjectMapper configureObjectMapper(ObjectMapper objectMapper) {
|
||||
// disable case sensitivity because EnvironmentSubstitutor maps MYPROPERTY to myproperty and not to myProperty
|
||||
return objectMapper
|
||||
.setConfig(objectMapper.getDeserializationConfig().with(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
|
||||
}
|
||||
});
|
||||
|
||||
bootstrap.setConfigurationSourceProvider(buildEnvironmentSubstitutor(bootstrap));
|
||||
}
|
||||
|
||||
private static EnvironmentSubstitutor buildEnvironmentSubstitutor(Bootstrap<CommaFeedConfiguration> bootstrap) {
|
||||
// enable config.yml string substitution
|
||||
// e.g. having a custom config.yml file with app.session.path=${SOME_ENV_VAR} will substitute SOME_ENV_VAR
|
||||
SubstitutingSourceProvider substitutingSourceProvider = new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
|
||||
new EnvironmentVariableSubstitutor(false));
|
||||
|
||||
// enable config.yml properties override with env variables prefixed with CF_
|
||||
// e.g. setting CF_APP_ALLOWREGISTRATIONS=true will set app.allowRegistrations to true
|
||||
return new EnvironmentSubstitutor("CF", substitutingSourceProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CommaFeedConfiguration config, Environment environment) throws Exception {
|
||||
public void run(CommaFeedConfiguration config, Environment environment) {
|
||||
PasswordConstraintValidator.setStrict(config.getApplicationSettings().getStrictPasswordPolicy());
|
||||
|
||||
// guice init
|
||||
@@ -180,7 +188,7 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
|
||||
websocketBundle.addEndpoint(serverEndpointConfig);
|
||||
|
||||
// Scheduled tasks
|
||||
Set<ScheduledTask> tasks = injector.getInstance(Key.get(new TypeLiteral<Set<ScheduledTask>>() {
|
||||
Set<ScheduledTask> tasks = injector.getInstance(Key.get(new TypeLiteral<>() {
|
||||
}));
|
||||
ScheduledExecutorService executor = environment.lifecycle()
|
||||
.scheduledExecutorService("task-scheduler", true)
|
||||
|
||||
@@ -18,7 +18,7 @@ public class FixedSizeSortedSet<E> {
|
||||
private final int capacity;
|
||||
|
||||
public FixedSizeSortedSet(int capacity, Comparator<? super E> comparator) {
|
||||
this.inner = new ArrayList<E>(Math.max(0, capacity));
|
||||
this.inner = new ArrayList<>(Math.max(0, capacity));
|
||||
this.capacity = capacity < 0 ? Integer.MAX_VALUE : capacity;
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ public class RedisCacheService extends CacheService {
|
||||
try (Jedis jedis = pool.getResource()) {
|
||||
String key = buildRedisEntryKey(feed);
|
||||
Set<String> members = jedis.smembers(key);
|
||||
for (String member : members) {
|
||||
list.add(member);
|
||||
}
|
||||
list.addAll(members);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.commafeed.backend.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
@@ -34,7 +33,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
}
|
||||
|
||||
public FeedCategory findByName(User user, String name, FeedCategory parent) {
|
||||
Predicate parentPredicate = null;
|
||||
Predicate parentPredicate;
|
||||
if (parent == null) {
|
||||
parentPredicate = category.parent.isNull();
|
||||
} else {
|
||||
@@ -44,7 +43,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
}
|
||||
|
||||
public List<FeedCategory> findByParent(User user, FeedCategory parent) {
|
||||
Predicate parentPredicate = null;
|
||||
Predicate parentPredicate;
|
||||
if (parent == null) {
|
||||
parentPredicate = category.parent.isNull();
|
||||
} else {
|
||||
@@ -54,7 +53,7 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
||||
}
|
||||
|
||||
public List<FeedCategory> findAllChildrenCategories(User user, FeedCategory parent) {
|
||||
return findAll(user).stream().filter(c -> isChild(c, parent)).collect(Collectors.toList());
|
||||
return findAll(user).stream().filter(c -> isChild(c, parent)).toList();
|
||||
}
|
||||
|
||||
private boolean isChild(FeedCategory child, FeedCategory parent) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.commafeed.backend.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.hibernate.SessionFactory;
|
||||
@@ -43,7 +42,7 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
||||
.having(count.gt(maxCapacity))
|
||||
.limit(max)
|
||||
.fetch();
|
||||
return tuples.stream().map(t -> new FeedCapacity(t.get(entry.feed.id), t.get(count))).collect(Collectors.toList());
|
||||
return tuples.stream().map(t -> new FeedCapacity(t.get(entry.feed.id), t.get(count))).toList();
|
||||
}
|
||||
|
||||
public int delete(Long feedId, long max) {
|
||||
|
||||
@@ -38,14 +38,11 @@ import jakarta.inject.Singleton;
|
||||
@Singleton
|
||||
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) {
|
||||
CompareToBuilder builder = new CompareToBuilder();
|
||||
builder.append(o2.getEntryUpdated(), o1.getEntryUpdated());
|
||||
builder.append(o2.getId(), o1.getId());
|
||||
return builder.toComparison();
|
||||
}
|
||||
private static final Comparator<FeedEntryStatus> STATUS_COMPARATOR_DESC = (o1, o2) -> {
|
||||
CompareToBuilder builder = new CompareToBuilder();
|
||||
builder.append(o2.getEntryUpdated(), o1.getEntryUpdated());
|
||||
builder.append(o2.getId(), o1.getId());
|
||||
return builder.toComparison();
|
||||
};
|
||||
|
||||
private static final Comparator<FeedEntryStatus> STATUS_COMPARATOR_ASC = Ordering.from(STATUS_COMPARATOR_DESC).reverse();
|
||||
@@ -239,7 +236,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
}
|
||||
placeholders = placeholders.subList(Math.max(offset, 0), size);
|
||||
|
||||
List<FeedEntryStatus> statuses = null;
|
||||
List<FeedEntryStatus> statuses;
|
||||
if (onlyIds) {
|
||||
statuses = placeholders;
|
||||
} else {
|
||||
@@ -264,7 +261,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
for (Tuple tuple : tuples) {
|
||||
Long count = tuple.get(entry.count());
|
||||
Date updated = tuple.get(entry.updated.max());
|
||||
uc = new UnreadCount(subscription.getId(), count, updated);
|
||||
uc = new UnreadCount(subscription.getId(), count == null ? 0 : count, updated);
|
||||
}
|
||||
return uc;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
import com.commafeed.backend.model.AbstractModel;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
@@ -74,14 +75,12 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
|
||||
}
|
||||
|
||||
public List<FeedSubscription> findByCategories(User user, List<FeedCategory> categories) {
|
||||
Set<Long> categoryIds = categories.stream().map(c -> c.getId()).collect(Collectors.toSet());
|
||||
return findAll(user).stream()
|
||||
.filter(s -> s.getCategory() != null && categoryIds.contains(s.getCategory().getId()))
|
||||
.collect(Collectors.toList());
|
||||
Set<Long> categoryIds = categories.stream().map(AbstractModel::getId).collect(Collectors.toSet());
|
||||
return findAll(user).stream().filter(s -> s.getCategory() != null && categoryIds.contains(s.getCategory().getId())).toList();
|
||||
}
|
||||
|
||||
private List<FeedSubscription> initRelations(List<FeedSubscription> list) {
|
||||
list.forEach(s -> initRelations(s));
|
||||
list.forEach(this::initRelations);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class GenericDAO<T extends AbstractModel> extends AbstractDAO<T>
|
||||
}
|
||||
|
||||
public int delete(Collection<T> objects) {
|
||||
objects.forEach(o -> delete(o));
|
||||
objects.forEach(this::delete);
|
||||
return objects.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,6 @@ public class UserRoleDAO extends GenericDAO<UserRole> {
|
||||
}
|
||||
|
||||
public Set<Role> findRoles(User user) {
|
||||
return findAll(user).stream().map(r -> r.getRole()).collect(Collectors.toSet());
|
||||
return findAll(user).stream().map(UserRole::getRole).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class DefaultFaviconFetcher extends AbstractFaviconFetcher {
|
||||
|
||||
private Favicon getIconInPage(String url) {
|
||||
|
||||
Document doc = null;
|
||||
Document doc;
|
||||
try {
|
||||
HttpResult result = getter.getBinary(url, TIMEOUT);
|
||||
doc = Jsoup.parse(new String(result.getContent()), url);
|
||||
@@ -109,8 +109,8 @@ public class DefaultFaviconFetcher extends AbstractFaviconFetcher {
|
||||
|
||||
log.debug("Found unconfirmed iconInPage at {}", href);
|
||||
|
||||
byte[] bytes = null;
|
||||
String contentType = null;
|
||||
byte[] bytes;
|
||||
String contentType;
|
||||
try {
|
||||
HttpResult result = getter.getBinary(href, TIMEOUT);
|
||||
bytes = result.getContent();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class FacebookFaviconFetcher extends AbstractFaviconFetcher {
|
||||
}
|
||||
|
||||
private String extractUserName(String url) {
|
||||
URI uri = null;
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class FeedFetcher {
|
||||
private final Set<FeedURLProvider> urlProviders;
|
||||
|
||||
public FeedFetcherResult fetch(String feedUrl, boolean extractFeedUrlFromHtml, String lastModified, String eTag, Date lastPublishedDate,
|
||||
String lastContentHash) throws FeedException, IOException, NotModifiedException, InterruptedException {
|
||||
String lastContentHash) throws FeedException, IOException, NotModifiedException {
|
||||
log.debug("Fetching feed {}", feedUrl);
|
||||
|
||||
int timeout = 20000;
|
||||
|
||||
@@ -184,7 +184,7 @@ public class FeedParser {
|
||||
}
|
||||
|
||||
private String getContent(SyndEntry item) {
|
||||
String content = null;
|
||||
String content;
|
||||
if (item.getContents().isEmpty()) {
|
||||
content = item.getDescription() == null ? null : item.getDescription().getValue();
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
|
||||
@@ -173,7 +172,7 @@ public class FeedRefreshEngine implements Managed {
|
||||
List<Feed> feeds = feedDAO.findNextUpdatable(max, lastLoginThreshold);
|
||||
// update disabledUntil to prevent feeds from being returned again by feedDAO.findNextUpdatable()
|
||||
Date nextUpdateDate = DateUtils.addMinutes(new Date(), config.getApplicationSettings().getRefreshIntervalMinutes());
|
||||
feedDAO.setDisabledUntil(feeds.stream().map(AbstractModel::getId).collect(Collectors.toList()), nextUpdateDate);
|
||||
feedDAO.setDisabledUntil(feeds.stream().map(AbstractModel::getId).toList(), nextUpdateDate);
|
||||
return feeds;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -150,7 +149,7 @@ public class FeedRefreshUpdater implements Managed {
|
||||
if (subscriptions == null) {
|
||||
feed.setMessage("No new entries found");
|
||||
} else if (insertedAtLeastOneEntry) {
|
||||
List<User> users = subscriptions.stream().map(FeedSubscription::getUser).collect(Collectors.toList());
|
||||
List<User> users = subscriptions.stream().map(FeedSubscription::getUser).toList();
|
||||
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
|
||||
cache.invalidateUserRootCategory(users.toArray(new User[0]));
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.commafeed.backend.feed;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -52,7 +51,7 @@ public class FeedRefreshWorker {
|
||||
|
||||
Integer maxFeedCapacity = config.getApplicationSettings().getMaxFeedCapacity();
|
||||
if (maxFeedCapacity > 0) {
|
||||
entries = entries.stream().limit(maxFeedCapacity).collect(Collectors.toList());
|
||||
entries = entries.stream().limit(maxFeedCapacity).toList();
|
||||
}
|
||||
|
||||
String urlAfterRedirect = feedFetcherResult.getUrlAfterRedirect();
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.ahocorasick.trie.Emit;
|
||||
import org.ahocorasick.trie.Trie;
|
||||
@@ -246,7 +245,7 @@ public class FeedUtils {
|
||||
}
|
||||
|
||||
public static List<Long> getSortedTimestamps(List<FeedEntry> entries) {
|
||||
return entries.stream().map(t -> t.getUpdated().getTime()).sorted(Collections.reverseOrder()).collect(Collectors.toList());
|
||||
return entries.stream().map(t -> t.getUpdated().getTime()).sorted(Collections.reverseOrder()).toList();
|
||||
}
|
||||
|
||||
public static String removeTrailingSlash(String url) {
|
||||
@@ -278,7 +277,7 @@ public class FeedUtils {
|
||||
return url;
|
||||
}
|
||||
|
||||
String result = null;
|
||||
String result;
|
||||
try {
|
||||
result = new URL(new URL(baseUrl), url).toString();
|
||||
} catch (MalformedURLException e) {
|
||||
@@ -307,7 +306,7 @@ public class FeedUtils {
|
||||
Elements elements = doc.select("img");
|
||||
for (Element element : elements) {
|
||||
String href = element.attr("src");
|
||||
if (href != null) {
|
||||
if (StringUtils.isNotBlank(href)) {
|
||||
String proxy = proxyImage(href);
|
||||
element.attr("src", proxy);
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ public class HtmlEntities {
|
||||
map.put("‌", "‌");
|
||||
|
||||
HTML_TO_NUMERIC_MAP = Collections.unmodifiableMap(map);
|
||||
HTML_ENTITIES = map.keySet().toArray(new String[map.size()]);
|
||||
NUMERIC_ENTITIES = map.values().toArray(new String[map.size()]);
|
||||
HTML_ENTITIES = map.keySet().toArray(new String[0]);
|
||||
NUMERIC_ENTITIES = map.values().toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.commafeed.backend.opml;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
@@ -34,20 +33,18 @@ public class OPMLExporter {
|
||||
opml.setCreated(new Date());
|
||||
|
||||
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
|
||||
Collections.sort(categories,
|
||||
(e1, e2) -> ObjectUtils.firstNonNull(e1.getPosition(), 0) - ObjectUtils.firstNonNull(e2.getPosition(), 0));
|
||||
categories.sort(Comparator.comparingInt(e -> ObjectUtils.firstNonNull(e.getPosition(), 0)));
|
||||
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(user);
|
||||
Collections.sort(subscriptions,
|
||||
(e1, e2) -> ObjectUtils.firstNonNull(e1.getPosition(), 0) - ObjectUtils.firstNonNull(e2.getPosition(), 0));
|
||||
subscriptions.sort(Comparator.comparingInt(e -> ObjectUtils.firstNonNull(e.getPosition(), 0)));
|
||||
|
||||
// export root categories
|
||||
for (FeedCategory cat : categories.stream().filter(c -> c.getParent() == null).collect(Collectors.toList())) {
|
||||
for (FeedCategory cat : categories.stream().filter(c -> c.getParent() == null).toList()) {
|
||||
opml.getOutlines().add(buildCategoryOutline(cat, categories, subscriptions));
|
||||
}
|
||||
|
||||
// export root subscriptions
|
||||
for (FeedSubscription sub : subscriptions.stream().filter(s -> s.getCategory() == null).collect(Collectors.toList())) {
|
||||
for (FeedSubscription sub : subscriptions.stream().filter(s -> s.getCategory() == null).toList()) {
|
||||
opml.getOutlines().add(buildSubscriptionOutline(sub));
|
||||
}
|
||||
|
||||
@@ -62,13 +59,13 @@ public class OPMLExporter {
|
||||
|
||||
for (FeedCategory child : categories.stream()
|
||||
.filter(c -> c.getParent() != null && c.getParent().getId().equals(cat.getId()))
|
||||
.collect(Collectors.toList())) {
|
||||
.toList()) {
|
||||
outline.getChildren().add(buildCategoryOutline(child, categories, subscriptions));
|
||||
}
|
||||
|
||||
for (FeedSubscription sub : subscriptions.stream()
|
||||
.filter(s -> s.getCategory() != null && s.getCategory().getId().equals(cat.getId()))
|
||||
.collect(Collectors.toList())) {
|
||||
.toList()) {
|
||||
outline.getChildren().add(buildSubscriptionOutline(sub));
|
||||
}
|
||||
return outline;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class RSSRDF10Parser extends RSS10Parser {
|
||||
|
||||
@Override
|
||||
public boolean isMyType(Document document) {
|
||||
boolean ok = false;
|
||||
boolean ok;
|
||||
|
||||
Element rssRoot = document.getRootElement();
|
||||
Namespace defaultNS = rssRoot.getNamespace();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class FeedEntryFilteringService {
|
||||
// classloader that prevents object creation
|
||||
ClassLoader cl = new ClassLoader() {
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
protected Class<?> loadClass(String name, boolean resolve) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -76,7 +76,7 @@ public class FeedEntryFilteringService {
|
||||
return true;
|
||||
}
|
||||
|
||||
Script script = null;
|
||||
Script script;
|
||||
try {
|
||||
script = ENGINE.createScript(filter);
|
||||
} catch (JexlException e) {
|
||||
@@ -95,7 +95,7 @@ public class FeedEntryFilteringService {
|
||||
|
||||
Callable<Object> callable = script.callable(context);
|
||||
Future<Object> future = executor.submit(callable);
|
||||
Object result = null;
|
||||
Object result;
|
||||
try {
|
||||
result = future.get(500, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -33,8 +33,8 @@ public class FeedEntryTagService {
|
||||
List<FeedEntryTag> addList = tagNames.stream()
|
||||
.filter(name -> !existingTagNames.contains(name))
|
||||
.map(name -> new FeedEntryTag(user, entry, name))
|
||||
.collect(Collectors.toList());
|
||||
List<FeedEntryTag> removeList = existingTags.stream().filter(tag -> !tagNames.contains(tag.getName())).collect(Collectors.toList());
|
||||
.toList();
|
||||
List<FeedEntryTag> removeList = existingTags.stream().filter(tag -> !tagNames.contains(tag.getName())).toList();
|
||||
|
||||
feedEntryTagDAO.saveOrUpdate(addList);
|
||||
feedEntryTagDAO.delete(removeList);
|
||||
|
||||
@@ -16,14 +16,11 @@ public abstract class ScheduledTask {
|
||||
protected abstract TimeUnit getTimeUnit();
|
||||
|
||||
public void register(ScheduledExecutorService executor) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ScheduledTask.this.run();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
Runnable runnable = () -> {
|
||||
try {
|
||||
ScheduledTask.this.run();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
};
|
||||
log.info("registering task {} for execution every {} {}, starting in {} {}", getClass().getSimpleName(), getPeriod(), getTimeUnit(),
|
||||
|
||||
@@ -33,10 +33,10 @@ public class SecurityCheckFactory implements Function<ContainerRequest, User> {
|
||||
@Override
|
||||
public User apply(ContainerRequest req) {
|
||||
Optional<User> user = apiKeyLogin();
|
||||
if (!user.isPresent()) {
|
||||
if (user.isEmpty()) {
|
||||
user = basicAuthenticationLogin();
|
||||
}
|
||||
if (!user.isPresent()) {
|
||||
if (user.isEmpty()) {
|
||||
user = cookieSessionLogin(new SessionHelper(request));
|
||||
}
|
||||
|
||||
@@ -60,9 +60,7 @@ public class SecurityCheckFactory implements Function<ContainerRequest, User> {
|
||||
|
||||
Optional<User> cookieSessionLogin(SessionHelper sessionHelper) {
|
||||
Optional<User> loggedInUser = sessionHelper.getLoggedInUser();
|
||||
if (loggedInUser.isPresent()) {
|
||||
userService.performPostLoginActivities(loggedInUser.get());
|
||||
}
|
||||
loggedInUser.ifPresent(userService::performPostLoginActivities);
|
||||
return loggedInUser;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -14,9 +13,7 @@ import com.commafeed.backend.model.FeedEntryContent;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedEntryTag;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.rometools.rome.feed.synd.SyndContent;
|
||||
import com.rometools.rome.feed.synd.SyndContentImpl;
|
||||
import com.rometools.rome.feed.synd.SyndEnclosure;
|
||||
import com.rometools.rome.feed.synd.SyndEnclosureImpl;
|
||||
import com.rometools.rome.feed.synd.SyndEntry;
|
||||
import com.rometools.rome.feed.synd.SyndEntryImpl;
|
||||
@@ -125,7 +122,7 @@ public class Entry implements Serializable {
|
||||
entry.setFeedUrl(sub.getFeed().getUrl());
|
||||
entry.setFeedLink(sub.getFeed().getLink());
|
||||
entry.setIconUrl(FeedUtils.getFaviconUrl(sub));
|
||||
entry.setTags(status.getTags().stream().map(FeedEntryTag::getName).collect(Collectors.toList()));
|
||||
entry.setTags(status.getTags().stream().map(FeedEntryTag::getName).toList());
|
||||
|
||||
if (content != null) {
|
||||
entry.setRtl(FeedUtils.isRTL(feedEntry));
|
||||
@@ -158,13 +155,13 @@ public class Entry implements Serializable {
|
||||
|
||||
SyndContentImpl content = new SyndContentImpl();
|
||||
content.setValue(getContent());
|
||||
entry.setContents(Collections.<SyndContent> singletonList(content));
|
||||
entry.setContents(Collections.singletonList(content));
|
||||
|
||||
if (getEnclosureUrl() != null) {
|
||||
SyndEnclosureImpl enclosure = new SyndEnclosureImpl();
|
||||
enclosure.setType(getEnclosureType());
|
||||
enclosure.setUrl(getEnclosureUrl());
|
||||
entry.setEnclosures(Collections.<SyndEnclosure> singletonList(enclosure));
|
||||
entry.setEnclosures(Collections.singletonList(enclosure));
|
||||
}
|
||||
|
||||
entry.setLink(getUrl());
|
||||
|
||||
@@ -2,15 +2,12 @@ package com.commafeed.frontend.resource;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -136,7 +133,7 @@ public class CategoryREST {
|
||||
|
||||
List<Long> excludedIds = null;
|
||||
if (StringUtils.isNotEmpty(excludedSubscriptionIds)) {
|
||||
excludedIds = Arrays.stream(excludedSubscriptionIds.split(",")).map(Long::valueOf).collect(Collectors.toList());
|
||||
excludedIds = Arrays.stream(excludedSubscriptionIds.split(",")).map(Long::valueOf).toList();
|
||||
}
|
||||
|
||||
if (ALL.equals(id)) {
|
||||
@@ -220,7 +217,7 @@ public class CategoryREST {
|
||||
feed.setTitle("CommaFeed - " + entries.getName());
|
||||
feed.setDescription("CommaFeed - " + entries.getName());
|
||||
feed.setLink(config.getApplicationSettings().getPublicUrl());
|
||||
feed.setEntries(entries.getEntries().stream().map(Entry::asRss).collect(Collectors.toList()));
|
||||
feed.setEntries(entries.getEntries().stream().map(Entry::asRss).toList());
|
||||
|
||||
SyndFeedOutput output = new SyndFeedOutput();
|
||||
StringWriter writer = new StringWriter();
|
||||
@@ -265,13 +262,7 @@ public class CategoryREST {
|
||||
|
||||
private void removeExcludedSubscriptions(List<FeedSubscription> subs, List<Long> excludedIds) {
|
||||
if (CollectionUtils.isNotEmpty(excludedIds)) {
|
||||
Iterator<FeedSubscription> it = subs.iterator();
|
||||
while (it.hasNext()) {
|
||||
FeedSubscription sub = it.next();
|
||||
if (excludedIds.contains(sub.getId())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
subs.removeIf(sub -> excludedIds.contains(sub.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,12 +352,7 @@ public class CategoryREST {
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
List<FeedCategory> categories = feedCategoryDAO.findByParent(user, parent);
|
||||
Collections.sort(categories, new Comparator<FeedCategory>() {
|
||||
@Override
|
||||
public int compare(FeedCategory o1, FeedCategory o2) {
|
||||
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
|
||||
}
|
||||
});
|
||||
categories.sort((o1, o2) -> ObjectUtils.compare(o1.getPosition(), o2.getPosition()));
|
||||
|
||||
int existingIndex = -1;
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
|
||||
@@ -65,7 +65,8 @@ public class EntryREST {
|
||||
Preconditions.checkNotNull(req.getRequests());
|
||||
|
||||
for (MarkRequest r : req.getRequests()) {
|
||||
markEntry(user, r);
|
||||
Preconditions.checkNotNull(r.getId());
|
||||
feedEntryService.markEntry(user, Long.valueOf(r.getId()), r.isRead());
|
||||
}
|
||||
|
||||
return Response.ok().build();
|
||||
|
||||
@@ -6,11 +6,9 @@ import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -225,7 +223,7 @@ public class FeedREST {
|
||||
feed.setTitle("CommaFeed - " + entries.getName());
|
||||
feed.setDescription("CommaFeed - " + entries.getName());
|
||||
feed.setLink(config.getApplicationSettings().getPublicUrl());
|
||||
feed.setEntries(entries.getEntries().stream().map(Entry::asRss).collect(Collectors.toList()));
|
||||
feed.setEntries(entries.getEntries().stream().map(Entry::asRss).toList());
|
||||
|
||||
SyndFeedOutput output = new SyndFeedOutput();
|
||||
StringWriter writer = new StringWriter();
|
||||
@@ -239,7 +237,7 @@ public class FeedREST {
|
||||
}
|
||||
|
||||
private FeedInfo fetchFeedInternal(String url) {
|
||||
FeedInfo info = null;
|
||||
FeedInfo info;
|
||||
url = StringUtils.trimToEmpty(url);
|
||||
url = prependHttp(url);
|
||||
try {
|
||||
@@ -268,7 +266,7 @@ public class FeedREST {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getUrl());
|
||||
|
||||
FeedInfo info = null;
|
||||
FeedInfo info;
|
||||
try {
|
||||
info = fetchFeedInternal(req.getUrl());
|
||||
} catch (Exception e) {
|
||||
@@ -490,12 +488,7 @@ public class FeedREST {
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(user, parent);
|
||||
Collections.sort(subs, new Comparator<FeedSubscription>() {
|
||||
@Override
|
||||
public int compare(FeedSubscription o1, FeedSubscription o2) {
|
||||
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
|
||||
}
|
||||
});
|
||||
subs.sort((o1, o2) -> ObjectUtils.compare(o1.getPosition(), o2.getPosition()));
|
||||
|
||||
int existingIndex = -1;
|
||||
for (int i = 0; i < subs.size(); i++) {
|
||||
@@ -549,7 +542,7 @@ public class FeedREST {
|
||||
public Response exportOpml(@Parameter(hidden = true) @SecurityCheck User user) {
|
||||
Opml opml = opmlExporter.export(user);
|
||||
WireFeedOutput output = new WireFeedOutput();
|
||||
String opmlString = null;
|
||||
String opmlString;
|
||||
try {
|
||||
opmlString = output.outputString(opml);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -206,7 +206,7 @@ public class UserREST {
|
||||
}
|
||||
|
||||
Optional<User> login = userService.login(user.getEmail(), request.getCurrentPassword());
|
||||
if (!login.isPresent()) {
|
||||
if (login.isEmpty()) {
|
||||
throw new BadRequestException("invalid password");
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ public class FeverREST {
|
||||
if (params.containsKey("items")) {
|
||||
if (params.containsKey("with_ids")) {
|
||||
String withIds = params.get("with_ids");
|
||||
List<String> entryIds = Stream.of(withIds.split(",")).map(String::trim).collect(Collectors.toList());
|
||||
List<String> entryIds = Stream.of(withIds.split(",")).map(String::trim).toList();
|
||||
resp.setItems(buildItems(user, subscriptions, entryIds));
|
||||
} else {
|
||||
Long sinceId = params.containsKey("since_id") ? Long.valueOf(params.get("since_id")) : null;
|
||||
@@ -216,10 +216,10 @@ public class FeverREST {
|
||||
.map(e -> {
|
||||
FeverFeedGroup fg = new FeverFeedGroup();
|
||||
fg.setGroupId(e.getKey());
|
||||
fg.setFeedIds(e.getValue().stream().map(FeedSubscription::getId).collect(Collectors.toList()));
|
||||
fg.setFeedIds(e.getValue().stream().map(FeedSubscription::getId).toList());
|
||||
return fg;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<FeverGroup> buildGroups(List<FeedCategory> categories) {
|
||||
@@ -228,7 +228,7 @@ public class FeverREST {
|
||||
g.setId(c.getId());
|
||||
g.setTitle(c.getName());
|
||||
return g;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private List<FeverFeed> buildFeeds(List<FeedSubscription> subscriptions) {
|
||||
@@ -242,18 +242,18 @@ public class FeverREST {
|
||||
f.setSpark(false);
|
||||
f.setLastUpdatedOnTime(s.getFeed().getLastUpdated() == null ? 0 : s.getFeed().getLastUpdated().toInstant().getEpochSecond());
|
||||
return f;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private List<Long> buildUnreadItemIds(User user, List<FeedSubscription> subscriptions) {
|
||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, null, null, 0,
|
||||
UNREAD_ITEM_IDS_BATCH_SIZE, ReadingOrder.desc, false, true, null, null, null);
|
||||
return statuses.stream().map(s -> s.getEntry().getId()).collect(Collectors.toList());
|
||||
return statuses.stream().map(s -> s.getEntry().getId()).toList();
|
||||
}
|
||||
|
||||
private List<Long> buildSavedItemIds(User user) {
|
||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findStarred(user, null, 0, SAVED_ITEM_IDS_BATCH_SIZE, ReadingOrder.desc, false);
|
||||
return statuses.stream().map(s -> s.getEntry().getId()).collect(Collectors.toList());
|
||||
return statuses.stream().map(s -> s.getEntry().getId()).toList();
|
||||
}
|
||||
|
||||
private List<FeverItem> buildItems(User user, List<FeedSubscription> subscriptions, List<String> entryIds) {
|
||||
@@ -276,7 +276,7 @@ public class FeverREST {
|
||||
private List<FeverItem> buildItems(User user, List<FeedSubscription> subscriptions, Long sinceId, Long maxId) {
|
||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, false, null, null, 0, ITEMS_BATCH_SIZE,
|
||||
ReadingOrder.desc, false, false, null, sinceId, maxId);
|
||||
return statuses.stream().map(this::mapStatus).collect(Collectors.toList());
|
||||
return statuses.stream().map(this::mapStatus).toList();
|
||||
}
|
||||
|
||||
private FeverItem mapStatus(FeedEntryStatus s) {
|
||||
@@ -301,7 +301,7 @@ public class FeverREST {
|
||||
f.setId(s.getFeed().getId());
|
||||
f.setData(String.format("data:%s;base64,%s", favicon.getMediaType(), Base64.getEncoder().encodeToString(favicon.getIcon())));
|
||||
return f;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private void mark(User user, String source, long id, String action, Date olderThan) {
|
||||
|
||||
@@ -172,7 +172,7 @@ public class FeverResponse {
|
||||
@Override
|
||||
public List<Long> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
String value = ctxt.readValue(p, String.class);
|
||||
return Stream.of(value.split(",")).map(Long::valueOf).collect(Collectors.toList());
|
||||
return Stream.of(value.split(",")).map(Long::valueOf).toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ abstract class AbstractCustomCodeServlet extends HttpServlet {
|
||||
resp.setContentType(getMimeType());
|
||||
|
||||
final Optional<User> user = new SessionHelper(req).getLoggedInUser();
|
||||
if (!user.isPresent()) {
|
||||
if (user.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.commafeed.CommaFeedConfiguration;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -20,7 +19,7 @@ public class LogoutServlet extends HttpServlet {
|
||||
private final CommaFeedConfiguration config;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
req.getSession().invalidate();
|
||||
resp.sendRedirect(resp.encodeRedirectURL(config.getApplicationSettings().getPublicUrl()));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -47,16 +46,14 @@ public class NextUnreadServlet extends HttpServlet {
|
||||
private final CommaFeedConfiguration config;
|
||||
|
||||
@Override
|
||||
protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
final String categoryId = req.getParameter(PARAM_CATEGORYID);
|
||||
String orderParam = req.getParameter(PARAM_READINGORDER);
|
||||
|
||||
SessionHelper sessionHelper = new SessionHelper(req);
|
||||
Optional<User> user = sessionHelper.getLoggedInUser();
|
||||
if (user.isPresent()) {
|
||||
unitOfWork.run(() -> userService.performPostLoginActivities(user.get()));
|
||||
}
|
||||
if (!user.isPresent()) {
|
||||
user.ifPresent(value -> unitOfWork.run(() -> userService.performPostLoginActivities(value)));
|
||||
if (user.isEmpty()) {
|
||||
resp.sendRedirect(resp.encodeRedirectURL(config.getApplicationSettings().getPublicUrl()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,15 +27,13 @@ public class WebSocketConfigurator extends Configurator {
|
||||
HttpSession httpSession = (HttpSession) request.getHttpSession();
|
||||
if (httpSession != null) {
|
||||
Optional<User> user = SessionHelper.getLoggedInUser(httpSession);
|
||||
if (user.isPresent()) {
|
||||
config.getUserProperties().put(SESSIONKEY_USERID, user.get().getId());
|
||||
}
|
||||
user.ifPresent(value -> config.getUserProperties().put(SESSIONKEY_USERID, value.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
|
||||
public <T> T getEndpointInstance(Class<T> endpointClass) {
|
||||
return (T) new WebSocketEndpoint(webSocketSessions);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user