Skip to content

Commit

Permalink
Issue #2607 - Do not show next link when not necessary
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Aug 9, 2021
1 parent 2901be1 commit 35bbf92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,16 +841,38 @@ 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 of the specified relation type in 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

0 comments on commit 35bbf92

Please sign in to comment.