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;
}
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));
}
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);
}
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));
}
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);
}
}
Aggregations