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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<guava.version>31.0.1-jre</guava.version>
<okhttp.version>4.9.3</okhttp.version>
<mockito.version>4.3.1</mockito.version>
<brapi-java-client.version>2.2-SNAPSHOT</brapi-java-client.version>
<brapi-java-client.version>2.2.1-SNAPSHOT</brapi-java-client.version>
<commons-io.version>2.11.0</commons-io.version>
<tika-app.version>2.2.1</tika-app.version>
<!-- Version of apache-poi depends on version of tika. Tika uses these. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@
@Secured(SecurityRule.IS_AUTHENTICATED)
public class ExperimentController {
private final BrAPITrialService experimentService;
private final ExperimentQueryMapper experimentQueryMapper;
private final ProgramService programService;
private final ExperimentalCollaboratorService experimentalCollaboratorService;
private final SecurityService securityService;
private final ProgramUserService programUserService;
private final RoleService roleService;

@Inject
public ExperimentController(BrAPITrialService experimentService, ExperimentQueryMapper experimentQueryMapper, ProgramService programService, ExperimentalCollaboratorService experimentalCollaboratorService, SecurityService securityService, ProgramUserService programUserService, RoleService roleService) {
public ExperimentController(BrAPITrialService experimentService, ProgramService programService, ExperimentalCollaboratorService experimentalCollaboratorService, SecurityService securityService, ProgramUserService programUserService, RoleService roleService) {
this.experimentService = experimentService;
this.experimentQueryMapper = experimentQueryMapper;
this.programService = programService;
this.experimentalCollaboratorService = experimentalCollaboratorService;
this.securityService = securityService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BrapiQuery implements PaginationParams {
private Integer page;

private String sortField;
private SortOrder sortOrder;
private SortOrder sortOrder = SortOrder.ASC;

public Integer getDefaultPage() {
return DEFAULT_PAGE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public HttpResponse<Response<DataResponse<List<BrAPIStudy>>>> getStudies(
return ResponseUtils.getBrapiQueryResponse(authorizedStudies, studyQueryMapper, queryParams, searchRequest);
}

// TODO: Instead of getting all studies for a program and filtering, doing the filtering on brapi side
// TODO: Instead of getting all studies for a program and filtering, doing the filtering on brapi side [BI-2922]
List<BrAPIStudy> studies = studyService.getStudies(programId)
.stream()
.peek(this::setDbIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import io.micronaut.security.rules.SecurityRule;
import lombok.extern.slf4j.Slf4j;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.core.BrAPITrial;
import org.brapi.v2.model.core.response.BrAPITrialListResponse;
import org.brapi.v2.model.core.response.BrAPITrialSingleResponse;
import org.breedinginsight.api.auth.*;
import org.breedinginsight.api.model.v1.request.query.SearchRequest;
Expand All @@ -43,8 +43,6 @@
import org.breedinginsight.services.ExperimentalCollaboratorService;
import org.breedinginsight.services.ProgramService;
import org.breedinginsight.services.ProgramUserService;
import org.breedinginsight.model.ProgramUser;
import org.breedinginsight.model.Role;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.utilities.Utilities;
import org.breedinginsight.utilities.response.ResponseUtils;
Expand All @@ -65,22 +63,19 @@ public class BrAPITrialsController {

private final String referenceSource;
private final BrAPITrialService experimentService;
private final ExperimentQueryMapper experimentQueryMapper;
private final SecurityService securityService;
private final ProgramUserService programUserService;
private final ExperimentalCollaboratorService experimentalCollaboratorService;
private final ProgramService programService;

@Inject
public BrAPITrialsController(BrAPITrialService experimentService,
ExperimentQueryMapper experimentQueryMapper,
@Property(name = "brapi.server.reference-source") String referenceSource,
SecurityService securityService,
ProgramUserService programUserService,
ExperimentalCollaboratorService experimentalCollaboratorService,
ProgramService programService) {
this.experimentService = experimentService;
this.experimentQueryMapper = experimentQueryMapper;
this.referenceSource = referenceSource;
this.securityService = securityService;
this.programUserService = programUserService;
Expand All @@ -92,7 +87,7 @@ public BrAPITrialsController(BrAPITrialService experimentService,
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roles = {ProgramSecuredRole.SYSTEM_ADMIN, ProgramSecuredRole.READ_ONLY, ProgramSecuredRole.PROGRAM_ADMIN
,ProgramSecuredRole.EXPERIMENTAL_COLLABORATOR })
public HttpResponse<Response<DataResponse<List<BrAPITrial>>>> getExperiments(
public HttpResponse<Response<DataResponse<BrAPITrial>>> getExperiments(
@PathVariable("programId") UUID programId,
@QueryValue @QueryValid(using = ExperimentQueryMapper.class) @Valid ExperimentQuery queryParams) {
try {
Expand All @@ -105,13 +100,27 @@ public HttpResponse<Response<DataResponse<List<BrAPITrial>>>> getExperiments(
// If the program user is an experimental collaborator, filter results for only authorized experiments.
Optional<ProgramUser> experimentalCollaborator = programUserService.getIfExperimentalCollaborator(programId, securityService.getUser().getId());
if (experimentalCollaborator.isPresent()) {
List<UUID> experimentIds = experimentalCollaboratorService.getAuthorizedExperimentIds(experimentalCollaborator.get().getId());
List<BrAPITrial> authorizedExperiments = experimentService.getTrialsByExperimentIds(program.get(), experimentIds).stream().peek(this::setDbIds).collect(Collectors.toList());
return ResponseUtils.getBrapiQueryResponse(authorizedExperiments, experimentQueryMapper, queryParams, searchRequest);
List<UUID> authorizedExperimentIds = experimentalCollaboratorService.getAuthorizedExperimentIds(experimentalCollaborator.get().getId());

if (authorizedExperimentIds.isEmpty()) {
// User is not authorized for any experiments, return empty response.
return ResponseUtils.getEmptyBrapiQueryResponse();
} else {
// User is authorized. Grab the experiment data from BrAPI.
BrAPITrialListResponse brapiResponse = experimentService.searchTrials(program.get(), authorizedExperimentIds, queryParams);

List<BrAPITrial> foundTrials = brapiResponse.getResult().getData();
foundTrials.forEach(this::setDbIds);

return ResponseUtils.getBrapiQueryResponse(foundTrials, brapiResponse);
}
}

List<BrAPITrial> experiments = experimentService.getExperiments(programId).stream().peek(this::setDbIds).collect(Collectors.toList());
return ResponseUtils.getBrapiQueryResponse(experiments, experimentQueryMapper, queryParams, searchRequest);
BrAPITrialListResponse brapiResponse = experimentService.searchTrials(program.get(), queryParams);

List<BrAPITrial> foundTrials = brapiResponse.getResult().getData();
foundTrials.forEach(this::setDbIds);
return ResponseUtils.getBrapiQueryResponse(foundTrials, brapiResponse);
} catch (ApiException e) {
log.info(e.getMessage(), e);
return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving experiments");
Expand Down Expand Up @@ -159,7 +168,7 @@ public HttpResponse<?> trialsTrialDbIdPut(@PathVariable("programId") UUID progra
return HttpResponse.notFound();
}

// TODO: Remove for trialDbId once cache is removed for that entity
// TODO: Verify that the programDbId does not need to be reset and that the BrAPI programDbId can be used instead [BI-2931]
private void setDbIds(BrAPITrial trial) {
trial.programDbId(Utilities.getExternalReference(trial.getExternalReferences(), Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.PROGRAMS))
.orElseThrow(() -> new IllegalStateException("No BI external reference found"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public List<BrAPIStudy> getStudiesByName(List<String> studyNames, Program progra
);
}

public List<BrAPIStudy> getStudiesByExperimentID(@NotNull UUID experimentId, Program program) throws ApiException {
// TODO: This should look up on trialDbId, and the trialDbId should be passed thru
public List<BrAPIStudy> getStudiesByBrAPITrialExRefId(@NotNull UUID brapiTrialExRefId, Program program) throws ApiException {
// TODO: If external references are removed for trial for studies, this method should look up on trialDbId, and the trialDbId should be passed through. [BI-2933]
BrAPIStudySearchRequest studySearch = new BrAPIStudySearchRequest();
studySearch.programDbIds(List.of(program.getBrapiProgram().getProgramDbId()));
studySearch.addExternalReferenceIdsItem(experimentId.toString());
studySearch.addExternalReferenceIdsItem(brapiTrialExRefId.toString());
studySearch.addExternalReferenceSourcesItem(Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.TRIALS));
StudiesApi api = brAPIEndpointProvider.get(programDAO.getCoreClient(program.getId()), StudiesApi.class);
return brAPIDAOUtil.search(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.v2.model.core.BrAPITrial;
import org.brapi.v2.model.core.request.BrAPITrialSearchRequest;
import org.brapi.v2.model.core.response.BrAPITrialListResponse;
import org.breedinginsight.brapi.v2.model.request.query.ExperimentQuery;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.exceptions.DoesNotExistException;
Expand All @@ -45,4 +48,9 @@ List<BrAPITrial> createBrAPITrials(List<BrAPITrial> brAPITrialList, UUID program
List<BrAPITrial> getTrialsByExperimentIds(Collection<UUID> experimentIds, Program program) throws ApiException;

void deleteBrAPITrial(Program program, BrAPITrial trial, boolean hard) throws ApiException;

BrAPITrialListResponse brapiTrialSearch(Program program, ExperimentQuery experimentQuery) throws ApiException;

BrAPITrialListResponse brapiTrialSearch(Program program, List<UUID> brapiTrialIds, ExperimentQuery experimentQuery) throws ApiException;

}
Loading
Loading