From d516c2ae9f1e38a38fecf70df712952e99b31c42 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:02:36 -0500 Subject: [PATCH 01/19] add listEntryNumbers to enum --- .../brapi/v2/constants/BrAPIAdditionalInfoFields.java | 1 + 1 file changed, 1 insertion(+) 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 1a633b9a1..78cccd942 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java +++ b/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java @@ -18,6 +18,7 @@ package org.breedinginsight.brapi.v2.constants; public final class BrAPIAdditionalInfoFields { + public static final String GERMPLASM_LIST_ENTRY_NUMBERS = "listEntryNumbers"; 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"; From 97dd2086965fc5d7568a509e3d65c4c9b05f2a36 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:04:18 -0500 Subject: [PATCH 02/19] add listEntryNumbers map to germplasm additionalInfo --- .../brapps/importer/model/base/Germplasm.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java index c2c74a433..1d846f9e8 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java +++ b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java @@ -143,7 +143,7 @@ public static String constructGermplasmListName(String listName, Program program return String.format("%s [%s-germplasm]", listName, program.getKey()); } - private BrAPIGermplasm constructBrAPIGermplasm(ProgramBreedingMethodEntity breedingMethod, User user) { + public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMethod, User user, String listName) { BrAPIGermplasm germplasm = new BrAPIGermplasm(); germplasm.setGermplasmName(getGermplasmName()); germplasm.setDefaultDisplayName(getGermplasmName()); @@ -158,6 +158,9 @@ private BrAPIGermplasm constructBrAPIGermplasm(ProgramBreedingMethodEntity breed createdBy.put(BrAPIAdditionalInfoFields.CREATED_BY_USER_ID, user.getId().toString()); createdBy.put(BrAPIAdditionalInfoFields.CREATED_BY_USER_NAME, user.getName()); germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.CREATED_BY, createdBy); + Map listEntryNumbers = new HashMap<>(); + listEntryNumbers.put(listName, entryNo); + germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS, listEntryNumbers); //TODO: Need to check that the acquisition date it in date format //brAPIGermplasm.setAcquisitionDate(pedigreeImport.getGermplasm().getAcquisitionDate()); germplasm.setCountryOfOriginCode(getCountryOfOrigin()); @@ -246,7 +249,7 @@ private void setBrAPIGermplasmCommitFields(BrAPIGermplasm germplasm, String prog } } - public BrAPIGermplasm constructBrAPIGermplasm(Program program, ProgramBreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal) { + public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal, String listName) { BrAPIGermplasm germplasm = constructBrAPIGermplasm(breedingMethod, user); if (commit) { setBrAPIGermplasmCommitFields(germplasm, program.getKey(), referenceSource, nextVal); @@ -261,4 +264,4 @@ public BrAPIGermplasm constructBrAPIGermplasm(Program program, ProgramBreedingMe return germplasm; } -} \ No newline at end of file +} From 4bd90073fa4d30427fbdd5d58fafe2bc9789b6c8 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:05:22 -0500 Subject: [PATCH 03/19] update process data to lookup germplasm entry numbers in the additionalInfo map --- .../brapi/v2/services/BrAPIGermplasmService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 6cc8446c8..658419cc0 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -112,14 +112,15 @@ public List getGermplasmListsByProgramId(UUID programId, HttpR } } - public List> processData(List germplasm){ + public List> processData(List germplasm, String listName){ List> processedData = new ArrayList<>(); for (BrAPIGermplasm germplasmEntry: germplasm) { HashMap row = new HashMap<>(); row.put("GID", Integer.valueOf(germplasmEntry.getAccessionNumber())); row.put("Name", germplasmEntry.getGermplasmName()); - row.put("Entry No", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsInt()); + row.put("Entry No", germplasmEntry.getAdditionalInfo() + .getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listName).getAsString()); row.put("Breeding Method", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_BREEDING_METHOD).getAsString()); String source = germplasmEntry.getSeedSource(); row.put("Source", source); @@ -187,7 +188,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType String fileName = createFileName(listData, listName); StreamedFile downloadFile; //Convert list data to List> data to pass into file writer - List> processedData = processData(germplasm); + List> processedData = processData(germplasm, listName); if (fileExtension == FileType.CSV){ downloadFile = CSVWriter.writeToDownload(columns, processedData, fileExtension); From 90a49de7e245dcbf9ef1ea6bf76545a1004d3886 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:18:18 -0500 Subject: [PATCH 04/19] update sorting in exportGermplasmList to use mapped entry numbers --- .../brapi/v2/services/BrAPIGermplasmService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 658419cc0..3d5828e1f 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -120,7 +120,7 @@ public List> processData(List germplasm, Str row.put("GID", Integer.valueOf(germplasmEntry.getAccessionNumber())); row.put("Name", germplasmEntry.getGermplasmName()); row.put("Entry No", germplasmEntry.getAdditionalInfo() - .getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listName).getAsString()); + .getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listName).getAsInt()); row.put("Breeding Method", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_BREEDING_METHOD).getAsString()); String source = germplasmEntry.getSeedSource(); row.put("Source", source); @@ -176,8 +176,11 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType //Retrieve germplasm data List germplasmNames = listData.getData(); List germplasm = germplasmDAO.getGermplasmByRawName(germplasmNames, programId); + //processGermplasmForDisplay, numbers - germplasm.sort(Comparator.comparingInt(g -> g.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsInt())); + germplasm.sort(Comparator.comparingInt(g -> + g.getAdditionalInfo().getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listData.getListName()).getAsInt())); + String listName = listData.getListName(); Optional optionalProgram = programService.getById(programId); From c5323518d71fb4a0e02c7997397f63f22f4014d4 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:58:00 -0500 Subject: [PATCH 05/19] pass import list name when constructing brapi germplasm --- .../brapps/importer/services/processors/GermplasmProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 18388251e..521873d70 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 @@ -273,7 +273,7 @@ public Map process(List importRows entryNumberCounts.put(germplasm.getEntryNo(), entryNumberCounts.containsKey(germplasm.getEntryNo()) ? entryNumberCounts.get(germplasm.getEntryNo()) + 1 : 1); - BrAPIGermplasm newGermplasm = germplasm.constructBrAPIGermplasm(program, breedingMethod, user, commit, BRAPI_REFERENCE_SOURCE, nextVal); + BrAPIGermplasm newGermplasm = germplasm.constructBrAPIGermplasm(program, breedingMethod, user, commit, BRAPI_REFERENCE_SOURCE, nextVal, importList.getListName()); newGermplasmList.add(newGermplasm); // Assign status of the germplasm From 3cf0225c29e194225d9f9bc4117a1c9786758a12 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Thu, 10 Nov 2022 09:47:36 -0500 Subject: [PATCH 06/19] pass listName to Germplasm#constructBrAPIGermplasm --- .../breedinginsight/brapps/importer/model/base/Germplasm.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java index 1d846f9e8..2a9d6e5c2 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java +++ b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java @@ -250,7 +250,7 @@ private void setBrAPIGermplasmCommitFields(BrAPIGermplasm germplasm, String prog } public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal, String listName) { - BrAPIGermplasm germplasm = constructBrAPIGermplasm(breedingMethod, user); + BrAPIGermplasm germplasm = constructBrAPIGermplasm(breedingMethod, user, listName); if (commit) { setBrAPIGermplasmCommitFields(germplasm, program.getKey(), referenceSource, nextVal); } From da902bafc03f75de260cd4300ab7de937af28b35 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Thu, 10 Nov 2022 13:06:13 -0500 Subject: [PATCH 07/19] remove importEntryNumber from additionalInfo for new germplasm --- .../breedinginsight/brapps/importer/model/base/Germplasm.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java index 2a9d6e5c2..b184076ab 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java +++ b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java @@ -149,7 +149,6 @@ public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMetho germplasm.setDefaultDisplayName(getGermplasmName()); germplasm.setGermplasmPUI(getGermplasmPUI()); germplasm.setCollection(getCollection()); - germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER, entryNo); germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID, getFemaleParentDBID()); germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID, getMaleParentDBID()); germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_ENTRY_NO, getFemaleParentEntryNo()); From 7695d20ffd4795b3c3955d974a034a26d58f0a22 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Thu, 17 Nov 2022 14:34:23 -0500 Subject: [PATCH 08/19] use germplasmListId instead of listName as key in entry number map --- .../v2/services/BrAPIGermplasmService.java | 60 ++++++++++++++++--- .../brapps/importer/model/base/Germplasm.java | 25 ++++---- .../processors/GermplasmProcessor.java | 7 ++- 3 files changed, 74 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 3d5828e1f..265b3f8fd 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -35,6 +35,7 @@ import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.function.ToIntFunction; import java.util.stream.Collectors; @Slf4j @@ -112,19 +113,25 @@ public List getGermplasmListsByProgramId(UUID programId, HttpR } } - public List> processData(List germplasm, String listName){ + public List> processData(List germplasm, UUID germplasmListId){ List> processedData = new ArrayList<>(); for (BrAPIGermplasm germplasmEntry: germplasm) { HashMap row = new HashMap<>(); row.put("GID", Integer.valueOf(germplasmEntry.getAccessionNumber())); row.put("Name", germplasmEntry.getGermplasmName()); - row.put("Entry No", germplasmEntry.getAdditionalInfo() - .getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listName).getAsInt()); row.put("Breeding Method", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_BREEDING_METHOD).getAsString()); String source = germplasmEntry.getSeedSource(); row.put("Source", source); + // Use the entry number in the list map if generated + if(germplasmListId.compareTo(new UUID(0,0)) == 0) { + row.put("Entry No", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsInt()); + } else { + row.put("Entry No", germplasmEntry.getAdditionalInfo() + .getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(germplasmListId.toString()).getAsInt()); + } + //If germplasm was imported with an external UID, it will be stored in external reference with same source as seed source List externalReferences = germplasmEntry.getExternalReferences(); for (BrAPIExternalReference reference: externalReferences){ @@ -178,9 +185,14 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType List germplasm = germplasmDAO.getGermplasmByRawName(germplasmNames, programId); //processGermplasmForDisplay, numbers - germplasm.sort(Comparator.comparingInt(g -> - g.getAdditionalInfo().getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listData.getListName()).getAsInt())); - + UUID germplasmListId = new UUID(0,0); + if(hasListExternalReference(listData)) { + germplasmListId = UUID.fromString(String.valueOf(listData.getExternalReferences().stream() + .filter(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())) + .map(e -> e.getReferenceID()) + .findFirst())); + } + germplasm.sort(Comparator.comparingInt(getEntryNumber(germplasmListId))); String listName = listData.getListName(); Optional optionalProgram = programService.getById(programId); @@ -191,7 +203,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType String fileName = createFileName(listData, listName); StreamedFile downloadFile; //Convert list data to List> data to pass into file writer - List> processedData = processData(germplasm, listName); + List> processedData = processData(germplasm, germplasmListId); if (fileExtension == FileType.CSV){ downloadFile = CSVWriter.writeToDownload(columns, processedData, fileExtension); @@ -202,6 +214,40 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType return new DownloadFile(fileName, downloadFile); } + private boolean hasListExternalReference(BrAPIListDetails listData) { + return listData.getExternalReferences().stream() + .anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); + } + private ToIntFunction getEntryNumber(UUID germplasmListId) { + try { + if(germplasmListId.compareTo(new UUID(0,0)) == 0) { + return this::getImportEntryNumber; + } else { + return g -> getGermplasmListEntryNumber(g, germplasmListId); + } + } catch(RuntimeException e) { + throw e; + } + } + + private Integer getImportEntryNumber(BrAPIGermplasm g) throws RuntimeException { + if(Objects.nonNull(g.getAdditionalInfo()) && + g.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER)) { + return g.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsInt(); + } else { + throw new RuntimeException(); + } + } + private Integer getGermplasmListEntryNumber(BrAPIGermplasm g, UUID germplasmListId) throws RuntimeException { + if(Objects.nonNull(g.getAdditionalInfo()) && + g.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS)) { + return g.getAdditionalInfo().getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS) + .get(germplasmListId.toString()).getAsInt(); + } else { + throw new RuntimeException(); + } + } + private String createFileName(BrAPIListDetails listData, String listName) { //TODO change timestamp to edit date when editing functionality is added String timestamp; diff --git a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java index b184076ab..08fe6827f 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java +++ b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java @@ -131,11 +131,16 @@ public BrAPIListNewRequest constructBrAPIList(Program program, String referenceS brapiList.setListName(constructGermplasmListName(listName, program)); brapiList.setListDescription(this.listDescription); brapiList.listType(BrAPIListTypes.GERMPLASM); - // Set external reference - BrAPIExternalReference reference = new BrAPIExternalReference(); - reference.setReferenceSource(String.format("%s/programs", referenceSource)); - reference.setReferenceID(program.getId().toString()); - brapiList.setExternalReferences(List.of(reference)); + + // Set external references + BrAPIExternalReference programReference = new BrAPIExternalReference(); + programReference.setReferenceSource(String.format("%s/programs", referenceSource)); + programReference.setReferenceID(program.getId().toString()); + BrAPIExternalReference listReference = new BrAPIExternalReference(); + listReference.setReferenceSource(String.format("%s/lists", referenceSource)); + listReference.setReferenceID(UUID.randomUUID().toString()); + brapiList.setExternalReferences(List.of(programReference, listReference)); + return brapiList; } @@ -143,7 +148,7 @@ public static String constructGermplasmListName(String listName, Program program return String.format("%s [%s-germplasm]", listName, program.getKey()); } - public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMethod, User user, String listName) { + public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMethod, User user, UUID listId) { BrAPIGermplasm germplasm = new BrAPIGermplasm(); germplasm.setGermplasmName(getGermplasmName()); germplasm.setDefaultDisplayName(getGermplasmName()); @@ -157,8 +162,8 @@ public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMetho createdBy.put(BrAPIAdditionalInfoFields.CREATED_BY_USER_ID, user.getId().toString()); createdBy.put(BrAPIAdditionalInfoFields.CREATED_BY_USER_NAME, user.getName()); germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.CREATED_BY, createdBy); - Map listEntryNumbers = new HashMap<>(); - listEntryNumbers.put(listName, entryNo); + Map listEntryNumbers = new HashMap<>(); + listEntryNumbers.put(listId, entryNo); germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS, listEntryNumbers); //TODO: Need to check that the acquisition date it in date format //brAPIGermplasm.setAcquisitionDate(pedigreeImport.getGermplasm().getAcquisitionDate()); @@ -248,8 +253,8 @@ private void setBrAPIGermplasmCommitFields(BrAPIGermplasm germplasm, String prog } } - public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal, String listName) { - BrAPIGermplasm germplasm = constructBrAPIGermplasm(breedingMethod, user, listName); + public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal, UUID listId) { + BrAPIGermplasm germplasm = constructBrAPIGermplasm(breedingMethod, user, listId); if (commit) { setBrAPIGermplasmCommitFields(germplasm, program.getKey(), referenceSource, nextVal); } 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 521873d70..adeed2832 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 @@ -273,7 +273,12 @@ public Map process(List importRows entryNumberCounts.put(germplasm.getEntryNo(), entryNumberCounts.containsKey(germplasm.getEntryNo()) ? entryNumberCounts.get(germplasm.getEntryNo()) + 1 : 1); - BrAPIGermplasm newGermplasm = germplasm.constructBrAPIGermplasm(program, breedingMethod, user, commit, BRAPI_REFERENCE_SOURCE, nextVal, importList.getListName()); + UUID importListId = UUID.fromString(String.valueOf(importList.getExternalReferences().stream() + .filter(e -> BRAPI_REFERENCE_SOURCE.concat("/lists").equals(e.getReferenceSource())) + .map(e -> e.getReferenceID()) + .findFirst())); + + BrAPIGermplasm newGermplasm = germplasm.constructBrAPIGermplasm(program, breedingMethod, user, commit, BRAPI_REFERENCE_SOURCE, nextVal, importListId); newGermplasmList.add(newGermplasm); // Assign status of the germplasm From 95862868e8385c9303866476a45d242f27d56e8d Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Thu, 17 Nov 2022 20:11:44 -0500 Subject: [PATCH 09/19] fix bugs --- .../v2/services/BrAPIGermplasmService.java | 32 ++++++++++++++++--- .../processors/GermplasmProcessor.java | 5 +-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 265b3f8fd..3fb7bf701 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.brapi.v2.model.core.BrAPIListSummary; import org.brapi.v2.model.core.BrAPIListTypes; +import org.brapi.v2.model.core.request.BrAPIListNewRequest; import org.brapi.v2.model.core.response.BrAPIListDetails; import org.brapi.v2.model.core.response.BrAPIListsListResponse; import org.brapi.v2.model.core.response.BrAPIListsSingleResponse; @@ -187,10 +188,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType //processGermplasmForDisplay, numbers UUID germplasmListId = new UUID(0,0); if(hasListExternalReference(listData)) { - germplasmListId = UUID.fromString(String.valueOf(listData.getExternalReferences().stream() - .filter(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())) - .map(e -> e.getReferenceID()) - .findFirst())); + germplasmListId = getGermplasmListId(listData); } germplasm.sort(Comparator.comparingInt(getEntryNumber(germplasmListId))); @@ -214,10 +212,36 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType return new DownloadFile(fileName, downloadFile); } + public UUID getGermplasmListId(BrAPIListDetails listData) { + if(Objects.nonNull(listData.getExternalReferences()) && hasListExternalReference(listData)) { + return UUID.fromString(listData.getExternalReferences().stream() + .filter(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())) + .map(e -> e.getReferenceID()).findAny().orElse("00000000-0000-0000-000000000000")); + } else { + return new UUID(0,0); + } + } + + public UUID getGermplasmListId(BrAPIListNewRequest importList) { + if(Objects.nonNull(importList.getExternalReferences()) && hasListExternalReference(importList)) { + return UUID.fromString(importList.getExternalReferences().stream() + .filter(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())) + .map(e -> e.getReferenceID()).findAny().orElse("00000000-0000-0000-000000000000")); + } else { + return new UUID(0,0); + } + } + private boolean hasListExternalReference(BrAPIListDetails listData) { return listData.getExternalReferences().stream() .anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); } + + private boolean hasListExternalReference(BrAPIListNewRequest importList) { + return importList.getExternalReferences().stream() + .anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); + } + private ToIntFunction getEntryNumber(UUID germplasmListId) { try { if(germplasmListId.compareTo(new UUID(0,0)) == 0) { 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 adeed2832..5f4f44740 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 @@ -273,10 +273,7 @@ public Map process(List importRows entryNumberCounts.put(germplasm.getEntryNo(), entryNumberCounts.containsKey(germplasm.getEntryNo()) ? entryNumberCounts.get(germplasm.getEntryNo()) + 1 : 1); - UUID importListId = UUID.fromString(String.valueOf(importList.getExternalReferences().stream() - .filter(e -> BRAPI_REFERENCE_SOURCE.concat("/lists").equals(e.getReferenceSource())) - .map(e -> e.getReferenceID()) - .findFirst())); + UUID importListId = brAPIGermplasmService.getGermplasmListId(importList); BrAPIGermplasm newGermplasm = germplasm.constructBrAPIGermplasm(program, breedingMethod, user, commit, BRAPI_REFERENCE_SOURCE, nextVal, importListId); From d34ffa826c27af60b2968c743a3dab516d1bf8d5 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Thu, 17 Nov 2022 20:21:38 -0500 Subject: [PATCH 10/19] code clean up --- .../brapi/v2/services/BrAPIGermplasmService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index 3fb7bf701..a7d3a4b10 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -186,10 +186,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType List germplasm = germplasmDAO.getGermplasmByRawName(germplasmNames, programId); //processGermplasmForDisplay, numbers - UUID germplasmListId = new UUID(0,0); - if(hasListExternalReference(listData)) { - germplasmListId = getGermplasmListId(listData); - } + UUID germplasmListId = getGermplasmListId(listData); germplasm.sort(Comparator.comparingInt(getEntryNumber(germplasmListId))); String listName = listData.getListName(); From 9c3353f346ec30239b9de8aaaa0d3e7d0189f7bf Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:12:56 -0500 Subject: [PATCH 11/19] update GermplasmTemplateMap#minimalImportUserSpecifiedEntryNumbersSuccess --- .../breedinginsight/brapps/importer/GermplasmTemplateMap.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java index c686897cb..61e51f5fa 100644 --- a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java +++ b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java @@ -177,7 +177,8 @@ public void minimalImportUserSpecifiedEntryNumbersSuccess() { for (int i = 0; i < previewRows.size(); i++) { JsonObject germplasm = previewRows.get(i).getAsJsonObject().getAsJsonObject("germplasm").getAsJsonObject("brAPIObject"); germplasmNames.add(germplasm.get("germplasmName").getAsString()); - assertEquals(Integer.toString(i+1), germplasm.getAsJsonObject("additionalInfo").get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString(), "Wrong entry number"); + int finalI = i; + gson.fromJson(germplasm.getAsJsonObject("additionalInfo").getAsJsonObject("listEntryNumbers"), Map.class).forEach((listId, entryNumber) -> assertEquals(Integer.toString(finalI +1), entryNumber)); } // Check the germplasm list From 32a9c74b5c4d41f7634a63e61b2936423dde599b Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Tue, 22 Nov 2022 14:06:03 -0500 Subject: [PATCH 12/19] update GermplasmTemplateMap#checkBasicResponse --- .../breedinginsight/brapps/importer/GermplasmTemplateMap.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java index 61e51f5fa..2aa02b0cb 100644 --- a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java +++ b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java @@ -178,7 +178,7 @@ public void minimalImportUserSpecifiedEntryNumbersSuccess() { JsonObject germplasm = previewRows.get(i).getAsJsonObject().getAsJsonObject("germplasm").getAsJsonObject("brAPIObject"); germplasmNames.add(germplasm.get("germplasmName").getAsString()); int finalI = i; - gson.fromJson(germplasm.getAsJsonObject("additionalInfo").getAsJsonObject("listEntryNumbers"), Map.class).forEach((listId, entryNumber) -> assertEquals(Integer.toString(finalI +1), entryNumber)); + gson.fromJson(germplasm.getAsJsonObject("additionalInfo").getAsJsonObject("listEntryNumbers"), Map.class).forEach((listId, entryNumber) -> assertEquals(Integer.toString(finalI +1), entryNumber, "Wrong entry number")); } // Check the germplasm list @@ -740,6 +740,7 @@ public void checkBasicResponse(JsonObject germplasm, Table fileData, Integer i) // Germplasm display name assertEquals(fileData.getString(i, "Name"), germplasm.get("defaultDisplayName").getAsString(), "Wrong display name"); // Entry Number + gson.fromJson(germplasm.getAsJsonObject("additionalInfo").getAsJsonObject("listEntryNumbers"), Map.class).forEach((listId, entryNumber) -> assertEquals(fileData.getString(i, "Entry No"), entryNumber, "Wrong entry number")); JsonObject additionalInfo = germplasm.getAsJsonObject("additionalInfo"); assertEquals(fileData.getString(i, "Entry No"), additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString(), "Wrong entry number"); // Created By User ID From e1fd0a1ef974b18b0161d52e162cedd30f64e2bc Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Tue, 22 Nov 2022 14:12:52 -0500 Subject: [PATCH 13/19] update GermplasmTemplateMap#headerCaseInsensitive --- .../breedinginsight/brapps/importer/GermplasmTemplateMap.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java index 2aa02b0cb..85bdea426 100644 --- a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java +++ b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java @@ -608,7 +608,8 @@ public void headerCaseInsensitive() { for (int i = 0; i < previewRows.size(); i++) { JsonObject germplasm = previewRows.get(i).getAsJsonObject().getAsJsonObject("germplasm").getAsJsonObject("brAPIObject"); germplasmNames.add(germplasm.get("germplasmName").getAsString()); - assertEquals(Integer.toString(i+1), germplasm.getAsJsonObject("additionalInfo").get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString(), "Wrong entry number"); + int finalI = i; + gson.fromJson(germplasm.getAsJsonObject("additionalInfo").getAsJsonObject("listEntryNumbers"), Map.class).forEach((listId, entryNumber) -> assertEquals(Integer.toString(finalI +1), entryNumber, "Wrong entry number")); } // Check the germplasm list From f749cb358106ad5c41b88bb88625b30397ab47ed Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Tue, 22 Nov 2022 21:29:40 -0500 Subject: [PATCH 14/19] use IllegalArgumentException --- .../v2/services/BrAPIGermplasmService.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index a7d3a4b10..f83b862b2 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -175,7 +175,7 @@ public List getGermplasmByList(UUID programId, String listId) th return germplasmDAO.getGermplasmByRawName(germplasmNames, programId); } else throw new ApiException(); } - public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws ApiException, IOException { + public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException { List columns = GermplasmFileColumns.getOrderedColumns(); //Retrieve germplasm list data @@ -239,33 +239,29 @@ private boolean hasListExternalReference(BrAPIListNewRequest importList) { .anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); } - private ToIntFunction getEntryNumber(UUID germplasmListId) { - try { - if(germplasmListId.compareTo(new UUID(0,0)) == 0) { - return this::getImportEntryNumber; - } else { - return g -> getGermplasmListEntryNumber(g, germplasmListId); - } - } catch(RuntimeException e) { - throw e; + private ToIntFunction getEntryNumber(UUID germplasmListId) throws IllegalArgumentException { + if(germplasmListId.compareTo(new UUID(0,0)) == 0) { + return this::getImportEntryNumber; + } else { + return g -> getGermplasmListEntryNumber(g, germplasmListId); } } - private Integer getImportEntryNumber(BrAPIGermplasm g) throws RuntimeException { + private Integer getImportEntryNumber(BrAPIGermplasm g) throws IllegalArgumentException { if(Objects.nonNull(g.getAdditionalInfo()) && g.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER)) { return g.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsInt(); } else { - throw new RuntimeException(); + throw new IllegalArgumentException(); } } - private Integer getGermplasmListEntryNumber(BrAPIGermplasm g, UUID germplasmListId) throws RuntimeException { + private Integer getGermplasmListEntryNumber(BrAPIGermplasm g, UUID germplasmListId) throws IllegalArgumentException { if(Objects.nonNull(g.getAdditionalInfo()) && g.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS)) { return g.getAdditionalInfo().getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS) .get(germplasmListId.toString()).getAsInt(); } else { - throw new RuntimeException(); + throw new IllegalArgumentException(); } } From d70e9a279e1ddb1bce72282e6b93455af015997d Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Mon, 23 Jan 2023 12:17:05 -0500 Subject: [PATCH 15/19] refactor germplasmService method --- .../brapi/v2/services/BrAPIGermplasmService.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index f83b862b2..a5d9122e5 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -17,6 +17,7 @@ import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapps.importer.daos.BrAPIListDAO; +import org.breedinginsight.brapps.importer.model.base.ExternalReference; import org.breedinginsight.brapps.importer.model.exports.FileType; import org.breedinginsight.model.Column; import org.breedinginsight.model.DownloadFile; @@ -210,7 +211,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType } public UUID getGermplasmListId(BrAPIListDetails listData) { - if(Objects.nonNull(listData.getExternalReferences()) && hasListExternalReference(listData)) { + if(Objects.nonNull(listData.getExternalReferences()) && hasListExternalReference(listData.getExternalReferences())) { return UUID.fromString(listData.getExternalReferences().stream() .filter(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())) .map(e -> e.getReferenceID()).findAny().orElse("00000000-0000-0000-000000000000")); @@ -220,7 +221,7 @@ public UUID getGermplasmListId(BrAPIListDetails listData) { } public UUID getGermplasmListId(BrAPIListNewRequest importList) { - if(Objects.nonNull(importList.getExternalReferences()) && hasListExternalReference(importList)) { + if(Objects.nonNull(importList.getExternalReferences()) && hasListExternalReference(importList.getExternalReferences())) { return UUID.fromString(importList.getExternalReferences().stream() .filter(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())) .map(e -> e.getReferenceID()).findAny().orElse("00000000-0000-0000-000000000000")); @@ -229,14 +230,9 @@ public UUID getGermplasmListId(BrAPIListNewRequest importList) { } } - private boolean hasListExternalReference(BrAPIListDetails listData) { - return listData.getExternalReferences().stream() - .anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); - } - - private boolean hasListExternalReference(BrAPIListNewRequest importList) { - return importList.getExternalReferences().stream() - .anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); + private boolean hasListExternalReference(List refs) throws IllegalArgumentException { + if (refs == null) throw new IllegalArgumentException(); + return refs.stream().anyMatch(e -> referenceSource.concat("/lists").equals(e.getReferenceSource())); } private ToIntFunction getEntryNumber(UUID germplasmListId) throws IllegalArgumentException { From f709da68e8b259c31c36b2b0b393e1ffd39234d9 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Tue, 7 Feb 2023 13:54:57 -0500 Subject: [PATCH 16/19] update germplsm query mapper to check for listEntryNumber --- .../brapi/v2/GermplasmController.java | 4 ++-- .../constants/BrAPIAdditionalInfoFields.java | 1 + .../v2/services/BrAPIGermplasmService.java | 15 ++++++++---- .../mappers/GermplasmQueryMapper.java | 23 +++++++++++++++---- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java index 0141fa3db..188d10fa0 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java +++ b/src/main/java/org/breedinginsight/brapi/v2/GermplasmController.java @@ -106,10 +106,10 @@ public HttpResponse>>> getGermplasm( @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) public HttpResponse>>> getGermplasmListRecords( @PathVariable("programId") UUID programId, - @PathVariable("listDbId") String listId, + @PathVariable("listDbId") String listDbId, @QueryValue @QueryValid(using = GermplasmQueryMapper.class) @Valid GermplasmQuery queryParams) { try { - List germplasm = germplasmService.getGermplasmByList(programId, listId); + List germplasm = germplasmService.getGermplasmByList(programId, listDbId); SearchRequest searchRequest = queryParams.constructSearchRequest(); return ResponseUtils.getBrapiQueryResponse(germplasm, germplasmQueryMapper, queryParams, searchRequest); } catch (Exception e) { 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 78cccd942..55a2c95f1 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java +++ b/src/main/java/org/breedinginsight/brapi/v2/constants/BrAPIAdditionalInfoFields.java @@ -19,6 +19,7 @@ public final class BrAPIAdditionalInfoFields { public static final String GERMPLASM_LIST_ENTRY_NUMBERS = "listEntryNumbers"; + public static final String GERMPLASM_LIST_ID = "listId"; 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"; diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index a5d9122e5..a6ac06035 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -166,14 +166,21 @@ public List> processData(List germplasm, UUI return processedData; } - public List getGermplasmByList(UUID programId, String listId) throws ApiException { + public List getGermplasmByList(UUID programId, String listDbId) throws ApiException { // get list germplasm names - BrAPIListsSingleResponse listResponse = brAPIListDAO.getListById(listId, programId); + BrAPIListsSingleResponse listResponse = brAPIListDAO.getListById(listDbId, programId); if(Objects.nonNull(listResponse) && Objects.nonNull(listResponse.getResult())) { - List germplasmNames = listResponse.getResult().getData(); + + // get the list ID stored in the list external references + UUID listId = getGermplasmListId(listResponse.getResult()); // get list BrAPI germplasm variables - return germplasmDAO.getGermplasmByRawName(germplasmNames, programId); + List germplasmNames = listResponse.getResult().getData(); + List germplasm = germplasmDAO.getGermplasmByRawName(germplasmNames, programId); + + // set the list ID in the germplasm additional info + germplasm.forEach(g -> g.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ID, listId)); + return germplasm; } else throw new ApiException(); } public DownloadFile exportGermplasmList(UUID programId, String listId, FileType fileExtension) throws IllegalArgumentException, ApiException, IOException { diff --git a/src/main/java/org/breedinginsight/utilities/response/mappers/GermplasmQueryMapper.java b/src/main/java/org/breedinginsight/utilities/response/mappers/GermplasmQueryMapper.java index a8b29503c..0b58c84d4 100644 --- a/src/main/java/org/breedinginsight/utilities/response/mappers/GermplasmQueryMapper.java +++ b/src/main/java/org/breedinginsight/utilities/response/mappers/GermplasmQueryMapper.java @@ -2,6 +2,7 @@ import com.google.gson.JsonObject; import lombok.Getter; +import org.brapi.v2.model.core.response.BrAPIListsSingleResponse; import org.brapi.v2.model.germ.BrAPIGermplasm; import org.breedinginsight.api.v1.controller.metadata.SortOrder; import org.breedinginsight.brapi.v1.model.ObservationVariable; @@ -24,10 +25,24 @@ public class GermplasmQueryMapper extends AbstractQueryMapper { public GermplasmQueryMapper() { fields = Map.ofEntries( - Map.entry("importEntryNumber", (germplasm) -> - germplasm.getAdditionalInfo() != null && germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER) ? - germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString() : - null), + Map.entry("importEntryNumber", (germplasm) ->{ + String entryNumber = null; + if (germplasm.getAdditionalInfo() != null) { + // if additionalInfo contains the importEntryNumber key then return the value + if (germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER)) { + entryNumber = germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString(); + } + + // if additionalInfo has both listEntryNumbers and listId keys then return the entry number + // mapped to the listId + if (germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS) + && germplasm.getAdditionalInfo().has(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ID)) { + String listId = germplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ID).getAsString(); + entryNumber = germplasm.getAdditionalInfo().getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS).get(listId).getAsString(); + } + } + return entryNumber; + }), Map.entry("accessionNumber", BrAPIGermplasm::getAccessionNumber), Map.entry("defaultDisplayName", BrAPIGermplasm::getDefaultDisplayName), Map.entry("breedingMethod", (germplasm) -> From 3b912a7512332a6ea3860a2ab9e27cf6c992b6ba Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 8 Feb 2023 10:38:33 -0500 Subject: [PATCH 17/19] refactor germplasm service --- .../brapi/v2/services/BrAPIGermplasmService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java index a6ac06035..b7c4fa323 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPIGermplasmService.java @@ -11,13 +11,10 @@ import org.brapi.v2.model.core.BrAPIListTypes; import org.brapi.v2.model.core.request.BrAPIListNewRequest; import org.brapi.v2.model.core.response.BrAPIListDetails; -import org.brapi.v2.model.core.response.BrAPIListsListResponse; import org.brapi.v2.model.core.response.BrAPIListsSingleResponse; import org.brapi.v2.model.germ.BrAPIGermplasm; -import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapps.importer.daos.BrAPIListDAO; -import org.breedinginsight.brapps.importer.model.base.ExternalReference; import org.breedinginsight.brapps.importer.model.exports.FileType; import org.breedinginsight.model.Column; import org.breedinginsight.model.DownloadFile; @@ -115,7 +112,7 @@ public List getGermplasmListsByProgramId(UUID programId, HttpR } } - public List> processData(List germplasm, UUID germplasmListId){ + public List> processListData(List germplasm, UUID germplasmListId){ List> processedData = new ArrayList<>(); for (BrAPIGermplasm germplasmEntry: germplasm) { @@ -127,7 +124,7 @@ public List> processData(List germplasm, UUI row.put("Source", source); // Use the entry number in the list map if generated - if(germplasmListId.compareTo(new UUID(0,0)) == 0) { + if(new UUID(0,0).compareTo(germplasmListId) == 0) { row.put("Entry No", germplasmEntry.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsInt()); } else { row.put("Entry No", germplasmEntry.getAdditionalInfo() @@ -206,7 +203,7 @@ public DownloadFile exportGermplasmList(UUID programId, String listId, FileType String fileName = createFileName(listData, listName); StreamedFile downloadFile; //Convert list data to List> data to pass into file writer - List> processedData = processData(germplasm, germplasmListId); + List> processedData = processListData(germplasm, germplasmListId); if (fileExtension == FileType.CSV){ downloadFile = CSVWriter.writeToDownload(columns, processedData, fileExtension); From 036c708ed782ee13e75b21e6ddfd602cad3f9a5e Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:58:39 -0500 Subject: [PATCH 18/19] fix conflict --- .../brapps/importer/model/base/Germplasm.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java index 08fe6827f..ae04e3a6b 100644 --- a/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java +++ b/src/main/java/org/breedinginsight/brapps/importer/model/base/Germplasm.java @@ -27,6 +27,7 @@ import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms; import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; import org.breedinginsight.brapps.importer.model.config.*; +import org.breedinginsight.dao.db.tables.pojos.BreedingMethodEntity; import org.breedinginsight.dao.db.tables.pojos.ProgramBreedingMethodEntity; import org.breedinginsight.model.Program; import org.breedinginsight.model.User; @@ -148,7 +149,7 @@ public static String constructGermplasmListName(String listName, Program program return String.format("%s [%s-germplasm]", listName, program.getKey()); } - public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMethod, User user, UUID listId) { + public BrAPIGermplasm constructBrAPIGermplasm(ProgramBreedingMethodEntity breedingMethod, User user, UUID listId) { BrAPIGermplasm germplasm = new BrAPIGermplasm(); germplasm.setGermplasmName(getGermplasmName()); germplasm.setDefaultDisplayName(getGermplasmName()); @@ -253,7 +254,7 @@ private void setBrAPIGermplasmCommitFields(BrAPIGermplasm germplasm, String prog } } - public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal, UUID listId) { + public BrAPIGermplasm constructBrAPIGermplasm(Program program, ProgramBreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier nextVal, UUID listId) { BrAPIGermplasm germplasm = constructBrAPIGermplasm(breedingMethod, user, listId); if (commit) { setBrAPIGermplasmCommitFields(germplasm, program.getKey(), referenceSource, nextVal); From 5f0f6693adcf31dd01a586c6bafb3a21bb3cd8c1 Mon Sep 17 00:00:00 2001 From: dmeidlin <14339308+dmeidlin@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:03:54 -0500 Subject: [PATCH 19/19] delete old assertion from GermplasmTemplateMap --- .../breedinginsight/brapps/importer/GermplasmTemplateMap.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java index 85bdea426..0b82c9c86 100644 --- a/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java +++ b/src/test/java/org/breedinginsight/brapps/importer/GermplasmTemplateMap.java @@ -743,7 +743,6 @@ public void checkBasicResponse(JsonObject germplasm, Table fileData, Integer i) // Entry Number gson.fromJson(germplasm.getAsJsonObject("additionalInfo").getAsJsonObject("listEntryNumbers"), Map.class).forEach((listId, entryNumber) -> assertEquals(fileData.getString(i, "Entry No"), entryNumber, "Wrong entry number")); JsonObject additionalInfo = germplasm.getAsJsonObject("additionalInfo"); - assertEquals(fileData.getString(i, "Entry No"), additionalInfo.get(BrAPIAdditionalInfoFields.GERMPLASM_IMPORT_ENTRY_NUMBER).getAsString(), "Wrong entry number"); // Created By User ID assertEquals(testUser.getId().toString(), additionalInfo.getAsJsonObject(BrAPIAdditionalInfoFields.CREATED_BY).get(BrAPIAdditionalInfoFields.CREATED_BY_USER_ID).getAsString(), "Wrong createdBy userId"); // Created by User name