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

BI-2344 - merging into develop #421

Merged
merged 11 commits into from
Oct 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ public HttpResponse<BrAPIPedigreeListResponse> pedigreeGet(@PathVariable("progra
try {
List<BrAPIPedigreeNode> pedigree = pedigreeDAO.getPedigree(
program.get(),
Optional.ofNullable(includeParents),
Optional.ofNullable(includeSiblings),
Optional.ofNullable(includeProgeny),
Optional.ofNullable(includeFullTree),
Optional.ofNullable(pedigreeDepth),
Optional.ofNullable(progenyDepth),
Optional.ofNullable(germplasmName));
includeParents,
includeSiblings,
includeProgeny,
includeFullTree,
pedigreeDepth,
progenyDepth,
germplasmName,
accessionNumber);

return HttpResponse.ok(
new BrAPIPedigreeListResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ public BrAPIPedigreeDAO(ProgramDAO programDAO, BrAPIDAOUtil brAPIDAOUtil,
*/
public List<BrAPIPedigreeNode> getPedigree(
Program program,
Optional<Boolean> includeParents,
Optional<Boolean> includeSiblings,
Optional<Boolean> includeProgeny,
Optional<Boolean> includeFullTree,
Optional<Integer> pedigreeDepth,
Optional<Integer> progenyDepth,
Optional<String> germplasmName
Boolean includeParents,
Boolean includeSiblings,
Boolean includeProgeny,
Boolean includeFullTree,
Integer pedigreeDepth,
Integer progenyDepth,
String germplasmName,
String accessionNumber
) throws ApiException {

PedigreeQueryParams pedigreeRequest = new PedigreeQueryParams();
Expand All @@ -94,13 +95,14 @@ public List<BrAPIPedigreeNode> getPedigree(
pedigreeRequest.externalReferenceId(extRefId);
pedigreeRequest.externalReferenceSource(extRefSrc);

includeParents.ifPresent(pedigreeRequest::includeParents);
includeSiblings.ifPresent(pedigreeRequest::includeSiblings);
includeProgeny.ifPresent(pedigreeRequest::includeProgeny);
includeFullTree.ifPresent(pedigreeRequest::includeFullTree);
pedigreeDepth.ifPresent(pedigreeRequest::pedigreeDepth);
progenyDepth.ifPresent(pedigreeRequest::progenyDepth);
germplasmName.ifPresent(pedigreeRequest::germplasmName);
if (includeParents != null) pedigreeRequest.includeParents(includeParents);
if (includeSiblings != null) pedigreeRequest.includeSiblings(includeSiblings);
if (includeProgeny != null) pedigreeRequest.includeProgeny(includeProgeny);
if (includeFullTree != null) pedigreeRequest.includeFullTree(includeFullTree);
if (pedigreeDepth != null) pedigreeRequest.pedigreeDepth(pedigreeDepth);
if (progenyDepth != null) pedigreeRequest.progenyDepth(progenyDepth);
if (germplasmName != null) pedigreeRequest.germplasmName(germplasmName);
if (accessionNumber != null) pedigreeRequest.accessionNumber(accessionNumber);
// TODO: other parameters

// TODO: write utility to do paging instead of hardcoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ public Optional<BrAPIGermplasm> getGermplasmByDBID(UUID programId, String germpl
return germplasmDAO.getGermplasmByDBID(germplasmId, programId);
}

public List<Map<String, Object>> processListData(List<BrAPIGermplasm> germplasm, BrAPIListDetails germplasmList){
public List<Map<String, Object>> processListData(List<BrAPIGermplasm> germplasm, BrAPIListDetails germplasmList, Program program){
Map<String, BrAPIGermplasm> germplasmByName = new HashMap<>();
for (BrAPIGermplasm g: germplasm) {
germplasmByName.put(g.getGermplasmName(), g);
// Use the full, unique germplasmName with programKey and accessionNumber (GID) for 2 reasons:
// 1. the BrAPI list items are full names, and
// 2. germplasmNames alone are not unique within a program, this led to unexpected behavior, see BI-2344.
String uniqueGermplasmName = String.format("%s [%s-%s]", g.getGermplasmName(), program.getKey(), g.getAccessionNumber());
g.setGermplasmName(uniqueGermplasmName); // Mutate the germplasmName in place for later use.
germplasmByName.put(uniqueGermplasmName, g);
}

List<Map<String, Object>> processedData = new ArrayList<>();
Expand All @@ -107,14 +112,13 @@ public List<Map<String, Object>> processListData(List<BrAPIGermplasm> germplasm,
for (String germplasmName: orderedGermplasmNames) {
// Increment entryNumber.
++entryNumber;
// Strip program key and accession number from germplasm name.
germplasmName = Utilities.removeUnknownProgramKey(germplasmName); // TODO: could move to the germplasmList != null codepath.
// Lookup the BrAPI germplasm in the map.
BrAPIGermplasm germplasmEntry = germplasmByName.get(germplasmName);

HashMap<String, Object> row = new HashMap<>();
row.put("GID", Integer.valueOf(germplasmEntry.getAccessionNumber()));
row.put("Germplasm Name", germplasmEntry.getGermplasmName());
// Strip programKey and accessionNumber from germplasmName for the file output.
row.put("Germplasm Name", Utilities.removeProgramKeyAnyAccession(germplasmEntry.getGermplasmName(), program.getKey()));
row.put("Breeding Method", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_BREEDING_METHOD).getAsString());
String source = germplasmEntry.getSeedSource();
row.put("Source", source);
Expand Down Expand Up @@ -217,7 +221,7 @@ private BrAPIGermplasm cloneBrAPIGermplasm(BrAPIGermplasm germplasm) {
return (BrAPIGermplasm) gson.fromJson(gson.toJson(germplasm), BrAPIGermplasm.class);
}

public DownloadFile exportGermplasm(UUID programId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException {
public DownloadFile exportGermplasm(UUID programId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException, DoesNotExistException {
List<Column> columns = GermplasmFileColumns.getOrderedColumns();

//Retrieve germplasm list data
Expand All @@ -238,7 +242,8 @@ public DownloadFile exportGermplasm(UUID programId, FileType fileExtension) thro

StreamedFile downloadFile;
//Convert list data to List<Map<String, Object>> data to pass into file writer
List<Map<String, Object>> processedData = processListData(germplasm, null);
Program program = programService.getById(programId).orElseThrow(() -> new DoesNotExistException("Could not find program: " + programId));
List<Map<String, Object>> processedData = processListData(germplasm, null, program);

if (fileExtension == FileType.CSV){
downloadFile = CSVWriter.writeToDownload(columns, processedData, fileExtension);
Expand All @@ -249,7 +254,7 @@ public DownloadFile exportGermplasm(UUID programId, FileType fileExtension) thro
return new DownloadFile(fileName, downloadFile);
}

public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException {
public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException, DoesNotExistException {
List<Column> columns = GermplasmFileColumns.getOrderedColumns();

//Retrieve germplasm list data
Expand All @@ -260,15 +265,12 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType
List<BrAPIGermplasm> germplasm = germplasmDAO.getGermplasmByRawName(germplasmNames, programId);

String listName = listData.getListName();
Optional<Program> optionalProgram = programService.getById(programId);
if (optionalProgram.isPresent()) {
Program program = optionalProgram.get();
listName = removeAppendedKey(listName, program.getKey());
}
Program program = programService.getById(programId).orElseThrow(() -> new DoesNotExistException("Could not find program: " + programId));
listName = removeAppendedKey(listName, program.getKey());
String fileName = createFileName(listData, listName);
StreamedFile downloadFile;
//Convert list data to List<Map<String, Object>> data to pass into file writer
List<Map<String, Object>> processedData = processListData(germplasm, listData);
List<Map<String, Object>> processedData = processListData(germplasm, listData, program);

if (fileExtension == FileType.CSV){
downloadFile = CSVWriter.writeToDownload(columns, processedData, fileExtension);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
# limitations under the License.
#


version=v1.1.0+852
versionInfo=https://github.com/Breeding-Insight/bi-api/commit/3fbb75f662c5600da816270d53699aa1192777b9
Loading