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 @@ -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