Skip to content
Closed
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,5 +47,6 @@ 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 CHANGELOG = "changeLog";
public static final String ENV_YEAR = "envYear";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.breedinginsight.brapps.importer.daos;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.brapi.client.v2.ApiResponse;
import org.brapi.client.v2.model.exceptions.ApiException;
Expand All @@ -24,11 +25,13 @@
import org.brapi.v2.model.pheno.BrAPIObservation;
import org.brapi.v2.model.pheno.request.BrAPIObservationSearchRequest;
import org.brapi.v2.model.pheno.response.BrAPIObservationListResponse;
import org.brapi.v2.model.pheno.response.BrAPIObservationSingleResponse;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.daos.ProgramDAO;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.brapi.BrAPIEndpointProvider;
import org.breedinginsight.utilities.BrAPIDAOUtil;
import org.breedinginsight.utilities.Utilities;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;
Expand All @@ -38,6 +41,7 @@
import static org.brapi.v2.model.BrAPIWSMIMEDataTypes.APPLICATION_JSON;

@Singleton
@Slf4j
public class BrAPIObservationDAO {

private ProgramDAO programDAO;
Expand Down Expand Up @@ -113,4 +117,25 @@ public List<BrAPIObservation> createBrAPIObservations(List<BrAPIObservation> brA
return brAPIDAOUtil.post(brAPIObservationList, upload, api::observationsPost, importDAO::update);
}

public BrAPIObservation updateBrAPIObservation(String dbId, BrAPIObservation observation, UUID programId) throws ApiException {
ObservationsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), ObservationsApi.class);
ApiResponse<BrAPIObservationSingleResponse> response;
BrAPIObservation updatedObservation = null;
try {
response = api.observationsObservationDbIdPut(dbId, observation);
if (response != null) {
BrAPIObservationSingleResponse body = response.getBody();
if (body == null) {
throw new ApiException("Response is missing body", 0, response.getHeaders(), null);
}
updatedObservation = body.getResult();
if (updatedObservation == null) {
throw new ApiException("Response body is missing result", 0, response.getHeaders(), response.getBody().toString());
}
}
} catch (ApiException e) {
log.error(Utilities.generateApiExceptionLogMessage(e));
}
return updatedObservation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@Getter
public enum ImportFieldTypeEnum {
BOOLEAN("BOOLEAN"),
TEXT("TEXT"),
NUMERICAL("NUMERICAL"),
INTEGER("INTEGER"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@

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

import org.brapi.client.v2.model.exceptions.ApiException;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.brapps.importer.model.response.ImportPreviewResponse;
import org.breedinginsight.model.Program;
import org.breedinginsight.model.User;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;
import tech.tablesaw.api.Table;

import java.util.List;
Expand All @@ -49,5 +44,5 @@ public String getWrongUserInputDataTypeMsg(String fieldName, String typeName) {
return String.format("User input, \"%s\" must be an %s", fieldName, typeName);
}
public ImportPreviewResponse process(List<BrAPIImport> brAPIImports, Table data, Program program, ImportUpload upload, User user, Boolean commit)
throws UnprocessableEntityException, DoesNotExistException, ValidatorException, ApiException, MissingRequiredInfoException {return null;}
throws Exception {return null;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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;

import lombok.Getter;
import lombok.Setter;

import java.util.UUID;

@Getter
@Setter
public class ChangeLogEntry {
private String originalValue;
private String reasonForChange;
private UUID changedBy;
private String dateOfChange;

public ChangeLogEntry(String originalValue, String reasonForChange, UUID changedBy, String dateOfChange) {
this.originalValue = originalValue;
this.reasonForChange = reasonForChange;
this.changedBy = changedBy;
this.dateOfChange = dateOfChange;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
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.brapps.importer.services.processors.ExperimentProcessor;
import org.breedinginsight.brapps.importer.services.processors.Processor;
import org.breedinginsight.brapps.importer.services.processors.ProcessorManager;
import org.breedinginsight.model.Program;
import org.breedinginsight.model.User;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;
import tech.tablesaw.api.Table;

import javax.inject.Inject;
Expand Down Expand Up @@ -70,7 +67,7 @@ public String getMissingColumnMsg(String columnName) {

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

ImportPreviewResponse response = null;
List<Processor> processors = List.of(experimentProcessorProvider.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
@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.BOOLEAN, collectTime = ImportCollectTimeEnum.UPLOAD)
@ImportFieldMetadata(id = "overwrite", name = "Overwrite", description = "Boolean flag to overwrite existing observation")
private String overwrite;

@ImportFieldType(type = ImportFieldTypeEnum.TEXT, collectTime = ImportCollectTimeEnum.UPLOAD)
@ImportFieldMetadata(id="overwriteReason", name="Overwrite Reason", description="Description of the reason for overwriting existing observations")
private String overwriteReason;

@ImportFieldType(type = ImportFieldTypeEnum.TEXT)
@ImportFieldMetadata(id = "germplasmName", name = Columns.GERMPLASM_NAME, description = "Name of germplasm")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@
package org.breedinginsight.brapps.importer.model.imports.germplasm;

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.response.ImportPreviewResponse;
import org.breedinginsight.brapps.importer.services.processors.*;
import org.breedinginsight.brapps.importer.services.processors.GermplasmProcessor;
import org.breedinginsight.brapps.importer.services.processors.Processor;
import org.breedinginsight.brapps.importer.services.processors.ProcessorManager;
import org.breedinginsight.model.Program;
import org.breedinginsight.model.User;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
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.*;
import java.util.List;

@Singleton
@Slf4j
Expand Down Expand Up @@ -66,7 +63,7 @@ public String getImportTypeId() {

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

ImportPreviewResponse response = null;
List<Processor> processors = List.of(germplasmProcessorProvider.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class MappingManager {

private ImportConfigManager configManager;

public static String wrongDataTypeMsg = "Column name \"%s\" must be integer type, but non-integer type provided.";
public static String blankRequiredField = "Required field \"%s\" cannot contain empty values";
public static String missingColumn = "Column name \"%s\" does not exist in file";
public static String missingUserInput = "User input, \"%s\" is required";
public static String wrongUserInputDataType = "User input, \"%s\" must be an %s";

@Inject
MappingManager(ImportConfigManager configManager) {
this.configManager = configManager;
Expand Down Expand Up @@ -339,13 +345,13 @@ private void mapUserInputField(Object parent, Field field, Map<String, Object> u

// Only supports user input at the top level of an object at the moment. No nested objects. Map<String, String>
String fieldId = metadata.id();
if (!userInput.containsKey(fieldId) && required != null) {
if ((userInput == null || !userInput.containsKey(fieldId)) && required != null) {
throw new UnprocessableEntityException(importService.getMissingUserInputMsg(metadata.name()));
}
else if (required != null && userInput.containsKey(fieldId) && userInput.get(fieldId).toString().isBlank()) {
throw new UnprocessableEntityException(importService.getMissingUserInputMsg(metadata.name()));
}
else if (userInput.containsKey(fieldId)) {
else if (userInput != null && userInput.containsKey(fieldId)) {
String value = userInput.get(fieldId).toString();
if (!isCorrectType(type.type(), value)) {
throw new UnprocessableEntityException(importService.getWrongUserInputDataTypeMsg(metadata.name(), type.type().toString().toLowerCase()));
Expand All @@ -371,11 +377,14 @@ private Boolean isCorrectType(ImportFieldTypeEnum expectedType, String value) {
if (!value.isBlank()) {
if (expectedType == ImportFieldTypeEnum.INTEGER) {
try {
Integer d = Integer.parseInt(value);
Integer.parseInt(value);
} catch (NumberFormatException nfe) {
return false;
}
}
if (expectedType == ImportFieldTypeEnum.BOOLEAN && !String.valueOf(Boolean.parseBoolean(value)).equals(value)) {
return false;
}
}
return true;
}
Expand Down
Loading