-
Notifications
You must be signed in to change notification settings - Fork 1
[BI-1818] View exp: Obs dataset tab, details, and summary stats #268
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
13 commits
Select commit
Hold shift + click to select a range
efb95c5
create ListController
dmeidlin db7f402
Update ListQuery to include xrefsource and xrefid
dmeidlin ec1c8ab
move GET /lists from BrAPIV2Controller to ListsController
dmeidlin 9d7dfbd
create Dataset class
dmeidlin 3cb7a95
add GET /dataset/{datasetId}{?stats} to ExperimentController
dmeidlin 0d9a340
add method TrialService::getDatasetData
dmeidlin 91aedbf
update stats calculation
dmeidlin f031a95
fix querymapper
dmeidlin f74dcdd
cleanup code
dmeidlin 271a302
respond to comments
dmeidlin 3a44782
fix program filter in list fetch
dmeidlin 38bf53e
respond to comment
dmeidlin 84e14c7
remove default settings for xref params
dmeidlin 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
111 changes: 111 additions & 0 deletions
111
src/main/java/org/breedinginsight/brapi/v2/ListController.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,111 @@ | ||
| /* | ||
| * 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.BrAPIListSummary; | ||
| import org.brapi.v2.model.core.BrAPIListTypes; | ||
| 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.ListQuery; | ||
| import org.breedinginsight.brapi.v2.services.BrAPIListService; | ||
| import org.breedinginsight.model.Program; | ||
| import org.breedinginsight.services.ProgramService; | ||
| import org.breedinginsight.services.exceptions.DoesNotExistException; | ||
| import org.breedinginsight.utilities.response.ResponseUtils; | ||
| import org.breedinginsight.utilities.response.mappers.ListQueryMapper; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.validation.Valid; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Slf4j | ||
| @Controller | ||
| @Secured(SecurityRule.IS_AUTHENTICATED) | ||
| public class ListController { | ||
|
|
||
| private final ProgramService programService; | ||
| private final BrAPIListService listService; | ||
| private final ListQueryMapper listQueryMapper; | ||
|
|
||
| @Inject | ||
| public ListController(ProgramService programService, BrAPIListService listService, | ||
| ListQueryMapper listQueryMapper) { | ||
| this.programService = programService; | ||
| this.listService = listService; | ||
| this.listQueryMapper = listQueryMapper; | ||
| } | ||
|
|
||
| //@Get(BrapiVersion.BRAPI_V2 + "/lists") | ||
| @Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/lists{?queryParams*}") | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL}) | ||
| public HttpResponse<Response<DataResponse<Object>>> getLists( | ||
| @PathVariable("programId") UUID programId, | ||
| @QueryValue @QueryValid(using = ListQueryMapper.class) @Valid ListQuery queryParams | ||
| ) throws DoesNotExistException, ApiException { | ||
| try { | ||
| Program program = programService | ||
| .getById(programId) | ||
| .orElseThrow(() -> new DoesNotExistException("Program does not exist")); | ||
|
|
||
| // get germplasm lists by default | ||
| BrAPIListTypes type = BrAPIListTypes.fromValue(queryParams.getListType()); | ||
| if (type == null) { | ||
| type = BrAPIListTypes.GERMPLASM; | ||
| } | ||
timparsons marked this conversation as resolved.
Show resolved
Hide resolved
davedrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String source = null; | ||
| String id = null; | ||
| if (queryParams.getExternalReferenceSource() != null && !queryParams.getExternalReferenceSource().isEmpty()) { | ||
| source = queryParams.getExternalReferenceSource(); | ||
| } | ||
| if (queryParams.getExternalReferenceId() != null && !queryParams.getExternalReferenceId().isEmpty()) { | ||
| id = queryParams.getExternalReferenceId(); | ||
| } | ||
|
|
||
| // If the date display format was sent as a query param, then update the query mapper. | ||
| String dateFormatParam = queryParams.getDateDisplayFormat(); | ||
| if (dateFormatParam != null) { | ||
| listQueryMapper.setDateDisplayFormat(dateFormatParam); | ||
| } | ||
| List<BrAPIListSummary> brapiLists = listService.getListSummariesByTypeAndXref(type, source, id, program); | ||
| SearchRequest searchRequest = queryParams.constructSearchRequest(); | ||
|
|
||
| return ResponseUtils.getBrapiQueryResponse(brapiLists, listQueryMapper, queryParams, searchRequest); | ||
|
|
||
| } catch (IllegalArgumentException e) { | ||
| log.info(e.getMessage(), e); | ||
| return HttpResponse.status(HttpStatus.UNPROCESSABLE_ENTITY, "Error parsing requested date format"); | ||
| } catch (ClassNotFoundException e) { | ||
| throw new RuntimeException(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
92 changes: 92 additions & 0 deletions
92
src/main/java/org/breedinginsight/brapi/v2/services/BrAPIListService.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,92 @@ | ||
| package org.breedinginsight.brapi.v2.services; | ||
|
|
||
| import io.micronaut.context.annotation.Property; | ||
| 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.BrAPIListSummary; | ||
| import org.brapi.v2.model.core.BrAPIListTypes; | ||
| import org.brapi.v2.model.core.request.BrAPIListSearchRequest; | ||
| import org.brapi.v2.model.core.response.BrAPIListsSingleResponse; | ||
| import org.breedinginsight.brapi.v2.dao.BrAPIGermplasmDAO; | ||
| import org.breedinginsight.brapps.importer.daos.*; | ||
| import org.breedinginsight.brapps.importer.services.ExternalReferenceSource; | ||
| import org.breedinginsight.model.Program; | ||
| import org.breedinginsight.services.exceptions.DoesNotExistException; | ||
| import org.breedinginsight.utilities.Utilities; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Slf4j | ||
| @Singleton | ||
| public class BrAPIListService { | ||
| private final String referenceSource; | ||
| private final BrAPIListDAO listDAO; | ||
| private final BrAPIGermplasmDAO germplasmDAO; | ||
|
|
||
| @Inject | ||
| public BrAPIListService(@Property(name = "brapi.server.reference-source") String referenceSource, | ||
| BrAPIListDAO listDAO, | ||
| BrAPIGermplasmDAO germplasmDAO) { | ||
|
|
||
| this.referenceSource = referenceSource; | ||
| this.listDAO = listDAO; | ||
| this.germplasmDAO = germplasmDAO; | ||
| } | ||
|
|
||
| public List<BrAPIListSummary> getListSummariesByTypeAndXref( | ||
| BrAPIListTypes type, | ||
| String xrefSource, | ||
| String xrefId, | ||
| Program program) throws ApiException, DoesNotExistException, ClassNotFoundException { | ||
| BrAPIListSearchRequest searchRequest = new BrAPIListSearchRequest(); | ||
| if (type != null) { | ||
| searchRequest.listType(type); | ||
| } | ||
| if (xrefSource != null && !xrefSource.isEmpty()) { | ||
| searchRequest.externalReferenceSources(List.of(xrefSource)); | ||
| } | ||
| if (xrefId != null && !xrefId.isEmpty()) { | ||
| searchRequest.externalReferenceIDs(List.of(xrefId)); | ||
| } | ||
| List<BrAPIListSummary> lists = listDAO.getListBySearch(searchRequest, program.getId()); | ||
| if (lists == null) { | ||
| throw new DoesNotExistException("list not returned from BrAPI service"); | ||
| } | ||
|
|
||
| List<BrAPIListSummary> programLists = lists.stream().filter(list -> { | ||
| Optional<BrAPIExternalReference> programXrefOptional = Utilities.getExternalReference(list.getExternalReferences(),Utilities.generateReferenceSource(referenceSource, ExternalReferenceSource.PROGRAMS)); | ||
| return programXrefOptional.isPresent() && programXrefOptional.get().getReferenceID().equals(program.getId().toString()); | ||
| }).collect(Collectors.toList()); | ||
| for (BrAPIListSummary list: programLists) { | ||
|
|
||
| // remove the program key from the list name | ||
| list.setListName(Utilities.removeProgramKeyAndUnknownAdditionalData(list.getListName(), program.getKey())); | ||
|
|
||
| // set the owner of the list items as the list owner | ||
| BrAPIListsSingleResponse listDetails = listDAO.getListById(list.getListDbId(), program.getId()); | ||
| List<String> listItemNames = listDetails.getResult().getData(); | ||
| switch (type) { | ||
| case OBSERVATIONVARIABLES: | ||
| break; | ||
| case GERMPLASM: | ||
| default: | ||
| String createdBy = germplasmDAO.getGermplasmByRawName(listItemNames, program.getId()).get(0) | ||
| .getAdditionalInfo() | ||
| .getAsJsonObject("createdBy") | ||
| .get("userName") | ||
| .getAsString(); | ||
| list.setListOwnerName(createdBy); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return programLists; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.