Skip to content
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

[bugfix] Add species when redirect to metadata search #434

Merged
merged 1 commit into from
Jul 8, 2024
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
17 changes: 14 additions & 3 deletions app/src/main/java/uk/ac/ebi/atlas/search/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,27 @@ public String parseJsonAsRequestParamsAndRedirect(
.newInstance()
.path(SEARCH_ENDPOINT);

addCategoryToURL(queryObject, searchUrlBuilder);

addSpeciesToURL(species, searchUrlBuilder);

return "redirect:" + searchUrlBuilder.build().toUriString();
}

private void addCategoryToURL(JsonObject queryObject, UriComponentsBuilder searchUrlBuilder) {
if (queryObject.get("category").getAsString().equals("metadata")) {
searchUrlBuilder
.pathSegment("metadata", queryObject.get("term").getAsString());
} else {
searchUrlBuilder
.queryParam(queryObject.get("category").getAsString(), queryObject.get("term").getAsString())
.queryParam("species", species);
.queryParam(queryObject.get("category").getAsString(), queryObject.get("term").getAsString());
}
}

return "redirect:" + searchUrlBuilder.build().toUriString();
private void addSpeciesToURL(String species, UriComponentsBuilder searchUrlBuilder) {
if (!species.isBlank()) {
searchUrlBuilder.queryParam("species", species);
}
}

@RequestMapping(value = SEARCH_ENDPOINT, method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
Expand Down
14 changes: 14 additions & 0 deletions app/src/test/java/uk/ac/ebi/atlas/search/SearchControllerWIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ void geneQueryAndSpeciesParamsAreParsedAndAddedToGetRequest() throws Exception {
.andExpect(redirectedUrl("/search?" + category + "=" + term + "&species=" + species));
}

@Test
void metadataAndSpeciesParamsAreParsedAndAddedToGetRequest() throws Exception {
var term = randomAlphanumeric(10);
var category = "metadata";
var species = randomAlphanumeric(4) + " " + randomAlphanumeric(6);

this.mockMvc.perform(
post("/search")
.param("geneQuery", GSON.toJson(ImmutableMap.of("term", term, "category", category)))
.param("species", species))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/search/" + category + "/" + term + "?species=" + species));
}

@Test
void otherRequestParamsAreIgnored() throws Exception {
var term = randomAlphanumeric(10);
Expand Down
Loading