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 @@ -40,4 +40,5 @@ public final class BrAPIAdditionalInfoFields {
public static final String EXPERIMENT_NUMBER = "experimentNumber";
public static final String ENVIRONMENT_NUMBER = "environmentNumber";
public static final String STUDY_NAME = "studyName";
public static final String OBSERVATION_DATASET_ID = "observationDatasetId";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.brapi.v2.model.core.BrAPIListTypes;
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.*;
import org.brapi.v2.model.pheno.BrAPIObservation;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.daos.ProgramDAO;
Expand Down Expand Up @@ -97,28 +97,69 @@ private List<BrAPIListSummary> processListsForProgram(List<BrAPIListSummary> pro
}
return filteredLists;
}
public List<String> updateBrAPIList(String brAPIListDbId, BrAPIListDetails mutatedList, UUID programId) throws ApiException {
ListsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), ListsApi.class);
BrAPIListNewRequest request = new BrAPIListNewRequest();
request.setAdditionalInfo(mutatedList.getAdditionalInfo());
request.setDateCreated(mutatedList.getDateCreated());
request.setDateModified(mutatedList.getDateModified());
request.setExternalReferences(mutatedList.getExternalReferences());
request.setListDescription(mutatedList.getListDescription());
request.setListName(mutatedList.getListName());
request.setListOwnerName(mutatedList.getListOwnerName());
request.setListOwnerPersonDbId(mutatedList.getListOwnerPersonDbId());
request.setListSize(mutatedList.getListSize());
request.setListSource(mutatedList.getListSource());
request.setListType(mutatedList.getListType());
request.setData(mutatedList.getData());

// Do manually, it doesn't like List<Object> to List<BrAPIListNewRequest> for some reason
ApiResponse<BrAPIListsSingleResponse> response;
try {
response = api.listsListDbIdPut(brAPIListDbId, request);
} catch (ApiException e) {
log.error(Utilities.generateApiExceptionLogMessage(e));
throw e;
}
if(response != null) {
BrAPIListsSingleResponse body = response.getBody();
if (body == null) {
throw new ApiException("Response is missing body", 0, response.getHeaders(), null);
}
BrAPIListDetails result = body.getResult();
if (result == null) {
throw new ApiException("Response body is missing result", 0, response.getHeaders(), response.getBody().toString());
}
if (result.getData() == null) {
throw new ApiException("Response result is missing data", 0, response.getHeaders(), response.getBody().toString());
}
return result.getData();
}

throw new ApiException("No response after creating list");
}

public List<BrAPIObservation> createBrAPILists(List<BrAPIListNewRequest> brapiLists, UUID programId, ImportUpload upload) throws ApiException {
public List<BrAPIListSummary> createBrAPILists(List<BrAPIListNewRequest> brapiLists, UUID programId, ImportUpload upload) throws ApiException {
ListsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), ListsApi.class);
// Do manually, it doesn't like List<Object> to List<BrAPIListNewRequest> for some reason
ApiResponse response;
ApiResponse<BrAPIListsListResponse> response;
try {
response = api.listsPost(brapiLists);
} catch (ApiException e) {
log.warn(Utilities.generateApiExceptionLogMessage(e));
throw e;
}
if(response != null) {
BrAPIResponse body = (BrAPIResponse) response.getBody();
BrAPIResponse<BrAPIListsListResponseResult> body = response.getBody();
if (body == null) {
throw new ApiException("Response is missing body");
throw new ApiException("Response is missing body", 0, response.getHeaders(), null);
}
BrAPIResponseResult result = (BrAPIResponseResult) body.getResult();
BrAPIResponseResult<BrAPIListSummary> result = body.getResult();
if (result == null) {
throw new ApiException("Response body is missing result");
throw new ApiException("Response body is missing result", 0, response.getHeaders(), response.getBody().toString());
}
if (result.getData() == null) {
throw new ApiException("Response result is missing data");
throw new ApiException("Response result is missing data", 0, response.getHeaders(), response.getBody().toString());
}
return result.getData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.brapi.client.v2.modules.core.TrialsApi;
import org.brapi.v2.model.core.BrAPITrial;
import org.brapi.v2.model.core.request.BrAPITrialSearchRequest;
import org.brapi.v2.model.core.response.BrAPIListDetails;
import org.brapi.v2.model.core.response.BrAPIListResponse;
import org.brapi.v2.model.core.response.BrAPITrialSingleResponse;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.brapps.importer.services.ExternalReferenceSource;
import org.breedinginsight.daos.ProgramDAO;
Expand Down Expand Up @@ -76,7 +79,10 @@ public List<BrAPITrial> createBrAPITrials(List<BrAPITrial> brAPITrialList, UUID
TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class);
return brAPIDAOUtil.post(brAPITrialList, upload, api::trialsPost, importDAO::update);
}

public BrAPITrial updateBrAPITrial(String trialDbId, BrAPITrial trial, UUID programId) throws ApiException {
TrialsApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(programId), TrialsApi.class);
return brAPIDAOUtil.put(trialDbId, trial, api::trialsTrialDbIdPut);
}
/**
* Fetch formatted trials/experiments for this program
* @param programId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.Setter;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.core.*;
import org.brapi.v2.model.core.response.BrAPIListDetails;
import org.brapi.v2.model.pheno.*;
import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields;
import org.breedinginsight.brapps.importer.model.config.*;
Expand Down Expand Up @@ -197,6 +198,23 @@ public BrAPIStudy constructBrAPIStudy(
return study;
}

public BrAPIListDetails constructDatasetDetails(
String name,
UUID datasetId,
String referenceSourceBase,
Program program, String trialId) {
BrAPIListDetails dataSetDetails = new BrAPIListDetails();
dataSetDetails.setListName(name);
dataSetDetails.setListType(BrAPIListTypes.OBSERVATIONVARIABLES);
dataSetDetails.setData(new ArrayList<>());
dataSetDetails.putAdditionalInfoItem("datasetType", "observationDataset");
List<BrAPIExternalReference> refs = new ArrayList<>();
addReference(refs, program.getId(), referenceSourceBase, ExternalReferenceSource.PROGRAMS);
addReference(refs, UUID.fromString(trialId), referenceSourceBase, ExternalReferenceSource.TRIALS);
addReference(refs, datasetId, referenceSourceBase, ExternalReferenceSource.DATASET);
dataSetDetails.setExternalReferences(refs);
return dataSetDetails;
}
public BrAPIObservationUnit constructBrAPIObservationUnit(
Program program,
String seqVal,
Expand Down Expand Up @@ -340,8 +358,7 @@ private List<BrAPIExternalReference> getObsUnitExternalReferences(


private void addReference(List<BrAPIExternalReference> refs, UUID uuid, String referenceBaseNameSource, ExternalReferenceSource refSourceName) {
BrAPIExternalReference reference;
reference = new BrAPIExternalReference();
BrAPIExternalReference reference = new BrAPIExternalReference();
reference.setReferenceSource(String.format("%s/%s", referenceBaseNameSource, refSourceName.getName()));
reference.setReferenceID(uuid.toString());
refs.add(reference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@

public enum ImportObjectState {
NEW,
EXISTING
EXISTING,
MUTATED
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ public PendingImportObject(ImportObjectState state, T brAPIObject, UUID id) {
public PendingImportObject(ImportObjectState state, T brAPIObject) {
this(state, brAPIObject, UUID.randomUUID());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum ExternalReferenceSource {
TRIALS("trials"),
STUDIES("studies"),
OBSERVATION_UNITS("observationunits"),
DATASET("dataset"),
LISTS("lists");

private String name;
Expand Down
Loading