Skip to content
Open
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 @@ -15,10 +15,7 @@
import org.brapi.client.v2.ApiResponse;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.client.v2.modules.germplasm.GermplasmApi;
import org.brapi.v2.model.BrAPIAcceptedSearchResponse;
import org.brapi.v2.model.BrAPIIndexPagination;
import org.brapi.v2.model.BrAPIMetadata;
import org.brapi.v2.model.BrAPIStatus;
import org.brapi.v2.model.*;
import org.brapi.v2.model.germ.*;
import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest;
import org.brapi.v2.model.germ.response.BrAPIGermplasmListResponse;
Expand All @@ -35,6 +32,7 @@
import org.breedinginsight.brapi.v2.model.request.query.GermplasmQuery;
import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService;
import org.breedinginsight.brapps.importer.model.exports.FileType;
import org.breedinginsight.brapps.importer.services.ExternalReferenceSource;
import org.breedinginsight.daos.ProgramDAO;
import org.breedinginsight.model.DownloadFile;
import org.breedinginsight.model.GermplasmGenotype;
Expand Down Expand Up @@ -428,8 +426,6 @@ public HttpResponse<Response<GermplasmGenotype>> getGermplasmGenotype(@PathVaria
@PathVariable("germplasmId") String germplasmId) {

try {
BrAPIGermplasm germplasm = germplasmDAO.getGermplasmByUUID(germplasmId, programId);

GermplasmGenotype germplasmGenotype = genoService.retrieveGenotypeData(programId, UUID.fromString(germplasmId));

Response<GermplasmGenotype> response = new Response(germplasmGenotype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.breedinginsight.services.geno.GenotypeService;
import org.breedinginsight.services.parsers.MimeTypeParser;
import org.breedinginsight.utilities.BrAPIDAOUtil;
import org.breedinginsight.utilities.Utilities;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;
import software.amazon.awssdk.services.s3.S3Client;
Expand Down Expand Up @@ -290,7 +291,12 @@ public GermplasmGenotype retrieveGenotypeData(UUID programId, UUID germplasmId)
if(verifyProgramExists(brAPIClient, program)) {

// get sample names from brapi server
List<BrAPISample> samples = fetchSamples(program, germplasmId);

String exrefId = Utilities.getExternalReference(germplasm.getExternalReferences(), referenceSource)
.orElseThrow(() -> new DoesNotExistException("Germplasm does not have external reference source. Unable to lookup associated sample data."))
.getReferenceId();

List<BrAPISample> samples = fetchSamples(program, UUID.fromString(exrefId));
List<String> sampleNames = samples.stream().map(BrAPISample::getSampleName).collect(Collectors.toList());

// get samples from gigwa given sample names
Expand Down Expand Up @@ -565,8 +571,8 @@ private List<BrAPISample> fetchGigwaSamples(BrAPIClient genoBrAPIClient, Program
}


private List<BrAPISample> fetchSamples(Program program, @NotNull UUID germplasmId) throws ApiException {
String germplasmIdString = germplasmId.toString();
private List<BrAPISample> fetchSamples(Program program, @NotNull UUID germplasmExRefId) throws ApiException {
String germplasmIdString = germplasmExRefId.toString();
java.util.List<String> germplasmIdList = List.of(germplasmIdString);
List<BrAPISample> sampleNames = sampleDAO.readSamplesByGermplasmIds(program, germplasmIdList);
return sampleNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.brapi.client.v2.modules.core.StudiesApi;
import org.brapi.client.v2.modules.genotype.SamplesApi;
import org.brapi.client.v2.modules.phenotype.ObservationUnitsApi;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.core.response.BrAPIProgramListResponse;
import org.brapi.v2.model.core.response.BrAPIStudyListResponse;
import org.brapi.v2.model.geno.BrAPISample;
Expand Down Expand Up @@ -382,13 +383,15 @@ public void testFetchGermplasmGenotype() throws AuthorizationException, ApiExcep

String germplasmName = "USDAMSP1";
String sampleName = germplasmName + "_A01";
BrAPIGermplasm germplasm = new BrAPIGermplasm().germplasmDbId(UUID.randomUUID().toString()).germplasmName(germplasmName);
// For the sample lookup, both the BrAPI germplasmDbId and BI exRefId is used because the sample table in BrAPI does not have an association with germplasm.
// The brAPI germplasmDbId is passed in by the frontend, and to find the sample, the exRefId is used.
BrAPIGermplasm germplasm = new BrAPIGermplasm().germplasmDbId(UUID.randomUUID().toString()).germplasmName(germplasmName).externalReferences(List.of(new BrAPIExternalReference().referenceSource(referenceSource).referenceId(UUID.randomUUID().toString())));

SamplesApi mockSamplesApi = spy(new SamplesApi());
BrAPISample sample = new BrAPISample().sampleName(sampleName)
.germplasmDbId(programKey + "§" + sampleName);
doReturn(List.of(sample)).when(sampleDAO)
.readSamplesByGermplasmIds(any(Program.class), eq(List.of(germplasm.getGermplasmDbId())));
.readSamplesByGermplasmIds(any(Program.class), eq(List.of(germplasm.getExternalReferences().get(0).getReferenceId())));
doReturn(new ApiResponse<>(200,
new HashMap<>(),
Pair.of(Optional.of(new BrAPISampleListResponse().result(new BrAPISampleListResponseResult().data(List.of(sample)))),
Expand All @@ -405,7 +408,7 @@ public void testFetchGermplasmGenotype() throws AuthorizationException, ApiExcep

GermplasmGenotype germplasmGenotype = gigwaGenoStorageService.retrieveGenotypeData(programId, UUID.fromString(germplasm.getGermplasmDbId()));

verify(sampleDAO).readSamplesByGermplasmIds(any(Program.class), eq(List.of(germplasm.getGermplasmDbId())));
verify(sampleDAO).readSamplesByGermplasmIds(any(Program.class), eq(List.of(germplasm.getExternalReferences().get(0).getReferenceId())));
verify(brAPIEndpointProvider, never()).get(any(BrAPIClient.class), eq(ObservationUnitsApi.class));
verify(mockSamplesApi).searchSamplesPost(argThat(searchRequest -> searchRequest.getGermplasmDbIds() != null &&
searchRequest.getGermplasmDbIds().contains(programKey + "§" + sample.getSampleName()) &&
Expand Down
Loading