Search in sources :

Example 1 with NcbiExportSubmission

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

the class ProjectExportController method getExportsForProject.

/**
 * Ajax method for getting the {@link NcbiExportSubmission}s for a given
 * {@link Project}
 *
 * @param projectId {@link Project} id
 * @param params    Parameters from the datatables request
 * @return DatatablesResponse of Map of submission params
 */
@RequestMapping("/ajax/projects/{projectId}/export/list")
@ResponseBody
public DataTablesResponse getExportsForProject(@DataTablesRequest DataTablesParams params, @PathVariable Long projectId) {
    Project project = projectService.read(projectId);
    List<NcbiExportSubmission> submissions = exportSubmissionService.getSubmissionsForProject(project);
    List<DataTablesResponseModel> dtExportSubmissions = submissions.stream().map(s -> new DTExportSubmission(s)).collect(Collectors.toList());
    return new DataTablesResponse(params, submissions.size(), dtExportSubmissions);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Builder(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder) java.util(java.util) DTExportSubmission(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTExportSubmission) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) Value(org.springframework.beans.factory.annotation.Value) Model(org.springframework.ui.Model) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) Sort(org.springframework.data.domain.Sort) NcbiExportSubmissionService(ca.corefacility.bioinformatics.irida.service.export.NcbiExportSubmissionService) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ca.corefacility.bioinformatics.irida.model.export(ca.corefacility.bioinformatics.irida.model.export) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Principal(java.security.Principal) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Project(ca.corefacility.bioinformatics.irida.model.project.Project) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) DTExportSubmission(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTExportSubmission) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)

Example 2 with NcbiExportSubmission

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

the class ExportUploadServiceTest method testGetResultsSubmitted.

@SuppressWarnings("unchecked")
@Test
public void testGetResultsSubmitted() throws IOException, UploadException {
    NcbiExportSubmissionService exportSubmissionService = mock(NcbiExportSubmissionService.class);
    NcbiBioSampleFiles sample2 = new NcbiBioSampleFiles();
    sample2.setId("NMLTEST2");
    NcbiBioSampleFiles sample3 = new NcbiBioSampleFiles();
    sample3.setId("NMLTEST3");
    NcbiExportSubmission submission = new NcbiExportSubmission();
    submission.setBioSampleFiles(Lists.newArrayList(sample2, sample3));
    submission.setDirectoryPath("submit/Test/example");
    when(exportSubmissionService.getSubmissionsWithState(any(Set.class))).thenReturn(Lists.newArrayList(submission));
    String report = "<?xml version='1.0' encoding='utf-8'?>\n" + "<SubmissionStatus submission_id=\"SUB189884\" status=\"processing\">\n" + "  <Action action_id=\"SUB189884-nmltest2\" target_db=\"SRA\" status=\"processing\">\n" + "    <Response status=\"processing\"/>\n" + "  </Action>\n" + "  <Action action_id=\"SUB189884-nmltest3\" target_db=\"SRA\" status=\"submitted\"/>\n" + "</SubmissionStatus>\n";
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    String submissionDirectory = baseDirectory + "/example";
    String reportFile = submissionDirectory + "/report.2.xml";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(submissionDirectory));
    fileSystem.add(new FileEntry(reportFile, report));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(exportSubmissionService, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        exportUploadService.updateRunningUploads();
    } finally {
        server.stop();
    }
    assertEquals("sample2 should have processing state", ExportUploadState.PROCESSING, sample2.getSubmissionStatus());
    assertEquals("sample3 should have processing state", ExportUploadState.SUBMITTED, sample3.getSubmissionStatus());
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Set(java.util.Set) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) Test(org.junit.Test)

Example 3 with NcbiExportSubmission

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

the class ExportUploadServiceTest method testUploadSubmissionBadServer.

@Test(expected = UploadException.class)
public void testUploadSubmissionBadServer() throws UploadException, IOException {
    NcbiExportSubmission submission = createFakeSubmission();
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    int ftpPort = 1;
    ExportUploadService exportUploadService = new ExportUploadService(null, null, new TestEmailController());
    exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
    String xml = "<xml></xml>";
    exportUploadService.uploadSubmission(submission, xml);
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) Test(org.junit.Test)

