Add alternate caller methods

This commit is contained in:
Tadgh 2021-06-30 17:54:09 -04:00
parent f66f9b992e
commit 9f3b262d6d
1 changed files with 17 additions and 12 deletions

View File

@ -25,22 +25,27 @@ public final class MdmPageLinkBuilder {
* @return the {@link MdmPageLinkTuple} * @return the {@link MdmPageLinkTuple}
*/ */
public static MdmPageLinkTuple buildMdmPageLinks(ServletRequestDetails theServletRequestDetails, Page<MdmLinkJson> theCurrentPage, MdmPageRequest thePageRequest) { public static MdmPageLinkTuple buildMdmPageLinks(ServletRequestDetails theServletRequestDetails, Page<MdmLinkJson> theCurrentPage, MdmPageRequest thePageRequest) {
MdmPageLinkTuple tuple = new MdmPageLinkTuple();
String urlWithoutPaging = RestfulServerUtils.createLinkSelfWithoutGivenParameters(theServletRequestDetails.getFhirServerBase(), theServletRequestDetails, Arrays.asList(PARAM_OFFSET, PARAM_COUNT)); String urlWithoutPaging = RestfulServerUtils.createLinkSelfWithoutGivenParameters(theServletRequestDetails.getFhirServerBase(), theServletRequestDetails, Arrays.asList(PARAM_OFFSET, PARAM_COUNT));
tuple.setSelfLink(buildLinkWithOffsetAndCount(urlWithoutPaging, thePageRequest.getCount(), thePageRequest.getOffset())); return buildMdmPageLinks(urlWithoutPaging, theCurrentPage, thePageRequest);
if (theCurrentPage.hasNext()) {
tuple.setNextLink(buildLinkWithOffsetAndCount(urlWithoutPaging,thePageRequest.getCount(), thePageRequest.getNextOffset()));
}
if (theCurrentPage.hasPrevious()) {
tuple.setPreviousLink(buildLinkWithOffsetAndCount(urlWithoutPaging,thePageRequest.getCount(), thePageRequest.getPreviousOffset()));
}
return tuple;
} }
private static String buildLinkWithOffsetAndCount(String theStartingUrl, int theCount, int theOffset) { public static MdmPageLinkTuple buildMdmPageLinks(String theUrlWithoutPaging, Page<MdmLinkJson> theCurrentPage, MdmPageRequest thePageRequest) {
MdmPageLinkTuple tuple = new MdmPageLinkTuple();
tuple.setSelfLink(buildLinkWithOffsetAndCount(theUrlWithoutPaging, thePageRequest.getCount(), thePageRequest.getOffset()));
if (theCurrentPage.hasNext()) {
tuple.setNextLink(buildLinkWithOffsetAndCount(theUrlWithoutPaging,thePageRequest.getCount(), thePageRequest.getNextOffset()));
}
if (theCurrentPage.hasPrevious()) {
tuple.setPreviousLink(buildLinkWithOffsetAndCount(theUrlWithoutPaging,thePageRequest.getCount(), thePageRequest.getPreviousOffset()));
}
return tuple;
}
public static String buildLinkWithOffsetAndCount(String theBaseUrl, int theCount, int theOffset) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(theStartingUrl); builder.append(theBaseUrl);
if (!theStartingUrl.contains("?")) { if (!theBaseUrl.contains("?")) {
builder.append("?"); builder.append("?");
} }
builder.append(PARAM_OFFSET).append("=").append(theOffset); builder.append(PARAM_OFFSET).append("=").append(theOffset);