Search in sources :

Example 1 with PubmedImportException

use of uk.ac.ebi.spot.goci.curation.exception.PubmedImportException in project goci by EBISPOT.

the class StudyController method importStudy.

// Save study found by Pubmed Id
// @ModelAttribute is a reference to the object holding the data entered in the form
@RequestMapping(value = "/new/import", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public synchronized String importStudy(@ModelAttribute PubmedIdForImport pubmedIdForImport, HttpServletRequest request, Model model) throws PubmedImportException, NoStudyDirectoryException {
    // Remove whitespace
    String pubmedId = pubmedIdForImport.getPubmedId().trim();
    // Check if there is an existing study with the same pubmed id
    Collection<Study> existingStudies = studyRepository.findByPubmedId(pubmedId);
    if (existingStudies.size() > 0) {
        throw new PubmedImportException();
    } else {
        // Pass to importer
        Study importedStudy = defaultPubMedSearchService.findPublicationSummary(pubmedId);
        Study savedStudy = studyOperationsService.createStudy(importedStudy, currentUserDetailsService.getUserFromRequest(request));
        // Create directory to store associated files
        try {
            studyFileService.createStudyDir(savedStudy.getId());
        } catch (NoStudyDirectoryException e) {
            getLog().error("No study directory exception");
            model.addAttribute("study", savedStudy);
            return "error_pages/study_dir_failure";
        }
        return "redirect:/studies/" + savedStudy.getId();
    }
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) NoStudyDirectoryException(uk.ac.ebi.spot.goci.curation.exception.NoStudyDirectoryException) PubmedImportException(uk.ac.ebi.spot.goci.curation.exception.PubmedImportException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 NoStudyDirectoryException (uk.ac.ebi.spot.goci.curation.exception.NoStudyDirectoryException)1 PubmedImportException (uk.ac.ebi.spot.goci.curation.exception.PubmedImportException)1 Study (uk.ac.ebi.spot.goci.model.Study)1