From 9a38c0fc37d1f63abd6d8d80c0da3920c59c77ac Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:57:11 -0400 Subject: [PATCH 1/8] [BI-1881] - work in progress --- .../constants/BrAPIAdditionalInfoFields.java | 2 + .../brapi/v2/dao/BrAPIGermplasmDAO.java | 66 +++++++++++-------- .../processors/GermplasmProcessor.java | 13 +++- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java b/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java index 27179be76..f82a718ed 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java +++ b/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java @@ -23,6 +23,8 @@ public final class BrAPIAdditionalInfoFields { public static final String GERMPLASM_RAW_PEDIGREE = "rawPedigree"; public static final String GERMPLASM_PEDIGREE_BY_NAME = "pedigreeByName"; public static final String GERMPLASM_PEDIGREE_BY_UUID = "pedigreeByUUID"; + public static final String GERMPLASM_FEMALE_PARENT_UUID = "femaleParentUUID"; + public static final String GERMPLASM_MALE_PARENT_UUID = "maleParentUUID"; public static final String GERMPLASM_IMPORT_ENTRY_NUMBER = "importEntryNumber"; public static final String GERMPLASM_FEMALE_PARENT_GID = "femaleParentGid"; public static final String GERMPLASM_MALE_PARENT_GID = "maleParentGid"; 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..6d597b983 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -158,9 +158,7 @@ private Map processGermplasmForDisplay(List programGermplasmMap = new HashMap<>(); log.trace("processing germ for display: " + programGermplasm); - Map programGermplasmByFullName = new HashMap<>(); for (BrAPIGermplasm germplasm: programGermplasm) { - programGermplasmByFullName.put(germplasm.getGermplasmName(), germplasm); JsonObject additionalInfo = germplasm.getAdditionalInfo(); if (additionalInfo != null && additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_BREEDING_METHOD_ID)) { @@ -192,46 +190,56 @@ private Map processGermplasmForDisplay(List parents = Arrays.asList("",""); + + // Get parent germplasm names without program key. + List parentNames = new ArrayList<>(); if (germplasm.getPedigree() != null) { - parents = Arrays.asList(germplasm.getPedigree().split("/")); - } - if (parents.size() >= 1) { - if (programGermplasmByFullName.containsKey(parents.get(0))) { - String femaleParentAccessionNumber = programGermplasmByFullName.get(parents.get(0)).getAccessionNumber(); - newPedigreeString = femaleParentAccessionNumber; - namePedigreeString = programGermplasmByFullName.get(parents.get(0)).getDefaultDisplayName(); - uuidPedigreeString = programGermplasmByFullName.get(parents.get(0)).getExternalReferences(). - stream().filter(ref -> ref.getReferenceSource().equals(referenceSource)). - map(ref -> ref.getReferenceID()).findFirst().orElse(""); - additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID, femaleParentAccessionNumber); - } else if (additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { - namePedigreeString = "Unknown"; + for (String name : Arrays.asList(germplasm.getPedigree().split("/", -1))) { + if (!name.isEmpty()) + { + // Strip program key. + name = Utilities.removeProgramKeyAndUnknownAdditionalData(name, programKey); + } + parentNames.add(name); } } - if (parents.size() == 2) { - if (programGermplasmByFullName.containsKey(parents.get(1))) { - String maleParentAccessionNumber = programGermplasmByFullName.get(parents.get(1)).getAccessionNumber(); - newPedigreeString += "/" + maleParentAccessionNumber; - namePedigreeString += "/" + programGermplasmByFullName.get(parents.get(1)).getDefaultDisplayName(); - uuidPedigreeString += "/" + programGermplasmByFullName.get(parents.get(1)).getExternalReferences(). - stream().filter(ref -> ref.getReferenceSource().equals(referenceSource)). - map(ref -> ref.getReferenceID()).findFirst().orElse(""); - additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID, maleParentAccessionNumber); + + // Update pedigree info for female parent. + if (parentNames.size() >= 1 && !parentNames.get(0).isEmpty()) + { + gidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; + namePedigreeString = parentNames.get(0); + uuidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; + // Throw a descriptive error if femaleParentUUID is absent. + if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID)) { + // TODO: link to BI-1881. + throw new InternalServerException("Germplasm has a female parent but femaleParentUUID is missing."); } + } else if (additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { + namePedigreeString = "Unknown"; } - //Add Unknown germplasm for display - if (additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { + // Update pedigree info for male parent. + if (parentNames.size() == 2 && !parentNames.get(1).isEmpty()) + { + gidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID).getAsString() : ""); + namePedigreeString += "/" + parentNames.get(1); + uuidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); + // Throw a descriptive error if maleParentUUID is absent. + if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID)) { + // TODO: link to BI-1881. + throw new InternalServerException("Germplasm has a male parent but maleParentUUID is missing."); + } + } else if (additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { namePedigreeString += "/Unknown"; } //For use in individual germplasm display additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); - germplasm.setPedigree(newPedigreeString); + germplasm.setPedigree(gidPedigreeString); BrAPIExternalReference extRef = germplasm.getExternalReferences().stream().filter(reference -> referenceSource.equals(reference.getReferenceSource())).findFirst().orElseThrow(() -> new IllegalStateException("No BI external reference found")); String germplasmId = extRef.getReferenceID(); diff --git a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java index 365236f01..f51f7c1fb 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java +++ b/src/main/java/org/breedinginsight/brapps/importer/services/processors/GermplasmProcessor.java @@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.brapi.client.v2.model.exceptions.ApiException; +import org.brapi.v2.model.BrAPIExternalReference; import org.brapi.v2.model.core.BrAPIListSummary; import org.brapi.v2.model.core.request.BrAPIListNewRequest; import org.brapi.v2.model.germ.BrAPIGermplasm; @@ -45,6 +46,7 @@ import org.breedinginsight.model.Program; import org.breedinginsight.model.User; import org.breedinginsight.services.exceptions.ValidatorException; +import org.breedinginsight.utilities.Utilities; import org.jooq.DSLContext; import tech.tablesaw.api.Table; @@ -717,11 +719,20 @@ else if (germplasmIndexByEntryNo.containsKey(germplasm.getFemaleParentEntryNo()) if (commit) { if (femaleParentFound) { brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID, femaleParent.getAccessionNumber()); + // Add femaleParentUUID to additionalInfo. + Optional femaleParentUUID = Utilities.getExternalReference(femaleParent.getExternalReferences(), BRAPI_REFERENCE_SOURCE); + if (femaleParentUUID.isPresent()) { + brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID, femaleParentUUID.get().getReferenceID()); + } } if (maleParent != null) { brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID, maleParent.getAccessionNumber()); - } + // Add maleParentUUID to additionalInfo. + Optional maleParentUUID = Utilities.getExternalReference(maleParent.getExternalReferences(), BRAPI_REFERENCE_SOURCE); + if (maleParentUUID.isPresent()) { + brAPIGermplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID, maleParentUUID.get().getReferenceID()); + } } } } } From dcd0a4843bda91ad7e750fe510a3fd69edabbd4e Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Tue, 19 Sep 2023 09:41:58 -0400 Subject: [PATCH 2/8] [BI-1881] - fixed failing test --- .../services/BrAPIGermplasmServiceUnitTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java b/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java index c78100eef..49d55d9e9 100644 --- a/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java +++ b/src/test/java/org/breedinginsight/services/BrAPIGermplasmServiceUnitTest.java @@ -36,6 +36,7 @@ import java.util.*; import java.util.stream.Collectors; +import static org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -92,6 +93,7 @@ public void getGermplasmListExport() { listResponse.setResult(listDetails); //Create Germplasm + String parentUuid = UUID.randomUUID().toString(); List germplasm = new ArrayList(); BrAPIGermplasm testGermplasm = new BrAPIGermplasm(); testGermplasm.setGermplasmName("Germplasm A [TEST-1]"); @@ -99,13 +101,13 @@ public void getGermplasmListExport() { testGermplasm.setAccessionNumber("1"); testGermplasm.setDefaultDisplayName("Germplasm A"); JsonObject additionalInfo = new JsonObject(); - additionalInfo.addProperty("importEntryNumber", "2"); - additionalInfo.addProperty("breedingMethod", "Allopolyploid"); + additionalInfo.addProperty(GERMPLASM_IMPORT_ENTRY_NUMBER, "2"); + additionalInfo.addProperty(GERMPLASM_BREEDING_METHOD, "Allopolyploid"); testGermplasm.setAdditionalInfo(additionalInfo); List externalRef = new ArrayList<>(); BrAPIExternalReference testReference = new BrAPIExternalReference(); testReference.setReferenceSource(referenceSource); - testReference.setReferenceID(UUID.randomUUID().toString()); + testReference.setReferenceID(parentUuid); externalRef.add(testReference); testGermplasm.setExternalReferences(externalRef); germplasm.add(testGermplasm); @@ -117,8 +119,9 @@ public void getGermplasmListExport() { testGermplasm.setDefaultDisplayName("Germplasm B"); testGermplasm.setPedigree("Germplasm A [TEST-1]"); additionalInfo = new JsonObject(); - additionalInfo.addProperty("importEntryNumber", "3"); - additionalInfo.addProperty("breedingMethod", "Autopolyploid"); + additionalInfo.addProperty(GERMPLASM_IMPORT_ENTRY_NUMBER, "3"); + additionalInfo.addProperty(GERMPLASM_BREEDING_METHOD, "Autopolyploid"); + additionalInfo.addProperty(GERMPLASM_FEMALE_PARENT_UUID, parentUuid); testGermplasm.setAdditionalInfo(additionalInfo); testReference = new BrAPIExternalReference(); testReference.setReferenceSource(referenceSource); From f6d060a53faad91fd3b899220af8006d163f0da3 Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Tue, 19 Sep 2023 14:29:42 -0400 Subject: [PATCH 3/8] [BI-1881] - added logging --- .../org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java | 4 ++++ 1 file changed, 4 insertions(+) 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 6d597b983..444b5a75e 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -216,6 +216,8 @@ private Map processGermplasmForDisplay(List processGermplasmForDisplay(List Date: Wed, 20 Sep 2023 15:16:29 -0400 Subject: [PATCH 4/8] [BI-1881] - updated comments and messages --- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 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 444b5a75e..98f8ef363 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -194,54 +194,54 @@ private Map processGermplasmForDisplay(List parentNames = new ArrayList<>(); - if (germplasm.getPedigree() != null) { - for (String name : Arrays.asList(germplasm.getPedigree().split("/", -1))) { - if (!name.isEmpty()) - { - // Strip program key. - name = Utilities.removeProgramKeyAndUnknownAdditionalData(name, programKey); - } - parentNames.add(name); + // Get parent germplasm names without program key. + // This is designed so that pedigree="female/" will result in parentNames=["female", ""] + // and pedigree="/male" will result in parentNames=["", "male"]; + // pedigree=null or pedigree="" will result in parentNames=[]. + List parentNames = new ArrayList<>(); + if (pedigree != null) { + // Note: split with limit=-1 applies pattern as many times as possible, allowing capture of leading or trailing empty strings. + for (String name : pedigree.split("/", -1)) { + if (!name.isEmpty()) + { + // Strip program key. + name = Utilities.removeProgramKeyAndUnknownAdditionalData(name, programKey); } + parentNames.add(name); } + } - // Update pedigree info for female parent. - if (parentNames.size() >= 1 && !parentNames.get(0).isEmpty()) - { - gidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; - namePedigreeString = parentNames.get(0); - uuidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; - // Throw a descriptive error if femaleParentUUID is absent. - if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID)) { - // TODO: link to BI-1881. - log.debug("Germplasm: " + germplasm.getGermplasmName()); - log.debug("Germplasm Pedigree: " + germplasm.getPedigree()); - throw new InternalServerException("Germplasm has a female parent but femaleParentUUID is missing."); - } - } else if (additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { - namePedigreeString = "Unknown"; + // Update pedigree info for female parent. + if (parentNames.size() >= 1 && !parentNames.get(0).isEmpty()) + { + gidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; + namePedigreeString = parentNames.get(0); + uuidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; + // Throw a descriptive error if femaleParentUUID is absent. + if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID)) { + log.debug("The germplasm data in your backing BrAPI service needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); + throw new InternalServerException("Germplasm (" + germplasm.getGermplasmName() + ") has a female parent but femaleParentUUID is missing (Pedigree: " + germplasm.getPedigree() + ")."); } - // Update pedigree info for male parent. - if (parentNames.size() == 2 && !parentNames.get(1).isEmpty()) - { - gidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID).getAsString() : ""); - namePedigreeString += "/" + parentNames.get(1); - uuidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); - // Throw a descriptive error if maleParentUUID is absent. - if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID)) { - // TODO: link to BI-1881. - log.debug("Germplasm: " + germplasm.getGermplasmName()); - log.debug("Germplasm Pedigree: " + germplasm.getPedigree()); - throw new InternalServerException("Germplasm has a male parent but maleParentUUID is missing."); - } - } else if (additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { - namePedigreeString += "/Unknown"; + } else if (additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { + namePedigreeString = "Unknown"; + } + // Update pedigree info for male parent. + if (parentNames.size() == 2 && !parentNames.get(1).isEmpty()) + { + gidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID).getAsString() : ""); + namePedigreeString += "/" + parentNames.get(1); + uuidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); + // Throw a descriptive error if maleParentUUID is absent. + if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID)) { + log.debug("The germplasm data in your backing BrAPI service needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); + throw new InternalServerException("Germplasm (" + germplasm.getGermplasmName() + ") has a male parent but maleParentUUID is missing (Pedigree: " + germplasm.getPedigree() + ")."); } - //For use in individual germplasm display - additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); - additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); + } else if (additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { + namePedigreeString += "/Unknown"; + } + //For use in individual germplasm display + additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); + additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); germplasm.setPedigree(gidPedigreeString); From 652194330a6268c4bc794146f1b493c3d02cdc61 Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:22:26 -0400 Subject: [PATCH 5/8] [BI-1881] - imported constants, simplified usages --- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 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 98f8ef363..b87ea8499 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -31,7 +31,7 @@ import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest; import org.brapi.v2.model.germ.response.BrAPIGermplasmSingleResponse; -import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; +import static org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields.*; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; @@ -112,9 +112,9 @@ public List getRawGermplasm(UUID programId) throws ApiException List cacheList = new ArrayList<>(programGermplasmCache.get(programId).values()); return cacheList.stream().map(germplasm -> { germplasm.setGermplasmName(Utilities.appendProgramKey(germplasm.getDefaultDisplayName(), program.getKey(), germplasm.getAccessionNumber())); - if(germplasm.getAdditionalInfo() != null && germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_RAW_PEDIGREE) - && !(germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_RAW_PEDIGREE).isJsonNull())) { - germplasm.setPedigree(germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_RAW_PEDIGREE).getAsString()); + if(germplasm.getAdditionalInfo() != null && germplasm.getAdditionalInfo().has(GERMPLASM_RAW_PEDIGREE) + && !(germplasm.getAdditionalInfo().get(GERMPLASM_RAW_PEDIGREE).isJsonNull())) { + germplasm.setPedigree(germplasm.getAdditionalInfo().get(GERMPLASM_RAW_PEDIGREE).getAsString()); } return germplasm; @@ -161,8 +161,8 @@ private Map processGermplasmForDisplay(List processGermplasmForDisplay(List processGermplasmForDisplay(List= 1 && !parentNames.get(0).isEmpty()) { - gidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; + gidPedigreeString = additionalInfo.has(GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; namePedigreeString = parentNames.get(0); - uuidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; + uuidPedigreeString = additionalInfo.has(GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; // Throw a descriptive error if femaleParentUUID is absent. - if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID)) { + if (!additionalInfo.has(GERMPLASM_FEMALE_PARENT_UUID)) { log.debug("The germplasm data in your backing BrAPI service needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); throw new InternalServerException("Germplasm (" + germplasm.getGermplasmName() + ") has a female parent but femaleParentUUID is missing (Pedigree: " + germplasm.getPedigree() + ")."); } - } else if (additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { + } else if (additionalInfo.has(FEMALE_PARENT_UNKNOWN) && additionalInfo.get(FEMALE_PARENT_UNKNOWN).getAsBoolean()) { namePedigreeString = "Unknown"; } // Update pedigree info for male parent. if (parentNames.size() == 2 && !parentNames.get(1).isEmpty()) { - gidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID).getAsString() : ""); + gidPedigreeString += "/" + (additionalInfo.has(GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(GERMPLASM_MALE_PARENT_GID).getAsString() : ""); namePedigreeString += "/" + parentNames.get(1); - uuidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); + uuidPedigreeString += "/" + (additionalInfo.has(GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); // Throw a descriptive error if maleParentUUID is absent. - if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID)) { + if (!additionalInfo.has(GERMPLASM_MALE_PARENT_UUID)) { log.debug("The germplasm data in your backing BrAPI service needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); throw new InternalServerException("Germplasm (" + germplasm.getGermplasmName() + ") has a male parent but maleParentUUID is missing (Pedigree: " + germplasm.getPedigree() + ")."); } - } else if (additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { + } else if (additionalInfo.has(MALE_PARENT_UNKNOWN) && additionalInfo.get(MALE_PARENT_UNKNOWN).getAsBoolean()) { namePedigreeString += "/Unknown"; } //For use in individual germplasm display - additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); - additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); + additionalInfo.addProperty(GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); + additionalInfo.addProperty(GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); germplasm.setPedigree(gidPedigreeString); From 9add27aee238e0f3bf22b48d3893b8d479ab5c4a Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:14:07 -0400 Subject: [PATCH 6/8] [BI-1847] - revert to passing only putBrAPIGermplasmList no longer need to pass all germplasm in program to processGermplasmForDisplay --- .../org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java | 4 +--- 1 file changed, 1 insertion(+), 3 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 b87ea8499..93cc7bbe6 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -306,9 +306,7 @@ public List updateBrAPIGermplasm(List putBrAPIGe if (!putBrAPIGermplasmList.isEmpty()) { postFunction = () -> { putGermplasm(putBrAPIGermplasmList, api); - // Need all program germplasm for processGermplasmForDisplay parents pedigree - List germplasm = getRawGermplasm(programId); - return processGermplasmForDisplay(germplasm, program.getKey()); + return processGermplasmForDisplay(putBrAPIGermplasmList, program.getKey()); }; } return programGermplasmCache.post(programId, postFunction); From 2e34aa120667f101fa935f30a030a7bb104e1219 Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:33:44 -0400 Subject: [PATCH 7/8] [BI-1847] - use result of putBrAPIGermplasmList made it consistent with how it was before changed for BI-1855 --- .../org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 93cc7bbe6..6b64d255f 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -305,8 +305,8 @@ public List updateBrAPIGermplasm(List putBrAPIGe try { if (!putBrAPIGermplasmList.isEmpty()) { postFunction = () -> { - putGermplasm(putBrAPIGermplasmList, api); - return processGermplasmForDisplay(putBrAPIGermplasmList, program.getKey()); + List putResponse = putGermplasm(putBrAPIGermplasmList, api); + return processGermplasmForDisplay(putResponse, program.getKey()); }; } return programGermplasmCache.post(programId, postFunction); From 0939586f56fb8673abca55f8bdc028cbab9cb950 Mon Sep 17 00:00:00 2001 From: mlm483 <128052931+mlm483@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:05:29 -0400 Subject: [PATCH 8/8] [BI-1881] - changes based on review qualified constants, improved log messages --- .../brapi/v2/dao/BrAPIGermplasmDAO.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 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 6b64d255f..58f0653bc 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java +++ b/src/main/java/org/breedinginsight/brapi/v2/dao/BrAPIGermplasmDAO.java @@ -31,7 +31,7 @@ import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest; import org.brapi.v2.model.germ.response.BrAPIGermplasmSingleResponse; -import static org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields.*; +import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapps.importer.daos.ImportDAO; import org.breedinginsight.brapps.importer.model.ImportUpload; import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; @@ -112,9 +112,9 @@ public List getRawGermplasm(UUID programId) throws ApiException List cacheList = new ArrayList<>(programGermplasmCache.get(programId).values()); return cacheList.stream().map(germplasm -> { germplasm.setGermplasmName(Utilities.appendProgramKey(germplasm.getDefaultDisplayName(), program.getKey(), germplasm.getAccessionNumber())); - if(germplasm.getAdditionalInfo() != null && germplasm.getAdditionalInfo().has(GERMPLASM_RAW_PEDIGREE) - && !(germplasm.getAdditionalInfo().get(GERMPLASM_RAW_PEDIGREE).isJsonNull())) { - germplasm.setPedigree(germplasm.getAdditionalInfo().get(GERMPLASM_RAW_PEDIGREE).getAsString()); + if(germplasm.getAdditionalInfo() != null && germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_RAW_PEDIGREE) + && !(germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_RAW_PEDIGREE).isJsonNull())) { + germplasm.setPedigree(germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_RAW_PEDIGREE).getAsString()); } return germplasm; @@ -161,8 +161,8 @@ private Map processGermplasmForDisplay(List processGermplasmForDisplay(List processGermplasmForDisplay(List= 1 && !parentNames.get(0).isEmpty()) { - gidPedigreeString = additionalInfo.has(GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; + gidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID).getAsString() : ""; namePedigreeString = parentNames.get(0); - uuidPedigreeString = additionalInfo.has(GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; + uuidPedigreeString = additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID).getAsString() : ""; // Throw a descriptive error if femaleParentUUID is absent. - if (!additionalInfo.has(GERMPLASM_FEMALE_PARENT_UUID)) { - log.debug("The germplasm data in your backing BrAPI service needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); + if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_UUID)) { + String programId = "unknown program"; + Optional exRef = Utilities.getExternalReference(germplasm.getExternalReferences(), referenceSource + "/programs"); + if (exRef.isPresent()) { + programId = exRef.get().getReferenceID(); + } + log.debug("The germplasm data for program " + programId + " needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); throw new InternalServerException("Germplasm (" + germplasm.getGermplasmName() + ") has a female parent but femaleParentUUID is missing (Pedigree: " + germplasm.getPedigree() + ")."); } - } else if (additionalInfo.has(FEMALE_PARENT_UNKNOWN) && additionalInfo.get(FEMALE_PARENT_UNKNOWN).getAsBoolean()) { + } else if (additionalInfo.has(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.FEMALE_PARENT_UNKNOWN).getAsBoolean()) { namePedigreeString = "Unknown"; } // Update pedigree info for male parent. if (parentNames.size() == 2 && !parentNames.get(1).isEmpty()) { - gidPedigreeString += "/" + (additionalInfo.has(GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(GERMPLASM_MALE_PARENT_GID).getAsString() : ""); + gidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID).getAsString() : ""); namePedigreeString += "/" + parentNames.get(1); - uuidPedigreeString += "/" + (additionalInfo.has(GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); + uuidPedigreeString += "/" + (additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID) ? additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID).getAsString() : ""); // Throw a descriptive error if maleParentUUID is absent. - if (!additionalInfo.has(GERMPLASM_MALE_PARENT_UUID)) { - log.debug("The germplasm data in your backing BrAPI service needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); + if (!additionalInfo.has(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_UUID)) { + String programId = "unknown program"; + Optional exRef = Utilities.getExternalReference(germplasm.getExternalReferences(), referenceSource + "/programs"); + if (exRef.isPresent()) { + programId = exRef.get().getReferenceID(); + } + log.debug("The germplasm data for program " + programId + " needs to be updated: https://github.com/Breeding-Insight/bi-api/pull/290"); throw new InternalServerException("Germplasm (" + germplasm.getGermplasmName() + ") has a male parent but maleParentUUID is missing (Pedigree: " + germplasm.getPedigree() + ")."); } - } else if (additionalInfo.has(MALE_PARENT_UNKNOWN) && additionalInfo.get(MALE_PARENT_UNKNOWN).getAsBoolean()) { + } else if (additionalInfo.has(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN) && additionalInfo.get(BrAPIAdditionalInfoFields.MALE_PARENT_UNKNOWN).getAsBoolean()) { namePedigreeString += "/Unknown"; } //For use in individual germplasm display - additionalInfo.addProperty(GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); - additionalInfo.addProperty(GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); + additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_NAME, namePedigreeString); + additionalInfo.addProperty(BrAPIAdditionalInfoFields.GERMPLASM_PEDIGREE_BY_UUID, uuidPedigreeString); germplasm.setPedigree(gidPedigreeString);