Search in sources :

Example 1 with NoStudyDirectoryException

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

the class StudyController method addStudy.

// Save newly added study details
// @ModelAttribute is a reference to the object holding the data entered in the form
@RequestMapping(value = "/new", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public synchronized String addStudy(@Valid @ModelAttribute Study study, BindingResult bindingResult, Model model, HttpServletRequest request) throws NoStudyDirectoryException {
    // If we have errors in the fields entered, i.e they are blank, then return these to form so user can fix
    if (bindingResult.hasErrors()) {
        model.addAttribute("study", study);
        // Return an empty pubmedIdForImport object to store user entered pubmed id
        model.addAttribute("pubmedIdForImport", new PubmedIdForImport());
        return "add_study";
    }
    Study savedStudy = studyOperationsService.createStudy(study, 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) PubmedIdForImport(uk.ac.ebi.spot.goci.curation.model.PubmedIdForImport) NoStudyDirectoryException(uk.ac.ebi.spot.goci.curation.exception.NoStudyDirectoryException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NoStudyDirectoryException

use of uk.ac.ebi.spot.goci.curation.exception.NoStudyDirectoryException 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)2 NoStudyDirectoryException (uk.ac.ebi.spot.goci.curation.exception.NoStudyDirectoryException)2 Study (uk.ac.ebi.spot.goci.model.Study)2 PubmedImportException (uk.ac.ebi.spot.goci.curation.exception.PubmedImportException)1 PubmedIdForImport (uk.ac.ebi.spot.goci.curation.model.PubmedIdForImport)1