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;
}
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);
}
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);
}
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);
}
}
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();
}
}
Aggregations