feat: add BinaryStorageInterceptorRegistrar for conditional interceptor registration, register against JPA interceptor service to also be triggered on dao level (e.g. bulk export)

This commit is contained in:
Patrick Werner
2026-02-16 11:55:17 +01:00
parent 78a068ab45
commit f4db064f92
2 changed files with 41 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
package ca.uhn.fhir.jpa.starter.common;
import ca.uhn.fhir.IHapiBootOrder;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor;
import ca.uhn.fhir.jpa.starter.AppProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
public class BinaryStorageInterceptorRegistrar {
private static final Logger ourLog = LoggerFactory.getLogger(BinaryStorageInterceptorRegistrar.class);
private final IInterceptorService myInterceptorService;
private final BinaryStorageInterceptor<?> myBinaryStorageInterceptor;
private final AppProperties myAppProperties;
public BinaryStorageInterceptorRegistrar(
IInterceptorService theInterceptorService,
BinaryStorageInterceptor<?> theBinaryStorageInterceptor,
AppProperties theAppProperties) {
myInterceptorService = theInterceptorService;
myBinaryStorageInterceptor = theBinaryStorageInterceptor;
myAppProperties = theAppProperties;
}
@EventListener(classes = {ContextRefreshedEvent.class})
@Order(IHapiBootOrder.REGISTER_INTERCEPTORS)
public void register() {
if (!myAppProperties.getBinary_storage_enabled()) {
ourLog.debug("Binary storage disabled; skipping BinaryStorageInterceptor registration");
return;
}
ourLog.info("Registering BinaryStorageInterceptor with JPA interceptor service");
myInterceptorService.registerInterceptor(myBinaryStorageInterceptor);
}
}

View File

@@ -15,7 +15,6 @@ import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.api.config.ThreadPoolFactoryConfig; import ca.uhn.fhir.jpa.api.config.ThreadPoolFactoryConfig;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor;
import ca.uhn.fhir.jpa.binary.provider.BinaryAccessProvider; import ca.uhn.fhir.jpa.binary.provider.BinaryAccessProvider;
import ca.uhn.fhir.jpa.config.util.HapiEntityManagerFactoryUtil; import ca.uhn.fhir.jpa.config.util.HapiEntityManagerFactoryUtil;
import ca.uhn.fhir.jpa.config.util.ResourceCountCacheUtil; import ca.uhn.fhir.jpa.config.util.ResourceCountCacheUtil;
@@ -323,7 +322,6 @@ public class StarterJpaConfig {
Optional<CorsInterceptor> corsInterceptor, Optional<CorsInterceptor> corsInterceptor,
IInterceptorBroadcaster interceptorBroadcaster, IInterceptorBroadcaster interceptorBroadcaster,
Optional<BinaryAccessProvider> binaryAccessProvider, Optional<BinaryAccessProvider> binaryAccessProvider,
BinaryStorageInterceptor binaryStorageInterceptor,
IValidatorModule validatorModule, IValidatorModule validatorModule,
Optional<GraphQLProvider> graphQLProvider, Optional<GraphQLProvider> graphQLProvider,
BulkDataExportProvider bulkDataExportProvider, BulkDataExportProvider bulkDataExportProvider,
@@ -455,7 +453,6 @@ public class StarterJpaConfig {
// Binary Storage // Binary Storage
if (appProperties.getBinary_storage_enabled() && binaryAccessProvider.isPresent()) { if (appProperties.getBinary_storage_enabled() && binaryAccessProvider.isPresent()) {
fhirServer.registerProvider(binaryAccessProvider.get()); fhirServer.registerProvider(binaryAccessProvider.get());
fhirServer.registerInterceptor(binaryStorageInterceptor);
} }
// Validation // Validation