use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin 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.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventMultipleProjects.
@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventMultipleProjects() {
Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
Project project = new Project("p1");
Project project2 = new Project("p2");
Sample sample = new Sample();
SequenceFile file = new SequenceFile();
SingleEndSequenceFile seqObj = new SingleEndSequenceFile(file);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(sample, seqObj);
when(psjRepository.getProjectForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true), new ProjectSampleJoin(project2, sample, true)));
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new DataAddedToSampleProjectEvent(project, sample));
Object[] args = {};
MethodEvent methodEvent = new MethodEvent(clazz, join, args);
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository, times(2)).save(captor.capture());
List<ProjectEvent> allValues = captor.getAllValues();
Set<Project> projects = Sets.newHashSet(project, project2);
for (ProjectEvent event : allValues) {
assertTrue(event instanceof DataAddedToSampleProjectEvent);
Project eventProject = event.getProject();
assertTrue(projects.contains(eventProject));
projects.remove(eventProject);
}
verify(projectRepository, times(2)).save(project);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectEventHandlerTest method testHandleSequenceFileAddedEventSingle.
@SuppressWarnings("unchecked")
@Test
public void testHandleSequenceFileAddedEventSingle() {
Class<? extends ProjectEvent> clazz = DataAddedToSampleProjectEvent.class;
Project project = new Project();
Sample sample = new Sample();
SequenceFile file = new SequenceFile();
SingleEndSequenceFile seqObj = new SingleEndSequenceFile(file);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(sample, seqObj);
when(psjRepository.getProjectForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
when(eventRepository.save(any(ProjectEvent.class))).thenReturn(new DataAddedToSampleProjectEvent(project, sample));
Object[] args = {};
MethodEvent methodEvent = new MethodEvent(clazz, join, args);
handler.delegate(methodEvent);
ArgumentCaptor<ProjectEvent> captor = ArgumentCaptor.forClass(ProjectEvent.class);
verify(eventRepository).save(captor.capture());
ProjectEvent event = captor.getValue();
assertTrue(event instanceof DataAddedToSampleProjectEvent);
verify(projectRepository).save(any(Project.class));
verify(sampleRepository).save(any(Sample.class));
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class ProjectSamplesControllerTest method testShareSampleToProject.
@SuppressWarnings("unchecked")
@Test
public void testShareSampleToProject() {
Long projectId = 1L;
List<Long> sampleIds = ImmutableList.of(2L, 3L);
Long newProjectId = 4L;
boolean removeFromOriginal = false;
Project oldProject = new Project("oldProject");
Project newProject = new Project("newProject");
Sample s2 = new Sample("s2");
Sample s3 = new Sample("s3");
ArrayList<Sample> sampleList = Lists.newArrayList(s2, s3);
boolean owner = true;
ArrayList<ProjectSampleJoin> joins = Lists.newArrayList(new ProjectSampleJoin(newProject, s2, owner), new ProjectSampleJoin(newProject, s3, owner));
when(projectService.read(projectId)).thenReturn(oldProject);
when(projectService.read(newProjectId)).thenReturn(newProject);
when(sampleService.readMultiple(any(Iterable.class))).thenReturn(sampleList);
when(projectService.shareSamples(oldProject, newProject, sampleList, owner)).thenReturn(joins);
controller.shareSampleToProject(projectId, sampleIds, newProjectId, removeFromOriginal, true, Locale.US);
verify(projectService).read(projectId);
verify(projectService).read(newProjectId);
verify(projectService).shareSamples(oldProject, newProject, sampleList, owner);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.
the class SamplesControllerTest method testGetSampleFilesNoAccess.
@SuppressWarnings("unchecked")
@Test
public void testGetSampleFilesNoAccess() throws IOException {
ExtendedModelMap model = new ExtendedModelMap();
Long sampleId = 1L;
Sample sample = new Sample();
SequenceFile file = new SequenceFile(Paths.get("/tmp"));
file.setId(2L);
Project project = new Project();
List<SampleSequencingObjectJoin> files = Lists.newArrayList(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class)).thenReturn(files);
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(false);
when(projectService.getProjectsForSample(sample)).thenReturn(Lists.newArrayList(new ProjectSampleJoin(project, sample, true)));
String sampleFiles = controller.getSampleFilesWithoutProject(model, sampleId);
assertEquals(SamplesController.SAMPLE_FILES_PAGE, sampleFiles);
assertFalse((boolean) model.get(SamplesController.MODEL_ATTR_CAN_MANAGE_SAMPLE));
verify(sampleService).read(sampleId);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
verify(sequencingObjectService).getSequencesForSampleOfType(sample, SequenceFilePair.class);
}
Aggregations