Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ public ImportResponse submitGenotypeData(UUID userId, UUID programId, UUID submi
progress.setId(upload.getImporterProgressId());
upload.setProgress(progress);

//Query all filenames to avoid duplicate file uploads
Comment thread
nickpalladino marked this conversation as resolved.
String fileName = uploadedFile.getFilename();
List<GenotypeImportDetails> existingImports = getGenotypeImports(programId);
for (GenotypeImportDetails existingImport : existingImports) {
if (existingImport.getGenotypingFileName().equals(fileName)){
ImportResponse response = new ImportResponse();
upload.getProgress().setStatuscode((short)HttpStatus.BAD_REQUEST.getCode());
upload.getProgress().setMessage(String.format("Import cannot proceed. File name '%s' already exists in the database.", fileName));
importDAO.updateProgress(upload.getProgress());
response.setImportId(upload.getId());
response.setProgress(progress);
return response;
}
}

String gigwaAuthToken;
try {
gigwaAuthToken = getAuthToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,39 @@ public void testSubmitInvalidHeader() throws ApiException {
assertEquals("Header row is not valid VCF format", response.getProgress().getMessage());
}

@Test
public void testSubmitSameFileName() throws ApiException, IOException {
UUID programId = UUID.fromString("29162e85-e739-4f19-9fd0-0c377ed59956");
String programKey = "TESTSUBMITDUPNAME";
UUID submissionId = UUID.randomUUID();
setupMocksForSubmitGenoData(programId, submissionId, buildSamplesFromValidVcf());

// First upload should be accepted for asynchronous processing.
AtomicReference<ImportResponse> importResponse = new AtomicReference<>();
assertTimeout(Duration.of(2, ChronoUnit.MINUTES), () -> importResponse.set(submitGenoData(programId, programKey, submissionId, "sample.vcf")), "Upload did not complete within the time period");

ImportResponse response = importResponse.get();
assertNotNull(response);
assertNotNull(response.getProgress());
assertEquals((short) HttpStatus.ACCEPTED.getCode(),
response.getProgress().getStatuscode(),
"Error importing geno file: " + response.getProgress().getMessage());

// The DAO is mocked: explicitly simulate the completed import before resubmitting.
doReturn(List.of(GenotypeImportDetails.builder()
.genotypingFileName("sample.vcf")
.build()))
.when(genotypeImportDAO).getGenotypeImportsByProgramId(programId);
AtomicReference<ImportResponse> importResponseTwo = new AtomicReference<>();
assertTimeout(Duration.of(2, ChronoUnit.MINUTES), () -> importResponseTwo.set(submitGenoData(programId, programKey, submissionId, "sample.vcf")), "Upload did not complete within the time period");

ImportResponse responseTwo = importResponseTwo.get();
assertNotNull(responseTwo);
assertNotNull(responseTwo.getProgress());
assertEquals((short) HttpStatus.BAD_REQUEST.getCode(), responseTwo.getProgress().getStatuscode());
assertEquals("Import cannot proceed. File name 'sample.vcf' already exists in the database.", responseTwo.getProgress().getMessage());
}

@Test
public void testSubmitMissingSubmissionSamples() throws ApiException {
UUID programId = UUID.fromString("29162e85-e739-4f19-9fd0-0c377ed59956");
Expand Down
Loading