@Test(expected = FileNotFoundException.class) public void processAndValidateNonexistentAssociationFile() throws Exception { File fileDoesNotExist = new File("test"); associationFileUploadService.processAndValidateAssociationFile(fileDoesNotExist, "full"); }
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()) { XSSFSheet sheet = null; try { sheet = sheetCreationService.createSheet(file.getAbsolutePath()); UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel); fileRows = uploadSheetProcessor.readSheetRows(sheet); } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException 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(); if (!fileRows.isEmpty()) { for (AssociationUploadRow row : fileRows) { getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath()); RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease); if (!rowValidationSummary.getErrors().isEmpty()) { rowValidationSummaries.add(rowValidationSummary); } } if (rowValidationSummaries.isEmpty()) { fileRows.forEach(row -> { associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease)); }); } } validationSummary.setAssociationSummaries(associationSummaries); validationSummary.setRowValidationSummaries(rowValidationSummaries); return validationSummary; }
AssociationFileUploadService { 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()) { XSSFSheet sheet = null; try { sheet = sheetCreationService.createSheet(file.getAbsolutePath()); UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel); fileRows = uploadSheetProcessor.readSheetRows(sheet); } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException 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(); if (!fileRows.isEmpty()) { for (AssociationUploadRow row : fileRows) { getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath()); RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease); if (!rowValidationSummary.getErrors().isEmpty()) { rowValidationSummaries.add(rowValidationSummary); } } if (rowValidationSummaries.isEmpty()) { fileRows.forEach(row -> { associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease)); }); } } validationSummary.setAssociationSummaries(associationSummaries); validationSummary.setRowValidationSummaries(rowValidationSummaries); return validationSummary; } }
AssociationFileUploadService { 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()) { XSSFSheet sheet = null; try { sheet = sheetCreationService.createSheet(file.getAbsolutePath()); UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel); fileRows = uploadSheetProcessor.readSheetRows(sheet); } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException 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(); if (!fileRows.isEmpty()) { for (AssociationUploadRow row : fileRows) { getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath()); RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease); if (!rowValidationSummary.getErrors().isEmpty()) { rowValidationSummaries.add(rowValidationSummary); } } if (rowValidationSummaries.isEmpty()) { fileRows.forEach(row -> { associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease)); }); } } validationSummary.setAssociationSummaries(associationSummaries); validationSummary.setRowValidationSummaries(rowValidationSummaries); return validationSummary; } @Autowired  AssociationFileUploadService(UploadSheetProcessorBuilder uploadSheetProcessorBuilder,
                                        AssociationRowProcessor associationRowProcessor,
                                        ValidationService validationService,
                                        SheetCreationService sheetCreationService,
                                        EnsemblRestTemplateService ensemblRestTemplateService); }
AssociationFileUploadService { 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()) { XSSFSheet sheet = null; try { sheet = sheetCreationService.createSheet(file.getAbsolutePath()); UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel); fileRows = uploadSheetProcessor.readSheetRows(sheet); } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException 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(); if (!fileRows.isEmpty()) { for (AssociationUploadRow row : fileRows) { getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath()); RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease); if (!rowValidationSummary.getErrors().isEmpty()) { rowValidationSummaries.add(rowValidationSummary); } } if (rowValidationSummaries.isEmpty()) { fileRows.forEach(row -> { associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease)); }); } } validationSummary.setAssociationSummaries(associationSummaries); validationSummary.setRowValidationSummaries(rowValidationSummaries); return validationSummary; } @Autowired  AssociationFileUploadService(UploadSheetProcessorBuilder uploadSheetProcessorBuilder,
                                        AssociationRowProcessor associationRowProcessor,
                                        ValidationService validationService,
                                        SheetCreationService sheetCreationService,
                                        EnsemblRestTemplateService ensemblRestTemplateService); ValidationSummary processAndValidateAssociationFile(File file, String validationLevel); }
AssociationFileUploadService { 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()) { XSSFSheet sheet = null; try { sheet = sheetCreationService.createSheet(file.getAbsolutePath()); UploadSheetProcessor uploadSheetProcessor = uploadSheetProcessorBuilder.buildProcessor(validationLevel); fileRows = uploadSheetProcessor.readSheetRows(sheet); } catch (InvalidFormatException | InvalidOperationException | IOException | NullPointerException 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(); if (!fileRows.isEmpty()) { for (AssociationUploadRow row : fileRows) { getLog().info("Syntax checking row: " + row.getRowNumber() + " of file, " + file.getAbsolutePath()); RowValidationSummary rowValidationSummary = createRowValidationSummary(row, eRelease); if (!rowValidationSummary.getErrors().isEmpty()) { rowValidationSummaries.add(rowValidationSummary); } } if (rowValidationSummaries.isEmpty()) { fileRows.forEach(row -> { associationSummaries.add(createAssociationSummary(row, validationLevel, eRelease)); }); } } validationSummary.setAssociationSummaries(associationSummaries); validationSummary.setRowValidationSummaries(rowValidationSummaries); return validationSummary; } @Autowired  AssociationFileUploadService(UploadSheetProcessorBuilder uploadSheetProcessorBuilder,
                                        AssociationRowProcessor associationRowProcessor,
                                        ValidationService validationService,
                                        SheetCreationService sheetCreationService,
                                        EnsemblRestTemplateService ensemblRestTemplateService); ValidationSummary processAndValidateAssociationFile(File file, String validationLevel);  }