Merge pull request #3105 from atmire/w2p-75404_self-links-contain-embeds

Self links contain embed params
This commit is contained in:
Tim Donohue
2021-02-12 09:48:12 -06:00
committed by GitHub
2 changed files with 19 additions and 2 deletions

View File

@@ -1021,15 +1021,18 @@ public class RestResourceController implements InitializingBean {
/**
* Internal method to convert the parameters provided as a MultivalueMap as a string to use in the self-link.
* This function will exclude all "embed" parameters and parameters starting with "embed."
* @param parameters
* @return encoded uriString containing request parameters
* @return encoded uriString containing request parameters without embed parameter
*/
private String getEncodedParameterStringFromRequestParams(
@RequestParam MultiValueMap<String, Object> parameters) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.newInstance();
for (String key : parameters.keySet()) {
uriComponentsBuilder.queryParam(key, parameters.get(key));
if (!StringUtils.equals(key, "embed") && !StringUtils.startsWith(key, "embed.")) {
uriComponentsBuilder.queryParam(key, parameters.get(key));
}
}
return uriComponentsBuilder.encode().build().toString();
}

View File

@@ -91,6 +91,20 @@ public class RestResourceControllerIT extends AbstractControllerIntegrationTest
endsWith("/api/core/metadatafields/search/byFieldName")));
}
@Test
public void selfLinkContainsRequestParametersAndEmbedsWhenProvided() throws Exception {
// When we call a search endpoint with additional parameters and an embed parameter
getClient().perform(get("/api/core/metadatafields/search/byFieldName?schema=dc&offset=0&embed=schema"))
// The self link should contain those same parameters
.andExpect(jsonPath("$._links.self.href", endsWith(
"/api/core/metadatafields/search/byFieldName?schema=dc&offset=0")));
getClient().perform(get("/api/core/metadatafields/search/byFieldName?schema=dc&offset=0&embed.size=schema=5"))
// The self link should contain those same parameters
.andExpect(jsonPath("$._links.self.href", endsWith(
"/api/core/metadatafields/search/byFieldName?schema=dc&offset=0")));
}
}