From 0cf2ad745dd0d92b14e297fbe3463799f22258df Mon Sep 17 00:00:00 2001 From: David Randolph Phillips Date: Thu, 24 Aug 2023 16:42:21 -0400 Subject: [PATCH 1/2] [BI-1881] WIP --- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 3adbb99ff..5116d5cce 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -296,7 +296,15 @@ public List updateBrAPIGermplasm(List putBrAPIGe putGermplasm(putBrAPIGermplasmList, api); // Need all program germplasm for processGermplasmForDisplay parents pedigree List germplasm = getRawGermplasm(programId); - return processGermplasmForDisplay(germplasm, program.getKey()); + Map allDisplayGermplasm = processGermplasmForDisplay(germplasm, program.getKey()); + Map updatedBrAPIGermplasmForDisplay = new HashMap<>(); + for (BrAPIGermplasm updatedGermplasm: putBrAPIGermplasmList) { + BrAPIExternalReference extRef = updatedGermplasm.getExternalReferences().stream().filter(reference -> referenceSource.equals(reference.getReferenceSource())).findFirst().orElseThrow(() -> new IllegalStateException("No BI external reference found")); + String germplasmId = extRef.getReferenceID(); + BrAPIGermplasm displayGerm = allDisplayGermplasm.get(germplasmId); + updatedBrAPIGermplasmForDisplay.put(germplasmId, displayGerm); + } + return updatedBrAPIGermplasmForDisplay; }; } return programGermplasmCache.post(programId, postFunction); From b7a686ed619491ea7cbc73f8f0face474085eaed Mon Sep 17 00:00:00 2001 From: David Randolph Phillips Date: Fri, 25 Aug 2023 13:15:42 -0400 Subject: [PATCH 2/2] [BI-1881] WIP --- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) 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 5116d5cce..938b76ee2 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -35,6 +35,7 @@ import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; +import org.breedinginsight.dao.db.tables.pojos.ProgramEntity; import org.breedinginsight.daos.ProgramDAO; import org.breedinginsight.daos.cache.ProgramCache; import org.breedinginsight.daos.cache.ProgramCacheProvider; @@ -145,21 +146,23 @@ private Map fetchProgramGermplasm(UUID programId) throws api::searchGermplasmPost, api::searchGermplasmSearchResultsDbIdGet, germplasmSearch - ), program.getKey()); + ), program); } /** * Process germplasm into a format for display - * @param programGermplasm + * @param germplasmList * @return Map * @throws ApiException */ - private Map processGermplasmForDisplay(List programGermplasm, String programKey) { + private Map processGermplasmForDisplay(List germplasmList, ProgramEntity program) throws ApiException { + String programKey = program.getKey(); // Process the germplasm Map programGermplasmMap = new HashMap<>(); - log.trace("processing germ for display: " + programGermplasm); + log.trace("processing germ for display: " + germplasmList); Map programGermplasmByFullName = new HashMap<>(); - for (BrAPIGermplasm germplasm: programGermplasm) { + boolean isExpanded_programGermplasmByFullName = false; + for (BrAPIGermplasm germplasm: germplasmList) { programGermplasmByFullName.put(germplasm.getGermplasmName(), germplasm); JsonObject additionalInfo = germplasm.getAdditionalInfo(); @@ -181,7 +184,7 @@ private Map processGermplasmForDisplay(List processGermplasmForDisplay(List= 1) { + // if the female parent germplasm is not found in the passed-in germplasmList, then expand the programGermplasmByFullName + // map so we can search all of the program's germplasm for the parent. + if( ! isExpanded_programGermplasmByFullName && !"NA".equals(parents.get(0)) && !programGermplasmByFullName.containsKey(parents.get(0)) ){ + if (! additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) || ! additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { + isExpanded_programGermplasmByFullName = expand_programGermplasmByFullName(program, programGermplasmByFullName); + } + } if (programGermplasmByFullName.containsKey(parents.get(0))) { String femaleParentAccessionNumber = programGermplasmByFullName.get(parents.get(0)).getAccessionNumber(); newPedigreeString = femaleParentAccessionNumber; @@ -213,11 +223,19 @@ private Map processGermplasmForDisplay(List ref.getReferenceSource().equals(referenceSource)). map(ref -> ref.getReferenceID()).findFirst().orElse(""); additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID, maleParentAccessionNumber); @@ -241,6 +259,16 @@ private Map processGermplasmForDisplay(List programGermplasmByFullName) throws ApiException { + List allProgramGermplasm = getRawGermplasm(program.getId()); + for (BrAPIGermplasm programGermplasm: allProgramGermplasm) { + if( ! programGermplasmByFullName.containsKey( programGermplasm.getGermplasmName() ) ){ + programGermplasmByFullName.put(programGermplasm.getGermplasmName(), programGermplasm); + } + } + return true; + } + // TODO: hack for now, probably should update breedbase // Made a JIRA card BI-1883 for this // Breedbase will return NA/NA for no pedigree or NA/father, mother/NA @@ -277,7 +305,7 @@ public List createBrAPIGermplasm(List postBrAPIG if (!postBrAPIGermplasmList.isEmpty()) { postFunction = () -> { List postResponse = brAPIDAOUtil.post(postBrAPIGermplasmList, upload, api::germplasmPost, importDAO::update); - return processGermplasmForDisplay(postResponse, program.getKey()); + return processGermplasmForDisplay(postResponse, program); }; } return programGermplasmCache.post(programId, postFunction); @@ -293,18 +321,8 @@ public List updateBrAPIGermplasm(List putBrAPIGe try { if (!putBrAPIGermplasmList.isEmpty()) { postFunction = () -> { - putGermplasm(putBrAPIGermplasmList, api); - // Need all program germplasm for processGermplasmForDisplay parents pedigree - List germplasm = getRawGermplasm(programId); - Map allDisplayGermplasm = processGermplasmForDisplay(germplasm, program.getKey()); - Map updatedBrAPIGermplasmForDisplay = new HashMap<>(); - for (BrAPIGermplasm updatedGermplasm: putBrAPIGermplasmList) { - BrAPIExternalReference extRef = updatedGermplasm.getExternalReferences().stream().filter(reference -> referenceSource.equals(reference.getReferenceSource())).findFirst().orElseThrow(() -> new IllegalStateException("No BI external reference found")); - String germplasmId = extRef.getReferenceID(); - BrAPIGermplasm displayGerm = allDisplayGermplasm.get(germplasmId); - updatedBrAPIGermplasmForDisplay.put(germplasmId, displayGerm); - } - return updatedBrAPIGermplasmForDisplay; + List germplasm = putGermplasm(putBrAPIGermplasmList, api); + return processGermplasmForDisplay(germplasm, program); }; } return programGermplasmCache.post(programId, postFunction);