Skip to content

Commit

Permalink
Merge pull request #304 from Breeding-Insight/bug/BI-1911-2
Browse files Browse the repository at this point in the history
BI-1911 fix QA findings
  • Loading branch information
davedrp authored Oct 30, 2023
2 parents ba01774 + 02369e3 commit f3545f1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public final class BrAPIAdditionalInfoFields {
public static final String MALE_PARENT_UNKNOWN = "maleParentUnknown";
public static final String TREATMENTS = "treatments";
public static final String GID = "gid";
public static final String ENV_YEAR = "envYear";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.breedinginsight.brapps.importer.services.processors;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.micronaut.context.annotation.Property;
import io.micronaut.context.annotation.Prototype;
import io.micronaut.http.HttpStatus;
Expand Down Expand Up @@ -894,27 +896,66 @@ private PendingImportObject<BrAPIStudy> fetchOrCreateStudyPIO(Program program, b
PendingImportObject<BrAPIStudy> pio;
if (studyByNameNoScope.containsKey(importRow.getEnv())) {
pio = studyByNameNoScope.get(importRow.getEnv());
if (! commit){
addYearToStudyAdditionalInfo(program, pio.getBrAPIObject());
}
} else {
PendingImportObject<BrAPITrial> trialPIO = this.trialByNameNoScope.get(importRow.getExpTitle());
UUID trialID = trialPIO.getId();
UUID id = UUID.randomUUID();
BrAPIStudy newStudy = importRow.constructBrAPIStudy(program, commit, BRAPI_REFERENCE_SOURCE, expSequenceValue, trialID, id, envNextVal);
newStudy.setLocationDbId(this.locationByName.get(importRow.getEnvLocation()).getId().toString()); //set as the BI ID to facilitate looking up locations when saving new studies

// It is assumed that the study has only one season, And that the Years and not
// the dbId's are stored in getSeason() list.
String year = newStudy.getSeasons().get(0);
if (commit) {
String year = newStudy.getSeasons().get(0); // It is assumed that the study has only one season
if(StringUtils.isNotBlank(year)) {
String seasonID = this.yearToSeasonDbId(year, program.getId());
newStudy.setSeasons(Collections.singletonList(seasonID));
}
} else {
addYearToStudyAdditionalInfo(program, newStudy, year);
}


pio = new PendingImportObject<>(ImportObjectState.NEW, newStudy, id);
this.studyByNameNoScope.put(importRow.getEnv(), pio);
}
return pio;
}


/*
* this finds the YEAR from the season list on the BrAPIStudy and then
* will add the year to the additionalInfo-field of the BrAPIStudy
* */
private void addYearToStudyAdditionalInfo(Program program, BrAPIStudy study) {
JsonObject additionalInfo = study.getAdditionalInfo();

//if it is already there, don't add it.
if(additionalInfo==null || additionalInfo.get(BrAPIAdditionalInfoFields.ENV_YEAR)==null) {
String seasonDbId = study.getSeasons().get(0);
String year = seasonDbIdToYear(seasonDbId, program.getId());
addYearToStudyAdditionalInfo(program, study, year);
}
}


/*
* this will add the given year to the additionalInfo field of the BrAPIStudy (if it does not already exist)
* */
private void addYearToStudyAdditionalInfo(Program program, BrAPIStudy study, String year) {
JsonObject additionalInfo = study.getAdditionalInfo();
if (additionalInfo==null){
additionalInfo = new JsonObject();
study.setAdditionalInfo(additionalInfo);
}
if( additionalInfo.get(BrAPIAdditionalInfoFields.ENV_YEAR)==null) {
additionalInfo.addProperty(BrAPIAdditionalInfoFields.ENV_YEAR, year);
}
}

private PendingImportObject<ProgramLocation> fetchOrCreateLocationPIO(ExperimentObservation importRow) {
PendingImportObject<ProgramLocation> pio;
if (locationByName.containsKey((importRow.getEnvLocation()))) {
Expand Down

0 comments on commit f3545f1

Please sign in to comment.