Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
da3bff2
[BI-1473] - Allow user to append existing germplasm with optional det…
HMS17 Sep 14, 2022
d704498
Update download link and test files
HMS17 Sep 14, 2022
fcd2b9d
Work in progress logic
HMS17 Sep 15, 2022
bfe2f6f
Merge branch 'develop' into feature/BI-1473
nickpalladino Feb 2, 2023
c580f0b
Updated migration version number
nickpalladino Feb 2, 2023
1928ef3
Updates to processing logic
nickpalladino Feb 28, 2023
2c62382
Merge branch 'develop' into feature/BI-1473
nickpalladino Feb 28, 2023
1c03d64
Brapi data updates work
nickpalladino Mar 9, 2023
3282d52
Some cleanup and bug fixes
nickpalladino Mar 16, 2023
8f80260
Remove dev token
nickpalladino Mar 16, 2023
b2bc961
Cleanup left over token stuff
nickpalladino Mar 16, 2023
60ed697
Merge branch 'develop' into feature/BI-1473
nickpalladino Mar 16, 2023
67c9fe8
Renamed migration after develop merge
nickpalladino Mar 16, 2023
1bd12bf
Fixed compilation issues
nickpalladino Mar 17, 2023
7172d7a
Fix migration version merge conflict
nickpalladino Mar 17, 2023
de17fde
Fix file causing test failure
nickpalladino Mar 27, 2023
3560fba
Fix list issue and cleanup
nickpalladino Mar 28, 2023
de75621
Remove extraneous stuff from token controller
nickpalladino Mar 28, 2023
dcb12ca
cleanup
nickpalladino Mar 28, 2023
690cf3b
spacing
nickpalladino Mar 28, 2023
10f50f0
Code review changes work in progress
nickpalladino Apr 7, 2023
d8ebfc2
Updated test
nickpalladino Apr 7, 2023
3cee4ee
Split out method
nickpalladino Apr 10, 2023
c16d207
Removed comment
nickpalladino Apr 10, 2023
5d5d414
Added unsupported operation exception
nickpalladino Apr 11, 2023
e43f622
Pedigree logic updated
nickpalladino Apr 14, 2023
d358d0b
Merge branch 'develop' into feature/BI-1473
nickpalladino Apr 19, 2023
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 @@ -70,5 +70,5 @@ public HttpResponse apiToken(@QueryValue @NotBlank String returnUrl) {
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import lombok.extern.slf4j.Slf4j;
import org.brapi.client.v2.ApiResponse;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.client.v2.model.queryParams.germplasm.GermplasmQueryParams;
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.brapi.v2.model.germ.response.BrAPIGermplasmListResponse;
import org.brapi.v2.model.germ.response.BrAPIGermplasmSingleResponse;
import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields;
import org.breedinginsight.brapps.importer.daos.ImportDAO;
import org.breedinginsight.brapps.importer.model.ImportUpload;
Expand Down Expand Up @@ -239,14 +238,34 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas
return programGermplasmMap;
}

public List<BrAPIGermplasm> importBrAPIGermplasm(List<BrAPIGermplasm> brAPIGermplasmList, UUID programId, ImportUpload upload) throws ApiException {
public List<BrAPIGermplasm> createBrAPIGermplasm(List<BrAPIGermplasm> postBrAPIGermplasmList, UUID programId, ImportUpload upload) {
GermplasmApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), GermplasmApi.class);
var program = programDAO.fetchOneById(programId);
Callable<Map<String, BrAPIGermplasm>> postFunction = null;
try {
Callable<Map<String, BrAPIGermplasm>> postFunction = () -> {
List<BrAPIGermplasm> postResponse = brAPIDAOUtil.post(brAPIGermplasmList, upload, api::germplasmPost, importDAO::update);
return processGermplasmForDisplay(postResponse, program.getKey());
};
if (!postBrAPIGermplasmList.isEmpty()) {
postFunction = () -> {
List<BrAPIGermplasm> postResponse = brAPIDAOUtil.post(postBrAPIGermplasmList, upload, api::germplasmPost, importDAO::update);
return processGermplasmForDisplay(postResponse, program.getKey());
};
}
return programGermplasmCache.post(programId, postFunction);
} catch (Exception e) {
throw new InternalServerException("Unknown error has occurred: " + e.getMessage(), e);
}
}

