@Test(expected = FileUploadException.class) public void uploadBlankFile() throws Exception { MockMultipartFile blankFile = new MockMultipartFile("data", "filename.txt", "text/plain", "".getBytes()); doThrow(new FileUploadException()).when(studyFileService).upload(blankFile, STUDY.getId()); associationUploadService.upload(blankFile, STUDY, SECURE_USER); }
@Transactional(readOnly = false) public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException { int s = study.getEvents().size(); if(s > 0){ getLog().trace("Study " + study.getId().toString() + " has " + s + " events"); } List<AssociationUploadErrorView> fileErrors = new ArrayList<>(); String originalFilename = file.getOriginalFilename(); getLog().info("Uploading file: ".concat(originalFilename)); try { uploadFile(file, study.getId()); File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename); ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full"); if (validationSummary != null) { long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream() .filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()) .count(); 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 { 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); } }
AssociationUploadService { @Transactional(readOnly = false) public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException { int s = study.getEvents().size(); if(s > 0){ getLog().trace("Study " + study.getId().toString() + " has " + s + " events"); } List<AssociationUploadErrorView> fileErrors = new ArrayList<>(); String originalFilename = file.getOriginalFilename(); getLog().info("Uploading file: ".concat(originalFilename)); try { uploadFile(file, study.getId()); File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename); ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full"); if (validationSummary != null) { long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream() .filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()) .count(); 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 { 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); } } }
AssociationUploadService { @Transactional(readOnly = false) public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException { int s = study.getEvents().size(); if(s > 0){ getLog().trace("Study " + study.getId().toString() + " has " + s + " events"); } List<AssociationUploadErrorView> fileErrors = new ArrayList<>(); String originalFilename = file.getOriginalFilename(); getLog().info("Uploading file: ".concat(originalFilename)); try { uploadFile(file, study.getId()); File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename); ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full"); if (validationSummary != null) { long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream() .filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()) .count(); 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 { 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); } } @Autowired  AssociationUploadService(AssociationFileUploadService associationFileUploadService,
                                    AssociationOperationsService associationOperationsService,
                                    StudyFileService studyFileService,
                                    StudyRepository studyRepository,
                                    @Qualifier("studyTrackingOperationServiceImpl") TrackingOperationService trackingOperationService); }
AssociationUploadService { @Transactional(readOnly = false) public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException { int s = study.getEvents().size(); if(s > 0){ getLog().trace("Study " + study.getId().toString() + " has " + s + " events"); } List<AssociationUploadErrorView> fileErrors = new ArrayList<>(); String originalFilename = file.getOriginalFilename(); getLog().info("Uploading file: ".concat(originalFilename)); try { uploadFile(file, study.getId()); File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename); ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full"); if (validationSummary != null) { long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream() .filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()) .count(); 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 { 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); } } @Autowired  AssociationUploadService(AssociationFileUploadService associationFileUploadService,
                                    AssociationOperationsService associationOperationsService,
                                    StudyFileService studyFileService,
                                    StudyRepository studyRepository,
                                    @Qualifier("studyTrackingOperationServiceImpl") TrackingOperationService trackingOperationService); static List<AssociationUploadErrorView> splitByXLSError(List<AssociationUploadErrorView> originalList); @Transactional(readOnly = false) List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user); }
AssociationUploadService { @Transactional(readOnly = false) public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException { int s = study.getEvents().size(); if(s > 0){ getLog().trace("Study " + study.getId().toString() + " has " + s + " events"); } List<AssociationUploadErrorView> fileErrors = new ArrayList<>(); String originalFilename = file.getOriginalFilename(); getLog().info("Uploading file: ".concat(originalFilename)); try { uploadFile(file, study.getId()); File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename); ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full"); if (validationSummary != null) { long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream() .filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()) .count(); 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 { 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); } } @Autowired  AssociationUploadService(AssociationFileUploadService associationFileUploadService,
                                    AssociationOperationsService associationOperationsService,
                                    StudyFileService studyFileService,
                                    StudyRepository studyRepository,
                                    @Qualifier("studyTrackingOperationServiceImpl") TrackingOperationService trackingOperationService); static List<AssociationUploadErrorView> splitByXLSError(List<AssociationUploadErrorView> originalList); @Transactional(readOnly = false) List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user);  }