use of ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent in project irida by phac-nml.
the class ProjectEventHandler method handleSampleRemovedEvent.
/**
* Create {@link SampleRemovedProjectEvent}s for any {@link Sample}s removed
* from a {@link Project}
*
* @param event
* the {@link MethodEvent} containing params from the method call
* @return a collectino of {@link SampleRemovedProjectEvent}s
*/
private Collection<SampleRemovedProjectEvent> handleSampleRemovedEvent(MethodEvent event) {
Collection<SampleRemovedProjectEvent> events = new ArrayList<>();
Optional<Object> projectOpt = Arrays.stream(event.getArgs()).filter(e -> e instanceof Project).findAny();
Optional<Object> sampleOpt = Arrays.stream(event.getArgs()).filter(e -> e instanceof Sample).findAny();
Optional<Object> sampleListOpt = Arrays.stream(event.getArgs()).filter(e -> e instanceof Iterable).findAny();
if (projectOpt.isPresent()) {
Project project = (Project) projectOpt.get();
if (sampleOpt.isPresent()) {
Sample sample = (Sample) sampleOpt.get();
events.add(eventRepository.save(new SampleRemovedProjectEvent(project, sample.getSampleName())));
} else if (sampleListOpt.isPresent()) {
@SuppressWarnings("unchecked") Iterable<Sample> samples = (Iterable<Sample>) sampleListOpt.get();
for (Sample sample : samples) {
events.add(eventRepository.save(new SampleRemovedProjectEvent(project, sample.getSampleName())));
}
}
}
return events;
}
Aggregations