|
|
@ -7,8 +7,6 @@ import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import javax.transaction.Transactional; |
|
|
|
|
|
|
|
import org.ros.chatto.dto.ActiveUserDTO; |
|
|
|
import org.ros.chatto.dto.UserRegistrationDTO; |
|
|
|
import org.ros.chatto.model.ChatUser; |
|
|
@ -22,32 +20,32 @@ import org.ros.chatto.repository.UserSessionRepository; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Service |
|
|
|
public class UserServiceImpl implements UserService { |
|
|
|
@Autowired |
|
|
|
UserRepository userRepository; |
|
|
|
private UserRepository userRepository; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
UserRoleRepository userRoleRepository; |
|
|
|
private UserRoleRepository userRoleRepository; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
PasswordEncoder passwordEncoder; |
|
|
|
private PasswordEncoder passwordEncoder; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
RoleService roleService; |
|
|
|
private RoleService roleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
UserRepositoryCustom userRepositoryCustom; |
|
|
|
private UserRepositoryCustom userRepositoryCustom; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserSessionRepository userSessionRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void saveChatUser(ChatUser user) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
ChatUser changedUser = userRepository.save(user); |
|
|
|
UserRole userRole = new UserRole(); |
|
|
|
userRole.setRole(roleService.getRole("USER")); |
|
|
@ -56,9 +54,7 @@ public class UserServiceImpl implements UserService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public void registerUser(UserRegistrationDTO userRegistrationDTO) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
ChatUser user = new ChatUser(); |
|
|
|
user.setUserName(userRegistrationDTO.getUserName()); |
|
|
|
user.setPassword(passwordEncoder.encode(userRegistrationDTO.getPassword())); |
|
|
@ -73,33 +69,23 @@ public class UserServiceImpl implements UserService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(readOnly = true) |
|
|
|
public List<String> findAllOtherUsers(String userName) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
return userRepositoryCustom.getAllUserNames(userName); |
|
|
|
return userRepository.findAllOtherUserNames(userName); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(readOnly = true) |
|
|
|
@Override |
|
|
|
public List<String> getAllRegularUsers() { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
return userRoleRepository.getAllRegularUser(); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(readOnly = true) |
|
|
|
public List<ActiveUserDTO> getOtherActiveUsers(String userName) { |
|
|
|
List<String> userList = findAllOtherUsers(userName); |
|
|
|
// List<String> onlineUsers = activeUserStore.getUsers(); |
|
|
|
|
|
|
|
List<UserSession> userSessionsList = userSessionRepository.findAll(); |
|
|
|
List<UserSession> userSessionsList = userSessionRepository.findAllUserSessions(); |
|
|
|
Map<String, UserSession> lastActiveMap = convertToMap(userSessionsList); |
|
|
|
// userList.forEach(u -> { |
|
|
|
// ActiveUserDTO activeUserDTO = new ActiveUserDTO(); |
|
|
|
// activeUserDTO.setUserName(u); |
|
|
|
// activeUserDTO.setOnline(false); |
|
|
|
// activeUserDTO.setLastActive(toLastActiveString(lastActiveMap.get(u))); |
|
|
|
// if (onlineUsers.contains(u)) { |
|
|
|
// activeUserDTO.setOnline(true); |
|
|
|
// } |
|
|
|
// activeUserDTOs.add(activeUserDTO); |
|
|
|
// }); |
|
|
|
|
|
|
|
List<ActiveUserDTO> activeUserDTOs = new ArrayList<ActiveUserDTO>(); |
|
|
|
userList.forEach(u -> { |
|
|
@ -121,20 +107,12 @@ public class UserServiceImpl implements UserService { |
|
|
|
return activeUserDTOs; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(readOnly = true) |
|
|
|
@Override |
|
|
|
public ChatUser findByUserName(String userName) { |
|
|
|
// TODO Auto-generated method stub |
|
|
|
return userRepository.findByUserName(userName); |
|
|
|
} |
|
|
|
|
|
|
|
// private Map<String, Instant> convertToMap(List<UserSession> userSessionList) { |
|
|
|
// Map<String, Instant> userMap = new HashMap<>(); |
|
|
|
// userSessionList.forEach(us -> { |
|
|
|
// userMap.put(us.getUser().getUserName(), us.getTimeStamp()); |
|
|
|
// }); |
|
|
|
// return userMap; |
|
|
|
// } |
|
|
|
|
|
|
|
private Map<String, UserSession> convertToMap(List<UserSession> userSessionList) { |
|
|
|
Map<String, UserSession> userMap = new HashMap<>(); |
|
|
|
userSessionList.forEach(us -> { |
|
|
|