Search in sources :

Example 1 with StudyPatchRequest

use of uk.ac.ebi.spot.goci.curation.dto.StudyPatchRequest in project goci by EBISPOT.

the class FileHandler method getStudyPatchRequests.

public static List<StudyPatchRequest> getStudyPatchRequests(FileUploadRequest fileUploadRequest) {
    CsvMapper mapper = new CsvMapper();
    CsvSchema schema = getSchemaFromMultiPartFile(fileUploadRequest.getMultipartFile());
    List<StudyPatchRequest> studyPatchRequests;
    try {
        InputStream inputStream = fileUploadRequest.getMultipartFile().getInputStream();
        MappingIterator<StudyPatchRequest> iterator = mapper.readerFor(StudyPatchRequest.class).with(schema).readValues(inputStream);
        studyPatchRequests = iterator.readAll();
    } catch (IOException e) {
        throw new FileUploadException("Could not read the file");
    }
    return studyPatchRequests;
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) InputStream(java.io.InputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) IOException(java.io.IOException) FileUploadException(uk.ac.ebi.spot.goci.curation.exception.FileUploadException) StudyPatchRequest(uk.ac.ebi.spot.goci.curation.dto.StudyPatchRequest)

Example 2 with StudyPatchRequest

use of uk.ac.ebi.spot.goci.curation.dto.StudyPatchRequest in project goci by EBISPOT.

the class StudyRestController method multiUploadFileModel.

@PostMapping(Endpoint.STUDIES)
public Object multiUploadFileModel(@Valid FileUploadRequest fileUploadRequest, BindingResult result) {
    if (result.hasErrors()) {
        throw new FileValidationException(result);
    }
    List<StudyPatchRequest> studyPatchRequests = FileHandler.getStudyPatchRequests(fileUploadRequest);
    List<Study> updatedStudies = new ArrayList<>();
    for (StudyPatchRequest request : studyPatchRequests) {
        log.info("Dataset with GCST {} and Curated Trait {} was loaded from file", request.getGcst(), request.getCuratedReportedTrait());
        String gcst = request.getGcst().trim();
        String curatedReportedTrait = request.getCuratedReportedTrait().trim();
        updatedStudies.add(studyDataService.updateStudyDiseaseTraitByAccessionId(curatedReportedTrait, gcst));
    }
    return new ResponseEntity<>(updatedStudies, HttpStatus.OK);
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) ResponseEntity(org.springframework.http.ResponseEntity) ArrayList(java.util.ArrayList) FileValidationException(uk.ac.ebi.spot.goci.curation.exception.FileValidationException) StudyPatchRequest(uk.ac.ebi.spot.goci.curation.dto.StudyPatchRequest)

Aggregations

StudyPatchRequest (uk.ac.ebi.spot.goci.curation.dto.StudyPatchRequest)2 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ResponseEntity (org.springframework.http.ResponseEntity)1 FileUploadException (uk.ac.ebi.spot.goci.curation.exception.FileUploadException)1 FileValidationException (uk.ac.ebi.spot.goci.curation.exception.FileValidationException)1 Study (uk.ac.ebi.spot.goci.model.Study)1