Search in sources :

Example 1 with DataAddedToSampleProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent in project irida by phac-nml.

the class ProjectEventHandler method handleIndividualSequenceFileAddedEvent.

/**
 * Create {@link DataAddedToSampleProjectEvent} for all {@link Project}s a
 * {@link Sample} belongs to
 *
 * @param join
 *            a {@link SampleSequencingObjectJoin} to turn into a
 *            {@link DataAddedToSampleProjectEvent}
 */
private Collection<DataAddedToSampleProjectEvent> handleIndividualSequenceFileAddedEvent(SampleSequencingObjectJoin join) {
    Sample subject = join.getSubject();
    Collection<DataAddedToSampleProjectEvent> events = new ArrayList<>();
    List<Join<Project, Sample>> projectForSample = psjRepository.getProjectForSample(subject);
    for (Join<Project, Sample> psj : projectForSample) {
        events.add(eventRepository.save(new DataAddedToSampleProjectEvent(psj.getSubject(), subject)));
    }
    return events;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)

Example 2 with DataAddedToSampleProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent 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 3 with DataAddedToSampleProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent in project irida by phac-nml.

the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventMultipleProjects.

@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventMultipleProjects() {
    Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
    Project project = new Project("p1");
    Project project2 = new Project("p2");
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile();
    SingleEndSequenceFile seqObj = new SingleEndSequenceFile(file);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(sample, seqObj);
    when(psjRepository.getProjectForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true), new ProjectSampleJoin(project2, sample, true)));
    when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new DataAddedToSampleProjectEvent(project, sample));
    Object[] args = {};
    MethodEvent methodEvent = new MethodEvent(clazz, join, args);
    handler.delegate(methodEvent);
    ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
    verify(eventRepository, times(2)).save(captor.capture());
    List<ProjectEvent> allValues = captor.getAllValues();
    Set<Project> projects = Sets.newHashSet(project, project2);
    for (ProjectEvent event : allValues) {
        assertTrue(event instanceof DataAddedToSampleProjectEvent);
        Project eventProject = event.getProject();
        assertTrue(projects.contains(eventProject));
        projects.remove(eventProject);
    }
    verify(projectRepository, times(2)).save(project);
}
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 4 with DataAddedToSampleProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent in project irida by phac-nml.

the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventSingle.

@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventSingle() {
    Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
    Project project = new Project();
    Sample sample = new Sample();
    SequenceFile file = new SequenceFile();
    SingleEndSequenceFile seqObj = new SingleEndSequenceFile(file);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(sample, seqObj);
    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, join, 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 DataAddedToSampleProjectEvent

use of ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent in project irida by phac-nml.

the class ProjectEventHandler method delegate.

/**
 * Handle translation of a {@link MethodEvent} into the correct
 * {@link ProjectEvent} subclass
 *
 * @param methodEvent
 *            Information from a method return annotated with
 *            {@link LaunchesProjectEvent}
 */
public void delegate(MethodEvent methodEvent) {
    Class<? extends ProjectEvent> eventClass = methodEvent.getEventClass();
    final Date eventDate = new Date();
    Collection<ProjectEvent> events = new ArrayList<>();
    if (eventClass.equals(SampleAddedProjectEvent.class)) {
        events.addAll(handleSampleAddedProjectEvent(methodEvent));
    } else if (eventClass.equals(UserRemovedProjectEvent.class)) {
        events.add(handleUserRemovedEvent(methodEvent));
    } else if (eventClass.equals(UserRoleSetProjectEvent.class)) {
        events.add(handleUserRoleSetProjectEvent(methodEvent));
    } else if (eventClass.equals(DataAddedToSampleProjectEvent.class)) {
        final Collection<DataAddedToSampleProjectEvent> dataAddedEvents = handleSequenceFileAddedEvent(methodEvent);
        /*
			 * We want the sample to show modification when these events are
			 * added, so update mod date
			 */
        for (final DataAddedToSampleProjectEvent e : dataAddedEvents) {
            final Sample s = e.getSample();
            s.setModifiedDate(eventDate);
            sampleRepository.save(s);
        }
        events.addAll(dataAddedEvents);
    } else if (eventClass.equals(UserGroupRoleSetProjectEvent.class)) {
        events.add(handleUserGroupRoleSetProjectEvent(methodEvent));
    } else if (eventClass.equals(UserGroupRemovedProjectEvent.class)) {
        events.add(handleUserGroupRemovedEvent(methodEvent));
    } else if (eventClass.equals(SampleRemovedProjectEvent.class)) {
        events.addAll(handleSampleRemovedEvent(methodEvent));
    } else {
        logger.warn("No handler found for event class " + eventClass.getName());
    }
    for (ProjectEvent e : events) {
        Project project = e.getProject();
        project.setModifiedDate(eventDate);
        projectRepository.save(project);
    }
}
Also used : UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) Date(java.util.Date) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) 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) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)

Aggregations

DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)5 Project (ca.corefacility.bioinformatics.irida.model.project.Project)5 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)5 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)4 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)4 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)4 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)4 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)4 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)4 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)3 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)1 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)1 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)1 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)1 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)1 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)1 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)1