-
Notifications
You must be signed in to change notification settings - Fork 1
BI-1845 - add listType parameter to GET /lists calls #284
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
9 commits
Select commit
Hold shift + click to select a range
91ba4bf
[BI-1845] - added TODO
mlm483 42549d8
[BI-1845] - 400 response for missing listType
mlm483 4ed65db
[BI-1845] - added listType param to tests
mlm483 d1de547
[BI-1845] - tested /lists 400 response
mlm483 7086f9d
[BI-1845] - return all lists if no listType specified
mlm483 6e523b6
[BI-1845] - added notice
mlm483 d029f0d
[BI-1845] - updated switch
mlm483 39305ce
Merge branch 'develop' into feature/BI-1845
mlm483 9db9abf
Merge branch 'develop' into feature/BI-1845
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,19 +72,20 @@ public List<BrAPIListSummary> getListSummariesByTypeAndXref( | |
| // 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); | ||
| if (type != null) { | ||
| switch (type) { | ||
|
Comment on lines
+75
to
+76
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. Prevents |
||
| case GERMPLASM: | ||
| String createdBy = germplasmDAO.getGermplasmByRawName(listItemNames, program.getId()).get(0) | ||
| .getAdditionalInfo() | ||
| .getAsJsonObject("createdBy") | ||
| .get("userName") | ||
| .getAsString(); | ||
| list.setListOwnerName(createdBy); | ||
| case OBSERVATIONVARIABLES: | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return programLists; | ||
|
|
||
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
190 changes: 190 additions & 0 deletions
190
src/test/java/org/breedinginsight/brapi/v2/ListControllerIntegrationTest.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,190 @@ | ||
| /* | ||
| * 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 com.google.gson.*; | ||
| import io.kowalski.fannypack.FannyPack; | ||
| import io.micronaut.http.HttpResponse; | ||
| import io.micronaut.http.HttpStatus; | ||
| import io.micronaut.http.client.RxHttpClient; | ||
| import io.micronaut.http.client.annotation.Client; | ||
| import io.micronaut.http.netty.cookies.NettyCookie; | ||
| import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
| import io.reactivex.Flowable; | ||
| import junit.framework.AssertionFailedError; | ||
| import lombok.SneakyThrows; | ||
| import org.breedinginsight.BrAPITest; | ||
| import org.breedinginsight.TestUtils; | ||
| import org.breedinginsight.api.auth.AuthenticatedUser; | ||
| import org.breedinginsight.brapps.importer.ImportTestUtils; | ||
| import org.breedinginsight.brapps.importer.model.imports.experimentObservation.ExperimentObservation; | ||
| import org.breedinginsight.model.Trait; | ||
| import org.breedinginsight.services.OntologyService; | ||
| import org.breedinginsight.services.exceptions.ValidatorException; | ||
| import org.breedinginsight.dao.db.tables.pojos.BiUserEntity; | ||
| import org.breedinginsight.daos.UserDAO; | ||
| import org.breedinginsight.model.Program; | ||
| import org.breedinginsight.services.SpeciesService; | ||
| import org.jooq.DSLContext; | ||
| import org.junit.jupiter.api.*; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import java.io.File; | ||
| import java.time.OffsetDateTime; | ||
| import java.util.*; | ||
|
|
||
| import static io.micronaut.http.HttpRequest.GET; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| @MicronautTest | ||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| @TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
| public class ListControllerIntegrationTest extends BrAPITest { | ||
|
|
||
| private Program program; | ||
| private String germplasmImportId; | ||
| private ImportTestUtils importTestUtils; | ||
| private String mappingId; | ||
| private BiUserEntity testUser; | ||
|
|
||
|
|
||
| @Inject | ||
| private SpeciesService speciesService; | ||
| @Inject | ||
| @Client("/${micronaut.bi.api.version}") | ||
| RxHttpClient client; | ||
| @Inject | ||
| private UserDAO userDAO; | ||
| @Inject | ||
| private DSLContext dsl; | ||
|
|
||
| private Gson gson = new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, (JsonDeserializer<OffsetDateTime>) | ||
| (json, type, context) -> OffsetDateTime.parse(json.getAsString())) | ||
| .create(); | ||
|
|
||
| private final String germplasmListName = "Program List"; | ||
| private final String germplasmListDesc = "Program List"; | ||
|
|
||
| @Inject | ||
| private OntologyService ontologyService; | ||
|
|
||
| @BeforeAll | ||
| @SneakyThrows | ||
| public void setup() { | ||
| importTestUtils = new ImportTestUtils(); | ||
| Map<String, Object> setupObjects = importTestUtils.setup(client, gson, dsl, speciesService, userDAO, super.getBrapiDsl(), "ExperimentsTemplateMap"); | ||
| mappingId = (String) setupObjects.get("mappingId"); | ||
| program = (Program) setupObjects.get("program"); | ||
| testUser = (BiUserEntity) setupObjects.get("testUser"); | ||
| FannyPack securityFp = (FannyPack) setupObjects.get("securityFp"); | ||
|
|
||
| dsl.execute(securityFp.get("InsertSystemRoleAdmin"), testUser.getId().toString()); | ||
|
|
||
| // Generate traits and persist them. | ||
| List<Trait> traits = importTestUtils.createTraits(1); | ||
| AuthenticatedUser user = new AuthenticatedUser(testUser.getName(), new ArrayList<>(), testUser.getId(), new ArrayList<>()); | ||
| try { | ||
| ontologyService.createTraits(program.getId(), traits, user, false); | ||
| } catch (ValidatorException e) { | ||
| System.err.println(e.getErrors()); | ||
| throw e; | ||
| } | ||
|
|
||
| // Get germplasm system import. | ||
| Flowable<HttpResponse<String>> call = client.exchange( | ||
| GET("/import/mappings?importName=germplasmtemplatemap").cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class | ||
| ); | ||
| HttpResponse<String> response = call.blockingFirst(); | ||
| germplasmImportId = JsonParser.parseString(response.body()).getAsJsonObject() | ||
| .getAsJsonObject("result") | ||
| .getAsJsonArray("data") | ||
| .get(0).getAsJsonObject().get("id").getAsString(); | ||
|
|
||
| // Insert program germplasm. | ||
| File file = new File("src/test/resources/files/germplasm_import/minimal_germplasm_import.csv"); | ||
| Map<String, String> germplasmListInfo = Map.ofEntries( | ||
| Map.entry("germplasmListName", germplasmListName), | ||
| Map.entry("germplasmListDescription", germplasmListDesc) | ||
| ); | ||
| TestUtils.uploadDataFile(client, program.getId(), germplasmImportId, germplasmListInfo, file); | ||
|
|
||
| // Make test experiment import. | ||
| Map<String, Object> newExp = new HashMap<>(); | ||
| newExp.put(ExperimentObservation.Columns.GERMPLASM_GID, "1"); | ||
| newExp.put(ExperimentObservation.Columns.TEST_CHECK, "T"); | ||
| newExp.put(ExperimentObservation.Columns.EXP_TITLE, "Test Exp"); | ||
| newExp.put(ExperimentObservation.Columns.EXP_UNIT, "Plot"); | ||
| newExp.put(ExperimentObservation.Columns.EXP_TYPE, "Phenotyping"); | ||
| newExp.put(ExperimentObservation.Columns.ENV, "New Env"); | ||
| newExp.put(ExperimentObservation.Columns.ENV_LOCATION, "Location A"); | ||
| newExp.put(ExperimentObservation.Columns.ENV_YEAR, "2023"); | ||
| newExp.put(ExperimentObservation.Columns.EXP_UNIT_ID, "a-1"); | ||
| newExp.put(ExperimentObservation.Columns.REP_NUM, "1"); | ||
| newExp.put(ExperimentObservation.Columns.BLOCK_NUM, "1"); | ||
| newExp.put(ExperimentObservation.Columns.ROW, "1"); | ||
| newExp.put(ExperimentObservation.Columns.COLUMN, "1"); | ||
| newExp.put(traits.get(0).getObservationVariableName(), "1"); | ||
|
|
||
| JsonObject result = importTestUtils.uploadAndFetch( | ||
| importTestUtils.writeDataToFile(List.of(newExp), traits), null, true, client, program, mappingId | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| @SneakyThrows | ||
| public void getAllListsSuccess() { | ||
| // A GET request to the brapi/v2/lists endpoint with no query params should return all lists. | ||
| Flowable<HttpResponse<String>> call = client.exchange( | ||
| GET(String.format("/programs/%s/brapi/v2/lists", program.getId().toString())) | ||
| .cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class | ||
| ); | ||
|
|
||
| // Ensure 200 OK response. | ||
| HttpResponse<String> response = call.blockingFirst(); | ||
| assertEquals(HttpStatus.OK, response.getStatus()); | ||
|
|
||
| // Parse result. | ||
| JsonObject result = JsonParser.parseString(response.body()).getAsJsonObject().getAsJsonObject("result"); | ||
| JsonArray data = result.getAsJsonArray("data"); | ||
|
|
||
| // Ensure all lists are returned. | ||
| assertEquals(2, data.size(), "Wrong number of lists were returned"); | ||
|
|
||
| // Ensure the list names and types are as expected. | ||
| List<String> listNames = List.of(germplasmListName, "Observation Dataset"); | ||
| List<String> listTypes = List.of("germplasm", "observationVariables"); | ||
| for (JsonElement element: data) { | ||
| JsonObject list = element.getAsJsonObject(); | ||
| if (listNames.contains(list.get("listName").getAsString())) { | ||
| int index = listNames.indexOf(list.get("listName").getAsString()); | ||
| assertEquals(list.get("listName").getAsString(), listNames.get(index), "List name incorrect"); | ||
| } else { | ||
| throw new AssertionFailedError("List name not found"); | ||
| } | ||
| if (listTypes.contains(list.get("listType").getAsString())) { | ||
| int index = listTypes.indexOf(list.get("listType").getAsString()); | ||
| assertEquals(list.get("listType").getAsString(), listTypes.get(index), "List type incorrect"); | ||
| } else { | ||
| throw new AssertionFailedError("List type not found"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
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 that this goes against the BrAPI spec. I think we should probably return all lists if the
typeparameter isnull. Worth confirming with @BrapiCoordinatorSelbyThere 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.
The BrAPI Spec does not specifically define what should happen if
listTypeis null.I would expect it to return all lists of all types, in line with other GET query parameters. You might also make
listTypea required parameter for your implementation.Defaulting
listTypeto germplasm is unusual, and might cause some confusion if it is not well documented, but it is not technically against the BrAPI spec.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.
Thanks for the input @BrapiCoordinatorSelby, all lists of all types are now returned.