-
Notifications
You must be signed in to change notification settings - Fork 1
[BI-1720] - Export Multiple Environment Datasets as Zip #263
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
29 commits
Select commit
Hold shift + click to select a range
48bc5b9
[BI-1720] - initial proof of concept
mlm483 f7d5a19
[BI-1720] - comments
mlm483 867e4c9
[BI-1720] - refactoring in progress
mlm483 809eaa7
[BI-1720] - cleaned up and fixed bugs
mlm483 a4653dd
[BI-1720] - expanded unit test (WIP)
mlm483 2ed7b63
[BI-1720] - completed unit test
mlm483 e48da59
[BI-1720] - updated comment
mlm483 c6a6cbf
[BI-1720] - removed unused imports
mlm483 cf113c7
[BI-1720] - fixed media type
mlm483 a95e95f
[BI-1720] - cleaned up ExperimentExportQuery.java
mlm483 4eb2c6f
[BI-1720] - simplified TestUtils::unzipFile
mlm483 65675f7
[BI-1720] - added BrAPI Study specific code
mlm483 7d0ea06
[BI-1720] - TODO
mlm483 11172c8
[BI-1720] - DRY
mlm483 84f7f54
[BI-1720] - study GET endpoint filtering working
mlm483 6d3040e
[BI-1720] - removed unused controller method
mlm483 6e0b36f
[BI-1720] - updated TODO
mlm483 18ce98f
Merge pull request #274 from Breeding-Insight/feature/BI-1720-brapi-s…
mlm483 be73324
[BI-1720] - renamed method
mlm483 0342789
[BI-1720] - removed unused methods
mlm483 8bebb8b
Merge pull request #275 from Breeding-Insight/feature/BI-1720-brapi-s…
mlm483 cf1727d
[BI-1720] - pulled in latest from develop
mlm483 47af603
[BI-1720] - clean up
mlm483 fdb4c4d
[BI-1720] - reverted ListQuery change
mlm483 7c0b3f7
[BI-1720] - added exRef source and ID to study query
mlm483 024f4e6
[BI-1720] - merged redundant BrAPIStudyDAO
mlm483 88a4cd5
[BI-1720] - cache studies on create
mlm483 6aa7cc8
[BI-1720] - made naming more consistent
mlm483 f975aa2
Merge branch 'develop' into feature/BI-1720
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
83 changes: 83 additions & 0 deletions
83
src/main/java/org/breedinginsight/brapi/v2/StudyController.java
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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.http.HttpResponse; | ||
| import io.micronaut.http.HttpStatus; | ||
| import io.micronaut.http.MediaType; | ||
| import io.micronaut.http.annotation.*; | ||
| import io.micronaut.security.annotation.Secured; | ||
| import io.micronaut.security.rules.SecurityRule; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.brapi.client.v2.model.exceptions.ApiException; | ||
| import org.brapi.v2.model.core.BrAPIStudy; | ||
| import org.breedinginsight.api.auth.ProgramSecured; | ||
| import org.breedinginsight.api.auth.ProgramSecuredRoleGroup; | ||
| import org.breedinginsight.api.model.v1.request.query.SearchRequest; | ||
| import org.breedinginsight.api.model.v1.response.DataResponse; | ||
| import org.breedinginsight.api.model.v1.response.Response; | ||
| import org.breedinginsight.api.model.v1.validators.QueryValid; | ||
| import org.breedinginsight.brapi.v1.controller.BrapiVersion; | ||
| import org.breedinginsight.brapi.v2.model.request.query.StudyQuery; | ||
| import org.breedinginsight.brapi.v2.services.BrAPIStudyService; | ||
| import org.breedinginsight.utilities.response.ResponseUtils; | ||
| import org.breedinginsight.utilities.response.mappers.StudyQueryMapper; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.validation.Valid; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Slf4j | ||
| @Controller("/${micronaut.bi.api.version}") | ||
| @Secured(SecurityRule.IS_AUTHENTICATED) | ||
| public class StudyController { | ||
|
|
||
| private final BrAPIStudyService studyService; | ||
| private final StudyQueryMapper studyQueryMapper; | ||
|
|
||
|
|
||
| @Inject | ||
| public StudyController(BrAPIStudyService studyService, StudyQueryMapper studyQueryMapper) { | ||
| this.studyService = studyService; | ||
| this.studyQueryMapper = studyQueryMapper; | ||
| } | ||
|
|
||
| @Get("/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/studies{?queryParams*}") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) | ||
| public HttpResponse<Response<DataResponse<List<BrAPIStudy>>>> getStudies( | ||
| @PathVariable("programId") UUID programId, | ||
| @QueryValue @QueryValid(using = StudyQueryMapper.class) @Valid StudyQuery queryParams) { | ||
| try { | ||
| log.debug("fetching studies for program: " + programId); | ||
|
|
||
| List<BrAPIStudy> studies = studyService.getStudies(programId); | ||
| queryParams.setSortField(studyQueryMapper.getDefaultSortField()); | ||
| queryParams.setSortOrder(studyQueryMapper.getDefaultSortOrder()); | ||
| SearchRequest searchRequest = queryParams.constructSearchRequest(); | ||
| return ResponseUtils.getBrapiQueryResponse(studies, studyQueryMapper, queryParams, searchRequest); | ||
| } catch (ApiException e) { | ||
| log.info(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.INTERNAL_SERVER_ERROR, "Error retrieving study"); | ||
| } catch (IllegalArgumentException e) { | ||
| log.info(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, "Error parsing requested date format"); | ||
| } | ||
| } | ||
| } |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/org/breedinginsight/brapi/v2/model/request/query/StudyQuery.java
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.breedinginsight.brapi.v2.model.request.query; | ||
|
|
||
| import io.micronaut.core.annotation.Introspected; | ||
| import lombok.Getter; | ||
| import org.breedinginsight.api.model.v1.request.query.FilterRequest; | ||
| import org.breedinginsight.api.model.v1.request.query.SearchRequest; | ||
| import org.breedinginsight.brapi.v1.model.request.query.BrapiQuery; | ||
| import org.jooq.tools.StringUtils; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Getter | ||
| @Introspected | ||
| public class StudyQuery extends BrapiQuery { | ||
| private String studyType; | ||
| private String locationDbId; | ||
| private String studyCode; | ||
| private String studyPUI; | ||
| private String commonCropName; | ||
| private String trialDbId; | ||
| private String studyDbId; | ||
| private String studyName; | ||
| private String externalReferenceSource; | ||
| private String externalReferenceId; | ||
|
|
||
| public SearchRequest constructSearchRequest() { | ||
| List<FilterRequest> filters = new ArrayList<>(); | ||
| if (!StringUtils.isBlank(getStudyType())) { | ||
| filters.add(constructFilterRequest("studyType", getStudyType())); | ||
| } | ||
| if (!StringUtils.isBlank(getLocationDbId())) { | ||
| filters.add(constructFilterRequest("locationDbId", getLocationDbId())); | ||
| } | ||
| if (!StringUtils.isBlank(getStudyCode())) { | ||
| filters.add(constructFilterRequest("studyCode", getStudyCode())); | ||
| } | ||
| if (!StringUtils.isBlank(getStudyPUI())) { | ||
| filters.add(constructFilterRequest("studyPUI", getStudyPUI())); | ||
| } | ||
| if (!StringUtils.isBlank(getCommonCropName())) { | ||
| filters.add(constructFilterRequest("commonCropName", getCommonCropName())); | ||
| } | ||
| if (!StringUtils.isBlank(getTrialDbId())) { | ||
| filters.add(constructFilterRequest("trialDbId", getTrialDbId())); | ||
| } | ||
| if (!StringUtils.isBlank(getStudyDbId())) { | ||
| filters.add(constructFilterRequest("studyDbId", getStudyDbId())); | ||
| } | ||
| if (!StringUtils.isBlank(getStudyName())) { | ||
| filters.add(constructFilterRequest("studyName", getStudyName())); | ||
| } | ||
| if (!StringUtils.isBlank(getExternalReferenceSource())) { | ||
| filters.add(constructFilterRequest("externalReferenceSource", getExternalReferenceSource())); | ||
| } | ||
| if (!StringUtils.isBlank(getExternalReferenceId())) { | ||
| filters.add(constructFilterRequest("externalReferenceId", getExternalReferenceId())); | ||
| } | ||
| return new SearchRequest(filters); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/main/java/org/breedinginsight/brapi/v2/services/BrAPIStudyService.java
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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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.services; | ||
|
|
||
| import io.micronaut.http.server.exceptions.InternalServerException; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.brapi.client.v2.model.exceptions.ApiException; | ||
| import org.brapi.v2.model.core.BrAPIStudy; | ||
| import org.breedinginsight.brapps.importer.daos.BrAPIStudyDAO; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Slf4j | ||
| @Singleton | ||
| public class BrAPIStudyService { | ||
|
|
||
| private final BrAPIStudyDAO studyDAO; | ||
|
|
||
| @Inject | ||
| public BrAPIStudyService(BrAPIStudyDAO studyDAO) { | ||
| this.studyDAO = studyDAO; | ||
| } | ||
|
|
||
| public List<BrAPIStudy> getStudies(UUID programId) throws ApiException { | ||
| try { | ||
| return studyDAO.getStudies(programId); | ||
| } catch (ApiException e) { | ||
| throw new InternalServerException(e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| } |
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.
I think
externalReferenceIdandexternalReferenceSourceshould be added to the query param, and probably change the frontend to send the request using those params instead oftrialDbId