details.setDiscussionStatuses(statusesInDiscussion);
return details;
}
public Collection<StatusDTO> buildStatusList(List<String> line) {
User currentUser = null;
Collection<Group> usergroups;
List<String> favoriteLine;
if (authenticationService.hasAuthenticatedUser()) {
currentUser = authenticationService.getCurrentUser();
usergroups = groupService.getGroupsForUser(currentUser);
favoriteLine = favoritelineRepository.getFavoriteline(currentUser.getLogin());
} else {
usergroups = Collections.emptyList();
favoriteLine = Collections.emptyList();
}
Collection<StatusDTO> statuses = new ArrayList<StatusDTO>(line.size());
for (String statusId : line) {
AbstractStatus abstractStatus = statusRepository.findStatusById(statusId);
if (abstractStatus != null) {
User statusUser = userService.getUserByLogin(abstractStatus.getLogin());
if (statusUser != null) {
// Security check
// bypass the security check when no user is logged in
// => for non-authenticated rss access
if ((currentUser != null) && !statusUser.getDomain().equals(currentUser.getDomain())) {
throw new DomainViolationException("User " + currentUser + " tried to access " +
" status : " + abstractStatus);
}
StatusDTO statusDTO = new StatusDTO();
statusDTO.setStatusId(abstractStatus.getStatusId());
statusDTO.setStatusDate(abstractStatus.getStatusDate());
statusDTO.setGeoLocalization(abstractStatus.getGeoLocalization());
statusDTO.setActivated(statusUser.getActivated());
StatusType type = abstractStatus.getType();
if (type == null) {
statusDTO.setType(StatusType.STATUS);
} else {
statusDTO.setType(abstractStatus.getType());
}
if (abstractStatus.getType().equals(StatusType.SHARE)) {
Share share = (Share) abstractStatus;
AbstractStatus originalStatus = statusRepository.findStatusById(share.getOriginalStatusId());
if (originalStatus != null) { // Find the original status
statusDTO.setTimelineId(share.getStatusId());
statusDTO.setSharedByUsername(share.getUsername());
statusUser = userService.getUserByLogin(originalStatus.getLogin());
addStatusToLine(statuses, statusDTO, originalStatus, statusUser, usergroups, favoriteLine);
} else {
log.debug("Original status has been deleted");
}
} else if (abstractStatus.getType().equals(StatusType.MENTION_SHARE)) {
MentionShare mentionShare = (MentionShare) abstractStatus;
AbstractStatus originalStatus = statusRepository.findStatusById(mentionShare.getOriginalStatusId());
if (originalStatus != null) { // Find the status that was shared
statusDTO.setTimelineId(mentionShare.getStatusId());
statusDTO.setSharedByUsername(mentionShare.getUsername());
statusUser = userService.getUserByLogin(mentionShare.getLogin());
addStatusToLine(statuses, statusDTO, originalStatus, statusUser, usergroups, favoriteLine);
} else {
log.debug("Mentioned status has been deleted");
}
} else if (abstractStatus.getType().equals(StatusType.MENTION_FRIEND)) {
MentionFriend mentionFriend = (MentionFriend) abstractStatus;
statusDTO.setTimelineId(mentionFriend.getStatusId());
statusDTO.setSharedByUsername(mentionFriend.getUsername());
statusUser = userService.getUserByLogin(mentionFriend.getFollowerLogin());
statusDTO.setFirstName(statusUser.getFirstName());
statusDTO.setLastName(statusUser.getLastName());
statusDTO.setAvatar(statusUser.getAvatar());
statusDTO.setUsername(statusUser.getUsername());
statuses.add(statusDTO);
} else if (abstractStatus.getType().equals(StatusType.ANNOUNCEMENT)) {
Announcement announcement = (Announcement) abstractStatus;
AbstractStatus originalStatus = statusRepository.findStatusById(announcement.getOriginalStatusId());
if (originalStatus != null) { // Find the status that was announced