diff --git a/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminController.java b/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminController.java index e35a6ab7..7b551989 100644 --- a/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminController.java +++ b/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminController.java @@ -238,10 +238,23 @@ public void putChromosomeChecksumsByAccession( "assembly also deletes all sequences that are associated with that assembly. This endpoint does" + " not return any data.") @DeleteMapping(value = "assemblies/{accession}") - public void deleteAssemblyByAccession( + public ResponseEntity deleteAssemblyByAccession( @PathVariable(name = "accession") @ApiParam(value = "INSDC or RefSeq assembly accession. Eg: " + "GCA_000001405.10") String asmAccession) { - handler.deleteAssemblyByAccession(asmAccession); + Optional assemblyOpt = handler.getAssemblyByAccession(asmAccession); + if (assemblyOpt.isPresent()) { + try { + handler.deleteAssemblyByAccession(assemblyOpt.get().getInsdcAccession()); + return ResponseEntity.ok("Assembly Deleted Successfully"); + } catch (Exception e) { + return new ResponseEntity<>("There was an error deleting assembly. " + + "The DB might be in inconsistent state, it is advised to retry deleting", + HttpStatus.INTERNAL_SERVER_ERROR); + } + } else { + return new ResponseEntity<>("The requested assembly for deletion could not be found", + HttpStatus.NOT_FOUND); + } } } diff --git a/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminHandler.java b/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminHandler.java index b0b18ccf..2c41672a 100644 --- a/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminHandler.java +++ b/src/main/java/uk/ac/ebi/eva/contigalias/controller/admin/AdminHandler.java @@ -78,7 +78,7 @@ public List getScheduledJobStatus() { } public void deleteAssemblyByAccession(String accession) { - assemblyService.deleteAssemblyByAccession(accession); + assemblyService.deleteEntriesForAssembly(accession); } public void putAssemblyChecksumsByAccession(String accession, String md5, String trunc512) { diff --git a/src/main/java/uk/ac/ebi/eva/contigalias/service/AssemblyService.java b/src/main/java/uk/ac/ebi/eva/contigalias/service/AssemblyService.java index c5a9e2e9..a49dcb8f 100644 --- a/src/main/java/uk/ac/ebi/eva/contigalias/service/AssemblyService.java +++ b/src/main/java/uk/ac/ebi/eva/contigalias/service/AssemblyService.java @@ -21,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; import org.springframework.stereotype.Service; import uk.ac.ebi.eva.contigalias.datasource.ENAAssemblyDataSource; import uk.ac.ebi.eva.contigalias.datasource.NCBIAssemblyDataSource; @@ -165,6 +167,7 @@ public void parseFileAndInsertAssembly(String accession) throws IOException { Files.deleteIfExists(downloadedNCBIFilePath); } + @Retryable(value = Exception.class, maxAttempts = 5, backoff = @Backoff(delay = 2000, multiplier=2)) public void deleteEntriesForAssembly(String accession) { chromosomeRepository.deleteChromosomeEntitiesByAssembly_InsdcAccession(accession); assemblyRepository.deleteAssemblyEntityByInsdcAccessionOrRefseq(accession); @@ -249,23 +252,6 @@ public Map> fetchAndInsertAssembly(List accessions) return accessionResult; } - public void deleteAssemblyByInsdcAccession(String insdcAccession) { - assemblyRepository.deleteAssemblyEntityByInsdcAccession(insdcAccession); - } - - public void deleteAssemblyByRefseq(String refseq) { - assemblyRepository.deleteAssemblyEntityByRefseq(refseq); - } - - public void deleteAssemblyByAccession(String accession) { - Optional assembly = getAssemblyByAccession(accession); - assembly.ifPresent(this::deleteAssembly); - } - - public void deleteAssembly(AssemblyEntity entity) { - assemblyRepository.delete(entity); - } - private DuplicateAssemblyException duplicateAssemblyInsertionException(String accession, AssemblyEntity present) { StringBuilder exception = new StringBuilder("A similar assembly already exists!"); if (accession != null) { diff --git a/src/test/java/uk/ac/ebi/eva/contigalias/scheduler/ENASequenceNameUpdaterTest.java b/src/test/java/uk/ac/ebi/eva/contigalias/scheduler/ENASequenceNameUpdaterTest.java index b6dd79db..1a759ae1 100644 --- a/src/test/java/uk/ac/ebi/eva/contigalias/scheduler/ENASequenceNameUpdaterTest.java +++ b/src/test/java/uk/ac/ebi/eva/contigalias/scheduler/ENASequenceNameUpdaterTest.java @@ -43,7 +43,7 @@ void setup() { @AfterEach void tearDown() { chromosomeEntities.stream().forEach(c -> chromosomeService.deleteChromosome(c)); - assemblyService.deleteAssembly(assemblyService.getAssemblyByAccession(GCA_ACCESSION_HAVING_CHROMOSOMES).get()); + assemblyService.deleteEntriesForAssembly(assemblyService.getAssemblyByAccession(GCA_ACCESSION_HAVING_CHROMOSOMES).get().getInsdcAccession()); } @Test diff --git a/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyAndChromosomeServiceIntegrationTest.java b/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyAndChromosomeServiceIntegrationTest.java index f0be306b..aa1f823e 100644 --- a/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyAndChromosomeServiceIntegrationTest.java +++ b/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyAndChromosomeServiceIntegrationTest.java @@ -77,7 +77,7 @@ void setup() { @AfterEach void tearDown() { chromosomeEntities.clear(); - assemblyService.deleteAssembly(assemblyEntity); + assemblyService.deleteEntriesForAssembly(assemblyEntity.getInsdcAccession()); } @Test @@ -188,7 +188,7 @@ void tearDown() { service.deleteChromosome(chromosomeEntity); } for (AssemblyEntity assemblyEntity : assemblyEntities) { - assemblyService.deleteAssembly(assemblyEntity); + assemblyService.deleteEntriesForAssembly(assemblyEntity.getInsdcAccession()); } assemblyEntities = null; chromosomeEntities = null; diff --git a/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyServiceIntegrationTest.java b/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyServiceIntegrationTest.java index 5b1ac463..891d4dfe 100644 --- a/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyServiceIntegrationTest.java +++ b/src/test/java/uk/ac/ebi/eva/contigalias/service/AssemblyServiceIntegrationTest.java @@ -79,7 +79,7 @@ void setup() { @AfterEach void tearDown() { for (AssemblyEntity entity : entities) { - service.deleteAssembly(entity); + service.deleteEntriesForAssembly(entity.getInsdcAccession()); } } @@ -102,7 +102,7 @@ void setup() { @AfterEach void tearDown() { - service.deleteAssemblyByRefseq(entity.getRefseq()); + service.deleteEntriesForAssembly(entity.getInsdcAccession()); } @Test @@ -147,7 +147,7 @@ void getAssembliesByTaxid() { } for (AssemblyEntity assemblyEntity : entities) { - service.deleteAssemblyByInsdcAccession(assemblyEntity.getInsdcAccession()); + service.deleteEntriesForAssembly(assemblyEntity.getInsdcAccession()); } }