use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventServiceImplIT method testGetEventsForProject.
@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testGetEventsForProject() {
Project project1 = projectService.read(1L);
Project project3 = projectService.read(3L);
Page<ProjectEvent> eventsForProject1 = projectEventService.getEventsForProject(project1, new PageRequest(0, 10));
Page<ProjectEvent> eventsForProject2 = projectEventService.getEventsForProject(project3, new PageRequest(0, 10));
assertEquals(0L, eventsForProject1.getTotalElements());
assertEquals(1L, eventsForProject2.getTotalElements());
ProjectEvent event2 = eventsForProject2.iterator().next();
assertEquals(project3, event2.getProject());
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventServiceImplIT method testGetEmptyEventsAfterDate.
@WithMockUser(username = "tom", password = "password1", roles = "ADMIN")
@Test
public void testGetEmptyEventsAfterDate() throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date beginning = formatter.parse("2013-07-18 15:00:00");
User user = userService.read(3L);
List<ProjectEvent> events = projectEventService.getEventsForUserAfterDate(user, beginning);
assertTrue("no events should be found", events.isEmpty());
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventEmailScheduledTaskImpl method emailUserTasks.
/**
* {@inheritDoc}
*/
@Override
public void emailUserTasks() {
if (emailController.isMailConfigured()) {
logger.trace("Checking for users with subscriptions");
List<User> usersWithEmailSubscriptions = userService.getUsersWithEmailSubscriptions();
Date lastTime = getPriorDateFromCronString(scheduledCronString);
logger.trace("Getting events after " + lastTime);
for (User user : usersWithEmailSubscriptions) {
logger.trace("Checking for events for user " + user.getUsername());
List<ProjectEvent> eventsToEmailToUser = eventService.getEventsForUserAfterDate(user, lastTime);
// Get the set of projects the user is subscribed to
Set<Project> projectsWithSubscription = projectService.getProjectsForUser(user).stream().filter(j -> {
ProjectUserJoin puj = (ProjectUserJoin) j;
return puj.isEmailSubscription();
}).map(j -> j.getSubject()).collect(Collectors.toSet());
// filter the events to ensure the user is subscribed
eventsToEmailToUser = eventsToEmailToUser.stream().filter(e -> projectsWithSubscription.contains(e.getProject())).collect(Collectors.toList());
if (!eventsToEmailToUser.isEmpty()) {
logger.trace("Sending subscription email to " + user.getUsername() + " with " + eventsToEmailToUser.size() + " events");
emailController.sendSubscriptionUpdateEmail(user, eventsToEmailToUser);
}
}
}
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventsController method getRecentEventsForProject.
/**
* Get recent {@link ProjectEvent}s for the given {@link Project}
*
* @param projectId
* The ID of the {@link Project} to get events for
* @param model
* Model for the view. Contains a list named "events". This will
* be a map which will contain "name" which is the name of the
* view fragment to use, and "event" which is a reference to the
* event itself
* @param size
* Number of events to show
* @return The name of the events view
*/
@RequestMapping("/project/{projectId}")
public String getRecentEventsForProject(@PathVariable Long projectId, Model model, @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer size) {
Project project = projectService.read(projectId);
Page<ProjectEvent> events = eventService.getEventsForProject(project, new PageRequest(0, size, Direction.DESC, "createdDate"));
List<Map<String, Object>> eventInfo = buildEventsListFromPage(events);
model.addAttribute("events", eventInfo);
return EVENTS_VIEW;
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventsController method buildEventsListFromPage.
/**
* Convert the Page of events to the list expected in the model
*
* @param events
* Page of {@link ProjectEvent}s
* @return A List<Map<String,Object>> containing the events and fragment
* names
*/
private List<Map<String, Object>> buildEventsListFromPage(Page<ProjectEvent> events) {
List<Map<String, Object>> eventInfo = new ArrayList<>();
for (ProjectEvent e : events) {
if (FRAGMENT_NAMES.containsKey(e.getClass())) {
Map<String, Object> info = new HashMap<>();
info.put("name", FRAGMENT_NAMES.get(e.getClass()));
info.put("event", e);
eventInfo.add(info);
}
}
return eventInfo;
}
Aggregations