apply intellij fixes

This commit is contained in:
Athou
2023-12-27 08:52:24 +01:00
parent 1b4b3ca52c
commit 9cd1cde571
43 changed files with 151 additions and 190 deletions

View File

@@ -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;
}

View File

@@ -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());

View File

@@ -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++) {

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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");
}

View File

@@ -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) {

View File

@@ -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();
}
}
}

View File

@@ -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;
}

View File

@@ -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()));
}

View File

@@ -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;
}

View File

@@ -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);
}
}