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);
}
}
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;
}
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;
}
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;
}
Aggregations