use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.
the class ProjectServiceImpl method addSampleToProject.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@LaunchesProjectEvent(SampleAddedProjectEvent.class)
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SEQUENCER') or (hasPermission(#project, 'isProjectOwner'))")
public ProjectSampleJoin addSampleToProject(Project project, Sample sample, boolean owner) {
logger.trace("Adding sample to project.");
// project already
if (sampleRepository.getSampleBySampleName(project, sample.getSampleName()) != null) {
throw new EntityExistsException("Sample with sequencer id '" + sample.getSampleName() + "' already exists in project " + project.getId());
}
// the relationshipRepository.
if (sample.getId() == null) {
logger.trace("Going to validate and persist sample prior to creating relationship.");
// validate the sample, then persist it:
Set<ConstraintViolation<Sample>> constraintViolations = validator.validate(sample);
if (constraintViolations.isEmpty()) {
sample = sampleRepository.save(sample);
} else {
throw new ConstraintViolationException(constraintViolations);
}
}
ProjectSampleJoin join = new ProjectSampleJoin(project, sample, owner);
try {
return psjRepository.save(join);
} catch (DataIntegrityViolationException e) {
throw new EntityExistsException("Sample [" + sample.getId() + "] has already been added to project [" + project.getId() + "]");
}
}
use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.
the class ProjectServiceImpl method removeUserGroupFromProject.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@LaunchesProjectEvent(UserGroupRemovedProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canManageLocalProjectSettings')")
public void removeUserGroupFromProject(Project project, UserGroup userGroup) throws ProjectWithoutOwnerException {
final UserGroupProjectJoin j = ugpjRepository.findByProjectAndUserGroup(project, userGroup);
if (!allowRoleChange(project, j.getProjectRole())) {
throw new ProjectWithoutOwnerException("Removing this user group would leave the project without an owner.");
}
ugpjRepository.delete(j);
}
use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.
the class ProjectServiceImpl method removeUserFromProject.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@LaunchesProjectEvent(UserRemovedProjectEvent.class)
@PreAuthorize("hasPermission(#project, 'canManageLocalProjectSettings')")
public void removeUserFromProject(Project project, User user) throws ProjectWithoutOwnerException {
ProjectUserJoin projectJoinForUser = pujRepository.getProjectJoinForUser(project, user);
if (!allowRoleChange(projectJoinForUser.getSubject(), projectJoinForUser.getProjectRole())) {
throw new ProjectWithoutOwnerException("Removing this user would leave the project without an owner");
}
pujRepository.delete(projectJoinForUser);
}
use of ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent in project irida by phac-nml.
the class ProjectServiceImpl method moveSamples.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@LaunchesProjectEvent(SampleAddedProjectEvent.class)
@PreAuthorize("hasPermission(#source, 'isProjectOwner') and hasPermission(#destination, 'isProjectOwner') " + "and hasPermission(#samples, 'canReadSample') " + "and ((not #giveOwner) or hasPermission(#samples, 'canUpdateSample') )")
public List<ProjectSampleJoin> moveSamples(Project source, Project destination, Collection<Sample> samples, boolean giveOwner) {
List<ProjectSampleJoin> newJoins = new ArrayList<>();
for (Sample sample : samples) {
ProjectSampleJoin newJoin = moveSampleBetweenProjects(source, destination, sample, giveOwner);
logger.trace("Moved 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 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