From 744e588b81afb15310acb597c7a7b59bb2bd426b Mon Sep 17 00:00:00 2001 From: HMS17 <84345306+HMS17@users.noreply.github.com> Date: Wed, 17 Aug 2022 15:35:38 -0400 Subject: [PATCH 1/6] [BI-1230] Unknown Germplasm, saving, display, start of pedigree work --- .../brapi/v2/GermplasmController.java | 80 ++++++++++++++++++- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 21 +++++ .../v2/services/BrAPIGermplasmService.java | 8 ++ .../processors/GermplasmProcessor.java | 52 ++++++++---- 4 files changed, 146 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java index 9f3792b2f..7f746edb6 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java @@ -1,5 +1,6 @@ package org.breedinginsight.brapi.v2; +import com.fasterxml.jackson.annotation.JsonProperty; import io.micronaut.http.HttpHeaders; import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpStatus; @@ -10,8 +11,15 @@ import io.micronaut.security.annotation.Secured; import io.micronaut.security.rules.SecurityRule; import lombok.extern.slf4j.Slf4j; +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.BrAPIMetadata; import org.brapi.v2.model.germ.BrAPIGermplasm; +import org.brapi.v2.model.germ.BrAPIParentType; +import org.brapi.v2.model.germ.BrAPIPedigreeNode; +import org.brapi.v2.model.germ.BrAPIPedigreeNodeParents; +import org.brapi.v2.model.germ.response.BrAPIGermplasmPedigreeResponse; import org.breedinginsight.api.auth.ProgramSecured; import org.breedinginsight.api.auth.ProgramSecuredRoleGroup; import org.breedinginsight.api.model.v1.request.query.SearchRequest; @@ -25,6 +33,7 @@ import org.breedinginsight.brapi.v2.model.response.mappers.GermplasmQueryMapper; import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService; import org.breedinginsight.brapps.importer.model.exports.FileType; +import org.breedinginsight.daos.ProgramDAO; import org.breedinginsight.model.DownloadFile; import org.breedinginsight.services.exceptions.DoesNotExistException; import org.breedinginsight.utilities.response.ResponseUtils; @@ -42,11 +51,14 @@ public class GermplasmController { private final BrAPIGermplasmService germplasmService; private final GermplasmQueryMapper germplasmQueryMapper; + private final ProgramDAO programDAO; + @Inject - public GermplasmController(BrAPIGermplasmService germplasmService, GermplasmQueryMapper germplasmQueryMapper) { + public GermplasmController(BrAPIGermplasmService germplasmService, GermplasmQueryMapper germplasmQueryMapper, ProgramDAO programDAO) { this.germplasmService = germplasmService; this.germplasmQueryMapper = germplasmQueryMapper; + this.programDAO = programDAO; } @Post("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/search/germplasm{?queryParams*}") @@ -124,4 +136,70 @@ public HttpResponse> getSingleGermplasm( return HttpResponse.status(HttpStatus.NOT_FOUND, "Germplasm not found"); } } + + + //todo add queryparams for includeSiblings and notation + @Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/germplasm/{germplasmId}/pedigree{?notation}{?includeSiblings}") + @Produces(MediaType.APPLICATION_JSON) + @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) + public HttpResponse getGermplasmPedigreeInfo( + @PathVariable("programId") UUID programId, + @PathVariable("germplasmId") String germplasmId, + @QueryValue(defaultValue = "") String notation, + @QueryValue(defaultValue = "false") Boolean includeSiblings) { + try { + log.debug("fetching pedigree for germ id:" + germplasmId +" for program: " + programId); + BrAPIPedigreeNode returnNode; + BrAPIGermplasmPedigreeResponse response; + BrAPIMetadata metadata; + if (germplasmId == "0") { + //todo check germplasmId is germplasmDbId + //Unknown germplasm node + returnNode = new BrAPIPedigreeNode(); + returnNode.setGermplasmDbId("0"); + returnNode.setGermplasmName("Unknown"); + returnNode.setParents(null); + returnNode.setSiblings(null); + returnNode.setPedigree(null); + metadata = new BrAPIMetadata(); + response = new BrAPIGermplasmPedigreeResponse(); + } else { + BrAPIGermplasm germplasm = germplasmService.getGermplasmByDBID(programId, germplasmId); + //Forward the pedigree call to the backing BrAPI system of the program passing the germplasmDbId that came in the request + GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId)); + ApiResponse pedigreeResponse = api.germplasmGermplasmDbIdPedigreeGet(germplasmId, notation, includeSiblings); + returnNode = pedigreeResponse.getBody().getResult(); + metadata = pedigreeResponse.getBody().getMetadata(); + response = pedigreeResponse.getBody(); + + //Add nodes for unknown parents if applicable + if (germplasm.getAdditionalInfo().has("femaleParentUnknown") && germplasm.getAdditionalInfo().get("femaleParentUnknown").getAsBoolean()) { + BrAPIPedigreeNodeParents unknownFemale = new BrAPIPedigreeNodeParents(); + unknownFemale.setGermplasmDbId("0"); + unknownFemale.setGermplasmName("Unknown"); + unknownFemale.setParentType(BrAPIParentType.FEMALE); + returnNode.addParentsItem(unknownFemale); + } + if (germplasm.getAdditionalInfo().has("maleParentUnknown") && germplasm.getAdditionalInfo().get("maleParentUnknown").getAsBoolean()) { + BrAPIPedigreeNodeParents unknownMale = new BrAPIPedigreeNodeParents(); + unknownMale.setGermplasmDbId("0"); + unknownMale.setGermplasmName("Unknown"); + unknownMale.setParentType(BrAPIParentType.FEMALE); + returnNode.addParentsItem(unknownMale); + } + } + response.setResult(returnNode); + return HttpResponse.ok(response); + } catch (InternalServerException e) { + log.info(e.getMessage(), e); + return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving pedigree node"); + } catch (DoesNotExistException e) { + log.info(e.getMessage(), e); + return HttpResponse.status(HttpStatus.NOT_FOUND, "Pedigree node not found"); + } catch (ApiException e) { + log.info(e.getMessage(), e); + return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving pedigree node"); + } + } + } diff --git a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java index c8f42b303..052da5b71 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -161,6 +161,7 @@ private Map processGermplasmForDisplay(List processGermplasmForDisplay(List cache = programGermplasmCache.get(programId); + //key is UUID, want to filter by DBID + BrAPIGermplasm germplasm = null; + if (cache != null) { + germplasm = cache.values().stream().filter(x -> x.getGermplasmDbId().equals(germplasmDbId)).collect(Collectors.toList()).get(0); + } + if (germplasm == null) { + throw new DoesNotExistException("DBID for this germplasm does not exist"); + } + return germplasm; + } + } diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index ced8c02f7..12a137b07 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -70,6 +70,14 @@ public BrAPIGermplasm getGermplasmByUUID(UUID programId, String germplasmId) thr } } + public BrAPIGermplasm getGermplasmByDBID(UUID programId, String germplasmId) throws DoesNotExistException { + try { + return germplasmDAO.getGermplasmByDBID(germplasmId, programId); + } catch (ApiException e) { + throw new InternalServerException(e.getMessage(), e); + } + } + public List getGermplasmListsByProgramId(UUID programId, HttpRequest request) throws DoesNotExistException, ApiException { if (!programService.exists(programId)) { diff --git a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java index e6ace6a6e..a1189a7c7 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java +++ b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java @@ -61,9 +61,9 @@ public class GermplasmProcessor implements Processor { private String BRAPI_REFERENCE_SOURCE; private BrAPIGermplasmService brAPIGermplasmService; - private BreedingMethodDAO breedingMethodDAO; - private BrAPIListDAO brAPIListDAO; - private DSLContext dsl; + private final BreedingMethodDAO breedingMethodDAO; + private final BrAPIListDAO brAPIListDAO; + private final DSLContext dsl; Map> germplasmByAccessionNumber = new HashMap<>(); Map fileGermplasmByName = new HashMap<>(); @@ -128,6 +128,8 @@ public void getExistingBrapiData(List importRows, Program program) List missingDbIds = new ArrayList<>(germplasmDBIDs); if (germplasmDBIDs.size() > 0) { try { + //Remove germplasm DBID of 0 todo may move this + germplasmDBIDs.remove("0"); existingParentGermplasms = brAPIGermplasmService.getRawGermplasmByAccessionNumber(new ArrayList<>(germplasmDBIDs), program.getId()); List existingDbIds = existingParentGermplasms.stream() .map(germplasm -> germplasm.getAccessionNumber()) @@ -149,6 +151,7 @@ public void getExistingBrapiData(List importRows, Program program) List dbGermplasm = brAPIGermplasmService.getGermplasmByDisplayName(new ArrayList<>(fileGermplasmByName.keySet()), program.getId()); dbGermplasm.stream().forEach(germplasm -> dbGermplasmByName.put(germplasm.getDefaultDisplayName(), germplasm)); + /* // Check for existing germplasm lists Boolean listNameDup = false; if (importRows.size() > 0 && importRows.get(0).getGermplasm().getListName() != null) { @@ -164,7 +167,7 @@ public void getExistingBrapiData(List importRows, Program program) } catch (ApiException e) { throw new InternalServerException(e.toString(), e); } - } + }*/ // Parent reference checks if (missingDbIds.size() > 0) { @@ -178,13 +181,13 @@ public void getExistingBrapiData(List importRows, Program program) Germplasm germplasm = importRow.getGermplasm(); // Check Female Parent if (germplasm.getFemaleParentEntryNo() != null) { - if (!germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo())) { + if ((!germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo())) && !(germplasm.getFemaleParentEntryNo().equals("0"))) { missingEntryNumbers.add(germplasm.getFemaleParentEntryNo()); } } // Check Male Parent if (germplasm.getMaleParentEntryNo() != null) { - if (!germplasmIndexByEntryNo.containsKey(germplasm.getMaleParentEntryNo())) { + if ((!germplasmIndexByEntryNo.containsKey(germplasm.getMaleParentEntryNo())) && !(germplasm.getMaleParentEntryNo().equals("0"))) { missingEntryNumbers.add(germplasm.getMaleParentEntryNo()); } } @@ -195,9 +198,10 @@ public void getExistingBrapiData(List importRows, Program program) arrayOfStringFormatter.apply(missingEntryNumbers))); } + /* if (listNameDup) { throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, listNameAlreadyExists); - } + }*/ } @Override @@ -352,8 +356,8 @@ private void createPostOrder() { List pedigreeArray = List.of(germplasm.getPedigree().split("/")); String femaleParent = pedigreeArray.get(0); String maleParent = pedigreeArray.size() > 1 ? pedigreeArray.get(1) : null; - if (created.contains(femaleParent)) { - if (maleParent == null || created.contains(maleParent)) { + if (created.contains(femaleParent) || germplasm.getAdditionalInfo().get("femaleParentUnknown").getAsBoolean()) { + if (maleParent == null || created.contains(maleParent) || germplasm.getAdditionalInfo().get("maleParentUnknown").getAsBoolean()) { createList.add(germplasm); } } @@ -434,16 +438,24 @@ public void constructPedigreeString(List importRows, Map importRows, Map Date: Mon, 22 Aug 2022 10:07:02 -0400 Subject: [PATCH 2/6] [BI-1230] Progeny endpoint attempt --- .../brapi/v2/GermplasmController.java | 84 ++++++++++++++++--- .../v2/services/BrAPIGermplasmService.java | 7 ++ 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java index 7f746edb6..911085d1a 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java @@ -14,12 +14,12 @@ 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.BrAPIIndexPagination; import org.brapi.v2.model.BrAPIMetadata; -import org.brapi.v2.model.germ.BrAPIGermplasm; -import org.brapi.v2.model.germ.BrAPIParentType; -import org.brapi.v2.model.germ.BrAPIPedigreeNode; -import org.brapi.v2.model.germ.BrAPIPedigreeNodeParents; +import org.brapi.v2.model.BrAPIStatus; +import org.brapi.v2.model.germ.*; import org.brapi.v2.model.germ.response.BrAPIGermplasmPedigreeResponse; +import org.brapi.v2.model.germ.response.BrAPIGermplasmProgenyResponse; import org.breedinginsight.api.auth.ProgramSecured; import org.breedinginsight.api.auth.ProgramSecuredRoleGroup; import org.breedinginsight.api.model.v1.request.query.SearchRequest; @@ -41,6 +41,8 @@ import javax.inject.Inject; import javax.validation.Valid; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.UUID; @@ -137,8 +139,6 @@ public HttpResponse> getSingleGermplasm( } } - - //todo add queryparams for includeSiblings and notation @Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/germplasm/{germplasmId}/pedigree{?notation}{?includeSiblings}") @Produces(MediaType.APPLICATION_JSON) @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) @@ -152,16 +152,25 @@ public HttpResponse getGermplasmPedigreeInfo( BrAPIPedigreeNode returnNode; BrAPIGermplasmPedigreeResponse response; BrAPIMetadata metadata; - if (germplasmId == "0") { - //todo check germplasmId is germplasmDbId + if (germplasmId.equals("0")) { //Unknown germplasm node returnNode = new BrAPIPedigreeNode(); returnNode.setGermplasmDbId("0"); returnNode.setGermplasmName("Unknown"); - returnNode.setParents(null); - returnNode.setSiblings(null); - returnNode.setPedigree(null); + returnNode.setParents(new ArrayList<>()); + returnNode.setSiblings(new ArrayList<>()); + returnNode.setPedigree("/"); metadata = new BrAPIMetadata(); + BrAPIStatus status = new BrAPIStatus(); + status.setMessage("Complete"); + status.setMessageType(BrAPIStatus.MessageTypeEnum.INFO); + BrAPIIndexPagination pagination = new BrAPIIndexPagination(); + pagination.setTotalPages(1); + pagination.setTotalCount(1); + pagination.setPageSize(1); + pagination.setCurrentPage(0); + metadata.setStatus(Collections.singletonList(status)); + metadata.setPagination(pagination); response = new BrAPIGermplasmPedigreeResponse(); } else { BrAPIGermplasm germplasm = germplasmService.getGermplasmByDBID(programId, germplasmId); @@ -189,6 +198,7 @@ public HttpResponse getGermplasmPedigreeInfo( } } response.setResult(returnNode); + response.setMetadata(metadata); return HttpResponse.ok(response); } catch (InternalServerException e) { log.info(e.getMessage(), e); @@ -202,4 +212,56 @@ public HttpResponse getGermplasmPedigreeInfo( } } + @Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/germplasm/{germplasmId}/progeny") + @Produces(MediaType.APPLICATION_JSON) + @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) + public HttpResponse getGermplasmProgenyInfo( + @PathVariable("programId") UUID programId, + @PathVariable("germplasmId") String germplasmId) { + try { + log.debug("fetching progeny for germ id:" + germplasmId +" for program: " + programId); + BrAPIProgenyNode returnNode; + BrAPIGermplasmProgenyResponse response; + BrAPIMetadata metadata; + if (germplasmId.equals("0")) { + //Unknown germplasm node + returnNode = new BrAPIProgenyNode(); + returnNode.setGermplasmDbId("0"); + returnNode.setGermplasmName("Unknown"); + returnNode.setProgeny(new ArrayList<>()); + + metadata = new BrAPIMetadata(); + BrAPIStatus status = new BrAPIStatus(); + status.setMessage("Complete"); + status.setMessageType(BrAPIStatus.MessageTypeEnum.INFO); + BrAPIIndexPagination pagination = new BrAPIIndexPagination(); + pagination.setTotalPages(1); + pagination.setTotalCount(1); + pagination.setPageSize(1); + pagination.setCurrentPage(0); + metadata.setStatus(Collections.singletonList(status)); + metadata.setPagination(pagination); + response = new BrAPIGermplasmProgenyResponse(); + response.setResult(returnNode); + response.setMetadata(metadata); + return HttpResponse.ok(response); + } else { + BrAPIGermplasm germplasm = germplasmService.getGermplasmByDBID(programId, germplasmId); + //Forward the progeny call to the backing BrAPI system of the program passing the germplasmDbId that came in the request + GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId)); + ApiResponse progenyResponse = api.germplasmGermplasmDbIdProgenyGet(germplasmId); + return HttpResponse.ok(progenyResponse.getBody()); + } + } catch (InternalServerException e) { + log.info(e.getMessage(), e); + return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving pedigree node"); + } catch (DoesNotExistException e) { + log.info(e.getMessage(), e); + return HttpResponse.status(HttpStatus.NOT_FOUND, "Pedigree node not found"); + } catch (ApiException e) { + log.info(e.getMessage(), e); + return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving pedigree node"); + } + } + } diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 12a137b07..169c171c7 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -64,6 +64,13 @@ public List getGermplasm(UUID programId) throws ApiException { public BrAPIGermplasm getGermplasmByUUID(UUID programId, String germplasmId) throws DoesNotExistException { try { + if (germplasmId.equals(0)){ + //Unknown germplasm todo check if this necessary + BrAPIGermplasm unknownGermplasm = new BrAPIGermplasm(); + unknownGermplasm.setGermplasmName("Unknown"); + unknownGermplasm.setGermplasmDbId("0"); + return unknownGermplasm; + } return germplasmDAO.getGermplasmByUUID(germplasmId, programId); } catch (ApiException e) { throw new InternalServerException(e.getMessage(), e); From a50223c5be77258cd6dc7d1591eff5eefd61eead Mon Sep 17 00:00:00 2001 From: HMS17 <84345306+HMS17@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:34:45 -0400 Subject: [PATCH 3/6] Unknown germplasm displays minus 10+ progeny --- .../brapi/v2/GermplasmController.java | 65 +++++++++++++------ .../brapi/v2/dao/BrAPIGermplasmDAO.java | 37 +++++++++++ .../v2/services/BrAPIGermplasmService.java | 7 -- .../processors/GermplasmProcessor.java | 13 ++-- 4 files changed, 89 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java index 911085d1a..f2075782f 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java @@ -29,6 +29,7 @@ import org.breedinginsight.api.model.v1.validators.SearchValid; import org.breedinginsight.brapi.v1.controller.BrapiVersion; import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery; +import org.breedinginsight.brapi.v2.dao.BrAPIGermplasmDAO; import org.breedinginsight.brapi.v2.model.request.query.GermplasmQuery; import org.breedinginsight.brapi.v2.model.response.mappers.GermplasmQueryMapper; import org.breedinginsight.brapi.v2.services.BrAPIGermplasmService; @@ -54,13 +55,15 @@ public class GermplasmController { private final BrAPIGermplasmService germplasmService; private final GermplasmQueryMapper germplasmQueryMapper; private final ProgramDAO programDAO; + private final BrAPIGermplasmDAO germplasmDAO; @Inject - public GermplasmController(BrAPIGermplasmService germplasmService, GermplasmQueryMapper germplasmQueryMapper, ProgramDAO programDAO) { + public GermplasmController(BrAPIGermplasmService germplasmService, GermplasmQueryMapper germplasmQueryMapper, ProgramDAO programDAO, BrAPIGermplasmDAO germplasmDAO) { this.germplasmService = germplasmService; this.germplasmQueryMapper = germplasmQueryMapper; this.programDAO = programDAO; + this.germplasmDAO = germplasmDAO; } @Post("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/search/germplasm{?queryParams*}") @@ -146,18 +149,22 @@ public HttpResponse getGermplasmPedigreeInfo( @PathVariable("programId") UUID programId, @PathVariable("germplasmId") String germplasmId, @QueryValue(defaultValue = "") String notation, - @QueryValue(defaultValue = "false") Boolean includeSiblings) { + @QueryValue(defaultValue = "false") Boolean includeSiblings) + { try { log.debug("fetching pedigree for germ id:" + germplasmId +" for program: " + programId); BrAPIPedigreeNode returnNode; BrAPIGermplasmPedigreeResponse response; BrAPIMetadata metadata; - if (germplasmId.equals("0")) { + if (germplasmId.endsWith("-Unknown")) { //Unknown germplasm node returnNode = new BrAPIPedigreeNode(); - returnNode.setGermplasmDbId("0"); + returnNode.setGermplasmDbId(germplasmId); returnNode.setGermplasmName("Unknown"); - returnNode.setParents(new ArrayList<>()); + + BrAPIPedigreeNodeParents emptyParents = new BrAPIPedigreeNodeParents(); + returnNode.addParentsItem(emptyParents); + returnNode.setSiblings(new ArrayList<>()); returnNode.setPedigree("/"); metadata = new BrAPIMetadata(); @@ -184,18 +191,24 @@ public HttpResponse getGermplasmPedigreeInfo( //Add nodes for unknown parents if applicable if (germplasm.getAdditionalInfo().has("femaleParentUnknown") && germplasm.getAdditionalInfo().get("femaleParentUnknown").getAsBoolean()) { BrAPIPedigreeNodeParents unknownFemale = new BrAPIPedigreeNodeParents(); - unknownFemale.setGermplasmDbId("0"); + unknownFemale.setGermplasmDbId(germplasm.getGermplasmDbId()+"-F-Unknown"); unknownFemale.setGermplasmName("Unknown"); unknownFemale.setParentType(BrAPIParentType.FEMALE); returnNode.addParentsItem(unknownFemale); } if (germplasm.getAdditionalInfo().has("maleParentUnknown") && germplasm.getAdditionalInfo().get("maleParentUnknown").getAsBoolean()) { BrAPIPedigreeNodeParents unknownMale = new BrAPIPedigreeNodeParents(); - unknownMale.setGermplasmDbId("0"); + unknownMale.setGermplasmDbId(germplasm.getGermplasmDbId()+"-M-Unknown"); unknownMale.setGermplasmName("Unknown"); - unknownMale.setParentType(BrAPIParentType.FEMALE); + unknownMale.setParentType(BrAPIParentType.MALE); returnNode.addParentsItem(unknownMale); } + + //If no parents, need to add empty parents for display to work + if (returnNode.getParents().isEmpty()) { + BrAPIPedigreeNodeParents emptyParents = new BrAPIPedigreeNodeParents(); + returnNode.addParentsItem(emptyParents); + } } response.setResult(returnNode); response.setMetadata(metadata); @@ -217,18 +230,29 @@ public HttpResponse getGermplasmPedigreeInfo( @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) public HttpResponse getGermplasmProgenyInfo( @PathVariable("programId") UUID programId, - @PathVariable("germplasmId") String germplasmId) { + @PathVariable("germplasmId") String germplasmId, + @QueryValue(defaultValue = "0") String page) { try { log.debug("fetching progeny for germ id:" + germplasmId +" for program: " + programId); BrAPIProgenyNode returnNode; BrAPIGermplasmProgenyResponse response; BrAPIMetadata metadata; - if (germplasmId.equals("0")) { - //Unknown germplasm node + if (germplasmId.endsWith("-Unknown")) { + //Unknown germplasm node, only has one child + //We know progeny and parent type based on germplasmId returnNode = new BrAPIProgenyNode(); - returnNode.setGermplasmDbId("0"); - returnNode.setGermplasmName("Unknown"); - returnNode.setProgeny(new ArrayList<>()); + returnNode.setGermplasmDbId(germplasmId); + returnNode.setGermplasmName("Unknown [-0]"); + ArrayList progeny = new ArrayList<>(); + BrAPIProgenyNodeProgeny singleProgeny = new BrAPIProgenyNodeProgeny(); + singleProgeny.setGermplasmDbId(germplasmId.split("-")[0]); + singleProgeny.setGermplasmName("todo"); //todo, see if necessary, preferable to avoid longer id string/making more endpoint calls + if (germplasmId.endsWith("F-Unknown")) { + singleProgeny.setParentType(BrAPIParentType.FEMALE); + } else { + singleProgeny.setParentType(BrAPIParentType.MALE); + } + returnNode.setProgeny(Collections.singletonList(singleProgeny)); metadata = new BrAPIMetadata(); BrAPIStatus status = new BrAPIStatus(); @@ -246,18 +270,21 @@ public HttpResponse getGermplasmProgenyInfo( response.setMetadata(metadata); return HttpResponse.ok(response); } else { - BrAPIGermplasm germplasm = germplasmService.getGermplasmByDBID(programId, germplasmId); //Forward the progeny call to the backing BrAPI system of the program passing the germplasmDbId that came in the request GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId)); - ApiResponse progenyResponse = api.germplasmGermplasmDbIdProgenyGet(germplasmId); + //need new method to make api call? + ApiResponse progenyResponse = germplasmDAO.getGermplasmProgenyByDBID(programId, germplasmId, page); + //ApiResponse progenyResponse = api.germplasmGermplasmDbIdProgenyGet(germplasmId); + //If no progeny, need to add empty progeny for display to work + if (progenyResponse.getBody().getResult().getProgeny().isEmpty()) { + BrAPIProgenyNodeProgeny emptyProgeny = new BrAPIProgenyNodeProgeny(); + progenyResponse.getBody().getResult().addProgenyItem(emptyProgeny); + } return HttpResponse.ok(progenyResponse.getBody()); } } catch (InternalServerException e) { log.info(e.getMessage(), e); return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving pedigree node"); - } catch (DoesNotExistException e) { - log.info(e.getMessage(), e); - return HttpResponse.status(HttpStatus.NOT_FOUND, "Pedigree node not found"); } catch (ApiException e) { log.info(e.getMessage(), e); return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving pedigree node"); diff --git a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java index 052da5b71..9d51f5caf 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -18,16 +18,21 @@ package org.breedinginsight.brapi.v2.dao; import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; import io.micronaut.context.annotation.Context; import io.micronaut.context.annotation.Property; import io.micronaut.http.server.exceptions.InternalServerException; import lombok.extern.slf4j.Slf4j; +import okhttp3.*; +import org.brapi.client.v2.ApiResponse; +import org.brapi.client.v2.BrAPIClient; import org.brapi.client.v2.model.exceptions.ApiException; import org.brapi.client.v2.modules.germplasm.GermplasmApi; import org.brapi.v2.model.BrAPIExternalReference; import org.brapi.v2.model.germ.BrAPIGermplasm; import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest; +import org.brapi.v2.model.germ.response.BrAPIGermplasmProgenyResponse; import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; @@ -40,6 +45,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Singleton; +import java.lang.reflect.Type; import java.util.*; import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -263,4 +269,35 @@ public BrAPIGermplasm getGermplasmByDBID(String germplasmDbId, UUID programId) t return germplasm; } + public ApiResponse getGermplasmProgenyByDBID(UUID programId, String germplasmDbId, String page) throws ApiException { + BrAPIClient apiClient = programDAO.getCoreClient(programId); + + if (germplasmDbId == null) { + throw new IllegalArgumentException("germplasmDbId cannot be null"); + } else { + Object localVarPostBody = null; + String localVarPath = "/germplasm/{germplasmDbId}/progeny".replaceAll("\\{germplasmDbId\\}", germplasmDbId); + Map localVarQueryParams = new HashMap(); + Map localVarCollectionQueryParams = new HashMap(); + Map localVarHeaderParams = new HashMap(); + Map localVarFormParams = new HashMap(); + apiClient.prepQueryParameter(localVarQueryParams, "page", page); + + String[] localVarAccepts = new String[]{"application/json"}; + String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); //todo next + if (localVarAccept != null) { + localVarHeaderParams.put("Accept", localVarAccept); + } + + String[] localVarContentTypes = new String[0]; + String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + localVarHeaderParams.put("Content-Type", localVarContentType); + String[] localVarAuthNames = new String[]{"AuthorizationToken"}; + Call call = apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames); + Type localVarReturnType = (new TypeToken() { + }).getType(); + return apiClient.execute(call, localVarReturnType);//verify, grab body, etc + } + } + } diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 169c171c7..12a137b07 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -64,13 +64,6 @@ public List getGermplasm(UUID programId) throws ApiException { public BrAPIGermplasm getGermplasmByUUID(UUID programId, String germplasmId) throws DoesNotExistException { try { - if (germplasmId.equals(0)){ - //Unknown germplasm todo check if this necessary - BrAPIGermplasm unknownGermplasm = new BrAPIGermplasm(); - unknownGermplasm.setGermplasmName("Unknown"); - unknownGermplasm.setGermplasmDbId("0"); - return unknownGermplasm; - } return germplasmDAO.getGermplasmByUUID(germplasmId, programId); } catch (ApiException e) { throw new InternalServerException(e.getMessage(), e); diff --git a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java index a1189a7c7..f6400d074 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java +++ b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java @@ -128,8 +128,6 @@ public void getExistingBrapiData(List importRows, Program program) List missingDbIds = new ArrayList<>(germplasmDBIDs); if (germplasmDBIDs.size() > 0) { try { - //Remove germplasm DBID of 0 todo may move this - germplasmDBIDs.remove("0"); existingParentGermplasms = brAPIGermplasmService.getRawGermplasmByAccessionNumber(new ArrayList<>(germplasmDBIDs), program.getId()); List existingDbIds = existingParentGermplasms.stream() .map(germplasm -> germplasm.getAccessionNumber()) @@ -151,13 +149,12 @@ public void getExistingBrapiData(List importRows, Program program) List dbGermplasm = brAPIGermplasmService.getGermplasmByDisplayName(new ArrayList<>(fileGermplasmByName.keySet()), program.getId()); dbGermplasm.stream().forEach(germplasm -> dbGermplasmByName.put(germplasm.getDefaultDisplayName(), germplasm)); - /* // Check for existing germplasm lists Boolean listNameDup = false; if (importRows.size() > 0 && importRows.get(0).getGermplasm().getListName() != null) { try { Germplasm row = importRows.get(0).getGermplasm(); - String listName = row.constructGermplasmListName(row.getListName(), program); + String listName = Germplasm.constructGermplasmListName(row.getListName(), program); List existingLists = brAPIListDAO.getListByName(List.of(listName), program.getId()); for (BrAPIListSummary existingList: existingLists) { if (existingList.getListName().equals(listName)) { @@ -167,7 +164,10 @@ public void getExistingBrapiData(List importRows, Program program) } catch (ApiException e) { throw new InternalServerException(e.toString(), e); } - }*/ + } + + //Remove id indicating unknown parent + missingDbIds.remove("0"); // Parent reference checks if (missingDbIds.size() > 0) { @@ -198,10 +198,9 @@ public void getExistingBrapiData(List importRows, Program program) arrayOfStringFormatter.apply(missingEntryNumbers))); } - /* if (listNameDup) { throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, listNameAlreadyExists); - }*/ + } } @Override From 1f0628712bc1ddefef316fdde8f9236e8e2b246c Mon Sep 17 00:00:00 2001 From: HMS17 <84345306+HMS17@users.noreply.github.com> Date: Wed, 7 Sep 2022 12:09:06 -0400 Subject: [PATCH 4/6] Cleanup --- .../brapi/v2/GermplasmController.java | 12 ++---- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 39 ------------------- .../processors/GermplasmProcessor.java | 5 +-- 3 files changed, 5 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java index f2075782f..e7a01aaea 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java @@ -1,6 +1,5 @@ package org.breedinginsight.brapi.v2; -import com.fasterxml.jackson.annotation.JsonProperty; import io.micronaut.http.HttpHeaders; import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpStatus; @@ -41,7 +40,6 @@ import javax.inject.Inject; import javax.validation.Valid; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -230,8 +228,7 @@ public HttpResponse getGermplasmPedigreeInfo( @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) public HttpResponse getGermplasmProgenyInfo( @PathVariable("programId") UUID programId, - @PathVariable("germplasmId") String germplasmId, - @QueryValue(defaultValue = "0") String page) { + @PathVariable("germplasmId") String germplasmId) { try { log.debug("fetching progeny for germ id:" + germplasmId +" for program: " + programId); BrAPIProgenyNode returnNode; @@ -246,7 +243,7 @@ public HttpResponse getGermplasmProgenyInfo( ArrayList progeny = new ArrayList<>(); BrAPIProgenyNodeProgeny singleProgeny = new BrAPIProgenyNodeProgeny(); singleProgeny.setGermplasmDbId(germplasmId.split("-")[0]); - singleProgeny.setGermplasmName("todo"); //todo, see if necessary, preferable to avoid longer id string/making more endpoint calls + singleProgeny.setGermplasmName("Name"); //does not seem necessary, preferable to avoid longer id string/making more endpoint calls if (germplasmId.endsWith("F-Unknown")) { singleProgeny.setParentType(BrAPIParentType.FEMALE); } else { @@ -272,9 +269,8 @@ public HttpResponse getGermplasmProgenyInfo( } else { //Forward the progeny call to the backing BrAPI system of the program passing the germplasmDbId that came in the request GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId)); - //need new method to make api call? - ApiResponse progenyResponse = germplasmDAO.getGermplasmProgenyByDBID(programId, germplasmId, page); - //ApiResponse progenyResponse = api.germplasmGermplasmDbIdProgenyGet(germplasmId); + ApiResponse progenyResponse = api.germplasmGermplasmDbIdProgenyGet(germplasmId); + //If no progeny, need to add empty progeny for display to work if (progenyResponse.getBody().getResult().getProgeny().isEmpty()) { BrAPIProgenyNodeProgeny emptyProgeny = new BrAPIProgenyNodeProgeny(); diff --git a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java index 9d51f5caf..a76180658 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -18,21 +18,16 @@ package org.breedinginsight.brapi.v2.dao; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import io.micronaut.context.annotation.Context; import io.micronaut.context.annotation.Property; import io.micronaut.http.server.exceptions.InternalServerException; import lombok.extern.slf4j.Slf4j; -import okhttp3.*; -import org.brapi.client.v2.ApiResponse; -import org.brapi.client.v2.BrAPIClient; import org.brapi.client.v2.model.exceptions.ApiException; import org.brapi.client.v2.modules.germplasm.GermplasmApi; import org.brapi.v2.model.BrAPIExternalReference; import org.brapi.v2.model.germ.BrAPIGermplasm; import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest; -import org.brapi.v2.model.germ.response.BrAPIGermplasmProgenyResponse; import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; @@ -45,7 +40,6 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Singleton; -import java.lang.reflect.Type; import java.util.*; import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -167,7 +161,6 @@ private Map processGermplasmForDisplay(List getGermplasmProgenyByDBID(UUID programId, String germplasmDbId, String page) throws ApiException { - BrAPIClient apiClient = programDAO.getCoreClient(programId); - - if (germplasmDbId == null) { - throw new IllegalArgumentException("germplasmDbId cannot be null"); - } else { - Object localVarPostBody = null; - String localVarPath = "/germplasm/{germplasmDbId}/progeny".replaceAll("\\{germplasmDbId\\}", germplasmDbId); - Map localVarQueryParams = new HashMap(); - Map localVarCollectionQueryParams = new HashMap(); - Map localVarHeaderParams = new HashMap(); - Map localVarFormParams = new HashMap(); - apiClient.prepQueryParameter(localVarQueryParams, "page", page); - - String[] localVarAccepts = new String[]{"application/json"}; - String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); //todo next - if (localVarAccept != null) { - localVarHeaderParams.put("Accept", localVarAccept); - } - - String[] localVarContentTypes = new String[0]; - String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); - localVarHeaderParams.put("Content-Type", localVarContentType); - String[] localVarAuthNames = new String[]{"AuthorizationToken"}; - Call call = apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames); - Type localVarReturnType = (new TypeToken() { - }).getType(); - return apiClient.execute(call, localVarReturnType);//verify, grab body, etc - } - } - } diff --git a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java index f6400d074..de32e6b70 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java +++ b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java @@ -469,7 +469,6 @@ else if (germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo()) } if ((germplasmByAccessionNumber.containsKey(germplasm.getMaleParentDBID()))) { BrAPIGermplasm maleParent = germplasmByAccessionNumber.get(maleParentDB).getBrAPIObject(); - //todo name for display retrieved here, irksome if (!femaleParentUnknown) pedigreeString += String.format("/%s", commit ? maleParent.getGermplasmName() : maleParent.getDefaultDisplayName()); } } else if (maleParentFile != null){ @@ -484,11 +483,9 @@ else if (germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo()) } } mappedBrAPIImport.get(i).getGermplasm().getBrAPIObject().setPedigree(pedigreeString); - //only set if unknown, or simpler to just always add boolean, todo, consider that previous imported values won't have that value + //Simpler to just always add boolean, but consider for logic that previous imported values won't have that additional info value mappedBrAPIImport.get(i).getGermplasm().getBrAPIObject().putAdditionalInfoItem("femaleParentUnknown", femaleParentUnknown); mappedBrAPIImport.get(i).getGermplasm().getBrAPIObject().putAdditionalInfoItem("maleParentUnknown", maleParentUnknown); - //Temporary measure until breedbase permits unknown female, knowm male pedigrees, but honestly messy todo - //mappedBrAPIImport.get(i).getGermplasm().getBrAPIObject().putAdditionalInfoItem("maleParentUnknown", maleParentUnknown); } } } From be8697c9786d32b4c0fad1b7dddb13d3acba6dc9 Mon Sep 17 00:00:00 2001 From: HMS17 <84345306+HMS17@users.noreply.github.com> Date: Wed, 7 Sep 2022 17:12:46 -0400 Subject: [PATCH 5/6] Temp page size change due to cache error --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2c4f8179e..e2dd614e2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -159,7 +159,7 @@ brapi: geno-url: ${brapi.server.default-url} reference-source: ${BRAPI_REFERENCE_SOURCE:breedinginsight.org} read-timeout: 10m - page-size: 1000 + page-size: 5000 search: wait-time: 1000 post-group-size: 100 From 3ba5c463ef0e45bcaba07ace8c367e443f17c3f6 Mon Sep 17 00:00:00 2001 From: HMS17 <84345306+HMS17@users.noreply.github.com> Date: Wed, 7 Sep 2022 17:32:37 -0400 Subject: [PATCH 6/6] Well that caused a build error --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e2dd614e2..2c4f8179e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -159,7 +159,7 @@ brapi: geno-url: ${brapi.server.default-url} reference-source: ${BRAPI_REFERENCE_SOURCE:breedinginsight.org} read-timeout: 10m - page-size: 5000 + page-size: 1000 search: wait-time: 1000 post-group-size: 100