use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventsController method getRecentEventsForUser.
/**
* Get recent {@link ProjectEvent}s for the currently logged in user
*
* @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 principal
* currently logged in principal
* @param size
* Number of events to show
* @return The name of the events view
*/
@RequestMapping("/current_user")
public String getRecentEventsForUser(Model model, Principal principal, @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) Integer size) {
String userName = principal.getName();
User user = userService.getUserByUsername(userName);
Page<ProjectEvent> events = eventService.getEventsForUser(user, 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 ProjectEventEmailScheduedTaskImplTest method testEmailUserPartialSubscriptoinTasks.
@SuppressWarnings("unchecked")
@Test
public void testEmailUserPartialSubscriptoinTasks() {
User tom = new User("tom", null, null, null, null, null);
Project p = new Project("testproject");
Project p2 = new Project("testproject2");
List<User> users = Lists.newArrayList(tom);
ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
join.setEmailSubscription(true);
ProjectUserJoin notSubscribed = new ProjectUserJoin(p2, tom, ProjectRole.PROJECT_OWNER);
List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join), new UserRoleSetProjectEvent(notSubscribed));
when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join, notSubscribed));
task.emailUserTasks();
verify(userService).getUsersWithEmailSubscriptions();
verify(eventService).getEventsForUserAfterDate(eq(tom), any(Date.class));
@SuppressWarnings("rawtypes") ArgumentCaptor<List> eventCaptor = ArgumentCaptor.forClass(List.class);
verify(emailController).sendSubscriptionUpdateEmail(eq(tom), eventCaptor.capture());
List<ProjectEvent> sentEvents = eventCaptor.getValue();
assertEquals("should send 1 event", 1, sentEvents.size());
ProjectEvent sentEvent = sentEvents.iterator().next();
assertEquals("should have sent from subscribed project", p, sentEvent.getProject());
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventEmailScheduedTaskImplTest method testEmailUserTasks.
@SuppressWarnings("unchecked")
@Test
public void testEmailUserTasks() {
Date priorDateFromCronString = ProjectEventEmailScheduledTaskImpl.getPriorDateFromCronString(task.getScheduledCronString());
User tom = new User("tom", null, null, null, null, null);
Project p = new Project("testproject");
List<User> users = Lists.newArrayList(tom);
ProjectUserJoin join = new ProjectUserJoin(p, tom, ProjectRole.PROJECT_OWNER);
join.setEmailSubscription(true);
List<ProjectEvent> events = Lists.newArrayList(new UserRoleSetProjectEvent(join));
when(userService.getUsersWithEmailSubscriptions()).thenReturn(users);
when(eventService.getEventsForUserAfterDate(eq(tom), any(Date.class))).thenReturn(events);
when(projectService.getProjectsForUser(tom)).thenReturn(Lists.newArrayList(join));
Date now = new Date();
task.emailUserTasks();
verify(userService).getUsersWithEmailSubscriptions();
ArgumentCaptor<Date> dateCaptor = ArgumentCaptor.forClass(Date.class);
verify(eventService).getEventsForUserAfterDate(eq(tom), dateCaptor.capture());
verify(emailController).sendSubscriptionUpdateEmail(tom, events);
Date testedDate = dateCaptor.getValue();
assertTrue("date should be before current time", now.after(testedDate));
assertTrue("date should be equal to or before scheduled time", priorDateFromCronString.before(testedDate) || priorDateFromCronString.equals(testedDate));
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventMultipleReturn.
@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventMultipleReturn() {
Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
Project project = new Project();
Sample sample = new Sample();
SequenceFile file = new SequenceFile();
SingleEndSequenceFile seqObj1 = new SingleEndSequenceFile(file);
SingleEndSequenceFile seqObj2 = new SingleEndSequenceFile(file);
SampleSequencingObjectJoin join1 = new SampleSequencingObjectJoin(sample, seqObj1);
SampleSequencingObjectJoin join2 = new SampleSequencingObjectJoin(sample, seqObj2);
when(psjRepository.getProjectForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new DataAddedToSampleProjectEvent(project, sample));
Object[] args = {};
MethodEvent methodEvent = new MethodEvent(clazz, Lists.newArrayList(join1, join2), args);
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof DataAddedToSampleProjectEvent);
verify(projectRepository).save(any(Project.class));
verify(sampleRepository).save(any(Sample.class));
}
use of ca.corefacility.bioinformatics.irida.model.event.ProjectEvent in project irida by phac-nml.
the class ProjectEventHandlerTest method testDelegateSampleAdded.
@Test
public void testDelegateSampleAdded() {
Class<? extends ProjectEvent> clazz = SampleAddedProjectEvent.class;
Project project = new Project();
Sample sample = new Sample();
ProjectSampleJoin returnValue = new ProjectSampleJoin(project, sample, true);
Object[] args = { project, sample };
MethodEvent methodEvent = new MethodEvent(clazz, returnValue, args);
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new SampleAddedProjectEvent(returnValue));
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof SampleAddedProjectEvent);
verify(projectRepository).save(any(Project.class));
}
Aggregations