Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-3505 update delete assembly endpoint #128

Merged
merged 3 commits into from
Feb 23, 2024
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 @@ -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<String> deleteAssemblyByAccession(
@PathVariable(name = "accession") @ApiParam(value = "INSDC or RefSeq assembly accession. Eg: " +
"GCA_000001405.10") String asmAccession) {
handler.deleteAssemblyByAccession(asmAccession);
Optional<AssemblyEntity> 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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public List<String> getScheduledJobStatus() {
}

public void deleteAssemblyByAccession(String accession) {
assemblyService.deleteAssemblyByAccession(accession);
assemblyService.deleteEntriesForAssembly(accession);
}

public void putAssemblyChecksumsByAccession(String accession, String md5, String trunc512) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -249,23 +252,6 @@ public Map<String, List<String>> fetchAndInsertAssembly(List<String> 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<AssemblyEntity> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void setup() {
@AfterEach
void tearDown() {
chromosomeEntities.clear();
assemblyService.deleteAssembly(assemblyEntity);
assemblyService.deleteEntriesForAssembly(assemblyEntity.getInsdcAccession());
}

@Test
Expand Down Expand Up @@ -188,7 +188,7 @@ void tearDown() {
service.deleteChromosome(chromosomeEntity);
}
for (AssemblyEntity assemblyEntity : assemblyEntities) {
assemblyService.deleteAssembly(assemblyEntity);
assemblyService.deleteEntriesForAssembly(assemblyEntity.getInsdcAccession());
}
assemblyEntities = null;
chromosomeEntities = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void setup() {
@AfterEach
void tearDown() {
for (AssemblyEntity entity : entities) {
service.deleteAssembly(entity);
service.deleteEntriesForAssembly(entity.getInsdcAccession());
}
}

Expand All @@ -102,7 +102,7 @@ void setup() {

@AfterEach
void tearDown() {
service.deleteAssemblyByRefseq(entity.getRefseq());
service.deleteEntriesForAssembly(entity.getInsdcAccession());
}

@Test
Expand Down Expand Up @@ -147,7 +147,7 @@ void getAssembliesByTaxid() {
}

for (AssemblyEntity assemblyEntity : entities) {
service.deleteAssemblyByInsdcAccession(assemblyEntity.getInsdcAccession());
service.deleteEntriesForAssembly(assemblyEntity.getInsdcAccession());
}
}

Expand Down
Loading