use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin 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.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class RESTAnalysisSubmissionController method getAnalysisInputFilePairs.
/**
* Get the {@link SequenceFilePair}s used for the {@link AnalysisSubmission}
*
* @param identifier
* {@link AnalysisSubmission} id
* @return list of {@link SequenceFilePair}s
*/
@RequestMapping("/{identifier}/sequenceFiles/pairs")
public ModelMap getAnalysisInputFilePairs(@PathVariable Long identifier) {
ModelMap map = new ModelMap();
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(identifier);
Set<SequenceFilePair> pairs = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SequenceFilePair.class);
ResourceCollection<SequenceFilePair> resources = new ResourceCollection<>(pairs.size());
for (SequenceFilePair pair : pairs) {
SampleSequencingObjectJoin join = sampleService.getSampleForSequencingObject(pair);
if (join != null) {
Long sampleId = join.getSubject().getId();
pair = RESTSampleSequenceFilesController.addSequencingObjectLinks(pair, sampleId);
resources.add(pair);
}
}
resources.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisInputFilePairs(identifier)).withSelfRel());
map.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
return map;
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class ProjectSamplesControllerTest method testDownloadSamples.
@Test
public void testDownloadSamples() throws IOException {
Project project = TestDataFactory.constructProject();
Sample sample = TestDataFactory.constructSample();
MockHttpServletResponse response = new MockHttpServletResponse();
Path path = Paths.get(FILE_PATH);
SequenceFile file = new SequenceFile(path);
ImmutableList<SampleSequencingObjectJoin> filejoin = ImmutableList.of(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(projectService.read(project.getId())).thenReturn(project);
when(sampleService.readMultiple(ImmutableList.of(sample.getId()))).thenReturn(ImmutableList.of(sample));
when(sequencingObjectService.getSequencingObjectsForSample(sample)).thenReturn(filejoin);
controller.downloadSamples(project.getId(), ImmutableList.of(sample.getId()), response);
verify(projectService).read(project.getId());
verify(sampleService).readMultiple(ImmutableList.of(sample.getId()));
verify(sequencingObjectService).getSequencingObjectsForSample(sample);
assertTrue("Response should contain a \"Content-Disposition\" header.", response.containsHeader("Content-Disposition"));
assertEquals("Content-Disposition should include the file name", "attachment; filename=\"test_project.zip\"", response.getHeader("Content-Disposition"));
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray()))) {
ZipEntry nextEntry = zipStream.getNextEntry();
String fileName = nextEntry.getName();
assertTrue("incorrect file in zip stream: " + file.getFileName(), fileName.endsWith(file.getFileName()));
}
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.
the class ProjectSamplesControllerTest method testDownloadSamplesWithSameName.
@Test
public void testDownloadSamplesWithSameName() throws IOException {
Project project = TestDataFactory.constructProject();
Sample sample = TestDataFactory.constructSample();
MockHttpServletResponse response = new MockHttpServletResponse();
Path path = Paths.get(FILE_PATH);
SequenceFile file = new SequenceFile(path);
ImmutableList<SampleSequencingObjectJoin> filejoin = ImmutableList.of(new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)), new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)), new SampleSequencingObjectJoin(sample, new SingleEndSequenceFile(file)));
when(projectService.read(project.getId())).thenReturn(project);
when(sampleService.readMultiple(ImmutableList.of(sample.getId()))).thenReturn(ImmutableList.of(sample));
when(sequencingObjectService.getSequencingObjectsForSample(sample)).thenReturn(filejoin);
controller.downloadSamples(project.getId(), ImmutableList.of(sample.getId()), response);
verify(projectService).read(project.getId());
verify(sampleService).readMultiple(ImmutableList.of(sample.getId()));
verify(sequencingObjectService).getSequencingObjectsForSample(sample);
assertTrue("Response should contain a \"Content-Disposition\" header.", response.containsHeader("Content-Disposition"));
assertEquals("Content-Disposition should include the file name", "attachment; filename=\"test_project.zip\"", response.getHeader("Content-Disposition"));
try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(response.getContentAsByteArray()))) {
Set<String> names = new HashSet<>();
ZipEntry nextEntry = zipStream.getNextEntry();
while (nextEntry != null) {
names.add(nextEntry.getName());
nextEntry = zipStream.getNextEntry();
}
assertEquals("should be 3 unique filenames", 3, names.size());
}
}
use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin 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