
001package ca.uhn.fhir.rest.server; 002 003/*- 004 * #%L 005 * HAPI FHIR - Server Framework 006 * %% 007 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import org.apache.commons.lang3.Validate; 024import org.hl7.fhir.instance.model.api.IBaseResource; 025 026import javax.annotation.Nonnull; 027import java.util.List; 028 029/** 030 * Bundle provider that uses named pages instead of counts 031 */ 032public class BundleProviderWithNamedPages extends SimpleBundleProvider { 033 034 private String myNextPageId; 035 private String myCurrentPageId; 036 private String myPreviousPageId; 037 038 /** 039 * Constructor 040 * 041 * @param theResultsInThisPage The complete list of results in the current page. Must not be null. 042 * @param theSearchId The ID for the search. Note that you should also populate {@link #setNextPageId(String)} and {@link #setPreviousPageId(String)} if these are known. Must not be <code>null</code> or blank. 043 * @param thePageId The ID for the current page. Note that you should also populate {@link #setNextPageId(String)} and {@link #setPreviousPageId(String)} if these are known. Must not be <code>null</code> or blank. 044 * @param theTotalResults The total number of result (if this is known), or <code>null</code> 045 * @see #setNextPageId(String) 046 * @see #setPreviousPageId(String) 047 */ 048 public BundleProviderWithNamedPages(List<IBaseResource> theResultsInThisPage, String theSearchId, String thePageId, Integer theTotalResults) { 049 super(theResultsInThisPage, theSearchId); 050 051 Validate.notNull(theResultsInThisPage, "theResultsInThisPage must not be null"); 052 Validate.notBlank(thePageId, "thePageId must not be null or blank"); 053 054 setCurrentPageId(thePageId); 055 setSize(theTotalResults); 056 } 057 058 @Override 059 public String getCurrentPageId() { 060 return myCurrentPageId; 061 } 062 063 public BundleProviderWithNamedPages setCurrentPageId(String theCurrentPageId) { 064 myCurrentPageId = theCurrentPageId; 065 return this; 066 } 067 068 @Override 069 public String getNextPageId() { 070 return myNextPageId; 071 } 072 073 public BundleProviderWithNamedPages setNextPageId(String theNextPageId) { 074 myNextPageId = theNextPageId; 075 return this; 076 } 077 078 @Override 079 public String getPreviousPageId() { 080 return myPreviousPageId; 081 } 082 083 public BundleProviderWithNamedPages setPreviousPageId(String thePreviousPageId) { 084 myPreviousPageId = thePreviousPageId; 085 return this; 086 } 087 088 @Nonnull 089 @Override 090 public List<IBaseResource> getResources(int theFromIndex, int theToIndex) { 091 return (List<IBaseResource>) getList(); // indexes are ignored for this provider type 092 } 093 094 @Override 095 public BundleProviderWithNamedPages setSize(Integer theSize) { 096 super.setSize(theSize); 097 return this; 098 } 099 100}