Skip to content
Merged
Show file tree
Hide file tree
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 @@ -26,6 +26,7 @@
import org.brapi.client.v2.modules.germplasm.GermplasmApi;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.germ.BrAPIGermplasm;
import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms;
import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest;
import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields;
import org.breedinginsight.brapps.importer.daos.ImportDAO;
Expand Down Expand Up @@ -111,6 +112,11 @@ public List<BrAPIGermplasm> getRawGermplasm(UUID programId) throws ApiException
private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws ApiException {
GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId));

// Get the program key
List<Program> programs = programDAO.get(programId);
if (programs.size() != 1) throw new InternalServerException("Program was not found for given key");
Program program = programs.get(0);

// Set query params and make call
BrAPIGermplasmSearchRequest germplasmSearch = new BrAPIGermplasmSearchRequest();
germplasmSearch.externalReferenceIDs(List.of(programId.toString()));
Expand All @@ -119,7 +125,7 @@ private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws
api::searchGermplasmPost,
api::searchGermplasmSearchResultsDbIdGet,
germplasmSearch
));
), program.getKey());
}

/**
Expand All @@ -128,7 +134,7 @@ private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws
* @return Map<Key = string representing germplasm UUID, value = formatted BrAPIGermplasm>
* @throws ApiException
*/
private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> programGermplasm) {
private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> programGermplasm, String programKey) {
// Process the germplasm
Map<String, BrAPIGermplasm> programGermplasmMap = new HashMap<>();
log.debug("processing germ for display: " + programGermplasm);
Expand All @@ -144,6 +150,14 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas
if (germplasm.getDefaultDisplayName() != null) {
germplasm.setGermplasmName(germplasm.getDefaultDisplayName());
}

// Remove program key
if (germplasm.getSynonyms() != null && !germplasm.getSynonyms().isEmpty()) {
for (BrAPIGermplasmSynonyms synonym: germplasm.getSynonyms()) {
String newSynonym = Utilities.removeProgramKey(synonym.getSynonym(), programKey, germplasm.getAccessionNumber());
synonym.setSynonym(newSynonym);
}
}
}

// Update pedigree string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.brapi.v2.model.core.response.BrAPIListDetails;
import org.brapi.v2.model.core.response.BrAPIListsListResponse;
import org.brapi.v2.model.germ.BrAPIGermplasm;
import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms;
import org.breedinginsight.brapps.importer.daos.BrAPIListDAO;
import org.breedinginsight.model.Column;
import org.breedinginsight.model.DownloadFile;
Expand All @@ -30,6 +31,7 @@
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Singleton
Expand Down Expand Up @@ -136,6 +138,15 @@ public DownloadFile exportGermplasmList(UUID programId, String listId) throws Ap
row.put("Female Parent GID", Double.parseDouble(germPedigree.femaleParent));
if (!germPedigree.maleParent.isEmpty()) row.put("Male Parent GID", Double.parseDouble(germPedigree.maleParent));
}

// Synonyms
if (germplasmEntry.getSynonyms() != null && !germplasmEntry.getSynonyms().isEmpty()) {
String joinedSynonyms = germplasmEntry.getSynonyms().stream()
.map(synonym -> synonym.getSynonym())
.collect(Collectors.joining(";"));
row.put("Synonyms", joinedSynonyms);
}

processedData.add(row);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.brapi.v2.model.core.BrAPIListTypes;
import org.brapi.v2.model.core.request.BrAPIListNewRequest;
import org.brapi.v2.model.germ.BrAPIGermplasm;
import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms;
import org.breedinginsight.brapps.importer.model.config.*;
import org.breedinginsight.dao.db.tables.pojos.BreedingMethodEntity;
import org.breedinginsight.model.Program;
Expand Down Expand Up @@ -65,6 +66,10 @@ public class Germplasm implements BrAPIObject {
@ImportFieldMetadata(id="externalUID", name="External UID", description = "External UID")
private String externalUID;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="synonyms", name="Synonyms", description = "Optional list of germplasm synonyms separated by semicolons (;).")
private String synonyms;

@ImportFieldType(type= ImportFieldTypeEnum.INTEGER)
@ImportFieldMetadata(id="entryNo", name="Entry No.", description = "The order of germplasm in the import list ( 1,2,3,….n). If no entry number is specified in the import germplasm list, the database will assign entry number upon import.")
private String entryNo;
Expand Down Expand Up @@ -192,6 +197,23 @@ public BrAPIGermplasm constructBrAPIGermplasm(BreedingMethodEntity breedingMetho
germplasm.putAdditionalInfoItem("breedingMethod", breedingMethod.getName());
}

