aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/model/Auth.java4
-rw-r--r--src/main/java/com/juick/server/EmailManager.java4
-rw-r--r--src/main/java/com/juick/server/KeystoreManager.java6
-rw-r--r--src/main/java/com/juick/server/TelegramBotManager.java2
-rw-r--r--src/main/java/com/juick/server/api/ApiSocialLogin.java9
-rw-r--r--src/main/java/com/juick/server/api/Notifications.java3
-rw-r--r--src/main/java/com/juick/server/api/Post.java11
-rw-r--r--src/main/java/com/juick/server/api/Users.java13
-rw-r--r--src/main/java/com/juick/server/api/activity/Profile.java1
-rw-r--r--src/main/java/com/juick/server/configuration/SecurityConfig.java2
-rw-r--r--src/main/java/com/juick/server/util/HttpBadRequestException.java1
-rw-r--r--src/main/java/com/juick/server/util/ImageUtils.java6
-rw-r--r--src/main/java/com/juick/server/www/controllers/MessagesWWW.java32
-rw-r--r--src/main/java/com/juick/server/www/controllers/Settings.java1
-rw-r--r--src/main/java/com/juick/server/www/controllers/SignUp.java1
-rw-r--r--src/main/java/com/juick/server/www/controllers/SocialLogin.java15
-rw-r--r--src/main/java/com/juick/server/www/filters/AnythingFilter.java (renamed from src/main/java/com/juick/server/www/controllers/AnythingFilter.java)2
-rw-r--r--src/main/java/com/juick/server/xmpp/JidConverter.java4
-rw-r--r--src/main/java/com/juick/service/EmailServiceImpl.java2
-rw-r--r--src/main/java/com/juick/service/ImagesServiceImpl.java3
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java5
-rw-r--r--src/main/java/com/juick/service/PushQueriesServiceImpl.java2
-rw-r--r--src/main/java/com/juick/service/SubscriptionServiceImpl.java1
-rw-r--r--src/main/java/com/juick/service/UserService.java1
-rw-r--r--src/main/java/com/juick/service/activities/AnnounceEvent.java4
-rw-r--r--src/main/java/com/juick/service/component/SystemEvent.java4
-rw-r--r--src/main/java/com/juick/util/DateFormatter.java1
-rw-r--r--src/main/java/com/juick/util/MessageUtils.java13
-rw-r--r--src/main/java/com/juick/util/PrettyTimeFormatter.java14
-rw-r--r--src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java2
-rw-r--r--src/main/java/ru/sape/SapeConnection.java3
31 files changed, 57 insertions, 115 deletions
diff --git a/src/main/java/com/juick/model/Auth.java b/src/main/java/com/juick/model/Auth.java
index 66125567..26815e04 100644
--- a/src/main/java/com/juick/model/Auth.java
+++ b/src/main/java/com/juick/model/Auth.java
@@ -21,8 +21,8 @@ package com.juick.model;
* Created by vt on 09/02/16.
*/
public class Auth {
- private String account;
- private String authCode;
+ private final String account;
+ private final String authCode;
public Auth(String account, String authCode) {
this.account = account;
diff --git a/src/main/java/com/juick/server/EmailManager.java b/src/main/java/com/juick/server/EmailManager.java
index edff7b70..570d2e6e 100644
--- a/src/main/java/com/juick/server/EmailManager.java
+++ b/src/main/java/com/juick/server/EmailManager.java
@@ -67,9 +67,7 @@ public class EmailManager implements NotificationListener {
}
if (MessageUtils.isPM(msg)) {
String subject = String.format("Private message from %s", msg.getUser().getName());
- emailService.getEmails(msg.getTo().getUid(), true).forEach(email -> {
- emailNotify(email, subject, msg);
- });
+ emailService.getEmails(msg.getTo().getUid(), true).forEach(email -> emailNotify(email, subject, msg));
} else if (MessageUtils.isReply(msg)) {
Message originalMessage = messagesService.getMessage(msg.getMid()).orElseThrow(IllegalStateException::new);
String subject = String.format("New reply to %s", originalMessage.getUser().getName());
diff --git a/src/main/java/com/juick/server/KeystoreManager.java b/src/main/java/com/juick/server/KeystoreManager.java
index b1ce7a56..15b62e35 100644
--- a/src/main/java/com/juick/server/KeystoreManager.java
+++ b/src/main/java/com/juick/server/KeystoreManager.java
@@ -23,14 +23,12 @@ public class KeystoreManager {
private KeyStore ks;
- private KeyManagerFactory kmf;
-
public KeystoreManager(Resource keystore, String keystorePassword) {
this.keystorePassword = keystorePassword;
try (InputStream ksIs = keystore.getInputStream()) {
ks = KeyStore.getInstance("PKCS12");
ks.load(ksIs, keystorePassword.toCharArray());
- kmf = KeyManagerFactory.getInstance(KeyManagerFactory
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory
.getDefaultAlgorithm());
kmf.init(ks, keystorePassword.toCharArray());
} catch (IOException | KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | CertificateException e) {
@@ -58,7 +56,7 @@ public class KeystoreManager {
public String getPublicKeyPem() {
String[] key = Base64Utils.encodeToString(getKeyPair().getPublic().getEncoded()).split("(?<=\\G.{64})");
return String.format("-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
- Arrays.asList(key).stream().collect(Collectors.joining("\n")));
+ String.join("\n", key));
}
public static PublicKey publicKeyOf(Person person) {
String pubkeyPem = person.getPublicKey().getPublicKeyPem();
diff --git a/src/main/java/com/juick/server/TelegramBotManager.java b/src/main/java/com/juick/server/TelegramBotManager.java
index 7ca9e347..32bd7096 100644
--- a/src/main/java/com/juick/server/TelegramBotManager.java
+++ b/src/main/java/com/juick/server/TelegramBotManager.java
@@ -213,7 +213,7 @@ public class TelegramBotManager implements NotificationListener {
juickLink.get().url()).build();
String path = uriComponents.getPath();
if (StringUtils.isNotEmpty(path) && path.length() > 1) {
- int mid = 0;
+ int mid;
try {
mid = Integer.parseInt(path.substring(3));
} catch (NumberFormatException e) {
diff --git a/src/main/java/com/juick/server/api/ApiSocialLogin.java b/src/main/java/com/juick/server/api/ApiSocialLogin.java
index 2d0a5c7e..efbb56f4 100644
--- a/src/main/java/com/juick/server/api/ApiSocialLogin.java
+++ b/src/main/java/com/juick/server/api/ApiSocialLogin.java
@@ -79,7 +79,6 @@ public class ApiSocialLogin {
private static final String TWITTER_VERIFY_URL = "https://api.twitter.com/1.1/account/verify_credentials.json";
@Inject
private ObjectMapper jsonMapper;
- private ServiceBuilder facebookBuilder, twitterBuilder, vkBuilder;
private OAuth20Service facebookAuthService, vkAuthService;
@Value("${twitter_consumer_key:appid}")
@@ -110,9 +109,9 @@ public class ApiSocialLogin {
@PostConstruct
public void init() {
- facebookBuilder = new ServiceBuilder(FACEBOOK_APPID);
- twitterBuilder = new ServiceBuilder(twitterConsumerKey);
- vkBuilder = new ServiceBuilder(VK_APPID);
+ ServiceBuilder facebookBuilder = new ServiceBuilder(FACEBOOK_APPID);
+ ServiceBuilder twitterBuilder = new ServiceBuilder(twitterConsumerKey);
+ ServiceBuilder vkBuilder = new ServiceBuilder(VK_APPID);
verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory)
.setAudience(Collections.singletonList(googleClientId))
.build();
@@ -260,7 +259,7 @@ public class ApiSocialLogin {
throw new HttpBadRequestException();
}
- Long vkID = NumberUtils.toLong(jsonUser.getId(), 0);
+ long vkID = NumberUtils.toLong(jsonUser.getId(), 0);
int uid = crosspostService.getUIDbyVKID(vkID);
if (uid > 0) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(redirectUrl);
diff --git a/src/main/java/com/juick/server/api/Notifications.java b/src/main/java/com/juick/server/api/Notifications.java
index 72988298..e7eada2a 100644
--- a/src/main/java/com/juick/server/api/Notifications.java
+++ b/src/main/java/com/juick/server/api/Notifications.java
@@ -41,7 +41,6 @@ import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.inject.Inject;
-import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -175,7 +174,7 @@ public class Notifications {
@RequestMapping(value = "/api/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doPut(
@Visitor User visitor,
- @RequestBody List<ExternalToken> list) throws IOException {
+ @RequestBody List<ExternalToken> list) {
list.forEach(t -> {
switch (t.getType()) {
case "gcm":
diff --git a/src/main/java/com/juick/server/api/Post.java b/src/main/java/com/juick/server/api/Post.java
index 59bd05a7..255b7290 100644
--- a/src/main/java/com/juick/server/api/Post.java
+++ b/src/main/java/com/juick/server/api/Post.java
@@ -28,7 +28,6 @@ import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.util.HttpUtils;
import com.juick.service.MessagesService;
-import com.juick.service.SubscriptionService;
import com.juick.service.UserService;
import com.juick.service.security.annotation.Visitor;
import org.apache.commons.lang3.StringUtils;
@@ -58,12 +57,8 @@ public class Post {
private UserService userService;
@Inject
private MessagesService messagesService;
- @Inject
- private SubscriptionService subscriptionService;
@Value("${upload_tmp_dir:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
private String tmpDir;
- @Value("${img_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
- private String imgDir;
@Inject
CommandsManager commandsManager;
@@ -155,7 +150,7 @@ public class Post {
@ResponseStatus(value = HttpStatus.OK)
public Status doPostRecomm(@Visitor User visitor, @RequestParam Integer mid) throws Exception {
Optional<com.juick.Message> message = messagesService.getMessage(mid);
- if (!message.isPresent()) {
+ if (message.isEmpty()) {
throw new HttpNotFoundException();
}
Message msg = message.get();
@@ -172,7 +167,7 @@ public class Post {
public Status doPostSubscribe(@Visitor User visitor,
@RequestParam Integer mid) throws Exception {
Optional<com.juick.Message> message = messagesService.getMessage(mid);
- if (!message.isPresent()) {
+ if (message.isEmpty()) {
throw new HttpNotFoundException();
}
Message msg = message.get();
@@ -199,7 +194,7 @@ public class Post {
logger.info("got reaction with type: {}", reactionId);
Optional<com.juick.Message> message = messagesService.getMessage(mid);
- if (!message.isPresent()) {
+ if (message.isEmpty()) {
throw new HttpNotFoundException();
}
Message msg = message.get();
diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java
index 6d7c7a45..d5c1b5d7 100644
--- a/src/main/java/com/juick/server/api/Users.java
+++ b/src/main/java/com/juick/server/api/Users.java
@@ -28,33 +28,22 @@ import com.juick.server.util.WebUtils;
import com.juick.server.www.WebApp;
import com.juick.service.*;
import com.juick.service.security.annotation.Visitor;
-import com.juick.service.security.entities.JuickUser;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.inject.Inject;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import static org.springframework.http.ResponseEntity.ok;
-import static org.springframework.http.ResponseEntity.status;
-
/**
* @author ugnich
*/
@@ -151,7 +140,7 @@ public class Users {
"If you don't know, what this mean - just ignore this mail.\n", authCode),
StringUtils.EMPTY, Collections.emptyMap())) {
throw new HttpBadRequestException();
- };
+ }
}
}
}
diff --git a/src/main/java/com/juick/server/api/activity/Profile.java b/src/main/java/com/juick/server/api/activity/Profile.java
index 88c76a93..a48958d2 100644
--- a/src/main/java/com/juick/server/api/activity/Profile.java
+++ b/src/main/java/com/juick/server/api/activity/Profile.java
@@ -23,7 +23,6 @@ import com.juick.server.api.activity.model.objects.Note;
import com.juick.server.api.activity.model.objects.OrderedCollection;
import com.juick.server.api.activity.model.objects.OrderedCollectionPage;
import com.juick.server.api.activity.model.objects.Person;
-import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.www.WebApp;
import com.juick.service.MessagesService;
diff --git a/src/main/java/com/juick/server/configuration/SecurityConfig.java b/src/main/java/com/juick/server/configuration/SecurityConfig.java
index c5fe4fbb..e69ff8f6 100644
--- a/src/main/java/com/juick/server/configuration/SecurityConfig.java
+++ b/src/main/java/com/juick/server/configuration/SecurityConfig.java
@@ -30,7 +30,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -38,7 +37,6 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.AuthenticationEntryPoint;
-import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
diff --git a/src/main/java/com/juick/server/util/HttpBadRequestException.java b/src/main/java/com/juick/server/util/HttpBadRequestException.java
index 242f2b09..892cb203 100644
--- a/src/main/java/com/juick/server/util/HttpBadRequestException.java
+++ b/src/main/java/com/juick/server/util/HttpBadRequestException.java
@@ -17,7 +17,6 @@
package com.juick.server.util;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
diff --git a/src/main/java/com/juick/server/util/ImageUtils.java b/src/main/java/com/juick/server/util/ImageUtils.java
index 2f5d3292..60bce1a0 100644
--- a/src/main/java/com/juick/server/util/ImageUtils.java
+++ b/src/main/java/com/juick/server/util/ImageUtils.java
@@ -1,6 +1,5 @@
-
/*
- * Copyright (C) 2008-2017, Juick
+ * Copyright (C) 2008-2019, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -34,7 +33,6 @@ import org.slf4j.LoggerFactory;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
-import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.io.File;
@@ -128,7 +126,7 @@ public class ImageUtils {
int width = originalImage.getWidth();
int height = originalImage.getHeight();
- int maxDimension = (width > height) ? width : height;
+ int maxDimension = Math.max(width, height);
BufferedImage image1024 = (maxDimension > 1024) ? Scalr.resize(originalImage, 1024) : originalImage;
BufferedImage image0512 = (maxDimension > 512) ? Scalr.resize(originalImage, 512) : originalImage;
BufferedImage image0160 = (maxDimension > 160) ? Scalr.resize(originalImage, 160) : originalImage;
diff --git a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
index d845aac6..1cd89914 100644
--- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
+++ b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
@@ -28,7 +28,6 @@ import com.juick.server.www.WebApp;
import com.juick.service.*;
import com.juick.service.security.annotation.Visitor;
import com.juick.util.MessageUtils;
-import org.apache.commons.codec.CharEncoding;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.text.StringEscapeUtils;
@@ -44,7 +43,6 @@ import ru.sape.Sape;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@@ -101,7 +99,7 @@ public class MessagesWWW {
@RequestParam(name = "to", required = false, defaultValue = "0") Long paramTo,
@RequestParam(name = "page", required = false, defaultValue = "0") Integer page,
@CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie,
- ModelMap model) throws IOException {
+ ModelMap model) {
if (tag != null) {
return "redirect:/tag/" + URLEncoder.encode(tag, StandardCharsets.UTF_8);
}
@@ -149,7 +147,7 @@ public class MessagesWWW {
throw new HttpNotFoundException();
}
- String head = "<meta name=\"Description\" content=\"" + title + "\" />\n";;
+ String head = "<meta name=\"Description\" content=\"" + title + "\" />\n";
if (paramBefore > 0 || paramShow != null) {
head = "<meta name=\"robots\" content=\"noindex\"/>";
@@ -166,9 +164,7 @@ public class MessagesWWW {
visitor.setUnreadCount(unread.size());
List<Integer> blUIDs = userService.checkBL(visitor.getUid(),
msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()));
- msgs.forEach(m -> {
- m.ReadOnly |= blUIDs.contains(m.getUser().getUid());
- });
+ msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid()));
}
model.addAttribute("msgs", msgs);
model.addAttribute("tags", tagService.getPopularTags());
@@ -183,7 +179,7 @@ public class MessagesWWW {
nextpage += "&amp;show=" + paramShow;
}
if (paramSearch != null) {
- nextpage += "&amp;search=" + URLEncoder.encode(paramSearch, CharEncoding.UTF_8);
+ nextpage += "&amp;search=" + URLEncoder.encode(paramSearch, StandardCharsets.UTF_8);
}
model.addAttribute("nextpage", nextpage);
}
@@ -206,7 +202,7 @@ public class MessagesWWW {
@PathVariable String uname,
@RequestParam(required = false, defaultValue = "0") Integer before,
@CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie,
- ModelMap model) throws IOException {
+ ModelMap model) {
com.juick.User user = userService.getUserByName(uname);
if (user.isBanned() || user.isAnonymous()) {
throw new HttpNotFoundException();
@@ -284,9 +280,7 @@ public class MessagesWWW {
visitor.setUnreadCount(unread.size());
List<Integer> blUIDs = userService.checkBL(visitor.getUid(),
msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList()));
- msgs.forEach(m -> {
- m.ReadOnly |= blUIDs.contains(m.getUser().getUid());
- });
+ msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid()));
}
model.addAttribute("msgs", msgs);
model.addAttribute("headers", head);
@@ -355,7 +349,7 @@ public class MessagesWWW {
@GetMapping("/{uname}/readers")
protected String doGetReaders(
@Visitor User visitor,
- @PathVariable String uname, ModelMap model) throws IOException {
+ @PathVariable String uname, ModelMap model) {
com.juick.User user = userService.getUserByName(uname);
visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("title", "Читатели " + user.getName());
@@ -370,7 +364,7 @@ public class MessagesWWW {
@GetMapping("/{uname}/bl")
protected String doGetBL(
@Visitor User visitor,
- @PathVariable String uname, ModelMap model) throws IOException {
+ @PathVariable String uname, ModelMap model) {
com.juick.User user = userService.getUserByName(uname);
if (visitor.getUid() != user.getUid()) {
throw new HttpForbiddenException();
@@ -391,7 +385,7 @@ public class MessagesWWW {
@PathVariable String tagName,
@CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie,
@RequestParam(required = false, defaultValue = "0") int before,
- ModelMap model) throws IOException {
+ ModelMap model) {
visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String paramTagStr = StringEscapeUtils.unescapeHtml4(tagName);
com.juick.Tag paramTag = tagService.getTag(paramTagStr, false);
@@ -399,13 +393,13 @@ public class MessagesWWW {
throw new HttpNotFoundException();
} else if (paramTag.SynonymID > 0 && paramTag.TID != paramTag.SynonymID) {
com.juick.Tag synTag = tagService.getTag(paramTag.SynonymID);
- String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(synTag.getName()), CharEncoding.UTF_8);
+ String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(synTag.getName()), StandardCharsets.UTF_8);
if (request.getQueryString() != null) {
url += "?" + request.getQueryString();
}
return "redirect:" + url;
} else if (!paramTag.getName().equals(paramTagStr)) {
- String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(paramTag.getName()), CharEncoding.UTF_8);
+ String url = "/tag/" + URLEncoder.encode(StringEscapeUtils.escapeHtml4(paramTag.getName()), StandardCharsets.UTF_8);
if (request.getQueryString() != null) {
url += "?" + request.getQueryString();
}
@@ -424,9 +418,7 @@ public class MessagesWWW {
visitor.getUid(),
msgs.stream().map(m -> m.getUser().getUid()).collect(Collectors.toList())
);
- msgs.forEach(m -> {
- m.ReadOnly |= blUIDs.contains(m.getUser().getUid());
- });
+ msgs.forEach(m -> m.ReadOnly |= blUIDs.contains(m.getUser().getUid()));
fillUserModel(model, visitor, visitor);
}
diff --git a/src/main/java/com/juick/server/www/controllers/Settings.java b/src/main/java/com/juick/server/www/controllers/Settings.java
index 370c2154..e147d058 100644
--- a/src/main/java/com/juick/server/www/controllers/Settings.java
+++ b/src/main/java/com/juick/server/www/controllers/Settings.java
@@ -111,7 +111,6 @@ public class Settings {
model.addAttribute("userinfo", userService.getUserInfo(visitor));
if (page.equals("auth-email")) {
if (emailService.verifyAddressByCode(visitor.getUid(), request.getParameter("code"))) {
- ;
model.addAttribute("result", "OK!");
} else {
model.addAttribute("result", "Sorry, code unknown.");
diff --git a/src/main/java/com/juick/server/www/controllers/SignUp.java b/src/main/java/com/juick/server/www/controllers/SignUp.java
index 5fce2d35..18dfc2eb 100644
--- a/src/main/java/com/juick/server/www/controllers/SignUp.java
+++ b/src/main/java/com/juick/server/www/controllers/SignUp.java
@@ -17,7 +17,6 @@
package com.juick.server.www.controllers;
import com.juick.User;
-import com.juick.model.AnonymousUser;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.www.WebApp;
diff --git a/src/main/java/com/juick/server/www/controllers/SocialLogin.java b/src/main/java/com/juick/server/www/controllers/SocialLogin.java
index e845247e..602f32c3 100644
--- a/src/main/java/com/juick/server/www/controllers/SocialLogin.java
+++ b/src/main/java/com/juick/server/www/controllers/SocialLogin.java
@@ -74,12 +74,11 @@ public class SocialLogin {
private String FACEBOOK_SECRET;
@Value("${ap_base_uri:http://localhost:8080/}")
private String baseUri;
- private String facebookRedirectUri;
private static final String VK_REDIRECT = "http://juick.com/_vklogin";
private static final String TWITTER_VERIFY_URL = "https://api.twitter.com/1.1/account/verify_credentials.json";
@Inject
private ObjectMapper jsonMapper;
- private ServiceBuilder facebookBuilder, twitterBuilder, vkBuilder;
+ private ServiceBuilder twitterBuilder;
private OAuth20Service facebookAuthService, vkAuthService;
@Value("${twitter_consumer_key:appid}")
@@ -104,11 +103,11 @@ public class SocialLogin {
@PostConstruct
public void init() {
- facebookBuilder = new ServiceBuilder(FACEBOOK_APPID);
+ ServiceBuilder facebookBuilder = new ServiceBuilder(FACEBOOK_APPID);
twitterBuilder = new ServiceBuilder(twitterConsumerKey);
- vkBuilder = new ServiceBuilder(VK_APPID);
+ ServiceBuilder vkBuilder = new ServiceBuilder(VK_APPID);
UriComponentsBuilder facebookRedirectBuilder = UriComponentsBuilder.fromUriString(baseUri);
- facebookRedirectUri = facebookRedirectBuilder.replacePath("/_fblogin").build().toUriString();
+ String facebookRedirectUri = facebookRedirectBuilder.replacePath("/_fblogin").build().toUriString();
facebookAuthService = facebookBuilder
.apiSecret(FACEBOOK_SECRET)
.callback(facebookRedirectUri)
@@ -168,7 +167,7 @@ public class SocialLogin {
} else {
if (!crosspostService.createFacebookUser(fbID, state, token.getAccessToken(), fb.getName())) {
if (StringUtils.isNotEmpty(fb.getEmail())) {
- logger.info("found {} for facebook user {}", fb.getEmail());
+ logger.info("found {} for facebook user {}", fb.getEmail(), fb.getName());
Integer userId = crosspostService.getUIDbyFBID(fbID);
if (!emailService.getEmails(userId, false).contains(fb.getEmail())) {
emailService.addEmail(userId, fb.getEmail());
@@ -265,7 +264,7 @@ public class SocialLogin {
throw new HttpBadRequestException();
}
- Long vkID = NumberUtils.toLong(jsonUser.getId(), 0);
+ long vkID = NumberUtils.toLong(jsonUser.getId(), 0);
int uid = crosspostService.getUIDbyVKID(vkID);
if (uid > 0) {
Cookie c = new Cookie("hash", userService.getHashByUID(uid));
@@ -295,7 +294,7 @@ public class SocialLogin {
byte[] secretKey = DigestUtils.sha256(telegramToken);
String resultString = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, secretKey).hmacHex(dataCheckString);
if (hash.equals(resultString)) {
- Long tgUser = Long.valueOf(params.get("id"));
+ long tgUser = Long.parseLong(params.get("id"));
int uid = telegramService.getUser(tgUser);
if (uid > 0) {
Cookie c = new Cookie("hash", userService.getHashByUID(uid));
diff --git a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java b/src/main/java/com/juick/server/www/filters/AnythingFilter.java
index 1f4cf75a..33fb62ea 100644
--- a/src/main/java/com/juick/server/www/controllers/AnythingFilter.java
+++ b/src/main/java/com/juick/server/www/filters/AnythingFilter.java
@@ -1,4 +1,4 @@
-package com.juick.server.www.controllers;
+package com.juick.server.www.filters;
import com.juick.server.util.WebUtils;
import com.juick.service.MessagesService;
diff --git a/src/main/java/com/juick/server/xmpp/JidConverter.java b/src/main/java/com/juick/server/xmpp/JidConverter.java
index e9a9707e..96c9ca74 100644
--- a/src/main/java/com/juick/server/xmpp/JidConverter.java
+++ b/src/main/java/com/juick/server/xmpp/JidConverter.java
@@ -4,10 +4,12 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import rocks.xmpp.addr.Jid;
+import javax.annotation.Nonnull;
+
public class JidConverter implements Converter<String, Jid> {
@Nullable
@Override
- public Jid convert(String jidStr) {
+ public Jid convert(@Nonnull String jidStr) {
return Jid.of(jidStr);
}
}
diff --git a/src/main/java/com/juick/service/EmailServiceImpl.java b/src/main/java/com/juick/service/EmailServiceImpl.java
index 78bdd42a..d5375ead 100644
--- a/src/main/java/com/juick/service/EmailServiceImpl.java
+++ b/src/main/java/com/juick/service/EmailServiceImpl.java
@@ -19,12 +19,10 @@ package com.juick.service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import javax.inject.Inject;
import java.util.List;
/**
diff --git a/src/main/java/com/juick/service/ImagesServiceImpl.java b/src/main/java/com/juick/service/ImagesServiceImpl.java
index 67c8360e..f91b6036 100644
--- a/src/main/java/com/juick/service/ImagesServiceImpl.java
+++ b/src/main/java/com/juick/service/ImagesServiceImpl.java
@@ -13,10 +13,9 @@ import java.nio.file.Paths;
public class ImagesServiceImpl implements ImagesService {
private ImageUtils imageUtils;
private String imgDir;
- private String tmpDir;
+
public ImagesServiceImpl(String imgDir, String tmpDir) {
this.imgDir = imgDir;
- this.tmpDir = tmpDir;
imageUtils = new ImageUtils(imgDir, tmpDir);
}
@Override
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index 8bcf47d3..c405fde4 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -23,7 +23,6 @@ import com.juick.User;
import com.juick.model.AnonymousUser;
import com.juick.model.PrivacyOpts;
import com.juick.model.ResponseReply;
-import com.juick.server.util.HttpNotFoundException;
import com.juick.server.www.WebApp;
import com.juick.util.MessageUtils;
import org.apache.commons.collections4.CollectionUtils;
@@ -601,7 +600,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
.addValue("uid", uid)
.addValue("before", before);
- List<Integer> mids = getNamedParameterJdbcTemplate().queryForList(
+ return getNamedParameterJdbcTemplate().queryForList(
"SELECT message_id FROM messages WHERE " +
"(user_id=:uid OR " +
"(EXISTS (SELECT 1 FROM subscr_users WHERE subscr_users.suser_id = :uid " +
@@ -624,8 +623,6 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"ORDER BY message_id DESC LIMIT 20",
sqlParameterSource,
Integer.class);
-
- return mids;
}
@Transactional(readOnly = true)
diff --git a/src/main/java/com/juick/service/PushQueriesServiceImpl.java b/src/main/java/com/juick/service/PushQueriesServiceImpl.java
index 7f97956c..9b1ee2f0 100644
--- a/src/main/java/com/juick/service/PushQueriesServiceImpl.java
+++ b/src/main/java/com/juick/service/PushQueriesServiceImpl.java
@@ -19,12 +19,10 @@ package com.juick.service;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.dao.DuplicateKeyException;
-import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
-import javax.inject.Inject;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index 5ce3593b..50f87699 100644
--- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -25,7 +25,6 @@ import com.juick.util.MessageUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.collections4.ListUtils;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 0d4efcfc..16afe08f 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -22,7 +22,6 @@ import com.juick.User;
import com.juick.model.Auth;
import javax.annotation.Nonnull;
-import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
diff --git a/src/main/java/com/juick/service/activities/AnnounceEvent.java b/src/main/java/com/juick/service/activities/AnnounceEvent.java
index 00dbea8c..7fb2be22 100644
--- a/src/main/java/com/juick/service/activities/AnnounceEvent.java
+++ b/src/main/java/com/juick/service/activities/AnnounceEvent.java
@@ -3,8 +3,8 @@ package com.juick.service.activities;
import org.springframework.context.ApplicationEvent;
public class AnnounceEvent extends ApplicationEvent {
- private String actorUri;
- private String messageUri;
+ private final String actorUri;
+ private final String messageUri;
public AnnounceEvent(Object source, String actor, String messageUri) {
super(source);
diff --git a/src/main/java/com/juick/service/component/SystemEvent.java b/src/main/java/com/juick/service/component/SystemEvent.java
index 11a10860..f5852ba4 100644
--- a/src/main/java/com/juick/service/component/SystemEvent.java
+++ b/src/main/java/com/juick/service/component/SystemEvent.java
@@ -1,12 +1,8 @@
package com.juick.service.component;
-import com.juick.Message;
-import com.juick.User;
import com.juick.server.api.SystemActivity;
import org.springframework.context.ApplicationEvent;
-import java.util.List;
-
public class SystemEvent extends ApplicationEvent {
private SystemActivity activity;
/**
diff --git a/src/main/java/com/juick/util/DateFormatter.java b/src/main/java/com/juick/util/DateFormatter.java
index 8f569562..0a14f3dc 100644
--- a/src/main/java/com/juick/util/DateFormatter.java
+++ b/src/main/java/com/juick/util/DateFormatter.java
@@ -20,7 +20,6 @@ package com.juick.util;
import org.apache.commons.lang3.StringUtils;
import java.time.Instant;
-import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 9b668b7c..b922d980 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -28,6 +28,7 @@ import org.springframework.web.util.UriComponentsBuilder;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -270,16 +271,12 @@ public class MessageUtils {
// TODO: check if it is really needed
public static String percentEncode(final String s) {
- String ret = StringUtils.EMPTY;
- try {
- ret = URLEncoder.encode(s, CharEncoding.UTF_8).replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
- } catch (UnsupportedEncodingException e) {
- }
- return ret;
+ return URLEncoder.encode(s, StandardCharsets.UTF_8).replace("+", "%20")
+ .replace("*", "%2A").replace("%7E", "~");
}
public static String formatMarkdownText(final Message msg) {
- String s = StringUtils.defaultString(msg.getText()).replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid()));
- return escapeMarkdown(s);
+ return StringUtils.defaultString(msg.getText())
+ .replaceAll(replyNumberRegex, String.format("$1[/$2](https://juick.com/m/%d#$2)$3", msg.getMid()));
}
public static String escapeMarkdown(final String s) {
return s.replace("_", "\\_").replace("*", "\\*")
diff --git a/src/main/java/com/juick/util/PrettyTimeFormatter.java b/src/main/java/com/juick/util/PrettyTimeFormatter.java
index 383f4d9a..792d185d 100644
--- a/src/main/java/com/juick/util/PrettyTimeFormatter.java
+++ b/src/main/java/com/juick/util/PrettyTimeFormatter.java
@@ -32,14 +32,12 @@ public class PrettyTimeFormatter {
// Cache PrettyTime per locale. LRU cache to prevent memory leak.
private static final Map<Locale, PrettyTime> PRETTY_TIME_LOCALE_MAP =
- new LinkedHashMap<Locale, PrettyTime>(MAX_CACHE_SIZE + 1, 1.1F, true)
- {
- @Override
- protected boolean removeEldestEntry(Map.Entry<Locale, PrettyTime> eldest)
- {
- return size() > MAX_CACHE_SIZE;
- }
- };
+ new LinkedHashMap<>(MAX_CACHE_SIZE + 1, 1.1F, true) {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<Locale, PrettyTime> eldest) {
+ return size() > MAX_CACHE_SIZE;
+ }
+ };
public String format(final Locale locale, final Date value)
{
diff --git a/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java b/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
index 1b75727e..27b9d970 100644
--- a/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
+++ b/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java
@@ -18,7 +18,6 @@
package com.mitchellbosecke.pebble.extension.filters;
import com.juick.Message;
-import com.juick.model.AnonymousUser;
import com.juick.util.MessageUtils;
import com.mitchellbosecke.pebble.extension.Filter;
import com.mitchellbosecke.pebble.extension.escaper.SafeString;
@@ -28,7 +27,6 @@ import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
/**
* Created by vitalyster on 04.05.2017.
diff --git a/src/main/java/ru/sape/SapeConnection.java b/src/main/java/ru/sape/SapeConnection.java
index a15658fa..ee5a5e5c 100644
--- a/src/main/java/ru/sape/SapeConnection.java
+++ b/src/main/java/ru/sape/SapeConnection.java
@@ -11,6 +11,7 @@ import java.io.Reader;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.*;
public class SapeConnection {
@@ -48,7 +49,7 @@ public class SapeConnection {
connection.setRequestMethod("GET");
connection.connect();
- r = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
+ r = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
StringWriter sw = new StringWriter();