mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #3105 from atmire/w2p-75404_self-links-contain-embeds
Self links contain embed params
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -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")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user