-
Notifications
You must be signed in to change notification settings - Fork 1
BI-1881 (Remove Need to Provide Parents to processGermplasmForDisplay) #288
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<String, BrAPIGermplasm> 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<Key = string representing germplasm UUID, value = formatted BrAPIGermplasm> | ||
| * @throws ApiException | ||
| */ | ||
| private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> programGermplasm, String programKey) { | ||
| private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> germplasmList, ProgramEntity program) throws ApiException { | ||
| String programKey = program.getKey(); | ||
| // Process the germplasm | ||
| Map<String, BrAPIGermplasm> programGermplasmMap = new HashMap<>(); | ||
| log.trace("processing germ for display: " + programGermplasm); | ||
| log.trace("processing germ for display: " + germplasmList); | ||
| Map<String, BrAPIGermplasm> 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<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas | |
| } | ||
|
|
||
| // Update pedigree string | ||
| for (BrAPIGermplasm germplasm: programGermplasm) { | ||
| for (BrAPIGermplasm germplasm: germplasmList) { | ||
| JsonObject additionalInfo = germplasm.getAdditionalInfo(); | ||
| if(additionalInfo == null) { | ||
| additionalInfo = new JsonObject(); | ||
|
|
@@ -200,6 +203,13 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas | |
| parents = Arrays.asList(germplasm.getPedigree().split("/")); | ||
| } | ||
| if (parents.size() >= 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<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas | |
| } | ||
| } | ||
| if (parents.size() == 2) { | ||
| if (programGermplasmByFullName.containsKey(parents.get(1))) { | ||
| String maleParentAccessionNumber = programGermplasmByFullName.get(parents.get(1)).getAccessionNumber(); | ||
| // if the male 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. | ||
| String maleParentName = parents.get(1); | ||
| if( ! isExpanded_programGermplasmByFullName && !"NA".equals(maleParentName) && !programGermplasmByFullName.containsKey(maleParentName)){ | ||
| if (!additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) || !additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { | ||
| isExpanded_programGermplasmByFullName = expand_programGermplasmByFullName(program, programGermplasmByFullName); | ||
| } | ||
| } | ||
| if (programGermplasmByFullName.containsKey(maleParentName)) { | ||
| String maleParentAccessionNumber = programGermplasmByFullName.get(maleParentName).getAccessionNumber(); | ||
| newPedigreeString += "/" + maleParentAccessionNumber; | ||
| namePedigreeString += "/" + programGermplasmByFullName.get(parents.get(1)).getDefaultDisplayName(); | ||
| uuidPedigreeString += "/" + programGermplasmByFullName.get(parents.get(1)).getExternalReferences(). | ||
| namePedigreeString += "/" + programGermplasmByFullName.get(maleParentName).getDefaultDisplayName(); | ||
| uuidPedigreeString += "/" + programGermplasmByFullName.get(maleParentName).getExternalReferences(). | ||
| stream().filter(ref -> ref.getReferenceSource().equals(referenceSource)). | ||
| map(ref -> ref.getReferenceID()).findFirst().orElse(""); | ||
| additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID, maleParentAccessionNumber); | ||
|
|
@@ -241,6 +259,16 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas | |
| return programGermplasmMap; | ||
| } | ||
|
|
||
| private boolean expand_programGermplasmByFullName(ProgramEntity program, Map<String, BrAPIGermplasm> programGermplasmByFullName) throws ApiException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless the underscore in the name is part of a convention I don't know about, I would remove it. |
||
| List<BrAPIGermplasm> allProgramGermplasm = getRawGermplasm(program.getId()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the original intent of this card was to grab the accession numbers from the pedigree string [programKey-accessionNumber] and use that to create the newPedigreeString rather than requiring the parent germplasm objects @timparsons? Although I'm not sure how it would create the name and UUID pedigree strings in that case. |
||
| 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<BrAPIGermplasm> createBrAPIGermplasm(List<BrAPIGermplasm> postBrAPIG | |
| if (!postBrAPIGermplasmList.isEmpty()) { | ||
| postFunction = () -> { | ||
| List<BrAPIGermplasm> postResponse = brAPIDAOUtil.post(postBrAPIGermplasmList, upload, api::germplasmPost, importDAO::update); | ||
| return processGermplasmForDisplay(postResponse, program.getKey()); | ||
| return processGermplasmForDisplay(postResponse, program); | ||
| }; | ||
| } | ||
| return programGermplasmCache.post(programId, postFunction); | ||
|
|
@@ -293,10 +321,8 @@ public List<BrAPIGermplasm> updateBrAPIGermplasm(List<BrAPIGermplasm> putBrAPIGe | |
| try { | ||
| if (!putBrAPIGermplasmList.isEmpty()) { | ||
| postFunction = () -> { | ||
| putGermplasm(putBrAPIGermplasmList, api); | ||
| // Need all program germplasm for processGermplasmForDisplay parents pedigree | ||
| List<BrAPIGermplasm> germplasm = getRawGermplasm(programId); | ||
| return processGermplasmForDisplay(germplasm, program.getKey()); | ||
| List<BrAPIGermplasm> germplasm = putGermplasm(putBrAPIGermplasmList, api); | ||
| return processGermplasmForDisplay(germplasm, program); | ||
| }; | ||
| } | ||
| return programGermplasmCache.post(programId, postFunction); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless the underscore in the name is part of a convention I don't know about, I would remove it.
isExpandedProgramGermplasmByFullNamewould be OK with me, something likeisMissingParentswould be OK too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1