Search in sources :

Example 1 with ValidationSummary

use of uk.ac.ebi.spot.goci.model.ValidationSummary in project goci by EBISPOT.

the class ValidatorApplication method runUpload.

private void runUpload(File file, String validationLevel) throws FileNotFoundException {
    ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(file, validationLevel);
    validationLogService.processErrors(inputFile, validationSummary);
}
Also used : ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary)

Example 2 with ValidationSummary

use of uk.ac.ebi.spot.goci.model.ValidationSummary in project goci by EBISPOT.

the class AssociationUploadService method upload.

public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException {
    // File errors will contain any validation errors and be returned to controller if any are found
    List<AssociationUploadErrorView> fileErrors = new ArrayList<>();
    String originalFilename = file.getOriginalFilename();
    getLog().info("Uploading file: ".concat(originalFilename));
    // Upload file
    try {
        uploadFile(file, study.getId());
        // Send file, including path, to SNP batch loader process
        File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename);
        ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full");
        if (validationSummary != null) {
            // Check if we have any row errors
            long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream().filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()).count();
            // Errors found
            if (rowErrorCount > 0) {
                studyFileService.deleteFile(study.getId(), originalFilename);
                getLog().error("Row errors found in file: " + originalFilename);
                validationSummary.getRowValidationSummaries().forEach(rowValidationSummary -> fileErrors.addAll(processRowError(rowValidationSummary)));
            } else {
                // Determine if we have any errors rather than warnings
                // Errors prevent saving association
                List<ValidationError> allAssociationsErrors = new ArrayList<>();
                validationSummary.getAssociationSummaries().forEach(associationSummary -> allAssociationsErrors.addAll(associationSummary.getErrors()));
                long associationErrorCount = allAssociationsErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
                if (associationErrorCount > 0) {
                    studyFileService.deleteFile(study.getId(), originalFilename);
                    getLog().error("Association errors found in file: " + originalFilename);
                    validationSummary.getAssociationSummaries().forEach(associationSummary -> fileErrors.addAll(processAssociationError(associationSummary)));
                } else {
                    Integer numberOfAssociations = validationSummary.getAssociationSummaries().size();
                    String description = numberOfAssociations.toString().concat(" associations created from upload of '").concat(originalFilename).concat("'");
                    createBatchUploadEvent(study, description, user);
                    saveAssociations(validationSummary.getAssociationSummaries(), study, user);
                }
            }
        }
        return fileErrors;
    } catch (IOException e) {
        throw new IOException(e);
    }
}
Also used : RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) File(java.io.File) TrackingOperationService(uk.ac.ebi.spot.goci.service.TrackingOperationService) ArrayList(java.util.ArrayList) List(java.util.List) Service(org.springframework.stereotype.Service) Association(uk.ac.ebi.spot.goci.model.Association) Qualifier(org.springframework.beans.factory.annotation.Qualifier) MultipartFile(org.springframework.web.multipart.MultipartFile) Study(uk.ac.ebi.spot.goci.model.Study) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) AssociationFileUploadService(uk.ac.ebi.spot.goci.service.AssociationFileUploadService) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) ArrayList(java.util.ArrayList) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 3 with ValidationSummary

use of uk.ac.ebi.spot.goci.model.ValidationSummary in project goci by EBISPOT.

the class AssociationFileUploadServiceTest method processAndValidateAssociationFile.

@Test
public void processAndValidateAssociationFile() throws Exception {
    // Create a temp file
    final File file = folder.newFile("myfile.txt");
    // Stubbing
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("test");
    when(sheetCreationService.createSheet(file.getAbsolutePath())).thenReturn(sheet);
    when(uploadSheetProcessorBuilder.buildProcessor("full")).thenReturn(uploadSheetProcessor);
    ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(file, "full");
    verify(sheetCreationService, times(1)).createSheet(Matchers.anyString());
    verify(uploadSheetProcessorBuilder, times(1)).buildProcessor("full");
    verify(uploadSheetProcessor, times(1)).readSheetRows(sheet);
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) File(java.io.File) Test(org.junit.Test)

Example 4 with ValidationSummary

use of uk.ac.ebi.spot.goci.model.ValidationSummary in project goci by EBISPOT.

the class AssociationFileUploadService method processAndValidateAssociationFile.

/**
     * Process uploaded file and return a list of errors
     *
     * @param file XLSX file supplied by user
     */
public ValidationSummary processAndValidateAssociationFile(File file, String validationLevel) throws FileNotFoundException, SheetProcessingException {
    ValidationSummary validationSummary = new ValidationSummary();
    Collection<RowValidationSummary> rowValidationSummaries = new ArrayList<>();
    Collection<AssociationSummary> associationSummaries = new ArrayList<>();
    Collection<AssociationUploadRow> fileRows = new ArrayList<>();
    if (file.exists()) {
        // Create sheet
        XSSFSheet sheet = null;
        try {
            // Create a sheet for reading
            sheet = sheetCreationService.createSheet(file.getAbsolutePath());
            // Process file, depending on validation level, into a generic row object
            UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel);
            fileRows = uploadSheetProcessor.readSheetRows(sheet);
        } catch (InvalidFormatException | InvalidOperationException | IOException e) {
            getLog().error("File: " + file.getName() + " cannot be processed", e);
            file.delete();
            throw new SheetProcessingException("File: " + file.getName() + " cannot be processed", e);
        }
    } else {
        getLog().error("File: " + file.getName() + " cannot be found");
        throw new FileNotFoundException("File does not exist");
    }
    String eRelease = ensemblRestTemplateService.getRelease();
    // Error check each row
    if (!fileRows.isEmpty()) {
        // Check for missing values and syntax errors that would prevent code creating an association
        for (AssociationUploadRow row : fileRows) {
            getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath());
            RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease);
            // Only store summary if there is an error
            if (!rowValidationSummary.getErrors().isEmpty()) {
                rowValidationSummaries.add(rowValidationSummary);
            }
        }
        if (rowValidationSummaries.isEmpty()) {
            //Proceed to carry out full checks of values
            fileRows.forEach(row -> {
                associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease));
            });
        }
    } else {
        getLog().error("Parsing file failed");
    }
    validationSummary.setAssociationSummaries(associationSummaries);
    validationSummary.setRowValidationSummaries(rowValidationSummaries);
    return validationSummary;
}
Also used : SheetProcessingException(uk.ac.ebi.spot.goci.exception.SheetProcessingException) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) AssociationUploadRow(uk.ac.ebi.spot.goci.model.AssociationUploadRow)

Aggregations

ValidationSummary (uk.ac.ebi.spot.goci.model.ValidationSummary)4 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)2 AssociationSummary (uk.ac.ebi.spot.goci.model.AssociationSummary)2 RowValidationSummary (uk.ac.ebi.spot.goci.model.RowValidationSummary)2 FileNotFoundException (java.io.FileNotFoundException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Service (org.springframework.stereotype.Service)1