Search in sources :

Example 6 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectEventHandler method handleUserGroupRemovedEvent.

/**
 * Create a {@link UserRemovedProjectEvent}. The method arguments must
 * contain a {@link Project} and {@link User}
 *
 * @param event
 *            The {@link MethodEvent} that this event is being launched from
 */
private ProjectEvent handleUserGroupRemovedEvent(MethodEvent event) {
    final Optional<Object> user = Arrays.stream(event.getArgs()).filter(e -> e instanceof UserGroup).findAny();
    final Optional<Object> project = Arrays.stream(event.getArgs()).filter(e -> e instanceof Project).findAny();
    if (!user.isPresent() || !project.isPresent()) {
        throw new IllegalArgumentException("Project or user group cannot be found on method annotated with @LaunchesProjectEvent(UserGroupRemovedProjectEvent.class)");
    }
    return eventRepository.save(new UserGroupRemovedProjectEvent((Project) project.get(), (UserGroup) user.get()));
}
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) UserGroupRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent) Project(ca.corefacility.bioinformatics.irida.model.project.Project) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 7 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method removeSampleFromProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canManageLocalProjectSettings')")
@LaunchesProjectEvent(SampleRemovedProjectEvent.class)
public void removeSampleFromProject(Project project, Sample sample) {
    ProjectSampleJoin readSampleForProject = psjRepository.readSampleForProject(project, sample);
    psjRepository.delete(readSampleForProject);
    // if the sample doesn't refer to any other projects, delete it
    if (psjRepository.getProjectForSample(sample).isEmpty()) {
        sampleRepository.delete(sample);
    }
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method shareSamples.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(SampleAddedProjectEvent.class)
@PreAuthorize("hasPermission(#source, 'canManageLocalProjectSettings')" + " and hasPermission(#destination, 'isProjectOwner')" + " and hasPermission(#samples, 'canReadSample')" + " and ((not #giveOwner) or hasPermission(#samples, 'canUpdateSample'))")
public List<ProjectSampleJoin> shareSamples(Project source, Project destination, Collection<Sample> samples, boolean giveOwner) {
    List<ProjectSampleJoin> newJoins = new ArrayList<>();
    for (Sample sample : samples) {
        ProjectSampleJoin newJoin = addSampleToProject(destination, sample, giveOwner);
        logger.trace("Shared sample " + sample.getId() + " to project " + destination.getId());
        newJoins.add(newJoin);
    }
    return newJoins;
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ArrayList(java.util.ArrayList) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method moveSampleBetweenProjects.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(SampleAddedProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or ( hasPermission(#source, 'isProjectOwner') and hasPermission(#destination, 'isProjectOwner'))")
public ProjectSampleJoin moveSampleBetweenProjects(Project source, Project destination, Sample sample, boolean owner) {
    ProjectSampleJoin join = addSampleToProject(destination, sample, owner);
    removeSampleFromProject(source, sample);
    return join;
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with LaunchesProjectEvent

use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.

the class ProjectServiceImpl method updateUserGroupProjectRole.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(UserGroupRoleSetProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canManageLocalProjectSettings')")
public Join<Project, UserGroup> updateUserGroupProjectRole(Project project, UserGroup userGroup, ProjectRole projectRole) throws ProjectWithoutOwnerException {
    final UserGroupProjectJoin j = ugpjRepository.findByProjectAndUserGroup(project, userGroup);
    if (j == null) {
        throw new EntityNotFoundException("Join between this project and group does not exist. Group: " + userGroup + " Project: " + project);
    }
    if (!allowRoleChange(project, j.getProjectRole())) {
        throw new ProjectWithoutOwnerException("This role change would leave the project without an owner");
    }
    j.setProjectRole(projectRole);
    return ugpjRepository.save(j);
}
Also used : ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Transactional (org.springframework.transaction.annotation.Transactional)10 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)6 ProjectWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 ArrayList (java.util.ArrayList)4 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)3 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 UserGroupRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.enums.UserGroupRemovedProjectEvent)2 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)2 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)2 SampleAddedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent)2 SampleRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.SampleRemovedProjectEvent)2 UserGroupRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserGroupRoleSetProjectEvent)2 UserRemovedProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent)2 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)2 Project (ca.corefacility.bioinformatics.irida.model.project.Project)2 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)2