[backend] Removed obsolete user service method

This commit is contained in:
Rohan Sircar 2020-07-20 22:04:12 +05:30
parent bf8d282629
commit b725458a8a
5 changed files with 13 additions and 30 deletions

View File

@ -1,6 +1,6 @@
package org.ros.chatto.model;
import java.util.Date;
import java.time.Instant;
import java.util.Set;
import javax.persistence.CascadeType;
@ -12,8 +12,6 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@ -43,9 +41,9 @@ public class ChatUser {
@Column(name = "name")
private String userName;
String password;
@Temporal(TemporalType.TIMESTAMP)
private Date joinDate;
private String password;
private Instant joinDate;
@ToString.Exclude
@EqualsAndHashCode.Exclude
@ -53,11 +51,4 @@ public class ChatUser {
CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
@JsonBackReference
private Set<UserRole> userRoles;
// @ToString.Exclude
// @EqualsAndHashCode.Exclude
// @OneToMany(mappedBy = "fromUser", cascade = { CascadeType.PERSIST,
// CascadeType.MERGE, CascadeType.DETACH,
// CascadeType.REFRESH })
// private List<ChatMessage> chatMessages;
}

View File

@ -10,11 +10,8 @@ import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends JpaRepository<ChatUser, Long> {
@Query("select cu from ChatUser cu where cu.userName = ?1")
public Optional<ChatUser> findByUserName(String userName);
@Query("select cu from ChatUser cu join fetch cu.userRoles where cu.userName = ?1")
public ChatUser findByUserNameWithRole(String userName);
public Optional<ChatUser> findByUserName(String userName);
@Query("select cu.userName from ChatUser cu where cu.userName != ?1")
public List<String> findAllOtherUserNames(String userName);

View File

@ -1,5 +1,6 @@
package org.ros.chatto.security;
import java.util.Optional;
import java.util.Set;
import org.ros.chatto.model.ChatUser;
@ -26,17 +27,19 @@ public class MyUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(final String username) {
log.trace("User Details - loading with username: {}", username);
ChatUser user = userService.getUserWithRole(username);
Optional<ChatUser> user = userService.getUser(username);
if (user == null) {
if (!user.isPresent()) {
log.warn("Request for unknown user {}", username);
throw new UsernameNotFoundException(username);
}
Set<UserRole> userRoles = user.getUserRoles();
ChatUser user2 = user.get();
return User.withUsername(user.getUserName())
.password(user.getPassword())
Set<UserRole> userRoles = user2.getUserRoles();
return User.withUsername(user2.getUserName())
.password(user2.getPassword())
.roles(userRoles.stream().map(ur -> ur.getRole().getName())
.toArray(size -> new String[size]))
.build();

View File

@ -25,8 +25,6 @@ public interface UserService {
public List<ActiveUserDTO> getOtherActiveUsers(String userName);
public ChatUser getUserWithRole(String userName);
public void incrementUserSession(String userName);
public UserSession decrementUserSession(String userName);

View File

@ -139,12 +139,6 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Transactional(readOnly = true)
public ChatUser getUserWithRole(final String userName) {
return userRepository.findByUserNameWithRole(userName);
}
@Override
public void incrementUserSession(final String userName) {
final Optional<ChatUser> chatUser = getUser(userName);