Search in sources :

Example 31 with SampleSequencingObjectJoin

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));
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UserRoleSetProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent) UserRemovedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.UserRemovedProjectEvent) DataAddedToSampleProjectEvent(ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent) ProjectEvent(ca.corefacility.bioinformatics.irida.model.event.ProjectEvent) SampleAddedProjectEvent(ca.corefacility.bioinformatics.irida.model.event.SampleAddedProjectEvent) Test(org.junit.Test)

Example 32 with SampleSequencingObjectJoin

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;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with SampleSequencingObjectJoin

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()));
    }
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ZipInputStream(java.util.zip.ZipInputStream) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ZipEntry(java.util.zip.ZipEntry) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Example 34 with SampleSequencingObjectJoin

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());
    }
}
Also used : Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ZipEntry(java.util.zip.ZipEntry) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ZipInputStream(java.util.zip.ZipInputStream) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 35 with SampleSequencingObjectJoin

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);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Aggregations

SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)54 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)45 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)30 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)30 Test (org.junit.Test)29 Project (ca.corefacility.bioinformatics.irida.model.project.Project)21 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)16 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)14 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)11 Path (java.nio.file.Path)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ModelMap (org.springframework.ui.ModelMap)9 ArrayList (java.util.ArrayList)8 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)7 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)5 DataAddedToSampleProjectEvent (ca.corefacility.bioinformatics.irida.model.event.DataAddedToSampleProjectEvent)4 User (ca.corefacility.bioinformatics.irida.model.user.User)4