// Synonyms
String blobSynonyms = getSynonyms();
List<BrAPIGermplasmSynonyms> brapiSynonyms = new ArrayList<>();
if (synonyms != null) {
List<String> synonyms = Arrays.asList(blobSynonyms.split(";")).stream()
.map(synonym -> synonym.strip())
.distinct()
Copy link
Member

Choose a reason for hiding this comment

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

Is silently dropping duplicates what is desired? Also synonyms are currently only removed as duplicate if case is the same. Is that what is wanted? Can also have the same synonyms for different germplasm (not including the key), not sure if that matters.

Copy link
Member

Choose a reason for hiding this comment

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

Relaying these questions to @shawnyarnes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shawn added comments to the JIRA card:

https://breedinginsight.atlassian.net/browse/BI-1420

Looks like duplicate synonyms for a single germplasm are supposed to be dropped. But, Shawn is requesting a warning message. Let's talk about this because it will be a decent to large amount of extra work to add on the warning messages because we don't have a great way to handle this kind of flow currently.

.collect(Collectors.toList());
// Create synonym
for (String synonym: synonyms) {
BrAPIGermplasmSynonyms brapiSynonym = new BrAPIGermplasmSynonyms();
brapiSynonym.setSynonym(synonym);
brapiSynonyms.add(brapiSynonym);
}
germplasm.setSynonyms(brapiSynonyms);
}

return germplasm;
}

Expand All @@ -214,6 +236,13 @@ private void setBrAPIGermplasmCommitFields(BrAPIGermplasm germplasm, String prog
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
germplasm.putAdditionalInfoItem("createdDate", formatter.format(now));

// Update our synonyms to <Synonym> [<program key>-<accessionNumber>]
if (germplasm.getSynonyms() != null && !germplasm.getSynonyms().isEmpty()) {
for (BrAPIGermplasmSynonyms synonym: germplasm.getSynonyms()) {
synonym.setSynonym(Utilities.appendProgramKey(synonym.getSynonym(), programKey, germplasm.getAccessionNumber()));
}
}
}

