Search in sources :

Example 1 with AnnouncementUserJoin

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());
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) AnnouncementUserJoin(ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin) Authentication(org.springframework.security.core.Authentication) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 2 with AnnouncementUserJoin

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.");
    }
}
Also used : AnnouncementUserJoin(ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

Example 3 with AnnouncementUserJoin

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);
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) AnnouncementUserJoin(ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin) AnnouncementService(ca.corefacility.bioinformatics.irida.service.AnnouncementService) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) AnnouncementsController(ca.corefacility.bioinformatics.irida.ria.web.AnnouncementsController) Before(org.junit.Before)

Example 4 with AnnouncementUserJoin

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;
}
Also used : DTAnnouncementUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser) User(ca.corefacility.bioinformatics.irida.model.user.User) AnnouncementUserJoin(ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AnnouncementUserJoin (ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin)4 User (ca.corefacility.bioinformatics.irida.model.user.User)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)1 Announcement (ca.corefacility.bioinformatics.irida.model.announcements.Announcement)1 AnnouncementsController (ca.corefacility.bioinformatics.irida.ria.web.AnnouncementsController)1 DTAnnouncementUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser)1 AnnouncementService (ca.corefacility.bioinformatics.irida.service.AnnouncementService)1 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)1 Transactional (javax.transaction.Transactional)1 Before (org.junit.Before)1 Test (org.junit.Test)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 Authentication (org.springframework.security.core.Authentication)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1