Search in sources :

Example 36 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class ReadSequencingObjectPermissionTest method testRejectPermission.

@Test
public void testRejectPermission() {
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
    when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertFalse("permission was granted.", permission.isAllowed(auth, 1L));
    verify(sequencingObjectRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(ssoRepository).getSampleForSequencingObject(sf);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 37 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class ReadSequencingObjectPermissionTest method testGrantPermission.

@Test
public void testGrantPermission() {
    Project p = new Project();
    Sample s = new Sample();
    List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
    projectSampleList.add(new ProjectSampleJoin(p, s, true));
    SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
    SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
    when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
    when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
    when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
    when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertTrue("permission was not granted.", permission.isAllowed(auth, 1L));
    verify(sequencingObjectRepository).findOne(1L);
    verify(psjRepository).getProjectForSample(s);
    verify(ssoRepository).getSampleForSequencingObject(sf);
    verify(readProjectPermission).isAllowed(any(), eq(p));
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Example 38 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class TestDataFactory method generateSequencingObjectsForSample.

public static List<SampleSequencingObjectJoin> generateSequencingObjectsForSample(Sample sample) {
    List<SampleSequencingObjectJoin> join = new ArrayList<>();
    for (long i = 0; i < 5; i++) {
        Path path = Paths.get("/tmp/sequence-files/fake-file" + Math.random() + ".fast");
        SequenceFile file = new SequenceFile(path);
        file.setId(i);
        SingleEndSequenceFile obj = new SingleEndSequenceFile(file);
        obj.setId(i);
        join.add(new SampleSequencingObjectJoin(sample, obj));
    }
    return join;
}
Also used : Path(java.nio.file.Path) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) ArrayList(java.util.ArrayList) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 39 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class SequencingObjectServiceImplIT method testGetUnpairedFilesForSample.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetUnpairedFilesForSample() {
    Sample s = sampleService.read(2L);
    Collection<SampleSequencingObjectJoin> sequencesForSampleOfType = objectService.getSequencesForSampleOfType(s, SingleEndSequenceFile.class);
    assertEquals(1, sequencesForSampleOfType.size());
    SampleSequencingObjectJoin join = sequencesForSampleOfType.iterator().next();
    assertEquals(new Long(4), join.getObject().getId());
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 40 with SampleSequencingObjectJoin

use of ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin in project irida by phac-nml.

the class SequencingObjectServiceImplIT method testConcatenateSequenceFiles.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testConcatenateSequenceFiles() throws IOException, InterruptedException, ConcatenateException {
    String newFileName = "newname";
    Sample sample = sampleService.read(1L);
    SequenceFile file1 = createSequenceFile("file1");
    SequenceFile file2 = createSequenceFile("file2");
    long originalLength = file1.getFile().toFile().length();
    SequencingObject so1 = new SingleEndSequenceFile(file1);
    SequencingObject so2 = new SingleEndSequenceFile(file2);
    SampleSequencingObjectJoin join1 = objectService.createSequencingObjectInSample(so1, sample);
    SampleSequencingObjectJoin join2 = objectService.createSequencingObjectInSample(so2, sample);
    // Wait 5 seconds. file processing should have run by then.
    Thread.sleep(5000);
    // re-read the original files so file processing will be complete
    so1 = objectService.read(join1.getObject().getId());
    so2 = objectService.read(join2.getObject().getId());
    Collection<SampleSequencingObjectJoin> originalSeqs = objectService.getSequencingObjectsForSample(sample);
    List<SequencingObject> fileSet = Lists.newArrayList(so1, so2);
    SampleSequencingObjectJoin concatenateSequences = objectService.concatenateSequences(fileSet, newFileName, sample, false);
    // Wait 5 seconds. file processing should have run by then.
    Thread.sleep(5000);
    Collection<SampleSequencingObjectJoin> newSeqs = objectService.getSequencingObjectsForSample(sample);
    // re-read the concatenated file so file processing will be complete
    concatenateSequences = sampleService.getSampleForSequencingObject(concatenateSequences.getObject());
    assertTrue("new seq collection should contain originals", newSeqs.containsAll(originalSeqs));
    assertTrue("new seq collection should contain new object", newSeqs.contains(concatenateSequences));
    assertEquals("new seq collection should have 1 more object", originalSeqs.size() + 1, newSeqs.size());
    SequencingObject newSeqObject = concatenateSequences.getObject();
    SequenceFile newFile = newSeqObject.getFiles().iterator().next();
    assertTrue("new file should contain new name", newFile.getFileName().contains(newFileName));
    long newFileSize = newFile.getFile().toFile().length();
    assertEquals("new file should be 2x size of originals", originalLength * 2, newFileSize);
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) WithMockUser(org.springframework.security.test.context.support.WithMockUser) 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