public List<BrAPIGermplasm> updateBrAPIGermplasm(List<BrAPIGermplasm> putBrAPIGermplasmList, UUID programId, ImportUpload upload) {
GermplasmApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), GermplasmApi.class);
var program = programDAO.fetchOneById(programId);
Callable<Map<String, BrAPIGermplasm>> postFunction = null;
try {
if (!putBrAPIGermplasmList.isEmpty()) {
postFunction = () -> {
List<BrAPIGermplasm> postResponse = putGermplasm(putBrAPIGermplasmList, api);
return processGermplasmForDisplay(postResponse, program.getKey());
};
}
return programGermplasmCache.post(programId, postFunction);
} catch (Exception e) {
throw new InternalServerException("Unknown error has occurred: " + e.getMessage(), e);
Expand Down Expand Up @@ -292,4 +311,17 @@ public List<BrAPIGermplasm> getGermplasmsByDBID(Collection<String> germplasmDbId
}
return germplasm;
}

public List<BrAPIGermplasm> putGermplasm(List<BrAPIGermplasm> germplasmList, GermplasmApi api) throws ApiException {
List<BrAPIGermplasm> listResult = new ArrayList<>();

// TODO: temporary until generic BrAPIDAOUtil code is written
// generic code should handle importer progress updates
for (BrAPIGermplasm germplasm : germplasmList) {
ApiResponse<BrAPIGermplasmSingleResponse> response = api.germplasmGermplasmDbIdPut(germplasm.getGermplasmDbId(), germplasm);
listResult.add(response.getBody().getResult());
}

return listResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,17 @@ private String removeAppendedKey(String listName, String programKey){
return listName.replace(appendedKey, "");
}

public List<BrAPIGermplasm> importBrAPIGermplasm(List<BrAPIGermplasm> brAPIGermplasmList, UUID programId, ImportUpload upload) throws ApiException {
return germplasmDAO.importBrAPIGermplasm(brAPIGermplasmList, programId, upload);
public List<BrAPIGermplasm> createBrAPIGermplasm(List<BrAPIGermplasm> postBrAPIGermplasmList, UUID programId, ImportUpload upload) {
return germplasmDAO.createBrAPIGermplasm(postBrAPIGermplasmList, programId, upload);
}

public List<BrAPIGermplasm> updateBrAPIGermplasm(List<BrAPIGermplasm> putBrAPIGermplasmList, UUID programId, ImportUpload upload) {
return germplasmDAO.updateBrAPIGermplasm(putBrAPIGermplasmList, programId, upload);
}

public List<BrAPIGermplasm> importBrAPIGermplasm(List<BrAPIGermplasm> postBrAPIGermplasmList, List<BrAPIGermplasm> putBrAPIGermplasmList,
UUID programId, ImportUpload upload) throws ApiException {
return germplasmDAO.createBrAPIGermplasm(postBrAPIGermplasmList, programId, upload);
}

public List<BrAPIGermplasm> getRawGermplasmByAccessionNumber(ArrayList<String> germplasmAccessionNumbers, UUID programId) throws ApiException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.breedinginsight.brapps.importer.model.base;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -109,6 +111,10 @@ public class Germplasm implements BrAPIObject {
@ImportFieldMetadata(id="collection", name="Family Name", description = "The name of the family this germplasm is a part of.")
private String collection;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="germplasmAccessionNumber", name="Accession Number", description = "The accession number of the germplasm if germplasm is being re-imported with updated synonyms/parents.")
private String accessionNumber;

// Removed for now, need to add to breedbase
/*@ImportType(type=ImportFieldType.LIST, clazz=GermplasmAttribute.class)
private List<GermplasmAttribute> germplasmAttributes;*/
Expand Down Expand Up @@ -150,12 +156,78 @@ public static String constructGermplasmListName(String listName, Program program
return String.format("%s [%s-germplasm]", listName, program.getKey());
}

public void updateBrAPIGermplasm(BrAPIGermplasm germplasm, Program program, UUID listId, boolean commit) {

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());
germplasm.putAdditionalInfoItem(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_ENTRY_NO, getMaleParentEntryNo());

// Append synonyms to germplasm that don't already exist
// Synonym comparison is based on name and type
if (synonyms != null) {
Set<BrAPIGermplasmSynonyms> existingSynonyms = new HashSet<>(germplasm.getSynonyms());
for (String synonym: synonyms.split(";")){
BrAPIGermplasmSynonyms brapiSynonym = new BrAPIGermplasmSynonyms();
brapiSynonym.setSynonym(synonym);
if (!existingSynonyms.contains(brapiSynonym)) {
germplasm.addSynonymsItem(brapiSynonym);
}
}
}

// Add germplasm to the new list
JsonObject listEntryNumbers = germplasm.getAdditionalInfo().getAsJsonObject(BrAPIAdditionalInfoFields.GERMPLASM_LIST_ENTRY_NUMBERS);
listEntryNumbers.addProperty(listId.toString(), entryNo);

// TODO: figure out why clear this out: brapi-server
germplasm.setBreedingMethodDbId(null);

if (commit) {
setUpdateCommitFields(germplasm, program.getKey());
}
}


public void setUpdateCommitFields(BrAPIGermplasm germplasm, String programKey) {

// Set germplasm name to <Name> [<program key>-<accessionNumber>]
String name = Utilities.appendProgramKey(germplasm.getDefaultDisplayName(), programKey, germplasm.getAccessionNumber());
germplasm.setGermplasmName(name);

// 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 boolean pedigreesEqual(BrAPIGermplasm brAPIGermplasm) {
JsonElement femaleGid = brAPIGermplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_GID);
String brapiFemaleGid = femaleGid != null ? femaleGid.getAsString() : null;
JsonElement maleGid = brAPIGermplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_GID);
String brapiMaleGid = maleGid != null ? maleGid.getAsString() : null;
JsonElement femaleEntryNo = brAPIGermplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_FEMALE_PARENT_ENTRY_NO);
String brapiFemaleEntryNo = femaleEntryNo != null ? femaleEntryNo.getAsString() : null;
JsonElement maleEntryNo = brAPIGermplasm.getAdditionalInfo().get(BrAPIAdditionalInfoFields.GERMPLASM_MALE_PARENT_ENTRY_NO);
String brapiMaleEntryNo = maleEntryNo != null ? maleEntryNo.getAsString() : null;