Example 4 with NcbiExportSubmission

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

the class ExportUploadServiceTest method testGetResultsWithAccession.

@SuppressWarnings("unchecked")
@Test
public void testGetResultsWithAccession() throws IOException, UploadException {
    NcbiExportSubmissionService exportSubmissionService = mock(NcbiExportSubmissionService.class);
    NcbiBioSampleFiles sample2 = new NcbiBioSampleFiles();
    sample2.setId("NMLTEST2");
    NcbiExportSubmission submission = new NcbiExportSubmission();
    submission.setBioSampleFiles(Lists.newArrayList(sample2));
    submission.setDirectoryPath("submit/Test/example");
    String newAccession = "SRR12345";
    when(exportSubmissionService.getSubmissionsWithState(any(Set.class))).thenReturn(Lists.newArrayList(submission));
    String report = "<?xml version='1.0' encoding='utf-8'?>\n" + "<SubmissionStatus submission_id=\"SUB11245\" status=\"processed-ok\">\n" + "  <Action action_id=\"SUB11245-nmltest2\" target_db=\"SRA\" status=\"processed-ok\" notify_submitter=\"true\">\n" + "    <Response status=\"processed-ok\">\n" + "      <Object target_db=\"SRA\" object_id=\"RUN:3119494\" spuid_namespace=\"NML\" spuid=\"nmltest2\" accession=\"" + newAccession + "\" status=\"updated\">\n" + "        <Meta>\n" + "          <SRAStudy>SRP12345</SRAStudy>\n" + "        </Meta>\n" + "      </Object>\n" + "    </Response>\n" + "  </Action>\n" + "</SubmissionStatus>";
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    String submissionDirectory = baseDirectory + "/example";
    String reportFile = submissionDirectory + "/report.2.xml";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(submissionDirectory));
    fileSystem.add(new FileEntry(reportFile, report));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(exportSubmissionService, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        exportUploadService.updateRunningUploads();
    } finally {
        server.stop();
    }
    assertEquals("sample2 should have processing state", ExportUploadState.PROCESSED_OK, sample2.getSubmissionStatus());
    assertEquals("sample2 should have an accession", newAccession, sample2.getAccession());
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Set(java.util.Set) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) Test(org.junit.Test)

Example 5 with NcbiExportSubmission

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

the class ExportUploadServiceTest method testUploadSubmission.

@Test
public void testUploadSubmission() throws UploadException, IOException {
    NcbiExportSubmission submission = createFakeSubmission();
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(baseDirectory));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(null, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        String xml = "<xml></xml>";
        exportUploadService.uploadSubmission(submission, xml);
    } finally {
        server.stop();
    }
    @SuppressWarnings("unchecked") List<String> listNames = fileSystem.listNames(baseDirectory);
    assertEquals("submission directory exists", 1, listNames.size());
    String createdDirectory = baseDirectory + "/" + listNames.iterator().next();
    assertTrue("submission.xml created", fileSystem.exists(createdDirectory + "/submission.xml"));
    assertTrue("submit.ready created", fileSystem.exists(createdDirectory + "/submit.ready"));
    SequenceFile createdFile = submission.getBioSampleFiles().iterator().next().getFiles().iterator().next().getSequenceFile();
    assertTrue("seqfile created", fileSystem.exists(createdDirectory + "/" + createdFile.getId() + ".fastq"));
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) Test(org.junit.Test)

Aggregations

NcbiExportSubmission (ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission)15 Test (org.junit.Test)9 NcbiBioSampleFiles (ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles)6 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)6 TestEmailController (ca.corefacility.bioinformatics.irida.service.impl.TestEmailController)6 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)5 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)4 UserAccount (org.mockftpserver.fake.UserAccount)4 DirectoryEntry (org.mockftpserver.fake.filesystem.DirectoryEntry)4 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)4 UnixFakeFileSystem (org.mockftpserver.fake.filesystem.UnixFakeFileSystem)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)3 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)3 Date (java.util.Date)3 NcbiXmlParseException (ca.corefacility.bioinformatics.irida.exceptions.NcbiXmlParseException)2 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)2 Builder (ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2