Search in sources :

Example 1 with AssociationUploadErrorView

use of uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView 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 2 with AssociationUploadErrorView

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

the class AssociationUploadService method processAssociationError.

/**
     * Process summary of association validation into object that can be returned to view
     *
     * @param associationSummary
     */
private List<AssociationUploadErrorView> processAssociationError(AssociationSummary associationSummary) {
    List<AssociationUploadErrorView> errors = new ArrayList<>();
    associationSummary.getErrors().forEach(validationError -> {
        AssociationUploadErrorView associationUploadErrorView = new AssociationUploadErrorView(associationSummary.getRowNumber(), validationError.getField(), validationError.getError(), validationError.getWarning(), validationError.getTypeError());
        errors.add(associationUploadErrorView);
    });
    return errors;
}
Also used : AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) ArrayList(java.util.ArrayList)

Example 3 with AssociationUploadErrorView

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

the class AssociationUploadService method processRowError.

/**
     * Process summary of row validation into object that can be returned to view
     *
     * @param rowValidationSummary
     */
private List<AssociationUploadErrorView> processRowError(RowValidationSummary rowValidationSummary) {
    List<AssociationUploadErrorView> errors = new ArrayList<>();
    rowValidationSummary.getErrors().forEach(validationError -> {
        AssociationUploadErrorView associationUploadErrorView = new AssociationUploadErrorView(rowValidationSummary.getRow().getRowNumber(), validationError.getField(), validationError.getError(), validationError.getWarning(), validationError.getTypeError());
        errors.add(associationUploadErrorView);
    });
    return errors;
}
Also used : AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) ArrayList(java.util.ArrayList)

Example 4 with AssociationUploadErrorView

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

the class AssociationUploadService method splitByXLSError.

// This static method allow us to split the List in two different lists.
// The original list will contain the scientific data error. The xlsListError will contain the XLS errors.
public static List<AssociationUploadErrorView> splitByXLSError(List<AssociationUploadErrorView> originalList) {
    List<AssociationUploadErrorView> xlsListError = new ArrayList<>();
    for (Iterator<AssociationUploadErrorView> iterator = originalList.iterator(); iterator.hasNext(); ) {
        AssociationUploadErrorView elem = iterator.next();
        if (elem.getTypeError().equals("excel")) {
            xlsListError.add(elem);
            iterator.remove();
        }
    }
    return xlsListError;
}
Also used : AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)4 AssociationUploadErrorView (uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView)4 File (java.io.File)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)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 MultipartFile (org.springframework.web.multipart.MultipartFile)1 EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)1 Association (uk.ac.ebi.spot.goci.model.Association)1 AssociationSummary (uk.ac.ebi.spot.goci.model.AssociationSummary)1 RowValidationSummary (uk.ac.ebi.spot.goci.model.RowValidationSummary)1 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)1 Study (uk.ac.ebi.spot.goci.model.Study)1 ValidationError (uk.ac.ebi.spot.goci.model.ValidationError)1