public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEntity breedingMethod, User user, boolean commit, String referenceSource, Supplier<BigInteger> nextVal) {
Expand All @@ -231,5 +260,4 @@ public BrAPIGermplasm constructBrAPIGermplasm(Program program, BreedingMethodEnt

return germplasm;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public enum GermplasmFileColumns {
ENTRY_NO("Entry No", Column.ColumnDataType.NUMERICAL),
FEMALE_PARENT_ENTRY_NO("Female Parent Entry No", Column.ColumnDataType.NUMERICAL),
MALE_PARENT_ENTRY_NO("Male Parent Entry No", Column.ColumnDataType.NUMERICAL),
EXTERNAL_UID("External UID", Column.ColumnDataType.STRING);
EXTERNAL_UID("External UID", Column.ColumnDataType.STRING),
SYNONYMS("Synonyms", Column.ColumnDataType.STRING);

private final Column column;

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/breedinginsight/utilities/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.breedinginsight.utilities;

import org.apache.commons.lang3.StringUtils;
import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -62,4 +63,22 @@ public static String appendProgramKey(String original, String programKey, String
return String.format("%s [%s]", original, programKey);
}
}

/**
* Remove program key from a string. Returns a new value instead of altering original string.
*
* @param original
* @param programKey
* @param additionalKeyData
* @return
*/
public static String removeProgramKey(String original, String programKey, String additionalKeyData) {
if(StringUtils.isNotEmpty(additionalKeyData)) {
String keyValue = String.format(" [%s-%s]", programKey, additionalKeyData);
return original.replace(keyValue, "");
} else {
String keyValue = String.format(" [%s]", programKey);
return original.replace(keyValue, "");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

update importer_mapping
set mapping = '[{"id": "f8d43c7e-a618-4c16-8829-3085f7202a67", "mapping": [{"id": "f384837e-ad8d-4dbe-b54e-87b57070bed1", "value": {"fileFieldName": "Name"}, "objectId": "germplasmName"}, {"id": "39628d14-458b-429b-8e66-bb48e0445a83", "value": {"fileFieldName": "Breeding Method"}, "objectId": "breedingMethod"}, {"id": "f1ba63e1-f5e4-433f-a53e-1c2f3e2fa71f", "value": {"fileFieldName": "Source"}, "objectId": "germplasmSource"}, {"id": "f5892565-f888-4596-be82-ab8eeabf37ce", "value": {"fileFieldName": "External UID"}, "objectId": "externalUID"}, {"id": "65507e5d-2d66-4595-8763-e772fe25c870", "value": {"fileFieldName": "Entry No"}, "objectId": "entryNo"}, {"id": "3eae24c1-ca4a-48a2-96d0-3cf4630acd3a", "value": {"fileFieldName": "Female Parent GID"}, "objectId": "femaleParentDBID"}, {"id": "2dbd7262-93a1-44b0-86b7-f5fca290b965", "value": {"fileFieldName": "Male Parent GID"}, "objectId": "maleParentDBID"}, {"id": "6f7f1539-6e8f-4ede-b7d3-3423cc63abec", "value": {"fileFieldName": "Female Parent Entry No"}, "objectId": "femaleParentEntryNo"}, {"id": "25fe9954-bca7-42f1-818a-5f71e242fa1f", "value": {"fileFieldName": "Male Parent Entry No"}, "objectId": "maleParentEntryNo"}, {"id": "b910adfe-a474-47a0-8410-514578898436", "value": {"fileFieldName": "Synonyms"}, "objectId": "synonyms"}, {"id": "15836d5f-8194-40a8-a771-114eaae31eb4", "objectId": "germplasmPUI"}, {"id": "675b6af8-5a17-4146-a503-2e4e1a65d5fa", "objectId": "acquisitionDate"}, {"id": "69a3bd3c-cebc-435c-acdd-0be62dda25ed", "objectId": "countryOfOrigin"}, {"id": "8ab25267-20f2-450e-89ca-21634ff8fadb", "objectId": "collection"}, {"id": "ce1701e2-2f61-4250-8595-9536e3f5ddcf", "objectId": "AdditionalInfo"}, {"id": "3470e9df-a028-45b7-943f-198bc62b6dbe", "objectId": "ExternalReference"}], "objectId": "Germplasm"}]',
file = '[{"Name": "BITest Pinot Noir", "Source": "Unknown", "Entry No": "1", "External UID": "", "Breeding Method": "UMM", "Male Parent GID": "", "Female Parent GID": "", "Male Parent Entry No": "", "Female Parent Entry No": "", "Synonyms": "test1;test2"}, {"Name": "BITest Pixie", "Source": "Winters Nursery", "Entry No": "2", "External UID": "", "Breeding Method": "CFV", "Male Parent GID": "", "Female Parent GID": "", "Male Parent Entry No": "", "Female Parent Entry No": "1", "Synonyms": "test1;test2"}, {"Name": "BITest BI002", "Source": "Ithaca Nursery", "Entry No": "7", "External UID": "12231321", "Breeding Method": "Biparental cross", "Male Parent GID": "", "Female Parent GID": "", "Male Parent Entry No": "", "Female Parent Entry No": "2", "Synonyms": "test1;test2"}, {"Name": "BITest BI003", "Source": "Ithaca Nursery", "Entry No": "8", "External UID": "", "Breeding Method": "BPC", "Male Parent GID": "", "Female Parent GID": "", "Male Parent Entry No": "7", "Female Parent Entry No": "2", "Synonyms": "test1;test2"}, {"Name": "BITest Pinot Noir", "Source": "Unknown", "Entry No": "3", "External UID": "", "Breeding Method": "UMM", "Male Parent GID": "", "Female Parent GID": "5fb01ea5-c212-4cfa-84e4-6d190379341f", "Male Parent Entry No": "", "Female Parent Entry No": "", "Synonyms": "test1;test2"}, {"Name": "BITest Pixie", "Source": "Winters Nursery", "Entry No": "4", "External UID": "", "Breeding Method": "CFV", "Male Parent GID": "640e8b58-1b1c-44a6-91a6-85b2b773376b", "Female Parent GID": "5fb01ea5-c212-4cfa-84e4-6d190379341f", "Male Parent Entry No": "", "Female Parent Entry No": "", "Synonyms": "test1;test2"}, {"Name": "BITest BI002", "Source": "Ithaca Nursery", "Entry No": "5", "External UID": "12231321", "Breeding Method": "Biparental cross", "Male Parent GID": "", "Female Parent GID": "5fb01ea5-c212-4cfa-84e4-6d190379341f", "Male Parent Entry No": "", "Female Parent Entry No": "2", "Synonyms": "test1;test2"}]'
where name = 'GermplasmTemplateMap';
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ public void fullImportPreviewSuccess() {
String referenceSource = reference.getAsJsonObject().get("referenceSource").getAsString();
assertTrue(referenceSource != BRAPI_REFERENCE_SOURCE, "Germplasm UUID was present, but should not be");
}

// Synonyms
JsonArray synonyms = germplasm.getAsJsonArray("synonyms");
for (JsonElement synonym: synonyms) {
String synonymName = synonym.getAsJsonObject().get("synonym").getAsString();
assertNotNull(synonymName);
}
}
}

Expand Down Expand Up @@ -299,6 +306,16 @@ public void fullImportCommitSuccess() {
}
}
assertTrue(referenceFound, "Germplasm UUID reference not found");

// Synonyms
String[] splitGermplasmName = germplasm.get("germplasmName").getAsString().split(" ");
String scope = splitGermplasmName[splitGermplasmName.length - 1];
JsonArray synonyms = germplasm.getAsJsonArray("synonyms");
for (JsonElement synonym: synonyms) {
String synonymName = synonym.getAsJsonObject().get("synonym").getAsString();
assertNotNull(synonymName);
assertTrue(synonymName.contains(scope), "Germplasm synonym was not properly scoped");
}
}

