public class UserStatusConverter {
private ScopeConnector scopeConnector;
public UserStatusDTO createUserStatusDto(UserStatus userStatus,
String userRepoRef, String scopeId) {
UserStatusDTO userStatusDto = new UserStatusDTO();
userStatusDto.setId(userStatus.getId());
userStatusDto.setUsername(userStatus.getUsername());
userStatusDto.setEnabled(Integer.valueOf(1).equals(
userStatus.getStatus()));
userStatusDto.setRef(userStatus.getRef());
StringBuilder buff = new StringBuilder();
for (Role role : userStatus.getRoles()) {
if (scopeId.equals(role.getScopeId())) {
buff.append(role.getName()).append(",");
} else {
ScopeDTO scopeDto = scopeConnector.findById(role.getScopeId());
buff.append(role.getName()).append("(")
.append(scopeDto.getName()).append("),");
}
}
if (buff.length() > 0) {
buff.deleteCharAt(buff.length() - 1);
}
userStatusDto.setAuthorities(buff.toString());
return userStatusDto;
}