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 @@ -26,7 +26,6 @@
import io.micronaut.http.server.exceptions.InternalServerException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.collections4.map.CaseInsensitiveMap;
import org.apache.commons.lang3.StringUtils;
import org.brapi.client.v2.JSON;
Expand Down Expand Up @@ -62,7 +61,6 @@
import org.breedinginsight.services.OntologyService;
import org.breedinginsight.services.ProgramLocationService;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;
Expand All @@ -72,7 +70,6 @@
import tech.tablesaw.columns.Column;

import javax.inject.Inject;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.OffsetDateTime;
Expand All @@ -87,14 +84,7 @@
public class ExperimentProcessor implements Processor {

private static final String NAME = "Experiment";
private static final String EXISTING_ENV = "Cannot create new observation unit %s for existing environment %s.<br/><br/>" +
"If you’re trying to add these units to the experiment, please create a new environment" +
" with all appropriate experiment units (NOTE: this will generate new Observation Unit Ids " +
"for each experiment unit).";
private static final String MISSING_OBS_UNIT_ID_ERROR = "Experiment Units are missing Observation Unit Id.<br/><br/>" +
"If you’re trying to add these units to the experiment, please create a new environment" +
" with all appropriate experiment units (NOTE: this will generate new Observation Unit Ids " +
"for each experiment unit).";
private static final String MISSING_OBS_UNIT_ID_ERROR = "Experimental entities are missing ObsUnitIDs";
private static final String MULTIPLE_EXP_TITLES = "File contains more than one Experiment Title";
private static final String MIDNIGHT = "T00:00:00-00:00";
private static final String TIMESTAMP_PREFIX = "TS:";
Expand Down Expand Up @@ -215,7 +205,7 @@ public Map<String, ImportPreviewStatistics> process(
Table data,
Program program,
User user,
boolean commit) throws UnprocessableEntityException, ApiException, ValidatorException {
boolean commit) throws ApiException, ValidatorException, MissingRequiredInfoException {
log.debug("processing experiment import");

ValidationErrors validationErrors = new ValidationErrors();
Expand Down Expand Up @@ -498,7 +488,7 @@ private String getVariableNameFromColumn(Column<?> column) {
return column.name();
}

private void initNewBrapiData(List<BrAPIImport> importRows, List<Column<?>> phenotypeCols, Program program, User user, List<Trait> referencedTraits, boolean commit) throws UnprocessableEntityException, ApiException {
private void initNewBrapiData(List<BrAPIImport> importRows, List<Column<?>> phenotypeCols, Program program, User user, List<Trait> referencedTraits, boolean commit) throws ApiException, MissingRequiredInfoException {

String expSequenceName = program.getExpSequence();
if (expSequenceName == null) {
Expand Down Expand Up @@ -933,7 +923,7 @@ private PendingImportObject<BrAPIGermplasm> getGidPOI(ExperimentObservation impo
return null;
}

private PendingImportObject<BrAPIObservationUnit> fetchOrCreateObsUnitPIO(Program program, boolean commit, String envSeqValue, ExperimentObservation importRow) throws UnprocessableEntityException, ApiException {
private PendingImportObject<BrAPIObservationUnit> fetchOrCreateObsUnitPIO(Program program, boolean commit, String envSeqValue, ExperimentObservation importRow) throws ApiException, MissingRequiredInfoException {
PendingImportObject<BrAPIObservationUnit> pio;
String key = createObservationUnitKey(importRow);
if (this.observationUnitByNameNoScope.containsKey(key)) {
Expand Down Expand Up @@ -963,8 +953,7 @@ private PendingImportObject<BrAPIObservationUnit> fetchOrCreateObsUnitPIO(Progra
List<BrAPIObservationUnit> existingOUs = brAPIObservationUnitDAO.getObservationUnitsForStudyDbId(studyPIO.getBrAPIObject().getStudyDbId(), program);
List<BrAPIObservationUnit> matchingOU = existingOUs.stream().filter(ou -> importRow.getExpUnitId().equals(Utilities.removeProgramKeyAndUnknownAdditionalData(ou.getObservationUnitName(), program.getKey()))).collect(Collectors.toList());
if (matchingOU.isEmpty()) {
throw new UnprocessableEntityException(String.format(EXISTING_ENV, importRow.getExpUnitId(),
Utilities.removeProgramKeyAndUnknownAdditionalData(studyPIO.getBrAPIObject().getStudyName(), program.getKey())));
throw new MissingRequiredInfoException(MISSING_OBS_UNIT_ID_ERROR);
} else {
pio = new PendingImportObject<>(ImportObjectState.EXISTING, (BrAPIObservationUnit) Utilities.formatBrapiObjForDisplay(matchingOU.get(0), BrAPIObservationUnit.class, program));
}
Expand Down Expand Up @@ -1066,7 +1055,7 @@ private void addObsVarsToDatasetDetails(PendingImportObject<BrAPIListDetails> pi
if (trait.getFullName() == null) {
id = trait.getObservationVariableName();
}

if (!details.getData().contains(id) && ImportObjectState.EXISTING != pio.getState()) {
details.getData().add(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public void verifyFailureNewOuExistingEnv(boolean commit) {
JsonObject result = JsonParser.parseString(upload.body()).getAsJsonObject().getAsJsonObject("result");
assertEquals(422, result.getAsJsonObject("progress").get("statuscode").getAsInt(), "Returned data: " + result);

assertTrue(result.getAsJsonObject("progress").get("message").getAsString().startsWith("Cannot create new observation unit"));
assertTrue(result.getAsJsonObject("progress").get("message").getAsString().startsWith("Experimental entities are missing ObsUnitIDs"));
}

@Test
Expand Down