use of ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin in project irida by phac-nml.
the class AnnouncementServiceImplIT method testGetReadAnnouncementsForUser.
@Test
@WithMockUser(username = "user", roles = "USER")
public void testGetReadAnnouncementsForUser() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = userService.getUserByUsername(auth.getName());
List<AnnouncementUserJoin> readList = announcementService.getReadAnnouncementsForUser(user);
assertEquals("Number of read announcements doesn't match expected value", 5, readList.size());
}
use of ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin in project irida by phac-nml.
the class AnnouncementServiceImpl method markAnnouncementAsUnreadByUser.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@PreAuthorize("hasAnyRole('ROLE_USER')")
public void markAnnouncementAsUnreadByUser(Announcement announcement, User user) throws EntityNotFoundException {
try {
final AnnouncementUserJoin join = announcementUserJoinRepository.getAnnouncementUserJoin(announcement, user);
Long id = join.getId();
announcementUserJoinRepository.delete(id);
} catch (NullPointerException e) {
throw new EntityNotFoundException("The user [" + user.getId() + "] has not yet read announcement [" + announcement.getId() + "]: cannot mark as unread.");
}
}
use of ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin in project irida by phac-nml.
the class AnnouncementsControllerTest method setUp.
@Before
public void setUp() {
userService = mock(UserService.class);
announcementService = mock(AnnouncementService.class);
announcementsController = new AnnouncementsController(userService, announcementService);
user = new User("testme", "test@me.com", "aaa", "John", "Curatcha", "2222222");
Announcement a1 = new Announcement("First message", user);
Announcement a2 = new Announcement("Second message", user);
announcementList = Lists.newArrayList(a1, a2);
AnnouncementUserJoin auj1 = new AnnouncementUserJoin(a1, user);
AnnouncementUserJoin auj2 = new AnnouncementUserJoin(a2, user);
announcementUserList = Lists.newArrayList(auj1, auj2);
}
use of ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin in project irida by phac-nml.
the class AnnouncementsController method getReadAnnouncementsAsUser.
/**
* Gets a list of {@link Announcement}s for the current {@link User}
*
* @param model
* Model for the view
* @param principal
* The user fetching the announcements (usually the one currently logged in)
* @return The announcement page containing announcement information for the user
*/
@RequestMapping(value = "/user/read", method = RequestMethod.GET)
public String getReadAnnouncementsAsUser(final Model model, Principal principal) {
User user = userService.getUserByUsername(principal.getName());
List<AnnouncementUserJoin> readAnnouncements = announcementService.getReadAnnouncementsForUser(user);
logger.trace("Announcements list size: " + readAnnouncements.size());
model.addAttribute("readAnnouncements", readAnnouncements);
return ANNOUNCEMENT_VIEW_READ;
}
Aggregations