Tidying
This commit is contained in:
parent
91dee55279
commit
883337a9f4
|
@ -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
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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<MdmLinkJson> 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("?")) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue