From 883337a9f4b71dd9c6a8f5aca0702a8fbfc2f9ae Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 30 Jun 2021 14:55:57 -0400 Subject: [PATCH] Tidying --- .../fhir/docs/server_jpa_mdm/mdm_operations.md | 4 ---- .../mdm/api/paging/MdmPageLinkBuilder.java | 18 +++++++++++++++--- .../fhir/mdm/api/paging/MdmPageRequest.java | 15 ++++++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_operations.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_operations.md index 1d03c7a13e2..3b191a26e6d 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_operations.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_operations.md @@ -695,7 +695,3 @@ This operation can also be done at the Instance level. When this is the case, th http://example.com/Patient/123/$mdm-submit http://example.com/Practitioner/456/$mdm-submit ``` - - - - diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageLinkBuilder.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageLinkBuilder.java index 7940cd1eb02..7aa82a5f3f4 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageLinkBuilder.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageLinkBuilder.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.mdm.api.paging; import ca.uhn.fhir.mdm.api.MdmLinkJson; import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; -import ca.uhn.fhir.util.ParametersUtil; import org.springframework.data.domain.Page; import java.util.Arrays; @@ -11,7 +10,20 @@ import java.util.Arrays; import static ca.uhn.fhir.rest.api.Constants.PARAM_COUNT; import static ca.uhn.fhir.rest.api.Constants.PARAM_OFFSET; +/** + * Builder to generate {@link MdmPageLinkTuple} objects, based on a given page of data and the incoming page request. + */ public final class MdmPageLinkBuilder { + + /** + * Generates an {@link MdmPageLinkTuple} which contains previous/self/next links for pagination purposes. + * + * @param theServletRequestDetails the incoming request details. Used to determine server base. + * @param theCurrentPage the page of MDM link data. Used for determining if there are next/previous pages available. + * @param thePageRequest the incoming Page request, containing requested offset and count. Used for building offset for outgoing URLs. + * + * @return the {@link MdmPageLinkTuple} + */ public static MdmPageLinkTuple buildMdmPageLinks(ServletRequestDetails theServletRequestDetails, Page theCurrentPage, MdmPageRequest thePageRequest) { MdmPageLinkTuple tuple = new MdmPageLinkTuple(); String urlWithoutPaging = RestfulServerUtils.createLinkSelfWithoutGivenParameters(theServletRequestDetails.getFhirServerBase(), theServletRequestDetails, Arrays.asList(PARAM_OFFSET, PARAM_COUNT)); @@ -23,9 +35,9 @@ public final class MdmPageLinkBuilder { tuple.setPreviousLink(buildLinkWithOffsetAndCount(urlWithoutPaging,thePageRequest.getCount(), thePageRequest.getPreviousOffset())); } return tuple; - } - protected static String buildLinkWithOffsetAndCount(String theStartingUrl, int theCount, int theOffset) { + + private static String buildLinkWithOffsetAndCount(String theStartingUrl, int theCount, int theOffset) { StringBuilder builder = new StringBuilder(); builder.append(theStartingUrl); if (!theStartingUrl.contains("?")) { diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageRequest.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageRequest.java index 8f3a04b5228..b79c8d6c05b 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageRequest.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/api/paging/MdmPageRequest.java @@ -1,7 +1,6 @@ package ca.uhn.fhir.mdm.api.paging; import ca.uhn.fhir.rest.server.IPagingProvider; -import ca.uhn.fhir.rest.server.IRestfulServerDefaults; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.dstu3.model.UnsignedIntType; @@ -12,6 +11,11 @@ import static ca.uhn.fhir.rest.api.Constants.PARAM_COUNT; import static ca.uhn.fhir.rest.api.Constants.PARAM_OFFSET; import static org.slf4j.LoggerFactory.getLogger; +/** + * This class is essentially just a data clump of offset + count, as well as the ability to convert itself into a standard + * {@link PageRequest} for spring data to use. The reason we don't use PageRequest natively is because it is concerned with `pages` and `counts`, + * but we are using `offset` and `count` which requires some minor translation. + */ public class MdmPageRequest { private static final Logger ourLog = getLogger(MdmPageRequest.class); @@ -34,10 +38,6 @@ public class MdmPageRequest { this.myPage = myOffset / myCount; } - public PageRequest toPageRequest() { - return PageRequest.of(this.myPage, this.myCount); - } - private void validatePagingParameters(int theOffset, int theCount) { String errorMessage = ""; @@ -67,7 +67,12 @@ public class MdmPageRequest { public int getNextOffset() { return myOffset + myCount; } + public int getPreviousOffset() { return myOffset - myCount; } + + public PageRequest toPageRequest() { + return PageRequest.of(this.myPage, this.myCount); + } }