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 @@ -17,6 +17,7 @@
import org.brapi.v2.model.core.response.BrAPIListsSingleResponse;
import org.brapi.v2.model.core.response.BrAPISeasonListResponse;
import org.brapi.v2.model.core.response.BrAPISeasonListResponseResult;
import org.brapi.v2.model.core.response.BrAPISeasonSingleResponse;
import org.brapi.v2.model.pheno.BrAPIObservation;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.daos.ProgramDAO;
Expand Down Expand Up @@ -56,6 +57,14 @@ public List<BrAPISeason> getSeasonByYear(String year, UUID programId) throws Api
return seasons;
}

public BrAPISeason getSeasonById(String id, UUID programId) throws ApiException {
SeasonsApi api = new SeasonsApi(programDAO.getCoreClient(programId));
ApiResponse<BrAPISeasonSingleResponse> apiResponse = api.seasonsSeasonDbIdGet(id);
BrAPISeasonSingleResponse seasonListResponse = apiResponse.getBody();
BrAPISeason season = seasonListResponse.getResult();
return season;
}

public BrAPISeason addOneSeason(BrAPISeason season, UUID programId) throws ApiException {
BrAPISeason resultSeason = null;
SeasonsApi api = new SeasonsApi(programDAO.getCoreClient(programId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class ExperimentProcessor implements Processor {

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

//These BrapiData-objects are initially populated by the getExistingBrapiData() method,
// then updated by the getNewBrapiData() method.
Expand Down Expand Up @@ -608,6 +610,9 @@ private Map<String, PendingImportObject<BrAPIStudy>> initialize_studyByNameNoSco
try {
existingStudies = brAPIStudyDAO.getStudiesByExperimentID(UUID.fromString(experimentIDStr), program);
existingStudies.forEach(existingStudy -> {
//Swap season DbId with year String
String seasonId = existingStudy.getSeasons().get(0);
existingStudy.setSeasons( List.of( this.seasonDbIdToYear( seasonId, program.getId() ) ) );

existingStudy.setStudyName(Utilities.removeProgramKeyAndUnknownAdditionalData(existingStudy.getStudyName(), program.getKey()));
studyByNameNoScope.put(
Expand Down Expand Up @@ -684,7 +689,7 @@ private String simpleStudyName(String scopedName){
private String yearsToSeasonDbId(List<String> years, UUID programId) {
String year = years.get(0);
String dbID = null;
if (this.yearToSeasonDbIdCache.containsKey(year) ){ // get it from cache if possable
if (this.yearToSeasonDbIdCache.containsKey(year) ){ // get it from cache if possible
dbID = this.yearToSeasonDbIdCache.get(year);
}
else{
Expand All @@ -694,6 +699,18 @@ private String yearsToSeasonDbId(List<String> years, UUID programId) {
return dbID;
}

private String seasonDbIdToYear(String seasonDbId, UUID programId) {
String year = null;
if (this.seasonDbIdToYearCache.containsKey(seasonDbId) ){ // get it from cache if possible
year = this.seasonDbIdToYearCache.get(seasonDbId);
}
else{
year = this.seasonDbIdToYearFromDatabase(seasonDbId,programId);
this.seasonDbIdToYearCache.put(seasonDbId, year);
}
return year;
}

private String yearToSeasonDbIdFromDatabase(String year, UUID programId) {
BrAPISeason targetSeason = null;
List<BrAPISeason> seasons;
Expand All @@ -720,6 +737,19 @@ private String yearToSeasonDbIdFromDatabase(String year, UUID programId) {
return seasonDbId;
}

private String seasonDbIdToYearFromDatabase(String seasonDbId, UUID programId) {
BrAPISeason targetSeason = null;
BrAPISeason season = null;
try {
season = this.brAPISeasonDAO.getSeasonById (seasonDbId, programId);
} catch (ApiException e) {
log.error(e.getResponseBody(), e);;
}
Integer yearInt = (season == null) ? null : season.getYear();;
String yearStr = (yearInt==null) ? "" : yearInt.toString();
return yearStr;
}

private boolean isTrialRefSource(BrAPIExternalReference brAPIExternalReference) {
return brAPIExternalReference.getReferenceSource().equals( String.format("%s/%s", BRAPI_REFERENCE_SOURCE, ExternalReferenceSource.TRIALS.getName()) );
}
Expand Down