Skip to content

Commit

Permalink
Add species when redirect to metadata search (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
ke4 authored Jul 8, 2024
1 parent bcbb6c5 commit 3cebf40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
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

0 comments on commit 3cebf40

Please sign in to comment.