|
3 | 3 | import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
|
4 | 4 | import ca.uhn.fhir.jpa.binary.api.IBinaryStorageSvc;
|
5 | 5 | import ca.uhn.fhir.jpa.binstore.DatabaseBinaryContentStorageSvcImpl;
|
| 6 | +import ca.uhn.fhir.jpa.binstore.FilesystemBinaryStorageSvcImpl; |
6 | 7 | import ca.uhn.fhir.jpa.config.HibernatePropertiesProvider;
|
7 | 8 | import ca.uhn.fhir.jpa.model.config.PartitionSettings;
|
8 | 9 | import ca.uhn.fhir.jpa.model.config.PartitionSettings.CrossPartitionReferenceMode;
|
|
23 | 24 | import org.springframework.context.annotation.*;
|
24 | 25 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
25 | 26 | import org.springframework.transaction.annotation.EnableTransactionManagement;
|
| 27 | +import org.springframework.util.Assert; |
26 | 28 |
|
27 | 29 | import java.util.HashSet;
|
28 | 30 | import java.util.stream.Collectors;
|
|
38 | 40 | public class FhirServerConfigCommon {
|
39 | 41 |
|
40 | 42 | private static final Logger ourLog = LoggerFactory.getLogger(FhirServerConfigCommon.class);
|
| 43 | + private static final int DEFAULT_FILESYSTEM_INLINE_THRESHOLD = 102_400; |
41 | 44 |
|
42 | 45 | public FhirServerConfigCommon(AppProperties appProperties) {
|
43 | 46 | ourLog.info(
|
@@ -222,8 +225,13 @@ public JpaStorageSettings jpaStorageSettings(AppProperties appProperties) {
|
222 | 225 | jpaStorageSettings.setLastNEnabled(true);
|
223 | 226 | }
|
224 | 227 |
|
225 |
| - if (appProperties.getInline_resource_storage_below_size() != 0) { |
226 |
| - jpaStorageSettings.setInlineResourceTextBelowSize(appProperties.getInline_resource_storage_below_size()); |
| 228 | + Integer inlineResourceThreshold = appProperties.getInline_resource_storage_below_size(); |
| 229 | + if (inlineResourceThreshold == null |
| 230 | + && appProperties.getBinary_storage_mode() == AppProperties.BinaryStorageMode.FILESYSTEM) { |
| 231 | + inlineResourceThreshold = resolveFilesystemMinimumBinarySize(appProperties); |
| 232 | + } |
| 233 | + if (inlineResourceThreshold != null && inlineResourceThreshold != 0) { |
| 234 | + jpaStorageSettings.setInlineResourceTextBelowSize(inlineResourceThreshold); |
227 | 235 | }
|
228 | 236 |
|
229 | 237 | jpaStorageSettings.setStoreResourceInHSearchIndex(appProperties.getStore_resource_in_lucene_index_enabled());
|
@@ -342,15 +350,39 @@ public HibernatePropertiesProvider jpaStarterDialectProvider(
|
342 | 350 | @Lazy
|
343 | 351 | @Bean
|
344 | 352 | public IBinaryStorageSvc binaryStorageSvc(AppProperties appProperties) {
|
345 |
| - DatabaseBinaryContentStorageSvcImpl binaryStorageSvc = new DatabaseBinaryContentStorageSvcImpl(); |
| 353 | + IBinaryStorageSvc binaryStorageSvc; |
| 354 | + |
| 355 | + if (appProperties.getBinary_storage_mode() == AppProperties.BinaryStorageMode.FILESYSTEM) { |
| 356 | + String baseDirectory = appProperties.getBinary_storage_filesystem_base_directory(); |
| 357 | + Assert.hasText( |
| 358 | + baseDirectory, |
| 359 | + "binary_storage_filesystem_base_directory must be provided when binary_storage_mode=FILESYSTEM"); |
| 360 | + |
| 361 | + FilesystemBinaryStorageSvcImpl filesystemSvc = new FilesystemBinaryStorageSvcImpl(baseDirectory); |
| 362 | + int minimumBinarySize = resolveFilesystemMinimumBinarySize(appProperties); |
| 363 | + filesystemSvc.setMinimumBinarySize(minimumBinarySize); |
| 364 | + |
| 365 | + if (appProperties.getMax_binary_size() != null) { |
| 366 | + filesystemSvc.setMaximumBinarySize(appProperties.getMax_binary_size().longValue()); |
| 367 | + } |
346 | 368 |
|
347 |
| - if (appProperties.getMax_binary_size() != null) { |
348 |
| - binaryStorageSvc.setMaximumBinarySize(appProperties.getMax_binary_size()); |
| 369 | + binaryStorageSvc = filesystemSvc; |
| 370 | + } else { |
| 371 | + DatabaseBinaryContentStorageSvcImpl databaseSvc = new DatabaseBinaryContentStorageSvcImpl(); |
| 372 | + if (appProperties.getMax_binary_size() != null) { |
| 373 | + databaseSvc.setMaximumBinarySize(appProperties.getMax_binary_size()); |
| 374 | + } |
| 375 | + binaryStorageSvc = databaseSvc; |
349 | 376 | }
|
350 | 377 |
|
351 | 378 | return binaryStorageSvc;
|
352 | 379 | }
|
353 | 380 |
|
| 381 | + private int resolveFilesystemMinimumBinarySize(AppProperties appProperties) { |
| 382 | + Integer inlineThreshold = appProperties.getInline_resource_storage_below_size(); |
| 383 | + return inlineThreshold == null ? DEFAULT_FILESYSTEM_INLINE_THRESHOLD : inlineThreshold; |
| 384 | + } |
| 385 | + |
354 | 386 | @Bean
|
355 | 387 | public IEmailSender emailSender(AppProperties appProperties) {
|
356 | 388 | if (appProperties.getSubscription() != null
|
|
0 commit comments