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 @@ -19,6 +19,7 @@
import org.brapi.v2.model.BrAPIIndexPagination;
import org.brapi.v2.model.BrAPIMetadata;
import org.brapi.v2.model.BrAPIStatus;
import org.brapi.v2.model.core.BrAPITrial;
import org.brapi.v2.model.germ.*;
import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest;
import org.brapi.v2.model.germ.response.BrAPIGermplasmListResponse;
Expand Down Expand Up @@ -185,7 +186,7 @@ private void batchProcessGermplasm(List<BrAPIGermplasm> germplasmList, String pr
@Get("/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/germplasm{?queryParams*}")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.PROGRAM_SCOPED_ROLES})
public HttpResponse<Response<DataResponse<List<BrAPIGermplasm>>>> getGermplasm(
public HttpResponse<Response<DataResponse<BrAPIGermplasm>>> getGermplasm(
@PathVariable("programId") UUID programId,
@QueryValue @QueryValid(using = GermplasmQueryMapper.class) @Valid GermplasmQuery queryParams) {
try {
Expand All @@ -198,15 +199,19 @@ public HttpResponse<Response<DataResponse<List<BrAPIGermplasm>>>> getGermplasm(
}

// Fetch all germplasm in the program unless a list id is supplied to return only germplasm in that collection
List<BrAPIGermplasm> germplasm = queryParams.getListDbId() == null ? germplasmService.getGermplasm(programId) : germplasmService.getGermplasmByList(programId, queryParams.getListDbId());
SearchRequest searchRequest = queryParams.constructSearchRequest();
return ResponseUtils.getBrapiQueryResponse(germplasm, germplasmQueryMapper, queryParams, searchRequest);
BrAPIGermplasmListResponse brapiResponse = queryParams.getListDbId() == null ? germplasmService.searchGermplasm(programId, queryParams) : germplasmService.getGermplasmByList(programId, queryParams);

List<BrAPIGermplasm> foundTrials = brapiResponse.getResult().getData();
return ResponseUtils.getBrapiQueryResponse(foundTrials, brapiResponse, queryParams);
} catch (ApiException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving germplasm");
} catch (IllegalArgumentException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, "Error parsing requested date format");
} catch (DoesNotExistException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.NOT_FOUND, "Supplied programId does not exist");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,15 @@ public List<BrAPIGermplasm> getRawGermplasm(UUID programId) throws ApiException

/**
* Process germplasm into a format for display
* @param programGermplasm
* @param germplasmToProcess
* @return Map<Key = string representing germplasm UUID, value = formatted BrAPIGermplasm>
* @throws ApiException
*/
private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> programGermplasm,
private List<BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> germplasmToProcess,
Program program) throws ApiException {
// Process the germplasm
Map<String, BrAPIGermplasm> programGermplasmMap = new HashMap<>();
log.trace("processing germ for display: " + programGermplasm);
for (BrAPIGermplasm germplasm: programGermplasm) {
log.trace("processing germ for display: " + germplasmToProcess);
for (BrAPIGermplasm germplasm: germplasmToProcess) {

JsonObject additionalInfo = germplasm.getAdditionalInfo();
if (additionalInfo != null && additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_BREEDING_METHOD_ID)) {
Expand Down Expand Up @@ -177,15 +176,15 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas

// This should ease concerns for extra time pulling this data. The intended usage is for the Germplasm data table,
// but any usage under 200 germs (current data table max size) should not be too large of a hit to the server or database.
boolean pedigreeExRefMutation = programGermplasm.size() <= dataTableMaxSize;
boolean pedigreeExRefMutation = germplasmToProcess.size() <= dataTableMaxSize;

if (pedigreeExRefMutation) {
// Only perform this operation for callers that require it
pedigreeBrAPIGermplasmDbIdByBICreatedExRef = getPedigreeGermplasmDbIdByBICreatedExRef(programGermplasm, program);
pedigreeBrAPIGermplasmDbIdByBICreatedExRef = getPedigreeGermplasmDbIdByBICreatedExRef(germplasmToProcess, program);
}

// Update pedigree string
for (BrAPIGermplasm germplasm: programGermplasm) {
for (BrAPIGermplasm germplasm: germplasmToProcess) {
JsonObject additionalInfo = germplasm.getAdditionalInfo();
if(additionalInfo == null) {
additionalInfo = new JsonObject();
Expand Down Expand Up @@ -271,14 +270,10 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas
additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString);
additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString);

germplasm.setPedigree(gidPedigreeString);

BrAPIExternalReference extRef = germplasm.getExternalReferences().stream().filter(reference -> referenceSource.equals(reference.getReferenceSource())).findFirst().orElseThrow(() -> new IllegalStateException("No BI external reference found"));
String germplasmId = extRef.getReferenceID();
programGermplasmMap.put(germplasmId, germplasm);
germplasm.setPedigree(gidPedigreeString);
}

return programGermplasmMap;
return germplasmToProcess;
}

private Map<String, String> getPedigreeGermplasmDbIdByBICreatedExRef(List<BrAPIGermplasm> brAPIGermplasm, Program program) throws ApiException {
Expand Down Expand Up @@ -320,7 +315,7 @@ private Map<String, String> getPedigreeGermplasmDbIdByBICreatedExRef(List<BrAPIG
searchRequest.setExternalReferenceSources(List.of(referenceSource));

// Reuse some code to properly set searchRequest with brapiProgramDbId, and proper paging
searchRequest = buildSearchRequest(program, null, null, searchRequest);
searchRequest = buildSearchRequest(program, searchRequest, null);

GermplasmApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), GermplasmApi.class);

Expand Down Expand Up @@ -364,7 +359,7 @@ private List<BrAPIGermplasm> getBrAPIGermplasmUsingBrAPIProgramId(GermplasmQuery
List<BrAPIGermplasm> result = brAPIDAOUtil.get(api::germplasmGet, germplasmQueryParams);

// TODO: Once cache is removed for this class, fix processGermplasmForDisplay to return List<BrAPIGermplasm> [BI-2906]
return new ArrayList<>(processGermplasmForDisplay(result, program).values());
return processGermplasmForDisplay(result, program);
}

// TODO: hack for now, probably should update breedbase
Expand Down Expand Up @@ -401,7 +396,7 @@ public List<BrAPIGermplasm> createBrAPIGermplasm(List<BrAPIGermplasm> postBrAPIG
try {
if (!postBrAPIGermplasmList.isEmpty()) {
List<BrAPIGermplasm> postResponse = brAPIDAOUtil.post(postBrAPIGermplasmList, upload, api::germplasmPost, importDAO::update);
return new ArrayList<>(processGermplasmForDisplay(postResponse, program).values());
return processGermplasmForDisplay(postResponse, program);
}
return new ArrayList<>();
} catch (Exception e) {
Expand All @@ -415,7 +410,7 @@ public List<BrAPIGermplasm> updateBrAPIGermplasm(List<BrAPIGermplasm> putBrAPIGe
try {
if (!putBrAPIGermplasmList.isEmpty()) {
List<BrAPIGermplasm> putResponse = putGermplasm(putBrAPIGermplasmList, api);
return new ArrayList<>(processGermplasmForDisplay(putResponse, program).values());
return processGermplasmForDisplay(putResponse, program);
}
return new ArrayList<>();
} catch (Exception e) {
Expand All @@ -432,39 +427,42 @@ public List<BrAPIGermplasm> getGermplasmByRawName(List<String> germplasmNames, U
.collect(Collectors.toList());
}

public BrAPIGermplasmListResponse searchGermplasmByRawName(List<String> germplasmNames, UUID programId, GermplasmQuery germplasmQuery) throws ApiException {
Program program = new Program(programDAO.fetchOneById(programId));

BrAPIGermplasmSearchRequest searchRequest = new BrAPIGermplasmSearchRequest();
searchRequest.setGermplasmNames(germplasmNames);

return brapiGermplasmSearchReturnResponse(program, searchRequest, germplasmQuery);
}

public List<BrAPIGermplasm> brapiGermplasmSearchReturnList(Program program,
List<String> brapiGermplasmIds) throws ApiException {
return brapiGermplasmSearchReturnResponse(program, brapiGermplasmIds, null).getResult().getData();
BrAPIGermplasmSearchRequest searchRequest) throws ApiException {
return brapiGermplasmSearchReturnResponse(program, searchRequest, null).getResult().getData();
}

public BrAPIGermplasmListResponse brapiGermplasmSearchReturnResponse(Program program,
List<String> brapiGermplasmIds,
BrAPIGermplasmSearchRequest searchRequest,
GermplasmQuery germplasmQuery) throws ApiException {

GermplasmApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), GermplasmApi.class);

BrAPIGermplasmSearchRequest brAPIGermplasmSearchRequest = buildSearchRequest(program, brapiGermplasmIds, germplasmQuery);
BrAPIGermplasmSearchRequest brAPIGermplasmSearchRequest = buildSearchRequest(program, searchRequest, germplasmQuery);

BrAPIGermplasmListResponse brAPIResponse =
brAPIDAOUtil.simpleSearch(
api::searchGermplasmPost,
brAPIGermplasmSearchRequest
);

// TODO: Once cache is removed for this class, fix processGermplasmForDisplay to return List<BrAPIGermplasm> [BI-2906]
List<BrAPIGermplasm> processedGermplasm =
new ArrayList<>(processGermplasmForDisplay(brAPIDAOUtil.getListResult(brAPIResponse), program).values());
List<BrAPIGermplasm> processedGermplasm = processGermplasmForDisplay(brAPIDAOUtil.getListResult(brAPIResponse), program);

brAPIResponse.getResult().setData(processedGermplasm);

return brAPIResponse;
}

private BrAPIGermplasmSearchRequest buildSearchRequest(Program program, List<String> brapiGermplasmIds, GermplasmQuery query) throws ApiException {
return buildSearchRequest(program, brapiGermplasmIds, query, null);
}

private BrAPIGermplasmSearchRequest buildSearchRequest(Program program, List<String> brapiGermplasmIds, GermplasmQuery germplasmQuery, BrAPIGermplasmSearchRequest searchRequestPassThru) throws ApiException {
private BrAPIGermplasmSearchRequest buildSearchRequest(Program program, BrAPIGermplasmSearchRequest searchRequestPassThru, GermplasmQuery germplasmQuery) throws ApiException {
BrAPIGermplasmSearchRequest searchRequest;

if (searchRequestPassThru == null) {
Expand All @@ -475,10 +473,6 @@ private BrAPIGermplasmSearchRequest buildSearchRequest(Program program, List<Str

searchRequest.programDbIds(List.of(brAPIDAOUtil.getBrAPIProgramDbId(program.getId())));

if (brapiGermplasmIds != null && !brapiGermplasmIds.isEmpty()) {
searchRequest.setGermplasmDbIds(new ArrayList<>(brapiGermplasmIds));
}

brAPIDAOUtil.setGenericSearchParameters(searchRequest, germplasmQuery);

return searchRequest;
Expand All @@ -487,7 +481,10 @@ private BrAPIGermplasmSearchRequest buildSearchRequest(Program program, List<Str
public BrAPIGermplasm getGermplasmByUUID(String germplasmId, UUID programId) throws ApiException, DoesNotExistException {
Program program = new Program(programDAO.fetchOneById(programId));

List<BrAPIGermplasm> result = brapiGermplasmSearchReturnList(program, List.of(germplasmId));
BrAPIGermplasmSearchRequest searchRequest = new BrAPIGermplasmSearchRequest();
searchRequest.setGermplasmDbIds(List.of(germplasmId));

List<BrAPIGermplasm> result = brapiGermplasmSearchReturnList(program, searchRequest);

if (result.size() > 1) {
throw new ApiException(String.format("Multiple germplasms found for germplasm with ID: [%s]", germplasmId));
Expand All @@ -502,7 +499,10 @@ public List<BrAPIGermplasm> getGermplasmsByDBID(Collection<String> germplasmDbId
// TODO: This method is mainly used by the download experiment export tool. This method will fail until we address the parameter limit for async Germplasm requests for germplasmDbIds > 4. Return to this use case during [BI-3021]
Program program = new Program(programDAO.fetchOneById(programId));

return brapiGermplasmSearchReturnList(program, new ArrayList<>(germplasmDbIds));
BrAPIGermplasmSearchRequest searchRequest = new BrAPIGermplasmSearchRequest();
searchRequest.setGermplasmDbIds(new ArrayList<>(germplasmDbIds));

return brapiGermplasmSearchReturnList(program, searchRequest);
}

public List<BrAPIGermplasm> putGermplasm(List<BrAPIGermplasm> germplasmList, GermplasmApi api) throws ApiException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.jooq.tools.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Introspected
Expand Down Expand Up @@ -67,4 +69,42 @@ public SearchRequest constructSearchRequest() {
}
return new SearchRequest(filters);
}

@Override
public Map<String, String> getFilterValuesByBrAPIColumnName() {
Map<String, String> filterValuesByBrAPIColumnName = new HashMap<>();

filterValuesByBrAPIColumnName.put("importEntryNumber", getImportEntryNumber());
filterValuesByBrAPIColumnName.put("accessionNumber", getAccessionNumber());
filterValuesByBrAPIColumnName.put("defaultDisplayName", getDefaultDisplayName());
filterValuesByBrAPIColumnName.put("breedingMethod", getBreedingMethod());
filterValuesByBrAPIColumnName.put("seedSource", getSeedSource());
filterValuesByBrAPIColumnName.put("pedigree", getPedigree());
filterValuesByBrAPIColumnName.put("femaleParentGID", getFemaleParentGID());
filterValuesByBrAPIColumnName.put("maleParentGID", getMaleParentGID());
filterValuesByBrAPIColumnName.put("createdDate", getCreatedDate());
filterValuesByBrAPIColumnName.put("createdBy", getCreatedByUserName());
filterValuesByBrAPIColumnName.put("synonyms", getSynonym());

return filterValuesByBrAPIColumnName;
}

@Override
public Map<String, String> getBrAPIColumnNamesByBiColumnName() {
Map<String, String> brAPIColumnNamesByBiColumnName = new HashMap<>();

brAPIColumnNamesByBiColumnName.put("importEntryNumber", "importEntryNumber");
brAPIColumnNamesByBiColumnName.put("accessionNumber", "accessionNumber");
brAPIColumnNamesByBiColumnName.put("defaultDisplayName", "defaultDisplayName");
brAPIColumnNamesByBiColumnName.put("breedingMethod", "breedingMethod");
brAPIColumnNamesByBiColumnName.put("seedSource", "seedSource");
brAPIColumnNamesByBiColumnName.put("pedigree", "pedigree");
brAPIColumnNamesByBiColumnName.put("femaleParentGID", "femaleParentGID");
brAPIColumnNamesByBiColumnName.put("maleParentGID", "maleParentGID");
brAPIColumnNamesByBiColumnName.put("createdDate", "createdDate");
brAPIColumnNamesByBiColumnName.put("createdBy", "createdByUserName");
brAPIColumnNamesByBiColumnName.put("synonyms", "synonyms");

return brAPIColumnNamesByBiColumnName;
}
}
Loading
Loading