-
Notifications
You must be signed in to change notification settings - Fork 1
[BI-2751] - Germplasm entry number weirdness #494
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
Open
HMS17
wants to merge
4
commits into
develop
Choose a base branch
from
bug/BI-2751
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ public class GermplasmProcessor implements Processor { | |
|
|
||
| public static String missingGIDsMsg = "The following GIDs were not found in the database: %s"; | ||
| public static String missingParentalGIDsMsg = "The following parental GIDs were not found in the database: %s"; | ||
| public static String missingParentalEntryNoMsg = "The following parental entry numbers were not found in the database: %s"; | ||
| public static String missingParentalEntryNoMsg = "The following parental entry numbers were not found in the file: %s"; | ||
| public static String badBreedMethodsMsg = "Invalid breeding method"; | ||
| public static String badGermplasmNameMsg = "Germplasm name cannot contain /"; | ||
| public static String missingEntryNumbersMsg = "Either all or none of the germplasm must have entry numbers"; | ||
|
|
@@ -137,14 +137,6 @@ public void getExistingBrapiData(List<BrAPIImport> importRows, Program program) | |
| BrAPIImport germplasmImport = importRows.get(i); | ||
| Germplasm germplasm = germplasmImport.getGermplasm(); | ||
| if (germplasm != null) { | ||
|
|
||
| // Retrieve parent accession numbers to assess if already in db | ||
| if (germplasm.getFemaleParentAccessionNumber() != null) { | ||
| germplasmAccessionNumbers.put(germplasm.getFemaleParentAccessionNumber(), true); | ||
| } | ||
| if (germplasm.getMaleParentAccessionNumber() != null) { | ||
| germplasmAccessionNumbers.put(germplasm.getMaleParentAccessionNumber(), true); | ||
| } | ||
| if (germplasm.getAccessionNumber() != null) { | ||
| germplasmAccessionNumbers.put(germplasm.getAccessionNumber(), false); | ||
| } | ||
|
|
@@ -159,6 +151,31 @@ public void getExistingBrapiData(List<BrAPIImport> importRows, Program program) | |
| } | ||
| } | ||
|
|
||
| // Get existing germplasm names | ||
| List<BrAPIGermplasm> dbGermplasm = brAPIGermplasmService.getGermplasmByDisplayName(new ArrayList<>(fileGermplasmByName.keySet()), program.getId()); | ||
| dbGermplasm.forEach(germplasm -> { | ||
| dbGermplasmByName.put(germplasm.getDefaultDisplayName(), germplasm); | ||
| dbGermplasmByAccessionNo.put(germplasm.getAccessionNumber(), germplasm); | ||
| }); | ||
|
|
||
| // Get parental accession nos in file | ||
| for (int i = 0; i < importRows.size(); i++) { | ||
| BrAPIImport germplasmImport = importRows.get(i); | ||
| Germplasm germplasm = germplasmImport.getGermplasm(); | ||
| if (germplasm != null) { | ||
| //Ignore this if germplasm already has a pedigree in the database | ||
| // Retrieve parent accession numbers to assess if already in db | ||
| if (!databaseGermplasmHasPedigree(germplasm)) { | ||
| if (germplasm.getFemaleParentAccessionNumber() != null) { | ||
| germplasmAccessionNumbers.put(germplasm.getFemaleParentAccessionNumber(), true); | ||
| } | ||
| if (germplasm.getMaleParentAccessionNumber() != null) { | ||
| germplasmAccessionNumbers.put(germplasm.getMaleParentAccessionNumber(), true); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If a parental accession number is present, it should exist in the database. | ||
| existingGermplasm = new ArrayList<>(); | ||
| List<String> missingParentalAccessionNumbers = germplasmAccessionNumbers.entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toList()); | ||
|
|
@@ -181,13 +198,6 @@ public void getExistingBrapiData(List<BrAPIImport> importRows, Program program) | |
| } | ||
| } | ||
|
|
||
| // Get existing germplasm names | ||
| List<BrAPIGermplasm> dbGermplasm = brAPIGermplasmService.getGermplasmByDisplayName(new ArrayList<>(fileGermplasmByName.keySet()), program.getId()); | ||
| dbGermplasm.forEach(germplasm -> { | ||
| dbGermplasmByName.put(germplasm.getDefaultDisplayName(), germplasm); | ||
| dbGermplasmByAccessionNo.put(germplasm.getAccessionNumber(), germplasm); | ||
| }); | ||
|
|
||
| // Check for existing germplasm lists | ||
| Boolean listNameDup = false; | ||
| if (importRows.size() > 0 && importRows.get(0).getGermplasm().getListName() != null) { | ||
|
|
@@ -223,27 +233,31 @@ public void getExistingBrapiData(List<BrAPIImport> importRows, Program program) | |
| arrayOfStringFormatter.apply(missingAccessionNumbers))); | ||
| } | ||
|
|
||
| List<String> missingEntryNumbers = new ArrayList<>(); | ||
| for (BrAPIImport importRow: importRows) { | ||
| Germplasm germplasm = importRow.getGermplasm(); | ||
| // Check Female Parent | ||
| if (germplasm.getFemaleParentEntryNo() != null) { | ||
| if ((!germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo())) && !(germplasm.getFemaleParentEntryNo().equals("0"))) { | ||
| missingEntryNumbers.add(germplasm.getFemaleParentEntryNo()); | ||
| List<String> missingEntryNumbers = new ArrayList<>(); | ||
| for (BrAPIImport importRow : importRows) { | ||
| Germplasm germplasm = importRow.getGermplasm(); | ||
|
|
||
| //If germplasm already has a pedigree, pedigree cannot be overwritten and file values for pedigree will be ignored | ||
| boolean pedigreeExists = databaseGermplasmHasPedigree(germplasm); | ||
|
|
||
| // Check Female Parent | ||
| if (germplasm.getFemaleParentEntryNo() != null && !pedigreeExists) { | ||
| 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())) && !(germplasm.getMaleParentEntryNo().equals("0"))) { | ||
| missingEntryNumbers.add(germplasm.getMaleParentEntryNo()); | ||
| // Check Male Parent | ||
| if (germplasm.getMaleParentEntryNo() != null && !pedigreeExists) { | ||
| if ((!germplasmIndexByEntryNo.containsKey(germplasm.getMaleParentEntryNo())) && !(germplasm.getMaleParentEntryNo().equals("0"))) { | ||
| missingEntryNumbers.add(germplasm.getMaleParentEntryNo()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (missingEntryNumbers.size() > 0) { | ||
| throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, | ||
| String.format(missingParentalEntryNoMsg, | ||
| arrayOfStringFormatter.apply(missingEntryNumbers))); | ||
| } | ||
| if (missingEntryNumbers.size() > 0) { | ||
| throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, | ||
| String.format(missingParentalEntryNoMsg, | ||
| arrayOfStringFormatter.apply(missingEntryNumbers))); | ||
| } | ||
|
|
||
| if (listNameDup) { | ||
| throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, listNameAlreadyExists); | ||
|
|
@@ -405,21 +419,8 @@ private boolean processExistingGermplasm(Germplasm germplasm, ValidationErrors v | |
| return false; | ||
| } | ||
|
|
||
| // Error conditions: | ||
| // has existing pedigree and file pedigree is different and not empty | ||
| // Valid conditions: | ||
| // no existing pedigree and file different pedigree | ||
| // existing pedigree and file pedigree same | ||
| // existing pedigree and file pedigree empty | ||
| if(hasPedigree(existingGermplasm) && germplasm.pedigreeExists()) { | ||
| if(!arePedigreesEqual(existingGermplasm, germplasm, importRows)) { | ||
| ValidationError ve = new ValidationError("Pedigree", pedigreeAlreadyExists, HttpStatus.UNPROCESSABLE_ENTITY); | ||
| validationErrors.addError(rowIndex + 2, ve); // +2 instead of +1 to account for the column header row. | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // if no existing pedigree and file has pedigree then validate and update | ||
| // if pedigree exists, file pedigree information should be ignored | ||
| if(germplasm.pedigreeExists() && !hasPedigree(existingGermplasm)) { | ||
| validatePedigree(germplasm, rowIndex + 2, validationErrors); | ||
| updatePedigree = true; | ||
|
|
@@ -460,6 +461,16 @@ private boolean hasPedigree(BrAPIGermplasm germplasm) { | |
| germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()); | ||
| } | ||
|
|
||
| //Used to check if germplasm already has a pedigree in the database, if so, pedigree information in file should be ignored | ||
| private boolean databaseGermplasmHasPedigree(Germplasm germplasm) { | ||
| if (germplasm.getAccessionNumber() == null || dbGermplasmByAccessionNo.get(germplasm.getAccessionNumber()) == null) { | ||
| return false; | ||
| } else { | ||
| BrAPIGermplasm dbGermplasm = dbGermplasmByAccessionNo.get(germplasm.getAccessionNumber()); | ||
| return hasPedigree(dbGermplasm); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Compare an existing germplasm's pedigree to the incoming germplasm's pedigree to ensure they are the same.<br><br> | ||
| * Assumes that an empty value for a given parent in the incoming germplasm is equal to the existing germplasm.<br><br> | ||
|
|
@@ -793,6 +804,8 @@ else if (germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo()) | |
| if (commit) { | ||
| if (femaleParentFound) { | ||
| brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID, femaleParent.getAccessionNumber()); | ||
| //entry number no longer needed for figuring out parentage, can remove (since same germplasm can have different entry numbers across multiple lists) | ||
| brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_ENTRY_NO, null); | ||
|
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 saw the comment in the PR description about these still showing up without a migration for old records. Is that something we need a card for? |
||
| // Add femaleParentUUID to additionalInfo. | ||
| Optional<BrAPIExternalReference> femaleParentUUID = Utilities.getExternalReference(femaleParent.getExternalReferences(), BRAPI_REFERENCE_SOURCE); | ||
| if (femaleParentUUID.isPresent()) { | ||
|
|
@@ -802,6 +815,8 @@ else if (germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo()) | |
|
|
||
| if (maleParent != null) { | ||
| brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID, maleParent.getAccessionNumber()); | ||
| //entry number no longer needed for figuring out parentage, can remove (since same germplasm can have different entry numbers across multiple lists) | ||
| brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_ENTRY_NO, null); | ||
| // Add maleParentUUID to additionalInfo. | ||
| Optional<BrAPIExternalReference> maleParentUUID = Utilities.getExternalReference(maleParent.getExternalReferences(), BRAPI_REFERENCE_SOURCE); | ||
| if (maleParentUUID.isPresent()) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changing this to silently ignore pedigree conflicts instead of rejecting conflicting updates seems like it could be misleading to the user. Was there a reason for removing this?