75404: [Issue 3062] Self links contain embed params

This commit is contained in:
Yana De Pauw
2021-01-04 11:33:46 +01:00
parent 250c87dc16
commit 01bf6caf1e
2 changed files with 14 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
* @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")) {
uriComponentsBuilder.queryParam(key, parameters.get(key));
}
}
return uriComponentsBuilder.encode().build().toString();
}

View File

@@ -91,6 +91,15 @@ 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")));
}
}