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
@@ -0,0 +1,75 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.breedinginsight.brapps.importer.model.imports.experimentObservation;

import lombok.extern.slf4j.Slf4j;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.brapps.importer.model.imports.BrAPIImport;
import org.breedinginsight.brapps.importer.model.imports.BrAPIImportService;
import org.breedinginsight.brapps.importer.model.imports.germplasm.GermplasmImport;
import org.breedinginsight.brapps.importer.model.response.ImportPreviewResponse;
import org.breedinginsight.brapps.importer.services.processors.*;
import org.breedinginsight.model.Program;
import org.breedinginsight.model.User;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;
import tech.tablesaw.api.Table;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.util.List;

@Singleton
@Slf4j
public class ExperimentImportService extends BrAPIImportService {

private final String IMPORT_TYPE_ID = "ExperimentImport";

private Provider<ExperimentProcessor> experimentProcessorProvider;
private Provider<ProcessorManager> processorManagerProvider;

@Inject
public ExperimentImportService(Provider<ExperimentProcessor> experimentProcessorProvider, Provider<ProcessorManager> processorManagerProvider)
{
this.experimentProcessorProvider = experimentProcessorProvider;
this.processorManagerProvider = processorManagerProvider;
}

@Override
public ExperimentObservation getImportClass() {
return new ExperimentObservation();
}

@Override
public String getImportTypeId() {
return IMPORT_TYPE_ID;
}

@Override
public ImportPreviewResponse process(List<BrAPIImport> brAPIImports, Table data, Program program, ImportUpload upload, User user, Boolean commit)
throws UnprocessableEntityException, ValidatorException, ApiException {

ImportPreviewResponse response = null;
List<Processor> processors = List.of(experimentProcessorProvider.get());
response = processorManagerProvider.get().process(brAPIImports, processors, program, upload, user, commit);
return response;

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.breedinginsight.brapps.importer.model.imports.experimentObservation;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.brapi.v2.model.core.*;
import org.brapi.v2.model.pheno.*;
import org.breedinginsight.brapps.importer.model.config.*;
import org.breedinginsight.brapps.importer.model.imports.BrAPIImport;
import org.breedinginsight.model.Program;
import org.breedinginsight.utilities.Utilities;

import java.math.BigInteger;
import java.util.*;
import java.util.function.Supplier;

@Getter
@Setter
@NoArgsConstructor
@ImportConfigMetadata(id="ExperimentImport", name="Experiment Import",
description = "This import is used to create Observation Unit and Experiment data")
public class ExperimentObservation implements BrAPIImport {

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="germplasmName", name="Germplasm Name", description = "Name of germplasm")
private String germplasmName;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="gid", name="Germplasm GID", description = "Unique germplasm identifier")
private String gid;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="test_or_check", name="Test or Check", description = "T test (T) and check (C) germplasm")
private String testOrCheck;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="exp_title", name="Experiment Title", description = "Title of experiment")
private String expTitle;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="expDescription", name="Experiment Description", description = "Description of experiment")
private String expDescription;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="expUnit", name="Experiment Unit", description = "experiment unit (Examples: plots, plant, tanks, hives, etc.)")
private String expUnit;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="expType", name="Experiment Type", description = "Description of experimental type (Examples: Performance trial, crossing block, seed orchard, etc)")
private String expType;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="env", name="Environment", description = "Free-text unique identifier for environment within the experiment. Common examples include: 1,2,3…n and/or a concationation of environment location and year")
private String env;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="envLocation", name="Environment Location", description = "Location of the environment")
private String envLocation;

@ImportFieldType(type= ImportFieldTypeEnum.INTEGER)
@ImportFieldMetadata(id="envYear", name="Environment Year", description = "Year corresponding to the environment")
private String envYear;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="expUnitId", name="Experiment Unit ID", description = "Human-readable alphanumeric identifier for experimental units unique within environment. Examples, like plot number, are often a numeric sequence.")
private String expUnitId;

@ImportFieldType(type= ImportFieldTypeEnum.INTEGER)
@ImportFieldMetadata(id="expReplicateNo", name="Experiment Replicate Number", description = "Sequential number of experimental replications")
private String expReplicateNo;

