-
Notifications
You must be signed in to change notification settings - Fork 1
BI-2258 - Endpoint filtering for Experimental Collaborator role #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
60ffbf0
[BI-2258] - added authorization to datasetExport
mlm483 af93ba4
[BI-2258] - merged develop into feature/BI-2258
mlm483 86e0892
[BI-2258] - added filtering for Experimental Collaborator
mlm483 7de97f9
[BI-2258] - merge develop into feature/BI-2258
mlm483 be4ba6f
[BI-2258] - implemented /seasons GET endpoint
mlm483 17c6098
[BI-2258] - added integration test for studies filtering
mlm483 ea4c341
[BI-2258] - added integration test for trials filtering
mlm483 d9e9e95
[BI-2258] - documented tests.
mlm483 dbdaa78
Merge branch 'develop' into feature/BI-2258
mlm483 b03360e
[BI-2258] - added notice
mlm483 e2534b4
[BI-2258] - added method documentation
mlm483 de49a17
[BI-2258] - added documentation
mlm483 4b13e24
[BI-2258] - reduced code duplication
mlm483 d3d5929
[BI-2258] - added notice
mlm483 d8e0935
[BI-2258] - merged develop into feature/BI-2258
mlm483 328e542
Merge branch 'develop' into feature/BI-2258
mlm483 9b11eb8
Merge branch 'develop' into feature/BI-2258
mlm483 bb57b96
[BI-2258] - merged develop into feature/BI-2258
mlm483 4418f21
[BI-2258] - removed duplicate SQL in test file
mlm483 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,20 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * 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.brapi.v2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.micronaut.context.annotation.Property; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -20,6 +37,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.breedinginsight.brapi.v2.model.request.query.ExperimentQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.breedinginsight.brapi.v2.services.BrAPITrialService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.breedinginsight.model.Program; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.breedinginsight.model.ProgramUser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,7 +51,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.inject.Inject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import javax.validation.Valid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Optional; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.UUID; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.stream.Collectors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -41,12 +65,26 @@ 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) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.experimentalCollaboratorService = experimentalCollaboratorService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.programService = programService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Get("/trials{?queryParams*}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -57,9 +95,22 @@ public HttpResponse<Response<DataResponse<List<BrAPITrial>>>> getExperiments( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @PathVariable("programId") UUID programId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @QueryValue @QueryValid(using = ExperimentQueryMapper.class) @Valid ExperimentQuery queryParams) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<BrAPITrial> experiments = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.debug("fetching trials for program: " + programId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<BrAPITrial> experiments = experimentService.getExperiments(programId).stream().peek(this::setDbIds).collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<ProgramUser> experimentalCollaborator = programUserService.getIfExperimentalCollaborator(programId, securityService.getUser().getId()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If the program user is an experimental collaborator, filter results. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (experimentalCollaborator.isPresent()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<Program> program = programService.getById(programId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (program.isEmpty()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return HttpResponse.notFound(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<UUID> experimentIds = experimentalCollaboratorService.getAuthorizedExperimentIds(experimentalCollaborator.get().getId()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| experiments = experimentService.getTrialsByExperimentIds(program.get(), experimentIds).stream().peek(this::setDbIds).collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| experiments = experimentService.getExperiments(programId).stream().peek(this::setDbIds).collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
+113
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment on the BrAPIStudiesController.java suggestion. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SearchRequest searchRequest = queryParams.constructSearchRequest(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ResponseUtils.getBrapiQueryResponse(experiments, experimentQueryMapper, queryParams, searchRequest); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (ApiException e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional methods could be used to refactor the fetching logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to test this and the BrAPITrialsController suggestions locally, they both resulted in build errors. Are there problems in my code as written that you would like me to address?