Skip to content
Closed
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 @@ -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;
Expand Down Expand Up @@ -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;
Copy link
Contributor

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.
isExpandedProgramGermplasmByFullName would be OK with me, something like isMissingParents would be OK too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

for (BrAPIGermplasm germplasm: germplasmList) {
programGermplasmByFullName.put(germplasm.getGermplasmName(), germplasm);

JsonObject additionalInfo = germplasm.getAdditionalInfo();
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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 {
Copy link
Contributor

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.

List<BrAPIGermplasm> allProgramGermplasm = getRawGermplasm(program.getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRawGermplasm hits the cache, calling it from the method processGermplasmForDisplay which is used to populate the cache may be causing the issues I'm seeing locally and in the TAF run.

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down