Search in sources :

Example 1 with SampleRemovedProjectEvent

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;
}
Also used : ProjectSampleJoinRepository(ca.corefacility.bioinformatics.irida.repositories.joins.project.ProjectSampleJoinRepository) Arrays(java.util.Arrays) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) ProjectEventRepository(ca.corefacility.bioinformatics.irida.repositories.ProjectEventRepository) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) SampleRepository(ca.corefacility.bioinformatics.irida.repositories.sample.SampleRepository) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ArrayList(java.util.ArrayList) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) ProjectRepository(ca.corefacility.bioinformatics.irida.repositories.ProjectRepository) Logger(org.slf4j.Logger) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Collection(java.util.Collection) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) SampleRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent) UserGroupRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent) Project(ca.corefacility.bioinformatics.irida.model.project.Project) List(java.util.List) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) Optional(java.util.Optional) User(ca.corefacility.bioinformatics.irida.model.user.User) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) SampleRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList)

Aggregations

LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)1 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)1 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)1 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)1 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)1 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)1 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)1 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)1 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)1 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)1 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)1 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)1 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)1 User (ca.corefacility.bioinformatics.irida.model.user.User)1 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)1 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)1 ProjectEventRepository (ca.corefacility.bioinformatics.irida.repositories.ProjectEventRepository)1 ProjectRepository (ca.corefacility.bioinformatics.irida.repositories.ProjectRepository)1