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