Search in sources :

Example 11 with NcbiExportSubmission

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

the class ExportUploadServiceTest method testUploadSubmissionBadCredentials.

@Test(expected = UploadException.class)
public void testUploadSubmissionBadCredentials() 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();
    // 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) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) Test(org.junit.Test)

Example 12 with NcbiExportSubmission

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

the class NcbiExportSubmissionServceTest method testCreate.

@Test
public void testCreate() {
    SingleEndSequenceFile sequenceFile = new SingleEndSequenceFile(new SequenceFile());
    NcbiBioSampleFiles ncbiBioSampleFiles = new NcbiBioSampleFiles("sample", Lists.newArrayList(sequenceFile), 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);
    verify(repository).save(submission);
}
Also used : 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) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Date(java.util.Date) Test(org.junit.Test)

Example 13 with NcbiExportSubmission

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

the class ExportUploadService method launchUpload.

/**
 * Check for new {@link NcbiExportSubmission}s to be uploaded and begin
 * their upload
 */
public synchronized void launchUpload() {
    logger.trace("Getting new exports");
    List<NcbiExportSubmission> submissionsWithState = exportSubmissionService.getSubmissionsWithState(ExportUploadState.NEW);
    for (NcbiExportSubmission submission : submissionsWithState) {
        try {
            logger.trace("Updating submission " + submission.getId());
            submission.setUploadState(ExportUploadState.UPLOADING);
            submission = exportSubmissionService.update(submission);
            String xmlContent = createXml(submission);
            submission = uploadSubmission(submission, xmlContent);
            submission.setUploadState(ExportUploadState.UPLOADED);
            submission = exportSubmissionService.update(submission);
        } catch (Exception e) {
            logger.error("Upload failed", e);
            submission.setUploadState(ExportUploadState.UPLOAD_ERROR);
            submission = exportSubmissionService.update(submission);
            emailController.sendNCBIUploadExceptionEmail(notificationAdminEmail, e, submission.getId());
        }
    }
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) 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)

Example 14 with NcbiExportSubmission

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

the class ProjectExportController method getDetailsView.

/**
 * Get the details view of a given {@link NcbiExportSubmission}
 *
 * @param projectId
 *            ID of the {@link Project} the export is for
 * @param submissionId
 *            the {@link NcbiExportSubmission} id
 * @param model
 *            model for the view
 * @return name of the details view
 */
@RequestMapping("/projects/{projectId}/export/{submissionId}")
public String getDetailsView(@PathVariable Long projectId, @PathVariable Long submissionId, Model model) {
    NcbiExportSubmission submission = exportSubmissionService.read(submissionId);
    Project project = projectService.read(projectId);
    model.addAttribute("submission", submission);
    model.addAttribute("activeNav", "export");
    model.addAttribute("project", project);
    return EXPORT_DETAILS_VIEW;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission)

Example 15 with NcbiExportSubmission

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

the class ProjectExportController method submitToNcbi.

/**
 * Save an NCBI submission to the database
 *
 * @param projectId
 *            the ID of the {@link Project} for the submission
 * @param submission
 *            A {@link SubmissionBody} describing the files to upload
 * @param principal
 *            the user submitting the upload
 * @return ID of the submission if successful
 * @throws InterruptedException
 *             if thread was not successfully put to sleep
 */
@RequestMapping(value = "/projects/{projectId}/export/ncbi", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> submitToNcbi(@PathVariable Long projectId, @RequestBody SubmissionBody submission, Principal principal) throws InterruptedException {
    Project project = projectService.read(projectId);
    User submitter = userService.getUserByUsername(principal.getName());
    List<NcbiBioSampleFiles> bioSampleFiles = new ArrayList<>();
    for (BioSampleBody sample : submission.getSamples()) {
        List<SingleEndSequenceFile> singleFiles = new ArrayList<>();
        sequencingObjectService.readMultiple(sample.getSingle()).forEach(f -> singleFiles.add((SingleEndSequenceFile) f));
        List<SequenceFilePair> paired = new ArrayList<>();
        sequencingObjectService.readMultiple(sample.getPaired()).forEach(f -> paired.add((SequenceFilePair) f));
        Builder sampleBuilder = new NcbiBioSampleFiles.Builder();
        sampleBuilder.bioSample(sample.getBioSample()).files(singleFiles).pairs(paired).instrumentModel(sample.getInstrumentModel()).libraryConstructionProtocol(sample.getLibraryConstructionProtocol()).libraryName(sample.getLibraryName()).librarySelection(sample.getLibrarySelection()).librarySource(sample.getLibrarySource()).libraryStrategy(sample.getLibraryStrategy()).namespace(submission.getNamespace());
        NcbiBioSampleFiles build = sampleBuilder.build();
        bioSampleFiles.add(build);
    }
    NcbiExportSubmission ncbiExportSubmission = new NcbiExportSubmission(project, submitter, submission.getBioProject(), submission.getOrganization(), submission.getNamespace(), submission.getReleaseDate(), bioSampleFiles);
    ncbiExportSubmission = exportSubmissionService.create(ncbiExportSubmission);
    return ImmutableMap.of("submissionId", ncbiExportSubmission.getId());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) User(ca.corefacility.bioinformatics.irida.model.user.User) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Builder(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)

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