// Check the germplasm list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,ANE,Wild,,,,,,
Germplasm 2,BAD,Wild,,,,,,
Germplasm 3,BAD1,Wild,,,,,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,ANE,Wild,,,,,,,
Germplasm 2,BAD,Wild,,,,,,,
Germplasm 3,BAD1,Wild,,,,,,,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,BCR,Wild,,,1,2,3,1234
Germplasm 2,BCR,Wild,,,2,1,2,5678
Germplasm 3,BCR,Wild,,,3,2,3,9123
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,BCR,Wild,,,1,2,3,1234,
Germplasm 2,BCR,Wild,,,2,1,2,5678,
Germplasm 3,BCR,Wild,,,3,2,3,9123,
14 changes: 7 additions & 7 deletions src/test/resources/files/germplasm_import/duplicate_db_names.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Full Germplasm 1,ANE,Wild,,,,,,
Full Germplasm 2,ANE,Wild,,,,,,
Full Germplasm 3,ANE,Wild,,,,,,
Unique Germplasm 1,ANE,Wild,,,,,,
File Germplasm 1,ANE,Wild,,,,,,
File Germplasm 1,ANE,Wild,,,,,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Full Germplasm 1,ANE,Wild,,,,,,,
Full Germplasm 2,ANE,Wild,,,,,,,
Full Germplasm 3,ANE,Wild,,,,,,,
Unique Germplasm 1,ANE,Wild,,,,,,,
File Germplasm 1,ANE,Wild,,,,,,,
File Germplasm 1,ANE,Wild,,,,,,,
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,BCR,Wild,,,1,,,
Germplasm 2,BCR,Wild,,,1,,,
Germplasm 3,BCR,Wild,,,3,,,
Germplasm 4,BCR,Wild,,,3,,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,BCR,Wild,,,1,,,,
Germplasm 2,BCR,Wild,,,1,,,,
Germplasm 3,BCR,Wild,,,3,,,,
Germplasm 4,BCR,Wild,,,3,,,,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,ANE,Wild,,,,,,
,ANE,Wild,,,,,,
Germplasm 3,ANE,,,,,,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,ANE,Wild,,,,,,,
,ANE,Wild,,,,,,,
Germplasm 3,ANE,,,,,,,,
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,,Wild,,,,,,
,,Wild,,,,,,
Germplasm 3,,,,,,,,
,,Wild,,,,,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,,Wild,,,,,,,
,,Wild,,,,,,,
Germplasm 3,,,,,,,,,
,,Wild,,,,,,,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,BCR,Wild,1000,,,,,
Germplasm 2,BCR,Cultivated,1001,,,,,
Germplasm 3,BCR,Kinda Wild,1002,,,,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,BCR,Wild,1000,,,,,,
Germplasm 2,BCR,Cultivated,1001,,,,,,
Germplasm 3,BCR,Kinda Wild,1002,,,,,,
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Germplasm 1,BCR,Wild,,,,1,,
Germplasm 2,BCR,Cultivated,,,,2,,
Germplasm 3,BCR,Kinda Wild,,,,3,,
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Germplasm 1,BCR,Wild,,,,1,,,
Germplasm 2,BCR,Cultivated,,,,2,,,
Germplasm 3,BCR,Kinda Wild,,,,3,,,
8 changes: 4 additions & 4 deletions src/test/resources/files/germplasm_import/full_import.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID
Full Germplasm 1,ANE,Wild,1,2,2,,,1234
Full Germplasm 2,ANE,Wild,2,,3,,,5678
Full Germplasm 3,ANE,Wild,,,4,2,3,9123
Name,Breeding Method,Source,Female Parent GID,Male Parent GID,Entry No,Female Parent Entry No,Male Parent Entry No,External UID,Synonyms
Full Germplasm 1,ANE,Wild,1,2,2,,,1234,test1;test2
Full Germplasm 2,ANE,Wild,2,,3,,,5678,test3;test2
Full Germplasm 3,ANE,Wild,,,4,2,3,9123,test3;test4
Loading