Search in sources :

Example 6 with FileUploadException

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

the class AssociationController method getValidationResult.

@RequestMapping(value = "/studies/{studyId}/associations/getValidationResults", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String getValidationResult(@PathVariable Long studyId, HttpSession session, Model model, RedirectAttributes redirectAttributes) throws ExecutionException, InterruptedException, SheetProcessingException, FileUploadException, IOException {
    Study study = studyRepository.findOne(studyId);
    model.addAttribute("study", study);
    Future<Boolean> f = (Future<Boolean>) session.getAttribute("future");
    f.get();
    Exception exception = (Exception) session.getAttribute("exception");
    if (exception == null) {
        model.addAttribute("status", "OK");
    } else {
        model.addAttribute("status", exception.getMessage());
    }
    // if an association has critical errors, go straight to that association
    if (session.getAttribute("criticalErrorsFound") != null) {
        Association association = associationRepository.getOne((Long) session.getAttribute("associationId"));
        model.addAttribute("study", study);
        model.addAttribute("measurementType", session.getAttribute("measurementType"));
        // Get mapping details
        model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(association));
        // Return any association errors
        model.addAttribute("errors", session.getAttribute("errors"));
        model.addAttribute("criticalErrorsFound", true);
        if (association.getSnpInteraction()) {
            model.addAttribute("form", associationOperationsService.generateForm(association));
            return "redirect:/associations/" + association.getId();
        } else {
            model.addAttribute("form", associationOperationsService.generateForm(association));
            // Determine view
            if (association.getMultiSnpHaplotype()) {
                return "redirect:/associations/" + association.getId();
            } else {
                return "redirect:/associations/" + association.getId();
            }
        }
    } else {
        String message = "Mapping complete, please check for any errors displayed in the 'Errors' column";
        redirectAttributes.addFlashAttribute("mappingComplete", message);
        return "redirect:/studies/" + studyId + "/associations";
    }
}
Also used : LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) Future(java.util.concurrent.Future) FileNotFoundException(java.io.FileNotFoundException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with FileUploadException

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

the class DiseaseTraitDtoAssembler method disassemble.

public static List<DiseaseTrait> disassemble(MultipartFile multipartFile) {
    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = FileHandler.getSchemaFromMultiPartFile(multipartFile);
    List<DiseaseTraitDto> diseaseTraitDtos;
    try {
        InputStream inputStream = multipartFile.getInputStream();
        MappingIterator<DiseaseTraitDto> iterator = mapper.readerFor(DiseaseTraitDto.class).with(schema).readValues(inputStream);
        diseaseTraitDtos = iterator.readAll();
    } catch (IOException ex) {
        throw new FileUploadException("Could not read the file");
    }
    List<DiseaseTrait> diseaseTraits = new ArrayList<>();
    diseaseTraitDtos.forEach(diseaseTraitDTO -> {
        DiseaseTrait diseaseTrait = new DiseaseTrait();
        diseaseTrait.setTrait(diseaseTraitDTO.getTrait());
        diseaseTraits.add(diseaseTrait);
    });
    return diseaseTraits;
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) DiseaseTrait(uk.ac.ebi.spot.goci.model.DiseaseTrait) InputStream(java.io.InputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ArrayList(java.util.ArrayList) DiseaseTraitDto(uk.ac.ebi.spot.goci.curation.dto.DiseaseTraitDto) IOException(java.io.IOException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException)

Example 8 with FileUploadException

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

the class AssociationUploadServiceTest method uploadBlankFile.

@Test(expected = FileUploadException.class)
public void uploadBlankFile() throws Exception {
    MockMultipartFile blankFile = new MockMultipartFile("data", "filename.txt", "text/plain", "".getBytes());
    doThrow(new FileUploadException()).when(studyFileService).upload(blankFile, STUDY.getId());
    associationUploadService.upload(blankFile, STUDY, SECURE_USER);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) Test(org.junit.Test)

Example 9 with FileUploadException

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

the class AssociationController method getUploadResult.

@RequestMapping(value = "/studies/{studyId}/associations/getUploadResults", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String getUploadResult(@PathVariable Long studyId, HttpSession session, Model model) throws ExecutionException, InterruptedException, SheetProcessingException, FileUploadException, IOException {
    Study study = studyRepository.findOne(studyId);
    model.addAttribute("study", study);
    Future<Boolean> f = (Future<Boolean>) session.getAttribute("future");
    f.get();
    Exception exception = (Exception) session.getAttribute("exception");
    if (exception == null) {
        model.addAttribute("status", "OK");
    } else {
        model.addAttribute("status", exception.getMessage());
    }
    if (session.getAttribute("ensemblMappingFailure") != null) {
        return "ensembl_mapping_failure";
    }
    List<AssociationUploadErrorView> fileErrors = (List<AssociationUploadErrorView>) session.getAttribute("fileErrors");
    List<AssociationUploadErrorView> xlsErrors = (List<AssociationUploadErrorView>) session.getAttribute("xlsErrors");
    if ((session.getAttribute("fileErrors") != null && !fileErrors.isEmpty()) || ((session.getAttribute("xlsErrors") != null && !xlsErrors.isEmpty()))) {
        getLog().debug("Shutting down executor service...");
        model.addAttribute("fileName", session.getAttribute("fileName"));
        model.addAttribute("fileErrors", fileErrors);
        model.addAttribute("xlsErrors", xlsErrors);
        return "error_pages/association_file_upload_error";
    } else {
        return "redirect:/studies/" + studyId + "/associations";
    }
}
Also used : AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) Future(java.util.concurrent.Future) FileNotFoundException(java.io.FileNotFoundException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) DataIntegrityException(uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FileUploadException (uk.ac.ebi.spot.goci.curation.exception.FileUploadException)9 IOException (java.io.IOException)7 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)4 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)4 InputStream (java.io.InputStream)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 DataIntegrityException (uk.ac.ebi.spot.goci.curation.exception.DataIntegrityException)2 EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)2 SheetProcessingException (uk.ac.ebi.spot.goci.exception.SheetProcessingException)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1