Search in sources :

Example 1 with ProjectEvent

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;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) User(ca.corefacility.bioinformatics.irida.model.user.User) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent) UserGroupRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ProjectEvent

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) List(java.util.List) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 3 with ProjectEvent

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));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Date(java.util.Date) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) Test(org.junit.Test)

Example 4 with ProjectEvent

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));
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) Test(org.junit.Test)

Example 5 with ProjectEvent

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));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) Test(org.junit.Test)

Aggregations

ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)30 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)29 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)23 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)23 Test (org.junit.Test)23 Project (ca.corefacility.bioinformatics.irida.model.project.Project)21 User (ca.corefacility.bioinformatics.irida.model.user.User)16 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)13 PageRequest (org.springframework.data.domain.PageRequest)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)8 Map (java.util.Map)8 Date (java.util.Date)7 List (java.util.List)7 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)5 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)5 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)5 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)5 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)5 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)4