use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class UpdateSamplePermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
final Project p1 = new Project();
final Project p2 = new Project();
final Sample s = new Sample();
when(projectSampleJoinRepository.getProjectForSample(s)).thenReturn(ImmutableList.of(new ProjectSampleJoin(p1, s, true), new ProjectSampleJoin(p2, s, true)));
when(projectOwnerPermission.isAllowed(auth, p1)).thenReturn(true);
when(projectOwnerPermission.isAllowed(auth, p2)).thenReturn(true);
assertTrue("Permission to update sample should be given.", updateSamplePermission.isAllowed(auth, s));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class UpdateSamplePermissionTest method testRejectPermissionWithNoProjects.
@Test
public void testRejectPermissionWithNoProjects() {
final Project p1 = new Project();
final Project p2 = new Project();
final Sample s = new Sample();
when(projectSampleJoinRepository.getProjectForSample(s)).thenReturn(ImmutableList.of(new ProjectSampleJoin(p1, s, true), new ProjectSampleJoin(p2, s, true)));
when(projectOwnerPermission.isAllowed(auth, p1)).thenReturn(false);
when(projectOwnerPermission.isAllowed(auth, p2)).thenReturn(false);
assertFalse("Permission to update sample should not be given.", updateSamplePermission.isAllowed(auth, s));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class TestDataFactory method getPageOfProjectSampleJoin.
public static Page<ProjectSampleJoin> getPageOfProjectSampleJoin() {
return new Page<ProjectSampleJoin>() {
@Override
public int getTotalPages() {
return 1;
}
@Override
public long getTotalElements() {
return 1;
}
@Override
public int getNumber() {
return 1;
}
@Override
public int getSize() {
return 1;
}
@Override
public int getNumberOfElements() {
return 1;
}
@Override
public List<ProjectSampleJoin> getContent() {
Project project = new Project("Joined Project");
project.setId(1L);
Sample sample = new Sample("Joined Sample");
sample.setId(23L);
ProjectSampleJoin join = new ProjectSampleJoin(project, sample, true);
return ImmutableList.of(join);
}
@Override
public boolean hasContent() {
return false;
}
@Override
public Sort getSort() {
return null;
}
@Override
public boolean isFirst() {
return false;
}
@Override
public boolean isLast() {
return false;
}
@Override
public boolean hasNext() {
return false;
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public Pageable nextPageable() {
return null;
}
@Override
public Pageable previousPageable() {
return null;
}
@Override
public Iterator<ProjectSampleJoin> iterator() {
return null;
}
};
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class SampleServiceImpl method mergeSamples.
/**
* {@inheritDoc}
*/
@Override
@Transactional
@PreAuthorize("hasPermission(#project, 'isProjectOwner') and hasPermission(#mergeInto, 'canUpdateSample') and hasPermission(#toMerge, 'canUpdateSample')")
public Sample mergeSamples(Project project, Sample mergeInto, Collection<Sample> toMerge) {
// confirm that all samples are part of the same project:
confirmProjectSampleJoin(project, mergeInto);
logger.debug("Merging samples " + toMerge.stream().map(t -> t.getId()).collect(Collectors.toList()) + " into sample [" + mergeInto.getId() + "]");
for (Sample s : toMerge) {
confirmProjectSampleJoin(project, s);
List<SampleSequencingObjectJoin> sequencesForSample = ssoRepository.getSequencesForSample(s);
for (SampleSequencingObjectJoin join : sequencesForSample) {
SequencingObject sequencingObject = join.getObject();
ssoRepository.delete(join);
addSequencingObjectToSample(mergeInto, sequencingObject);
}
Collection<SampleGenomeAssemblyJoin> genomeAssemblyJoins = getAssembliesForSample(s);
for (SampleGenomeAssemblyJoin join : genomeAssemblyJoins) {
GenomeAssembly genomeAssembly = join.getObject();
logger.trace("Removing genome assembly [" + genomeAssembly.getId() + "] from sample [" + s.getId() + "]");
sampleGenomeAssemblyJoinRepository.delete(join);
logger.trace("Adding genome assembly [" + genomeAssembly.getId() + "] to sample [" + mergeInto.getId() + "]");
SampleGenomeAssemblyJoin newJoin = new SampleGenomeAssemblyJoin(mergeInto, genomeAssembly);
sampleGenomeAssemblyJoinRepository.save(newJoin);
}
// have to remove the sample to be deleted from its project:
ProjectSampleJoin readSampleForProject = psjRepository.readSampleForProject(project, s);
psjRepository.delete(readSampleForProject);
sampleRepository.delete(s.getId());
}
return mergeInto;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin 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() + "]");
}
}
Aggregations