return ((getFemaleParentDBID() == null && brapiFemaleGid == null) || (getFemaleParentDBID() != null && getFemaleParentDBID().equals(brapiFemaleGid))) &&
((getMaleParentDBID() == null && brapiMaleGid == null) || (getMaleParentDBID() != null && getMaleParentDBID().equals(brapiMaleGid))) &&
((getFemaleParentEntryNo() == null && brapiFemaleEntryNo == null) || (getFemaleParentEntryNo() != null && getFemaleParentEntryNo().equals(brapiFemaleEntryNo))) &&
((getMaleParentEntryNo() == null && brapiMaleEntryNo == null) || (getMaleParentEntryNo() != null && getMaleParentEntryNo().equals(brapiMaleEntryNo)));
}

public BrAPIGermplasm constructBrAPIGermplasm(ProgramBreedingMethodEntity breedingMethod, User user, UUID listId) {
BrAPIGermplasm germplasm = new BrAPIGermplasm();
germplasm.setGermplasmName(getGermplasmName());
germplasm.setDefaultDisplayName(getGermplasmName());
germplasm.setGermplasmPUI(getGermplasmPUI());
germplasm.setCollection(getCollection());
germplasm.setGermplasmDbId(getAccessionNumber());
//TODO: maybe remove germplasm import entry number
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class ExperimentProcessor implements Processor {
private final OntologyService ontologyService;
private final FileMappingUtil fileMappingUtil;


// used to make the yearsToSeasonDbId() function more efficient
private final Map<String, String> yearToSeasonDbIdCache = new HashMap<>();
// used to make the seasonDbIdtoYear() function more efficient
Expand Down
Loading