use of uk.ac.ebi.spot.goci.model.AssociationSummary in project goci by EBISPOT.
the class AssociationFileUploadService method createAssociationSummary.
/**
* Process uploaded file, create an association and return a list of its errors
*
* @param row Row to validate and convert into an association
* @param validationLevel level of validation to run
*/
private AssociationSummary createAssociationSummary(AssociationUploadRow row, String validationLevel, String eRelease) {
getLog().info("Creating association summary for row " + row.getRowNumber());
Association association = associationRowProcessor.createAssociationFromUploadRow(row);
Collection<ValidationError> errors = validationService.runAssociationValidation(association, validationLevel, eRelease);
AssociationSummary associationSummary = new AssociationSummary();
associationSummary.setRowNumber(row.getRowNumber());
associationSummary.setAssociation(association);
associationSummary.setErrors(errors);
return associationSummary;
}
use of uk.ac.ebi.spot.goci.model.AssociationSummary in project goci by EBISPOT.
the class ValidationLogService method processErrors.
public void processErrors(File checkedFile, ValidationSummary validationSummary) {
Collection<AssociationSummary> associationSummaries = validationSummary.getAssociationSummaries();
Collection<RowValidationSummary> rowValidationSummaries = validationSummary.getRowValidationSummaries();
/// Create the log file
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'-T'HH-mm-ss");
String now = dateFormat.format(new Date());
String filePath = checkedFile.getParent();
// If there is no file path just use current working dir
if (filePath == null) {
filePath = Paths.get(".").toAbsolutePath().normalize().toString();
}
String input_name = "";
if (checkedFile.getName().contains(".xlsx")) {
input_name = checkedFile.getName().replace(".xlsx", "");
}
String logName = filePath.concat(File.separator).concat(("Validation_results_").concat(input_name).concat("_").concat(now).concat(".txt"));
System.out.println("Validation log written to " + logName);
getLog().info("Validation log written to " + logName);
// Write errors to file
boolean fileCreationSuccess = false;
File file = new File(logName);
try {
if (!file.exists()) {
fileCreationSuccess = file.createNewFile();
}
} catch (IOException e) {
getLog().error("Creating validation log failed");
e.printStackTrace();
}
if (fileCreationSuccess) {
FileWriter fw = null;
try {
fw = new FileWriter(file.getAbsoluteFile());
} catch (IOException e) {
getLog().error("Accessing validation log failed");
e.printStackTrace();
}
BufferedWriter bw = new BufferedWriter(fw);
try {
writeErrorToFile(bw, associationSummaries, rowValidationSummaries);
} catch (IOException e) {
getLog().error("Writing to validation log failed");
e.printStackTrace();
}
} else {
getLog().error("Creating validation log failed");
}
}
use of uk.ac.ebi.spot.goci.model.AssociationSummary 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.model.AssociationSummary 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;
}
use of uk.ac.ebi.spot.goci.model.AssociationSummary in project goci by EBISPOT.
the class AssociationUploadService method saveAssociations.
private void saveAssociations(Collection<AssociationSummary> associationSummaries, Study study, SecureUser user) throws EnsemblMappingException {
for (AssociationSummary associationSummary : associationSummaries) {
Association newAssociation = associationSummary.getAssociation();
// Add creation event
associationOperationsService.createAssociationCreationEvent(newAssociation, user);
// Save association
associationOperationsService.saveAssociation(newAssociation, study, associationSummary.getErrors());
// associationOperationsService.runMapping(study.getHousekeeping().getCurator(), newAssociation, user);
}
}
Aggregations