001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.config;
021
022import ca.uhn.fhir.jpa.api.IDaoRegistry;
023import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
024import ca.uhn.fhir.jpa.config.util.ResourceCountCacheUtil;
025import ca.uhn.fhir.jpa.config.util.ValidationSupportConfigUtil;
026import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl;
027import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
028import ca.uhn.fhir.jpa.dao.search.HSearchSortHelperImpl;
029import ca.uhn.fhir.jpa.dao.search.IHSearchSortHelper;
030import ca.uhn.fhir.jpa.provider.DaoRegistryResourceSupportedSvc;
031import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
032import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
033import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl;
034import ca.uhn.fhir.jpa.util.ResourceCountCache;
035import ca.uhn.fhir.jpa.validation.JpaValidationSupportChain;
036import ca.uhn.fhir.rest.api.IResourceSupportedSvc;
037import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
038import org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport;
039import org.springframework.beans.factory.annotation.Autowired;
040import org.springframework.context.annotation.Bean;
041import org.springframework.context.annotation.Configuration;
042import org.springframework.context.annotation.Import;
043import org.springframework.context.annotation.Primary;
044
045@Configuration
046@Import({JpaConfig.class})
047public class HapiJpaConfig {
048
049        @Autowired
050        private ISearchParamRegistry mySearchParamRegistry;
051
052        @Bean
053        public IHSearchSortHelper extendedFulltextSortHelper() {
054                return new HSearchSortHelperImpl(mySearchParamRegistry);
055        }
056
057        @Bean
058        public IFulltextSearchSvc fullTextSearchSvc() {
059                return new FulltextSearchSvcImpl();
060        }
061
062        @Bean
063        public IStaleSearchDeletingSvc staleSearchDeletingSvc() {
064                return new StaleSearchDeletingSvcImpl();
065        }
066
067        @Primary
068        @Bean
069        public CachingValidationSupport validationSupportChain(JpaValidationSupportChain theJpaValidationSupportChain) {
070                return ValidationSupportConfigUtil.newCachingValidationSupport(theJpaValidationSupportChain);
071        }
072
073        @Bean
074        public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
075                return new DatabaseBackedPagingProvider();
076        }
077
078        @Bean
079        public IResourceSupportedSvc resourceSupportedSvc(IDaoRegistry theDaoRegistry) {
080                return new DaoRegistryResourceSupportedSvc(theDaoRegistry);
081        }
082
083        @Bean(name = "myResourceCountsCache")
084        public ResourceCountCache resourceCountsCache(IFhirSystemDao<?, ?> theSystemDao) {
085                return ResourceCountCacheUtil.newResourceCountCache(theSystemDao);
086        }
087}