Skip to content

Commit

Permalink
changed the return object/type of the ingestion endpoint into a more …
Browse files Browse the repository at this point in the history
…standardized one
  • Loading branch information
waterflow80 committed Jan 3, 2024
1 parent 9a38601 commit 468ce6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException;
import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException;
import uk.ac.ebi.eva.evaseqcol.exception.IncorrectAccessionException;
import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity;
import uk.ac.ebi.eva.evaseqcol.service.SeqColService;

import java.io.IOException;
Expand Down Expand Up @@ -54,10 +55,8 @@ public ResponseEntity<?> fetchAndInsertSeqColByAssemblyAccession(
example = "GCA_000146045.2",
required = true) @PathVariable String asmAccession) {
try {
List<String> level0Digests = seqColService.fetchAndInsertAllSeqColByAssemblyAccession(asmAccession);
return new ResponseEntity<>(
"Successfully inserted seqCol object(s) for assembly accession " + asmAccession + "\nSeqCol digests=" + level0Digests
, HttpStatus.OK);
IngestionResultEntity ingestionResult = seqColService.fetchAndInsertAllSeqColByAssemblyAccession(asmAccession);
return ResponseEntity.ok(ingestionResult);
} catch (IncorrectAccessionException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SeqColExtendedDataEntity<T> {
@Transient
// This is needed when constructing multiple seqCol objects from the datasource to
// identify the naming convention used for the sequences.
// Note: This will probably be required by the namesAttributeList and might be null for the others
private SeqColEntity.NamingConvention namingConvention;

public enum AttributeType {
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException;
import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException;
import uk.ac.ebi.eva.evaseqcol.exception.UnableToLoadServiceInfoException;
import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity;
import uk.ac.ebi.eva.evaseqcol.model.InsertedSeqColEntity;
import uk.ac.ebi.eva.evaseqcol.utils.JSONExtData;
import uk.ac.ebi.eva.evaseqcol.utils.JSONIntegerListExtData;
import uk.ac.ebi.eva.evaseqcol.utils.JSONStringListExtData;
Expand Down Expand Up @@ -154,14 +156,16 @@ public void removeAllSeqCol() {
* NOTE: All possible seqCol objects means with all possible/provided naming conventions that could be found in the
* assembly report.
* Return the list of level 0 digests of the inserted seqcol objects*/
public List<String> fetchAndInsertAllSeqColByAssemblyAccession(
public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession(
String assemblyAccession) throws IOException, DuplicateSeqColException {
List<String> insertedSeqColDigests = new ArrayList<>();
IngestionResultEntity ingestionResultEntity = new IngestionResultEntity();
ingestionResultEntity.setAssemblyAccession(assemblyAccession);
Optional<Map<String, Object>> seqColDataMap = ncbiSeqColDataSource
.getAllPossibleSeqColExtendedData(assemblyAccession);
if (!seqColDataMap.isPresent()) {
logger.warn("No seqCol data corresponding to assemblyAccession " + assemblyAccession + " could be found on NCBI datasource");
return insertedSeqColDigests;
ingestionResultEntity.setErrorMessage("No seqCol data corresponding to assemblyAccession " + assemblyAccession + " could be found on NCBI datasource");
return ingestionResultEntity;
}

// Retrieving the Map's data
Expand Down Expand Up @@ -198,17 +202,25 @@ public List<String> fetchAndInsertAllSeqColByAssemblyAccession(
seqColStringListExtDataEntities, seqColIntegerListExtDataEntities, extendedNamesEntity.getNamingConvention()
);

Optional<String> seqColDigest = insertSeqColL1AndL2( // TODO: Check for possible self invocation problem
levelOneEntity, seqColStringListExtDataEntities, seqColIntegerListExtDataEntities);
if (seqColDigest.isPresent()) {
logger.info(
"Successfully inserted seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention());
insertedSeqColDigests.add(seqColDigest.get());
} else {
logger.warn("Could not insert seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention());
try {
Optional<String> seqColDigest = insertSeqColL1AndL2( // TODO: Check for possible self invocation problem
levelOneEntity, seqColStringListExtDataEntities, seqColIntegerListExtDataEntities);
if (seqColDigest.isPresent()) {
logger.info(
"Successfully inserted seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention());
InsertedSeqColEntity insertedSeqCol = new InsertedSeqColEntity(seqColDigest.get(), extendedNamesEntity.getNamingConvention().toString());
ingestionResultEntity.addInsertedSeqCol(insertedSeqCol);
ingestionResultEntity.incrementNumberOfInsertedSeqCols();
} else {
logger.warn("Could not insert seqCol for assembly Accession " + assemblyAccession + " with naming convention " + extendedNamesEntity.getNamingConvention());
}
} catch (DuplicateSeqColException e) {
logger.info("Seqcol for " + assemblyAccession + " and naming convention " + extendedNamesEntity.getNamingConvention() +
" already exists. Skipping.");
continue;
}
}
return insertedSeqColDigests;
return ingestionResultEntity;
}

/**
Expand Down

0 comments on commit 468ce6a

Please sign in to comment.