Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e77ac44
[BI-1146] WIP
davedrp Mar 10, 2022
8245f0b
[BI-1146] experiment import: fix import template migration
Apr 20, 2022
f345aab
[BI-1146] support for summary stats
davedrp Apr 26, 2022
ef1d80d
[BI-1146] refactor. added code for coditionally required cells
davedrp Apr 29, 2022
4b9e373
[BI-1146] refactor. added getNewBrapiData()
davedrp May 2, 2022
565be9f
[BI-1146] remove unneeded Classes, clean up code
davedrp May 3, 2022
15c37be
[BI-1146] added validation for unique observation Unit Id
davedrp May 27, 2022
3facc3d
[BI-1146] Fixed bug. If spreadsheet cell is 'T', tableSaw assumes t…
davedrp May 27, 2022
0f21719
[BI-1189] WIP
davedrp May 10, 2022
2520ecc
[BI-1189] added studySequence to Program model object
davedrp May 12, 2022
d2193e8
BI-1189 WIP
davedrp May 17, 2022
84fb5a1
[BI-1189] added external references
davedrp May 23, 2022
21c775d
[BI-1189] fixed bugs, convert year to season DbId
davedrp May 25, 2022
ab9cad4
[BI-1189] Add experiment sequence number to study name
davedrp May 27, 2022
4bf78f1
[BI-1189] remove references to study sequence
davedrp May 27, 2022
b87056a
[BI-1189] caching for year-to-seasonDbId
davedrp May 27, 2022
c56f5a7
[BI-1189]Addrssed the PR comments by HMS17
davedrp Jun 2, 2022
4d6ac34
[BI-1189]Addrssed more PR comments by HMS17
davedrp Jun 7, 2022
14e5f7b
[BI-1189] responses of PR comments from Chris T
davedrp Jul 6, 2022
4ca4dfe
[BI-1189]Addrssed more PR comments by Chris T
davedrp Jul 8, 2022
ae77f3b
Merge branch 'future/1.0' into feature/BI-1189
timparsons Jul 20, 2022
71b5351
[BI-1189] appending experiment number to study names when searching f…
timparsons Jul 20, 2022
2bfdf31
[BI-1189] added experiment sequence number to study name
davedrp Jul 23, 2022
5d3ac00
[BI-1189] fixed bug. Added ExternalReferenceSource.java to emumerate …
davedrp Jul 25, 2022
6bfe649
[BI-1189] two small changes suggested by Tim in PR
davedrp Jul 29, 2022
be90382
Merge branch 'future/1.0' into feature/BI-1189
davedrp Aug 1, 2022
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 @@ -32,4 +32,8 @@ public final class BrAPIAdditionalInfoFields {
public static final String GERMPLASM_BREEDING_METHOD_ID = "breedingMethodId";
public static final String GERMPLASM_BREEDING_METHOD = "breedingMethod";
public static final String CREATED_DATE = "createdDate";
public static final String DEFAULT_OBSERVATION_LEVEL = "defaultObservationLevel";
public static final String OBSERVATION_LEVEL = "observationLevel";
public static final String EXPERIMENT_TYPE = "experimentType";
public static final String EXPERIMENT_NUMBER = "experimentNumber";
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.breedinginsight.brapps.importer.services.FileImportService;
import org.breedinginsight.services.exceptions.*;

import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -110,7 +111,7 @@ public HttpResponse<Response<ImportResponse>> getUploadData(@PathVariable UUID p
@AddMetadata
@ProgramSecured(roles = {ProgramSecuredRole.BREEDER, ProgramSecuredRole.SYSTEM_ADMIN})
public HttpResponse<Response<ImportResponse>> commitData(@PathVariable UUID programId, @PathVariable UUID mappingId,
@PathVariable UUID uploadId, @Body Map<String, Object> userInput) {
@PathVariable UUID uploadId, @Body @Nullable Map<String, Object> userInput) {
try {
AuthenticatedUser actingUser = securityService.getUser();
ImportResponse result = fileImportService.updateUpload(programId, uploadId, actingUser, userInput, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.breedinginsight.brapps.importer.daos;

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.core.SeasonQueryParams;
import org.brapi.client.v2.modules.core.ListsApi;
import org.brapi.client.v2.modules.core.SeasonsApi;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.BrAPIResponse;
import org.brapi.v2.model.BrAPIResponseResult;
import org.brapi.v2.model.core.BrAPIListSummary;
import org.brapi.v2.model.core.BrAPIListTypes;
import org.brapi.v2.model.core.BrAPISeason;
import org.brapi.v2.model.core.request.BrAPIListNewRequest;
import org.brapi.v2.model.core.request.BrAPIListSearchRequest;
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.pheno.BrAPIObservation;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.daos.ProgramDAO;
import org.breedinginsight.utilities.BrAPIDAOUtil;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

@Slf4j
public class BrAPISeasonDAO {

private ProgramDAO programDAO;
private ImportDAO importDAO;

@Inject
public BrAPISeasonDAO(ProgramDAO programDAO, ImportDAO importDAO) {
this.programDAO = programDAO;
this.importDAO = importDAO;
}

public List<BrAPISeason> getSeasonByYear(String year, UUID programId) throws ApiException {
SeasonsApi api = new SeasonsApi(programDAO.getCoreClient(programId));
SeasonQueryParams queryParams =
SeasonQueryParams.builder()
.year( year )
.pageSize( 10000 )
.build();
List<BrAPISeason> seasons = new ArrayList<>();
ApiResponse<BrAPISeasonListResponse> apiResponse = api.seasonsGet( queryParams );
BrAPISeasonListResponse seasonListResponse = apiResponse.getBody();
BrAPISeasonListResponseResult result = seasonListResponse.getResult();
seasons = result.getData();

return seasons;
}

public BrAPISeason addOneSeason(BrAPISeason season, UUID programId) throws ApiException {
BrAPISeason resultSeason = null;
SeasonsApi api = new SeasonsApi(programDAO.getCoreClient(programId));

ApiResponse<BrAPISeasonListResponse> apiResponse = api.seasonsPost(Arrays.asList(season));
BrAPISeasonListResponse seasonListResponse = apiResponse.getBody();
BrAPISeasonListResponseResult result = seasonListResponse.getResult();
List<BrAPISeason> seasons = result.getData();
if (seasons.size() > 0) {
resultSeason = seasons.get(0);
}
return resultSeason;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.breedinginsight.brapps.importer.daos;

import io.micronaut.context.annotation.Property;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.client.v2.modules.core.StudiesApi;
import org.brapi.v2.model.core.BrAPIStudy;
Expand All @@ -32,6 +33,8 @@

@Singleton
public class BrAPIStudyDAO {
@Property(name = "brapi.server.reference-source")
private String BRAPI_REFERENCE_SOURCE;

private ProgramDAO programDAO;
private ImportDAO importDAO;
Expand All @@ -54,6 +57,19 @@ public List<BrAPIStudy> getStudyByName(List<String> studyNames, Program program)
);
}

public List<BrAPIStudy> getStudiesByExperimentID(UUID experimentID, Program program ) throws ApiException {
BrAPIStudySearchRequest studySearch = new BrAPIStudySearchRequest();
studySearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId()));
studySearch.addExternalReferenceIDsItem(experimentID.toString());
studySearch.addExternalReferenceSourcesItem(BRAPI_REFERENCE_SOURCE + "/trials");
StudiesApi api = new StudiesApi(programDAO.getCoreClient(program.getId()));
return BrAPIDAOUtil.search(
api::searchStudiesPost,
api::searchStudiesSearchResultsDbIdGet,
studySearch
);
}

public List<BrAPIStudy> createBrAPIStudy(List<BrAPIStudy> brAPIStudyList, UUID programId, ImportUpload upload) throws ApiException {
StudiesApi api = new StudiesApi(programDAO.getCoreClient(programId));
return BrAPIDAOUtil.post(brAPIStudyList, upload, api::studiesPost, importDAO::update);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.core.*;
import org.brapi.v2.model.pheno.*;
import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields;
import org.breedinginsight.brapps.importer.model.config.*;
import org.breedinginsight.brapps.importer.model.imports.BrAPIImport;
import org.breedinginsight.brapps.importer.services.ExternalReferenceSource;
import org.breedinginsight.model.BrAPIConstants;
import org.breedinginsight.model.Program;
import org.breedinginsight.utilities.Utilities;

Expand Down Expand Up @@ -106,11 +110,14 @@ public class ExperimentObservation implements BrAPIImport {
@ImportFieldMetadata(id="ObsUnitID", name="Observation Unit ID", description = "A database generated unique identifier for experimental observation units")
private String ObsUnitID;

public BrAPITrial constructBrAPITrial(Program program, boolean commit) {
public BrAPITrial constructBrAPITrial(Program program, boolean commit, String referenceSource, UUID id, String expSeqValue) {
BrAPIProgram brapiProgram = program.getBrapiProgram();
BrAPITrial trial = new BrAPITrial();
if( commit ){
trial.setTrialName( getTrialNameWithProgramKey( program ));
trial.setTrialName( Utilities.appendProgramKey(getExpTitle(), program.getKey() ));

// Set external reference
trial.setExternalReferences(getTrialExternalReferences(program, referenceSource, id));
}
else{
trial.setTrialName( getExpTitle() );
Expand All @@ -120,14 +127,11 @@ public BrAPITrial constructBrAPITrial(Program program, boolean commit) {
trial.setProgramDbId(brapiProgram.getProgramDbId());
trial.setProgramName(brapiProgram.getProgramName());

// TODO: Get to a constant
trial.putAdditionalInfoItem("defaultObservationLevel", getExpUnit());
trial.putAdditionalInfoItem("experimentType", getExpType());
return trial;
}
trial.putAdditionalInfoItem( BrAPIAdditionalInfoFields.DEFAULT_OBSERVATION_LEVEL, getExpUnit());
trial.putAdditionalInfoItem( BrAPIAdditionalInfoFields.EXPERIMENT_TYPE, getExpType());
trial.putAdditionalInfoItem( BrAPIAdditionalInfoFields.EXPERIMENT_NUMBER, expSeqValue);

public String getTrialNameWithProgramKey(Program program){
return String.format("%s [%s]", getExpTitle(), program.getKey());
return trial;
}

public BrAPILocation constructBrAPILocation() {
Expand All @@ -136,10 +140,19 @@ public BrAPILocation constructBrAPILocation() {
return location;
}

public BrAPIStudy constructBrAPIStudy(Program program, Supplier<BigInteger> nextVal, boolean commit) {
public BrAPIStudy constructBrAPIStudy(
Program program,
boolean commit,
String referenceSource,
String expSequenceValue,
UUID trialId,
UUID id) {
BrAPIStudy study = new BrAPIStudy();
if ( commit ){
study.setStudyName(Utilities.appendProgramKey(getEnv(), program.getKey(), nextVal.get().toString()));
study.setStudyName(Utilities.appendProgramKey(getEnv(), program.getKey(), expSequenceValue));

// Set external reference
study.setExternalReferences(getStudyExternalReferences(program, referenceSource, trialId, id));
}
else {
study.setStudyName(getEnv());
Expand All @@ -149,51 +162,69 @@ public BrAPIStudy constructBrAPIStudy(Program program, Supplier<BigInteger> next
study.setLocationName(getEnvLocation());
study.setTrialName(getExpTitle());

List<String> seasonsList= new ArrayList<>();
seasonsList.add(getEnvYear());
study.setSeasons(seasonsList);
/*
TODO: Not used
List<String> seasonList = new ArrayList<>();
seasonList.add( getEnvYear() );
study.setSeasons( seasonList );

String designType = "Analysis"; // to support the BRApi server, the design type must be one of the following:
// 'CRD','Alpha','MAD','Lattice','Augmented','RCBD','p-rep','splitplot','greenhouse','Westcott', or 'Analysis'
// For now it will be hardcoded to 'Analysis'
BrAPIStudyExperimentalDesign design = new BrAPIStudyExperimentalDesign();
design.setPUI(getExperimentalDesignPUI());
design.setPUI(designType);
design.setDescription(designType);
study.setExperimentalDesign(design);
*/

return study;
}

public BrAPIObservationUnit constructBrAPIObservationUnit(Program program, Supplier<BigInteger> nextVal, boolean commit) {
public BrAPIObservationUnit constructBrAPIObservationUnit(
Program program,
Supplier<BigInteger> nextVal,
boolean commit,
String germplasmName,
String referenceSource,
UUID trialID,
UUID studyID,
UUID id
) {

BrAPIObservationUnit observationUnit = new BrAPIObservationUnit();
if( commit){
observationUnit.setObservationUnitName( Utilities.appendProgramKey(getExpUnitId(), program.getKey(), nextVal.get().toString()));

// Set external reference
observationUnit.setExternalReferences(getObsUnitExternalReferences(program, referenceSource, trialID, studyID, id));
}
else {
observationUnit.setObservationUnitName(getExpUnitId());
}
observationUnit.setStudyName(getEnv());

// TODO: Set the germplasm
//observationUnit.setGermplasmName(getGermplasm().getReferenceValue());
if(germplasmName==null){
germplasmName = getGermplasmName();
}
observationUnit.setGermplasmName(germplasmName);

BrAPIObservationUnitPosition position = new BrAPIObservationUnitPosition();
BrAPIObservationUnitLevelRelationship level = new BrAPIObservationUnitLevelRelationship();
level.setLevelName(getExpUnit());
level.setLevelName("plot"); //BreedBase only accepts "plot" or "plant"
level.setLevelCode( getExpUnitId() );
position.setObservationLevel(level);
observationUnit.putAdditionalInfoItem(BrAPIAdditionalInfoFields.OBSERVATION_LEVEL, getExpUnit());

// Exp Unit
List<BrAPIObservationUnitLevelRelationship> levelRelationships = new ArrayList<>();
if( getExpReplicateNo() !=null ) {
BrAPIObservationUnitLevelRelationship repLvl = new BrAPIObservationUnitLevelRelationship();
repLvl.setLevelName("replicate");
repLvl.setLevelName(BrAPIConstants.REPLICATE.getValue());
repLvl.setLevelCode(getExpReplicateNo());
levelRelationships.add(repLvl);
}

// Block number
if( getExpBlockNo() != null ) {
BrAPIObservationUnitLevelRelationship repLvl = new BrAPIObservationUnitLevelRelationship();
repLvl.setLevelName("block");
repLvl.setLevelName( BrAPIConstants.REPLICATE.getValue() );
repLvl.setLevelCode(getExpBlockNo());
levelRelationships.add(repLvl);
}
Expand Down Expand Up @@ -227,4 +258,39 @@ public BrAPIObservationUnit constructBrAPIObservationUnit(Program program, Suppl
return observationUnit;
}

private List<BrAPIExternalReference> getBrAPIExternalReferences(
Program program, String referenceSourceBaseName, UUID trialId, UUID studyId, UUID obsUnitId) {
List<BrAPIExternalReference> refs = new ArrayList<>();

addReference(refs, program.getId(), referenceSourceBaseName, ExternalReferenceSource.PROGRAMS);
if( trialId != null ) { addReference(refs, trialId, referenceSourceBaseName, ExternalReferenceSource.TRIALS); }
if( studyId != null ) { addReference(refs, studyId, referenceSourceBaseName, ExternalReferenceSource.STUDIES); }
if( obsUnitId != null ) { addReference(refs, obsUnitId, referenceSourceBaseName, ExternalReferenceSource.OBSERVATION_UNITS); }

return refs;
}

private List<BrAPIExternalReference> getTrialExternalReferences(
Program program, String referenceSourceBaseName, UUID trialId) {
return getBrAPIExternalReferences(program, referenceSourceBaseName, trialId, null, null);
}
private List<BrAPIExternalReference> getStudyExternalReferences(
Program program, String referenceSourceBaseName, UUID trialId, UUID studyId) {
return getBrAPIExternalReferences(program, referenceSourceBaseName, trialId, studyId, null);
}
private List<BrAPIExternalReference> getObsUnitExternalReferences(
Program program, String referenceSourceBaseName, UUID trialId, UUID studyId, UUID obsUnitId) {
return getBrAPIExternalReferences(program, referenceSourceBaseName, trialId, studyId, null);
}


private void addReference(List<BrAPIExternalReference> refs, UUID uuid, String referenceBaseNameSource, ExternalReferenceSource refSourceName) {
BrAPIExternalReference reference;
reference = new BrAPIExternalReference();
reference.setReferenceSource( String.format("%s/%s", referenceBaseNameSource, refSourceName.getName()) );
reference.setReferenceID(uuid.toString());
refs.add(reference);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public class PendingImportObject<T> {
private T brAPIObject;
private UUID id;

public PendingImportObject(ImportObjectState state, T brAPIObject) {
public PendingImportObject(ImportObjectState state, T brAPIObject, UUID id) {
this.state = state;
this.brAPIObject = brAPIObject;
this.id = UUID.randomUUID();
this.id = id;
}
public PendingImportObject(ImportObjectState state, T brAPIObject) {
this(state, brAPIObject, UUID.randomUUID());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.breedinginsight.brapps.importer.services;

import lombok.Getter;

@Getter
public enum ExternalReferenceSource {
PROGRAMS("programs"),
TRIALS("trials"),
STUDIES("studies"),
OBSERVATION_UNITS("observationunits");

private String name;

ExternalReferenceSource(String name) {
this.name = name;
}
}

Loading