001package ca.uhn.fhir.rest.server;
002
003/*-
004 * #%L
005 * HAPI FHIR - Server Framework
006 * %%
007 * Copyright (C) 2014 - 2019 University Health Network
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 java.util.List;
027
028/**
029 * Bundle provider that uses named pages instead of counts
030 */
031public class BundleProviderWithNamedPages extends SimpleBundleProvider {
032
033        private String myNextPageId;
034        private String myCurrentPageId;
035        private String myPreviousPageId;
036
037        /**
038         * Constructor
039         *
040         * @param theResultsInThisPage The complete list of results in the current page. Must not be null.
041         * @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.
042         * @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.
043         * @param theTotalResults      The total number of result (if this is known), or <code>null</code>
044         * @see #setNextPageId(String)
045         * @see #setPreviousPageId(String)
046         */
047        public BundleProviderWithNamedPages(List<IBaseResource> theResultsInThisPage, String theSearchId, String thePageId, Integer theTotalResults) {
048                super(theResultsInThisPage, theSearchId);
049
050                Validate.notNull(theResultsInThisPage, "theResultsInThisPage must not be null");
051                Validate.notBlank(thePageId, "thePageId must not be null or blank");
052
053                setCurrentPageId(thePageId);
054                setSize(theTotalResults);
055        }
056
057        @Override
058        public String getCurrentPageId() {
059                return myCurrentPageId;
060        }
061
062        public BundleProviderWithNamedPages setCurrentPageId(String theCurrentPageId) {
063                myCurrentPageId = theCurrentPageId;
064                return this;
065        }
066
067        @Override
068        public String getNextPageId() {
069                return myNextPageId;
070        }
071
072        public BundleProviderWithNamedPages setNextPageId(String theNextPageId) {
073                myNextPageId = theNextPageId;
074                return this;
075        }
076
077        @Override
078        public String getPreviousPageId() {
079                return myPreviousPageId;
080        }
081
082        public BundleProviderWithNamedPages setPreviousPageId(String thePreviousPageId) {
083                myPreviousPageId = thePreviousPageId;
084                return this;
085        }
086
087        @Override
088        public List<IBaseResource> getResources(int theFromIndex, int theToIndex) {
089                return getList(); // indexes are ignored for this provider type
090        }
091
092        @Override
093        public BundleProviderWithNamedPages setSize(Integer theSize) {
094                super.setSize(theSize);
095                return this;
096        }
097
098}