Allow custom operations/providers in addition to interceptors (#654)

* Allow custom operations/providers to be added in the same way custom interceptors are currently loaded

* Add new property to documentation and default yaml file

* Add test for custom operation
This commit is contained in:
David Conlan
2024-03-04 02:39:03 +10:00
committed by GitHub
parent 3ea85a05aa
commit 4226648867
7 changed files with 193 additions and 0 deletions

View File

@@ -97,12 +97,16 @@ public class AppProperties {
private final List<String> custom_interceptor_classes = new ArrayList<>();
private final List<String> custom_provider_classes = new ArrayList<>();
public List<String> getCustomInterceptorClasses() {
return custom_interceptor_classes;
}
public List<String> getCustomProviderClasses() {
return custom_provider_classes;
}
public Boolean getOpenapi_enabled() {

View File

@@ -455,6 +455,9 @@ public class StarterJpaConfig {
fhirServer.registerProvider(theIpsOperationProvider.get());
}
// register custom providers
registerCustomProviders(fhirServer, appContext, appProperties.getCustomProviderClasses());
return fhirServer;
}
@@ -497,6 +500,45 @@ public class StarterJpaConfig {
}
}
/**
* check the properties for custom provider classes and registers them.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private void registerCustomProviders(
RestfulServer fhirServer, ApplicationContext theAppContext, List<String> customProviderClasses) {
if (customProviderClasses == null) {
return;
}
for (String className : customProviderClasses) {
Class clazz;
try {
clazz = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Provider class was not found on classpath: " + className, e);
}
// first check if the class a Bean in the app context
Object provider = null;
try {
provider = theAppContext.getBean(clazz);
} catch (NoSuchBeanDefinitionException ex) {
// no op - if it's not a bean we'll try to create it
}
// if not a bean, instantiate the interceptor via reflection
if (provider == null) {
try {
provider = clazz.getConstructor().newInstance();
} catch (Exception e) {
throw new ConfigurationException("Unable to instantiate provider class : " + className, e);
}
}
fhirServer.registerProvider(provider);
}
}
public static IServerConformanceProvider<?> calculateConformanceProvider(
IFhirSystemDao fhirSystemDao,
RestfulServer fhirServer,

View File

@@ -178,6 +178,11 @@ hapi:
# or will be instantiated via reflection using an no-arg contructor; then registered with the server
#custom-interceptor-classes:
# comma-separated list of fully qualified provider classes.
# classes listed here will be fetched from the Spring context when combined with 'custom-bean-packages',
# or will be instantiated via reflection using an no-arg contructor; then registered with the server
#custom-provider-classes:
# Threadpool size for BATCH'ed GETs in a bundle.
# bundle_batch_pool_size: 10
# bundle_batch_pool_max_size: 50