4207-getpagesoffset-set-to-total-number-of-resources-results-in-inconsistent-amount-of-entries-when-requests-are-sent-consecutively (#4209)
* Added test * Added solution * Changelog * Changes made based on comments
This commit is contained in:
parent
a0183608f9
commit
f68d905226
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 4207
|
||||
title: "Previously to improve performance, if the total number of resources was less than the _getpageoffset,
|
||||
the results would default to last resource offset. This is especially evident when requests are consecutive
|
||||
resulting in one entry being displayed in some requests. This issue is now fixed."
|
|
@ -369,17 +369,15 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
count = result.preferredPageSize();
|
||||
}
|
||||
|
||||
Integer offsetI = RestfulServerUtils.tryToExtractNamedParameter(theRequest, Constants.PARAM_PAGINGOFFSET);
|
||||
if (offsetI == null || offsetI < 0) {
|
||||
offsetI = 0;
|
||||
Integer offset = RestfulServerUtils.tryToExtractNamedParameter(theRequest, Constants.PARAM_PAGINGOFFSET);
|
||||
if (offset == null || offset < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
Integer resultSize = result.size();
|
||||
int start;
|
||||
int start = offset;
|
||||
if (resultSize != null) {
|
||||
start = Math.max(0, Math.min(offsetI, resultSize - 1));
|
||||
} else {
|
||||
start = offsetI;
|
||||
start = Math.max(0, Math.min(offset, resultSize));
|
||||
}
|
||||
|
||||
ResponseEncoding responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theRequest, theServer.getDefaultResponseEncoding());
|
||||
|
|
|
@ -146,6 +146,37 @@ public class PagingTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testSendingSameRequestConsecutivelyResultsInSameResponse() throws Exception {
|
||||
initBundleProvider(10);
|
||||
myServerExtension.getRestfulServer().registerProvider(new DummyPatientResourceProvider());
|
||||
myServerExtension.getRestfulServer().setPagingProvider(pagingProvider);
|
||||
|
||||
when(pagingProvider.canStoreSearchResults()).thenReturn(true);
|
||||
when(pagingProvider.getDefaultPageSize()).thenReturn(10);
|
||||
when(pagingProvider.getMaximumPageSize()).thenReturn(50);
|
||||
when(pagingProvider.storeResultList(any(RequestDetails.class), any(IBundleProvider.class))).thenReturn("ABCD");
|
||||
when(pagingProvider.retrieveResultList(any(RequestDetails.class), anyString())).thenReturn(ourBundleProvider);
|
||||
|
||||
String nextLink;
|
||||
String base = "http://localhost:" + myServerExtension.getPort();
|
||||
HttpGet get = new HttpGet(base + "/Patient?_getpagesoffset=10");
|
||||
String responseContent;
|
||||
try (CloseableHttpResponse resp = ourClient.execute(get)) {
|
||||
assertEquals(200, resp.getStatusLine().getStatusCode());
|
||||
responseContent = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);
|
||||
|
||||
Bundle bundle = ourContext.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(0, bundle.getEntry().size());
|
||||
}
|
||||
try (CloseableHttpResponse resp = ourClient.execute(get)) {
|
||||
assertEquals(200, resp.getStatusLine().getStatusCode());
|
||||
responseContent = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8);
|
||||
|
||||
Bundle bundle = ourContext.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(0, bundle.getEntry().size());
|
||||
}
|
||||
}
|
||||
private void checkParam(String theUri, String theCheckedParam, String theExpectedValue) {
|
||||
Optional<String> paramValue = URLEncodedUtils.parse(theUri, CHARSET_UTF8).stream()
|
||||
.filter(nameValuePair -> nameValuePair.getName().equals(theCheckedParam))
|
||||
|
|
Loading…
Reference in New Issue