001/*-
002 * #%L
003 * HAPI FHIR JPA Server - Batch2 Task Processor
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.batch2.api;
021
022import ca.uhn.fhir.batch2.jobs.parameters.PartitionedUrl;
023import ca.uhn.fhir.interceptor.model.RequestPartitionId;
024import ca.uhn.fhir.rest.api.server.RequestDetails;
025
026import java.util.List;
027import java.util.stream.Collectors;
028
029/**
030 * Provides the list of {@link PartitionedUrl} that a job should run against.
031 */
032public interface IJobPartitionProvider {
033
034        /**
035         * Provides the list of partitions to run job steps against, based on the request that initiates the job.
036         * @param theRequestDetails the requestDetails
037         * @param theOperation the operation being run which corresponds to the job
038         * @return the list of partitions
039         */
040        List<RequestPartitionId> getPartitions(RequestDetails theRequestDetails, String theOperation);
041
042        /**
043         * Provides the list of {@link PartitionedUrl} to run job steps against, based on the request that initiates the job
044         * and the urls that it's configured with.
045         * @param theRequestDetails the requestDetails
046         * @param theUrls the urls to run the job against
047         * @return the list of {@link PartitionedUrl}
048         */
049        default List<PartitionedUrl> getPartitionedUrls(RequestDetails theRequestDetails, List<String> theUrls) {
050                return theUrls.stream().map(url -> new PartitionedUrl().setUrl(url)).collect(Collectors.toList());
051        }
052}