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.jobs.parameters; 021 022import ca.uhn.fhir.interceptor.model.RequestPartitionId; 023import ca.uhn.fhir.model.api.IModelJson; 024import com.fasterxml.jackson.annotation.JsonProperty; 025import jakarta.annotation.Nonnull; 026import jakarta.annotation.Nullable; 027import org.apache.commons.lang3.StringUtils; 028 029import java.util.ArrayList; 030import java.util.List; 031import java.util.stream.Collectors; 032 033/** 034 * Can be used to configure parameters for batch2 jobs. 035 * Please note that these need to be backward compatible as we do not have a way to migrate them to a different structure at the moment. 036 */ 037public class PartitionedUrlJobParameters implements IModelJson { 038 @JsonProperty(value = "partitionId") 039 @Nullable 040 private RequestPartitionId myRequestPartitionId; 041 042 @JsonProperty("batchSize") 043 private Integer myBatchSize; 044 045 @JsonProperty("partitionedUrl") 046 private List<PartitionedUrl> myPartitionedUrls; 047 048 public void setRequestPartitionId(@Nullable RequestPartitionId theRequestPartitionId) { 049 myRequestPartitionId = theRequestPartitionId; 050 } 051 052 @Nullable 053 public RequestPartitionId getRequestPartitionId() { 054 return myRequestPartitionId; 055 } 056 057 public void setBatchSize(int theBatchSize) { 058 myBatchSize = theBatchSize; 059 } 060 061 @Nullable 062 public Integer getBatchSize() { 063 return myBatchSize; 064 } 065 066 public List<PartitionedUrl> getPartitionedUrls() { 067 if (myPartitionedUrls == null) { 068 myPartitionedUrls = new ArrayList<>(); 069 } 070 // TODO MM: added for backward compatibility, it can be removed once requestPartitionId is deprecated 071 myPartitionedUrls.stream() 072 .filter(thePartitionedUrl -> thePartitionedUrl.getRequestPartitionId() == null) 073 .forEach(thePartitionedUrl -> thePartitionedUrl.setRequestPartitionId(myRequestPartitionId)); 074 return myPartitionedUrls; 075 } 076 077 public void addPartitionedUrl(@Nonnull PartitionedUrl theUrl) { 078 getPartitionedUrls().add(theUrl); 079 } 080 081 public void addUrl(@Nonnull String theUrl) { 082 getPartitionedUrls().add(new PartitionedUrl().setUrl(theUrl)); 083 } 084 085 public List<String> getUrls() { 086 return getPartitionedUrls().stream() 087 .map(PartitionedUrl::getUrl) 088 .filter(url -> !StringUtils.isBlank(url)) 089 .collect(Collectors.toList()); 090 } 091}