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 java.util.Collections;
024import java.util.List;
025
026import org.hl7.fhir.instance.model.api.IBaseResource;
027
028import ca.uhn.fhir.model.primitive.InstantDt;
029import ca.uhn.fhir.rest.api.server.IBundleProvider;
030import ca.uhn.fhir.util.CoverageIgnore;
031
032import javax.annotation.Nonnull;
033
034/**
035 * Utility methods for working with {@link IBundleProvider}
036 */
037public class BundleProviders {
038
039        /** Non instantiable */
040        @CoverageIgnore
041        private BundleProviders() {
042                //nothing
043        }
044
045        /**
046         * Create a new unmodifiable empty resource list with the current time as the publish date.
047         */
048        public static IBundleProvider newEmptyList() {
049                final InstantDt published = InstantDt.withCurrentTime();
050                return new IBundleProvider() {
051                        @Nonnull
052                        @Override
053                        public List<IBaseResource> getResources(int theFromIndex, int theToIndex) {
054                                return Collections.emptyList();
055                        }
056
057                        @Override
058                        public Integer size() {
059                                return 0;
060                        }
061
062                        @Override
063                        public InstantDt getPublished() {
064                                return published;
065                        }
066
067                        @Override
068                        public Integer preferredPageSize() {
069                                return null;
070                        }
071
072                        @Override
073                        public String getUuid() {
074                                return null;
075                        }
076                };
077        }
078
079        public static IBundleProvider newList(IBaseResource theResource) {
080                return new SimpleBundleProvider(theResource);
081        }
082
083        public static IBundleProvider newList(List<IBaseResource> theResources) {
084                return new SimpleBundleProvider(theResources);
085        }
086}