Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2607 - Do not show next link when not necessary #2670

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,37 @@ public static void assertResponseBundle(Bundle bundle, BundleType expectedType,
}
}


/**
* Gets the self link of the bundle.
* @param bundle the bundle
* @return the self link, or null
*/
protected String getSelfLink(Bundle bundle) {
return getLink(bundle, "self");
}


/**
* Gets the next link of the bundle.
* @param bundle the bundle
* @return the next link, or null
*/
protected String getNextLink(Bundle bundle) {
return getLink(bundle, "next");
}

/**
* Gets the link with the specified relation type of the bundle.
* @param bundle the bundle
* @param relation the relation type
* @return the link, or null
*/
private String getLink(Bundle bundle, String relation) {
for (Bundle.Link link : bundle.getLink()) {
String type = link.getRelation().getValue();
String uri = link.getUrl().getValue();
if ("self".equals(type)) {
if (relation.equals(type)) {
return uri;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,25 @@ public void testSearchPractitioner_total_none() {
assertNotNull(bundle);
assertNull(bundle.getTotal());
assertTrue(bundle.getEntry().size() == 1);
assertNotNull(getSelfLink(bundle));
assertNull(getNextLink(bundle));
}

@Test(groups = { "server-search" }, dependsOnMethods = {"testCreatePractitioner" })
public void testSearchPractitioner_total_none_exact_count() {
WebTarget target = getWebTarget();
Response response =
target.path("Practitioner").queryParam("_id", practitionerId)
.queryParam("_count", "1")
.queryParam("_total", "none")
.request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
assertNotNull(bundle);
assertNull(bundle.getTotal());
assertTrue(bundle.getEntry().size() == 1);
assertNotNull(getSelfLink(bundle));
assertNotNull(getNextLink(bundle));
}

@Test(groups = { "server-search" }, dependsOnMethods = {"testCreatePractitioner" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ private Bundle addLinks(FHIRPagingContext context, Bundle responseBundle, String
// to avoid unnecessarily paging through additional page numbers < 1
int nextPageNumber = Math.max(context.getPageNumber() + 1, 1);
if (nextPageNumber <= context.getLastPageNumber()
&& (nextPageNumber == 1 || context.getTotalCount() != null || context.getMatchCount() > 0)) {
&& (nextPageNumber == 1 || context.getTotalCount() != null || context.getMatchCount() == context.getPageSize())) {

// starting with the self URI
String nextLinkUrl = selfUri;
Expand Down