use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementsController method submitCreateAnnouncement.
/**
* Create a new announcement
*
* @param message
* The content of the message for the announcement
* @param model
* The model for the view
* @param principal
* The currently logged in user creating the announcement
* @return A redirect to the announcement control centre page
*/
@RequestMapping(value = "/create", method = RequestMethod.POST)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String submitCreateAnnouncement(@RequestParam(required = true) String message, Model model, Principal principal) {
User creator = userService.getUserByUsername(principal.getName());
Announcement a = new Announcement(message, creator);
try {
announcementService.create(a);
} catch (Exception e) {
model.addAttribute("errors", "Announcement was not created successfully");
}
return "redirect:/announcements/admin";
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementsController method getUnreadAnnouncementsForUser.
/**
* Gets a list of Announcements that the current user hasn't read yet
*
* @param model
* Model for the view
* @param principal
* The current user
* @return the fragment for viewing announcements in the dashboard
*/
@RequestMapping(value = "/user/unread")
public String getUnreadAnnouncementsForUser(final Model model, Principal principal) {
User user = userService.getUserByUsername(principal.getName());
List<Announcement> unreadAnnouncements = announcementService.getUnreadAnnouncementsForUser(user);
Collections.sort(unreadAnnouncements, Collections.reverseOrder());
model.addAttribute("announcements", unreadAnnouncements);
return ANNOUNCEMENT_VIEW;
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementsController method getAnnouncementsAdmin.
/**
* Get all announcements to be displayed in a DataTables for admin control centre
*
* @param params
* {@link DataTablesParams} for the current DataTable.
*
* @return {@link DataTablesResponse}
*/
@RequestMapping(value = "/control/ajax/list")
@PreAuthorize("hasRole('ROLE_ADMIN')")
@ResponseBody
public DataTablesResponse getAnnouncementsAdmin(@DataTablesRequest DataTablesParams params) {
final Page<Announcement> page = announcementService.search(AnnouncementSpecification.searchAnnouncement(params.getSearchValue()), new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
final List<DataTablesResponseModel> announcements = page.getContent().stream().map(DTAnnouncementAdmin::new).collect(Collectors.toList());
return new DataTablesResponse(params, page, announcements);
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementsControllerTest method testSubmitUpdatedAnnouncement.
@Test
public void testSubmitUpdatedAnnouncement() {
long id = 1L;
String message = "Updated message and announcement.";
ExtendedModelMap model = new ExtendedModelMap();
Announcement a = new Announcement(message, user);
when(announcementService.read(any(Long.class))).thenReturn(a);
when(announcementService.update(any(Announcement.class))).thenReturn(a);
String page = announcementsController.submitUpdatedAnnouncement(id, message, model);
assertTrue("Unexpected redirect to page", page.equals("redirect:/announcements/admin"));
verify(announcementService, times(1)).update(any(Announcement.class));
verify(announcementService, times(1)).read(any(Long.class));
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementsControllerTest method testGetAnnouncementDetailsPage.
@Test
public void testGetAnnouncementDetailsPage() {
long id = 1L;
ExtendedModelMap model = new ExtendedModelMap();
String message = "A new announcement";
String page = null;
Announcement a = new Announcement(message, user);
when(announcementService.read(id)).thenReturn(a);
when(announcementService.countReadsForOneAnnouncement(any(Announcement.class))).thenReturn(0L);
when(userService.count()).thenReturn(1L);
page = announcementsController.getAnnouncementDetailsPage(id, model);
assertTrue("Unexpected redirect to a page", page.equals(ANNOUNCEMENT_DETAILS));
assertEquals("Unexpected number of users", 1L, (model.get("numTotal")));
assertEquals("Unexpected number of reads", 0L, (model.get("numReads")));
assertTrue("Unexpected announcement", message.equals(((Announcement) model.get("announcement")).getMessage()));
verify(announcementService, times(1)).read(id);
verify(announcementService).countReadsForOneAnnouncement(a);
verify(userService).count();
}
Aggregations