Skip to content
Open
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 @@ -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";
Expand Down Expand Up @@ -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);
}
Expand All @@ -159,6 +151,28 @@ 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) {
// 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 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());
Expand All @@ -181,13 +195,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) {
Expand Down Expand Up @@ -223,27 +230,28 @@ 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();

// Check Female Parent
if (germplasm.getFemaleParentEntryNo() != null) {
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) {
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);
Expand Down Expand Up @@ -460,6 +468,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
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>
Expand Down Expand Up @@ -793,6 +811,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);
// Add femaleParentUUID to additionalInfo.
Optional<BrAPIExternalReference> femaleParentUUID = Utilities.getExternalReference(femaleParent.getExternalReferences(), BRAPI_REFERENCE_SOURCE);
if (femaleParentUUID.isPresent()) {
Expand All @@ -802,6 +822,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()) {
Expand Down