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.batch2; 021 022import ca.uhn.fhir.batch2.coordinator.DefaultJobPartitionProvider; 023import ca.uhn.fhir.batch2.jobs.parameters.PartitionedUrl; 024import ca.uhn.fhir.context.FhirContext; 025import ca.uhn.fhir.interceptor.model.RequestPartitionId; 026import ca.uhn.fhir.jpa.entity.PartitionEntity; 027import ca.uhn.fhir.jpa.partition.IPartitionLookupSvc; 028import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc; 029import ca.uhn.fhir.jpa.searchparam.MatchUrlService; 030 031import java.util.List; 032import java.util.stream.Collectors; 033 034/** 035 * The default JPA implementation, which uses {@link IRequestPartitionHelperSvc} and {@link IPartitionLookupSvc} 036 * to compute the {@link PartitionedUrl} list to run a batch2 job. 037 * The latter will be used to handle cases when the job is configured to run against all partitions 038 * (bulk system operation) and will return the actual list with all the configured partitions. 039 */ 040@Deprecated 041public class JpaJobPartitionProvider extends DefaultJobPartitionProvider { 042 private final IPartitionLookupSvc myPartitionLookupSvc; 043 044 public JpaJobPartitionProvider( 045 IRequestPartitionHelperSvc theRequestPartitionHelperSvc, IPartitionLookupSvc thePartitionLookupSvc) { 046 super(theRequestPartitionHelperSvc); 047 myPartitionLookupSvc = thePartitionLookupSvc; 048 } 049 050 public JpaJobPartitionProvider( 051 FhirContext theFhirContext, 052 IRequestPartitionHelperSvc theRequestPartitionHelperSvc, 053 MatchUrlService theMatchUrlService, 054 IPartitionLookupSvc thePartitionLookupSvc) { 055 super(theFhirContext, theRequestPartitionHelperSvc, theMatchUrlService); 056 myPartitionLookupSvc = thePartitionLookupSvc; 057 } 058 059 @Override 060 public List<RequestPartitionId> getAllPartitions() { 061 return myPartitionLookupSvc.listPartitions().stream() 062 .map(PartitionEntity::toRequestPartitionId) 063 .collect(Collectors.toList()); 064 } 065}