@ImportFieldType(type= ImportFieldTypeEnum.INTEGER)
@ImportFieldMetadata(id="expBlockNo", name="Experiment Block Number", description = "Sequential number of blocks in an experimental design")
private String expBlockNo;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="row", name="Row", description = "Horizontal (y-axis) position in 2D Cartesian space.")
private String row;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="column", name="Column", description = "Vertical (x-axis) position in 2D Cartesian space.")
private String column;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id="treatmentFactors", name="Exp Treatment Factor Name", description = "treatement factors in an experiment with applied variables, like fertilizer or water regimens.")
private String treatmentFactors;

@ImportFieldType(type= ImportFieldTypeEnum.TEXT)
@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) {
BrAPIProgram brapiProgram = program.getBrapiProgram();
BrAPITrial trial = new BrAPITrial();
if( commit ){
trial.setTrialName( getTrialNameWithProgramKey( program ));
}
else{
trial.setTrialName( getExpTitle() );
}
trial.setTrialDescription(getExpDescription());
trial.setActive(true);
trial.setProgramDbId(brapiProgram.getProgramDbId());
trial.setProgramName(brapiProgram.getProgramName());

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

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

public BrAPILocation constructBrAPILocation() {
BrAPILocation location = new BrAPILocation();
location.setLocationName(getEnvLocation());
return location;
}

public BrAPIStudy constructBrAPIStudy(Program program, Supplier<BigInteger> nextVal, boolean commit) {
BrAPIStudy study = new BrAPIStudy();
if ( commit ){
study.setStudyName(Utilities.appendProgramKey(getEnv(), program.getKey(), nextVal.get().toString()));
}
else {
study.setStudyName(getEnv());
}
study.setActive(true);
study.setStudyType(getExpType());
study.setLocationName(getEnvLocation());
study.setTrialName(getExpTitle());
study.setSeasons( List.of( getEnvYear()==null ? "" : getEnvYear() ) );
/*
TODO: Not used
BrAPIStudyExperimentalDesign design = new BrAPIStudyExperimentalDesign();
design.setPUI(getExperimentalDesignPUI());
study.setExperimentalDesign(design);
*/

return study;
}

public BrAPIObservationUnit constructBrAPIObservationUnit(Program program, Supplier<BigInteger> nextVal, boolean commit) {

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

// TODO: Set the germplasm
//observationUnit.setGermplasmName(getGermplasm().getReferenceValue());

BrAPIObservationUnitPosition position = new BrAPIObservationUnitPosition();
BrAPIObservationUnitLevelRelationship level = new BrAPIObservationUnitLevelRelationship();
level.setLevelName(getExpUnit());
position.setObservationLevel(level);

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

// Block number
if( getExpBlockNo() != null ) {
BrAPIObservationUnitLevelRelationship repLvl = new BrAPIObservationUnitLevelRelationship();
repLvl.setLevelName("block");
repLvl.setLevelCode(getExpBlockNo());
levelRelationships.add(repLvl);
}
position.setObservationLevelRelationships(levelRelationships);

// Test or Check
if("C".equals(getTestOrCheck())){
position.setEntryType(BrAPIEntryTypeEnum.CHECK);
} else {
position.setEntryType(BrAPIEntryTypeEnum.TEST);
}

// X and Y coordinates
if (getRow() != null) {
position.setPositionCoordinateX(getRow());
position.setPositionCoordinateXType(BrAPIPositionCoordinateTypeEnum.GRID_ROW);
}
if (getColumn() != null) {
position.setPositionCoordinateY(getColumn());
position.setPositionCoordinateYType(BrAPIPositionCoordinateTypeEnum.GRID_ROW);
}
observationUnit.setObservationUnitPosition(position);

// Treatment factors
if (getTreatmentFactors() != null) {
BrAPIObservationTreatment treatment = new BrAPIObservationTreatment();
treatment.setFactor(getTreatmentFactors());
observationUnit.setTreatments(List.of(treatment));
}

return observationUnit;
}

}

This file was deleted.

Loading