Search in sources :

Example 6 with NcbiExportSubmission

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

the class ExportUploadServiceTest method createFakeSubmission.

/**
 * Create a fake submission for test uploads
 *
 * @return a {@link NcbiExportSubmission}
 * @throws IOException
 *             if the test file couldn't be created
 */
private NcbiExportSubmission createFakeSubmission() throws IOException {
    NcbiExportSubmission submission = new NcbiExportSubmission();
    submission.setId(1L);
    NcbiBioSampleFiles ncbiBioSampleFiles = new NcbiBioSampleFiles();
    Path tempFile = Files.createTempFile("sequencefile", ".fastq");
    SequenceFile sequenceFile = new SequenceFile(tempFile);
    sequenceFile.setId(1L);
    SingleEndSequenceFile singleFile = new SingleEndSequenceFile(sequenceFile);
    singleFile.setId(1L);
    ncbiBioSampleFiles.setFiles(Lists.newArrayList(singleFile));
    submission.setBioSampleFiles(Lists.newArrayList(ncbiBioSampleFiles));
    return submission;
}
Also used : Path(java.nio.file.Path) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

Example 7 with NcbiExportSubmission

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

the class NcbiExportSubmissionServceTest method testCreateNoFiles.

@Test(expected = IllegalArgumentException.class)
public void testCreateNoFiles() {
    NcbiBioSampleFiles ncbiBioSampleFiles = new NcbiBioSampleFiles("sample", Lists.newArrayList(), Lists.newArrayList(), null, "library_name", null, null, null, "library_construction_protocol", "namespace");
    NcbiExportSubmission submission = new NcbiExportSubmission(null, null, "bioProjectId", "organization", "ncbiNamespace", new Date(), Lists.newArrayList(ncbiBioSampleFiles));
    service.create(submission);
}
Also used : NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Date(java.util.Date) Test(org.junit.Test)

Example 8 with NcbiExportSubmission

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

the class NcbiExportSubmissionServceTest method testCreatePairs.

@Test
public void testCreatePairs() {
    SequenceFile sequenceFile = new SequenceFile();
    NcbiBioSampleFiles ncbiBioSampleFiles = new NcbiBioSampleFiles("sample", Lists.newArrayList(), Lists.newArrayList(new SequenceFilePair(sequenceFile, sequenceFile)), null, "library_name", null, null, null, "library_construction_protocol", "namespace");
    NcbiExportSubmission submission = new NcbiExportSubmission(null, null, "bioProjectId", "organization", "ncbiNamespace", new Date(), Lists.newArrayList(ncbiBioSampleFiles));
    service.create(submission);
    verify(repository).save(submission);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Date(java.util.Date) Test(org.junit.Test)

Example 9 with NcbiExportSubmission

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

the class ExportUploadService method updateRunningUploads.

/**
 * Check local database for submissions which may have updates on the NCBI
 * server and update them as necessary.
 */
public synchronized void updateRunningUploads() {
    logger.trace("Getting running exports");
    List<NcbiExportSubmission> submissionsWithState = exportSubmissionService.getSubmissionsWithState(updateableStates);
    FTPClient client = null;
    try {
        for (NcbiExportSubmission submission : submissionsWithState) {
            // connect to FTP site
            client = getFtpClient();
            try {
                logger.trace("Getting report for submission " + submission.getId());
                InputStream xmlStream = getLatestXMLStream(client, submission);
                if (xmlStream != null) {
                    NcbiExportSubmission updateSubmissionForXml = updateSubmissionForXml(submission, xmlStream);
                    exportSubmissionService.update(updateSubmissionForXml);
                    xmlStream.close();
                }
            } catch (NcbiXmlParseException e) {
                logger.error("Error getting response", e);
                submission.setUploadState(ExportUploadState.UPLOAD_ERROR);
                submission = exportSubmissionService.update(submission);
                emailController.sendNCBIUploadExceptionEmail(notificationAdminEmail, e, submission.getId());
            } catch (IOException e) {
                logger.error("Error closing XML stream", e);
            }
        }
        disconnectFtpCient(client);
    } catch (Exception e) {
        logger.error("Couldn't connect to FTP site", e);
    } finally {
        disconnectFtpCient(client);
    }
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FTPClient(org.apache.commons.net.ftp.FTPClient) XPathExpressionException(javax.xml.xpath.XPathExpressionException) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) NcbiXmlParseException(ca.corefacility.bioinformatics.irida.exceptions.NcbiXmlParseException) NcbiXmlParseException(ca.corefacility.bioinformatics.irida.exceptions.NcbiXmlParseException)

Example 10 with NcbiExportSubmission

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

the class ExportUploadServiceTest method testUploadSubmissionNoBaseDirectory.

@Test(expected = UploadException.class)
public void testUploadSubmissionNoBaseDirectory() 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("/home/test"));
    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();
    }
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) 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