diff options
author | Vitaly Takmazov | 2018-08-29 15:10:51 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-08-29 15:10:51 +0300 |
commit | 61a28570ca25ae789cca09736ddc427e172ac213 (patch) | |
tree | b1f490597d5f2999121310ae479b38e33eb5fb71 | |
parent | 22514aa83e418770c8f60ea1b5ce943daa2383ef (diff) |
getUserByName is non nullable
6 files changed, 9 insertions, 8 deletions
diff --git a/juick-common/src/main/java/com/juick/server/CommandsManager.java b/juick-common/src/main/java/com/juick/server/CommandsManager.java index 58c07255..50cdb202 100644 --- a/juick-common/src/main/java/com/juick/server/CommandsManager.java +++ b/juick-common/src/main/java/com/juick/server/CommandsManager.java @@ -229,7 +229,7 @@ public class CommandsManager { help = "BL @username - add @username to your blacklist") public CommandResult blacklistUser(User user_from, URI attachment, String... arguments) { User blUser = userService.getUserByName(arguments[0]); - if (blUser != null) { + if (!blUser.isAnonymous()) { PrivacyQueriesService.PrivacyResult result = privacyQueriesService.blacklistUser(user_from, blUser); if (result == PrivacyQueriesService.PrivacyResult.Added) { return CommandResult.fromString("User added to your blacklist"); @@ -243,7 +243,7 @@ public class CommandsManager { help = "BL *tag - add *tag to your blacklist") public CommandResult blacklistTag(User user_from, URI attachment, String... arguments) { User blUser = userService.getUserByName(arguments[0]); - if (blUser != null) { + if (!blUser.isAnonymous()) { Tag tag = tagService.getTag(arguments[0], false); if (tag != null) { PrivacyQueriesService.PrivacyResult result = privacyQueriesService.blacklistTag(user_from, tag); diff --git a/juick-common/src/main/java/com/juick/service/UserService.java b/juick-common/src/main/java/com/juick/service/UserService.java index ef49a8ab..cfeaaa51 100644 --- a/juick-common/src/main/java/com/juick/service/UserService.java +++ b/juick-common/src/main/java/com/juick/service/UserService.java @@ -44,7 +44,7 @@ public interface UserService { Optional<User> getUserByUID(int uid); - User getUserByName(String username); + @Nonnull User getUserByName(String username); User getUserByEmail(String email); diff --git a/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java b/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java index adb0ab44..59425fab 100644 --- a/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java +++ b/juick-common/src/main/java/com/juick/service/security/JuickUserDetailsService.java @@ -43,7 +43,7 @@ public class JuickUserDetailsService implements UserDetailsService { com.juick.User user = userService.getUserByName(username); - if (user != null) { + if (!user.isAnonymous()) { user.setAuthHash(userService.getHashByUID(user.getUid())); return new JuickUser(user); } diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java index db6463dd..80c718b7 100644 --- a/juick-server/src/main/java/com/juick/server/api/Messages.java +++ b/juick-server/src/main/java/com/juick/server/api/Messages.java @@ -100,7 +100,7 @@ public class Messages { List<Integer> mids; if (!StringUtils.isEmpty(uname)) { User user = userService.getUserByName(uname); - if (user != null) { + if (!user.isAnonymous()) { if (!StringUtils.isEmpty(media)) { mids = messagesService.getUserPhotos(user.getUid(), 0, before); } else if (!StringUtils.isEmpty(tag)) { diff --git a/juick-server/src/main/java/com/juick/server/api/Users.java b/juick-server/src/main/java/com/juick/server/api/Users.java index c91581a0..237b7ed6 100644 --- a/juick-server/src/main/java/com/juick/server/api/Users.java +++ b/juick-server/src/main/java/com/juick/server/api/Users.java @@ -106,7 +106,7 @@ public class Users { } else { if (WebUtils.isUserName(uname)) { com.juick.User u = userService.getUserByName(uname); - if (u != null && u.getUid() > 0) { + if (!u.isAnonymous()) { uid = u.getUid(); } } @@ -131,7 +131,7 @@ public class Users { } else { if (WebUtils.isUserName(uname)) { com.juick.User u = userService.getUserByName(uname); - if (u != null && u.getUid() > 0) { + if (!u.isAnonymous()) { uid = u.getUid(); } } diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java index 077fb01d..bcdb7a13 100644 --- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java @@ -33,6 +33,7 @@ import org.springframework.jdbc.support.KeyHolder; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Nonnull; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -126,6 +127,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { } @Transactional(readOnly = true) + @Nonnull @Override public User getUserByName(final String username) { if (StringUtils.isNotBlank(username)) { @@ -135,7 +137,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { if (!list.isEmpty()) return list.get(0); } - // TODO: @NonNullable ? return AnonymousUser.INSTANCE; } |