I am learning spring and am wondering about this service class's method. Is there a way to split this method up? Is there a way to use spring framework to make this method more readable? Should I move any of it to the controller or the DAO or should I split it into more service methods?
// UserBean has fields: username, password, first name, last name, etc.
// The UserBean parameter has 2 non-null fields: username and password.
public UserBean getUserDetails(UserBean bean) {
UserEntity entity = new UserEntity();
BeanUtils.copyProperties(bean, entity);
// Gets user from DB based on UserBean's username and password.
// Returns null if not found.
entity = this.userDao.getUser(entity);
if (entity == null) {
return null;
}
// Fill in the rest of the UserBean's data from the DB
UserBean userBean = new UserBean();
BeanUtils.copyProperties(entity, userBean);
// calculate time since last login based on DB timestamp
userBean.setTimeSinceLastLogin(this.getSecondsSinceLastLogin(entity.getLastLogin()));
// update DB with new timestamp
entity.setLastLogin(new Date());
this.userDao.updateUser(entity);
return userBean;
}
copyProperties
twice or at least at once? As fo me It can be ommited. \$\endgroup\$