diff --git a/pom.xml b/pom.xml index 7653c5c55..6981c8753 100644 --- a/pom.xml +++ b/pom.xml @@ -217,6 +217,17 @@ + + io.smallrye + jandex-maven-plugin + 3.2.7 + + + make-index + jandex + + + com.qmino miredot-plugin diff --git a/src/main/java/org/ohdsi/webapi/CacheConfig.java b/src/main/java/org/ohdsi/webapi/CacheConfig.java index 8e9eecf41..da855bc67 100644 --- a/src/main/java/org/ohdsi/webapi/CacheConfig.java +++ b/src/main/java/org/ohdsi/webapi/CacheConfig.java @@ -2,8 +2,10 @@ import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; @Configuration +@Lazy(false) @EnableCaching public class CacheConfig { diff --git a/src/main/java/org/ohdsi/webapi/DataAccessConfig.java b/src/main/java/org/ohdsi/webapi/DataAccessConfig.java index fa585bf6b..f94e1dc37 100644 --- a/src/main/java/org/ohdsi/webapi/DataAccessConfig.java +++ b/src/main/java/org/ohdsi/webapi/DataAccessConfig.java @@ -11,6 +11,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @@ -36,6 +37,7 @@ * */ @Configuration +@Lazy(false) @EnableTransactionManagement @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class) public class DataAccessConfig { diff --git a/src/main/java/org/ohdsi/webapi/FlywayConfig.java b/src/main/java/org/ohdsi/webapi/FlywayConfig.java index e4523178c..f369cb6b2 100644 --- a/src/main/java/org/ohdsi/webapi/FlywayConfig.java +++ b/src/main/java/org/ohdsi/webapi/FlywayConfig.java @@ -9,6 +9,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; import com.zaxxer.hikari.HikariDataSource; @@ -19,6 +20,7 @@ * Java-based migrations can access Spring beans via the static ApplicationContextHolder. */ @Configuration +@Lazy(false) @ConditionalOnProperty(prefix = "spring.flyway", name = "enabled", matchIfMissing = true) public class FlywayConfig { diff --git a/src/main/java/org/ohdsi/webapi/JobConfig.java b/src/main/java/org/ohdsi/webapi/JobConfig.java index 4164ba77d..60807390f 100644 --- a/src/main/java/org/ohdsi/webapi/JobConfig.java +++ b/src/main/java/org/ohdsi/webapi/JobConfig.java @@ -26,6 +26,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Primary; import org.springframework.core.task.TaskExecutor; import org.springframework.jdbc.core.JdbcTemplate; @@ -36,6 +37,7 @@ * Spring Batch 5.x configuration for Java 21 / Spring Boot 3.2 */ @Configuration +@Lazy(false) @EnableBatchProcessing public class JobConfig { diff --git a/src/main/java/org/ohdsi/webapi/JobInvalidator.java b/src/main/java/org/ohdsi/webapi/JobInvalidator.java index cfe17febe..442001e37 100644 --- a/src/main/java/org/ohdsi/webapi/JobInvalidator.java +++ b/src/main/java/org/ohdsi/webapi/JobInvalidator.java @@ -9,15 +9,15 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; import org.springframework.transaction.support.TransactionTemplate; -import jakarta.annotation.PostConstruct; import java.util.Calendar; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; + @Component -@DependsOn("flyway") public class JobInvalidator { private static final Logger log = LoggerFactory.getLogger(JobInvalidator.class); @@ -37,8 +37,8 @@ public JobInvalidator(JobRepository repository, this.jobExecutionDao = jobExecutionDao; } - @PostConstruct - private void invalidateGenerations() { + @EventListener(ApplicationReadyEvent.class) + public void invalidateGenerations() { transactionTemplateRequiresNew.execute(s -> { jobExecutionDao.getRunningJobExecutions().forEach(this::invalidationJobExecution); return null; diff --git a/src/main/java/org/ohdsi/webapi/LogConfiguration.java b/src/main/java/org/ohdsi/webapi/LogConfiguration.java deleted file mode 100644 index 419234945..000000000 --- a/src/main/java/org/ohdsi/webapi/LogConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.ohdsi.webapi; - -// import org.ohdsi.webapi.arachne.logging.LoggingEventMessageFactory; // Not needed -// import org.ohdsi.webapi.arachne.logging.LoggingService; // Not needed -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class LogConfiguration { - - // Commented out - LoggingService and LoggingEventMessageFactory not available - // These were part of Arachne logging dependency that was removed - /* - @Bean - public LoggingEventMessageFactory loggingEventMessageFactory(){ - return new LoggingEventMessageFactory(); - } - - @Bean - public LoggingService loggingService(LoggingEventMessageFactory factory){ - return new LoggingService(factory); - } - */ -} diff --git a/src/main/java/org/ohdsi/webapi/SchedulerConfiguration.java b/src/main/java/org/ohdsi/webapi/SchedulerConfiguration.java index f00510021..d27934b68 100644 --- a/src/main/java/org/ohdsi/webapi/SchedulerConfiguration.java +++ b/src/main/java/org/ohdsi/webapi/SchedulerConfiguration.java @@ -4,12 +4,14 @@ import com.cronutils.model.definition.CronDefinitionBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import static com.cronutils.model.CronType.QUARTZ; @Configuration +@Lazy(false) public class SchedulerConfiguration { @Bean diff --git a/src/main/java/org/ohdsi/webapi/ShiroConfiguration.java b/src/main/java/org/ohdsi/webapi/ShiroConfiguration.java index 301998d59..12fa38dff 100644 --- a/src/main/java/org/ohdsi/webapi/ShiroConfiguration.java +++ b/src/main/java/org/ohdsi/webapi/ShiroConfiguration.java @@ -9,10 +9,7 @@ import org.apache.shiro.web.servlet.AbstractShiroFilter; import org.ohdsi.webapi.shiro.AtlasWebSecurityManager; import org.ohdsi.webapi.shiro.lockout.*; -import org.ohdsi.webapi.shiro.management.DataSourceAccessBeanPostProcessor; -import org.ohdsi.webapi.shiro.management.DisabledSecurity; import org.ohdsi.webapi.shiro.management.Security; -import org.ohdsi.webapi.shiro.management.datasource.DataSourceAccessParameterResolver; import org.ohdsi.webapi.shiro.realms.JwtAuthRealm; import org.ohdsi.webapi.shiro.subject.WebDelegatingRunAsSubjectFactory; import org.slf4j.Logger; @@ -20,13 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Lazy; import jakarta.servlet.Filter; import java.util.Map; @@ -37,6 +34,7 @@ */ @Configuration +@Lazy(false) public class ShiroConfiguration { private static final Logger log = LoggerFactory.getLogger(ShiroConfiguration.class); @@ -47,8 +45,6 @@ public class ShiroConfiguration { private long initialDuration; @Value("${security.duration.increment}") private long increment; - @Value("${spring.aop.proxy-target-class:false}") - private Boolean proxyTargetClass; @Autowired protected ApplicationEventPublisher eventPublisher; @@ -121,13 +117,6 @@ public LockoutStrategy lockoutStrategy() { return new ExponentLockoutStrategy(initialDuration, increment, maxLoginAttempts); } - @Bean - @ConditionalOnMissingBean(value = DisabledSecurity.class) - public DataSourceAccessBeanPostProcessor dataSourceAccessBeanPostProcessor(DataSourceAccessParameterResolver parameterResolver) { - - return new DataSourceAccessBeanPostProcessor(parameterResolver, proxyTargetClass); - } - /** * Register the Shiro filter with the servlet container. * This is necessary for Spring Boot to properly apply the filter to all requests. diff --git a/src/main/java/org/ohdsi/webapi/exampleapplication/ExampleApplicationConfig.java b/src/main/java/org/ohdsi/webapi/exampleapplication/ExampleApplicationConfig.java deleted file mode 100644 index 5f89eb043..000000000 --- a/src/main/java/org/ohdsi/webapi/exampleapplication/ExampleApplicationConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.ohdsi.webapi.exampleapplication; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.Configuration; - -/** - * - */ -@Configuration -public class ExampleApplicationConfig { - - private static final Logger log = LoggerFactory.getLogger(ExampleApplicationConfig.class); - - //random @Beans -} diff --git a/src/main/java/org/ohdsi/webapi/security/PermissionService.java b/src/main/java/org/ohdsi/webapi/security/PermissionService.java index 9516cede5..924b563f4 100644 --- a/src/main/java/org/ohdsi/webapi/security/PermissionService.java +++ b/src/main/java/org/ohdsi/webapi/security/PermissionService.java @@ -43,8 +43,10 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.WebApplicationContext; -import jakarta.annotation.PostConstruct; import java.io.Serializable; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -106,8 +108,8 @@ public PermissionService( this.conversionService = conversionService; } - @PostConstruct - private void postConstruct() { + @EventListener(ApplicationReadyEvent.class) + public void postConstruct() { this.repositories = new Repositories(appContext); diff --git a/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java b/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java index 825c7be5e..d7ffecdf0 100644 --- a/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java +++ b/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java @@ -34,11 +34,9 @@ import org.springframework.batch.core.job.builder.SimpleJobBuilder; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.step.builder.StepBuilder; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.DependsOn; import org.springframework.core.convert.ConversionService; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -52,8 +50,11 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.web.server.ResponseStatusException; +import jakarta.annotation.PostConstruct; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Collection; @@ -79,8 +80,7 @@ */ @RestController @RequestMapping("/cdmresults") -@DependsOn({"jobInvalidator", "flyway"}) -public class CDMResultsService extends AbstractDaoService implements InitializingBean { +public class CDMResultsService extends AbstractDaoService { private final Logger logger = LoggerFactory.getLogger(CDMResultsService.class); private static final String CONCEPT_COUNT_SQL = "/resources/cdmresults/sql/getConceptRecordCount.sql"; @@ -135,9 +135,13 @@ public class CDMResultsService extends AbstractDaoService implements Initializin @Autowired private ConversionService conversionService; - @Override - public void afterPropertiesSet() throws Exception { + @PostConstruct + public void initQueryRunner() { queryRunner.init(this.getSourceDialect(), objectMapper); + } + + @EventListener(ApplicationReadyEvent.class) + public void onApplicationReady() { warmCaches(); } diff --git a/src/main/java/org/ohdsi/webapi/service/CohortGenerationService.java b/src/main/java/org/ohdsi/webapi/service/CohortGenerationService.java index 27f19c998..5eb952727 100644 --- a/src/main/java/org/ohdsi/webapi/service/CohortGenerationService.java +++ b/src/main/java/org/ohdsi/webapi/service/CohortGenerationService.java @@ -31,7 +31,6 @@ import org.springframework.batch.repeat.exception.ExceptionHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.DependsOn; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; import org.springframework.transaction.PlatformTransactionManager; @@ -39,9 +38,10 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.support.TransactionTemplate; -import jakarta.annotation.PostConstruct; - import java.util.Arrays; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import java.util.Calendar; import java.util.List; import java.util.Objects; @@ -57,7 +57,6 @@ import static org.ohdsi.webapi.Constants.Params.DEMOGRAPHIC_STATS; @Component -@DependsOn("flyway") public class CohortGenerationService extends AbstractDaoService implements GeneratesNotification { private final CohortDefinitionRepository cohortDefinitionRepository; @@ -193,7 +192,7 @@ private JobParametersBuilder getJobParametersBuilder(Source source, CohortDefini return builder; } - @PostConstruct + @EventListener(ApplicationReadyEvent.class) public void init(){ invalidateCohortGenerations(); diff --git a/src/main/java/org/ohdsi/webapi/shiro/annotations/CcGenerationId.java b/src/main/java/org/ohdsi/webapi/shiro/annotations/CcGenerationId.java deleted file mode 100644 index 8c6e7b278..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/annotations/CcGenerationId.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.ohdsi.webapi.shiro.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface CcGenerationId { -} diff --git a/src/main/java/org/ohdsi/webapi/shiro/annotations/DataSourceAccess.java b/src/main/java/org/ohdsi/webapi/shiro/annotations/DataSourceAccess.java deleted file mode 100644 index 4e7dc6d30..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/annotations/DataSourceAccess.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.ohdsi.webapi.shiro.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface DataSourceAccess { -} diff --git a/src/main/java/org/ohdsi/webapi/shiro/annotations/SourceId.java b/src/main/java/org/ohdsi/webapi/shiro/annotations/SourceId.java deleted file mode 100644 index 373e7cae7..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/annotations/SourceId.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.ohdsi.webapi.shiro.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface SourceId { -} diff --git a/src/main/java/org/ohdsi/webapi/shiro/annotations/SourceKey.java b/src/main/java/org/ohdsi/webapi/shiro/annotations/SourceKey.java deleted file mode 100644 index 1ca842b5c..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/annotations/SourceKey.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.ohdsi.webapi.shiro.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface SourceKey { -} diff --git a/src/main/java/org/ohdsi/webapi/shiro/management/DataSourceAccessBeanPostProcessor.java b/src/main/java/org/ohdsi/webapi/shiro/management/DataSourceAccessBeanPostProcessor.java deleted file mode 100644 index f72e07e93..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/management/DataSourceAccessBeanPostProcessor.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.ohdsi.webapi.shiro.management; - -import org.aopalliance.intercept.MethodInterceptor; -import org.ohdsi.webapi.shiro.annotations.DataSourceAccess; -import org.ohdsi.webapi.shiro.management.datasource.AccessorParameterBinding; -import org.ohdsi.webapi.shiro.management.datasource.DataSourceAccessParameterResolver; -import org.ohdsi.webapi.util.AnnotationReflectionUtils; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Method; -import java.util.*; - -public class DataSourceAccessBeanPostProcessor implements BeanPostProcessor { - - private Boolean proxyTargetClass; - - private DataSourceAccessParameterResolver accessParameterResolver; - - public DataSourceAccessBeanPostProcessor(DataSourceAccessParameterResolver accessParameterResolver, Boolean proxyTargetClass) { - - this.accessParameterResolver = accessParameterResolver; - this.proxyTargetClass = proxyTargetClass; - } - - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - - return bean; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - - Class type = bean.getClass(); - final List annotatedMethods = getMethodsAnnotatedWith(type); - Object result = bean; - if (!annotatedMethods.isEmpty()) { - ProxyFactory factory = new ProxyFactory(bean); - factory.setProxyTargetClass(proxyTargetClass); - factory.addAdvice((MethodInterceptor) invocation -> { - Method method = invocation.getMethod(); - Object[] args = invocation.getArguments(); - Optional originalAnnotatedMethod = annotatedMethods.stream().filter(m -> - Objects.equals(m.getName(), method.getName()) - && Objects.equals(m.getReturnType(), method.getReturnType()) - && Arrays.equals(m.getParameterTypes(), method.getParameterTypes())).findFirst(); - if (originalAnnotatedMethod.isPresent()) { - AccessorParameterBinding binding = accessParameterResolver.resolveParameterBinding(originalAnnotatedMethod.get()); - if (Objects.nonNull(binding)) { - Object value = args[binding.getParameterIndex()]; - binding.getDataSourceAccessor().checkAccess(value); - } - } - return method.invoke(bean, args); - }); - result = factory.getProxy(); - } - return result; - } - - private Method findMethod(Method m1, Method m2) { - if (m2.getDeclaringClass().isAssignableFrom(m2.getDeclaringClass())) { - if (Objects.equals(m1.getName(), m2.getName())) { - return ReflectionUtils.findMethod(m1.getDeclaringClass(), m1.getName(), m1.getParameterTypes()); - } - } - return null; - } - - private List getMethodsAnnotatedWith(final Class type) { - List methods = AnnotationReflectionUtils.getMethodsAnnotatedWith(type, DataSourceAccess.class); - methods.forEach(m -> { - if (Objects.isNull(accessParameterResolver.resolveParameterBinding(m))) { - throw new BeanInitializationException(String.format("One of method: %s parameters should be annotated with SourceKey of CcGenerationId", m.toString())); - } - }); - return methods; - } - - -} diff --git a/src/main/java/org/ohdsi/webapi/shiro/management/DisabledSecurity.java b/src/main/java/org/ohdsi/webapi/shiro/management/DisabledSecurity.java index 249ad749f..55cd5ae7e 100644 --- a/src/main/java/org/ohdsi/webapi/shiro/management/DisabledSecurity.java +++ b/src/main/java/org/ohdsi/webapi/shiro/management/DisabledSecurity.java @@ -12,7 +12,6 @@ import org.ohdsi.webapi.shiro.filters.CorsFilter; import org.ohdsi.webapi.shiro.filters.HideResourceFilter; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @@ -25,7 +24,6 @@ @Component @Primary @ConditionalOnProperty(name = "security.provider", havingValue = Constants.SecurityProviders.DISABLED) -@DependsOn("flyway") public class DisabledSecurity extends Security { @Override diff --git a/src/main/java/org/ohdsi/webapi/shiro/management/datasource/AccessorParameterBinding.java b/src/main/java/org/ohdsi/webapi/shiro/management/datasource/AccessorParameterBinding.java deleted file mode 100644 index 18855c209..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/management/datasource/AccessorParameterBinding.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.ohdsi.webapi.shiro.management.datasource; - -public class AccessorParameterBinding { - private Integer parameterIndex; - private DataSourceAccessor dataSourceAccessor; - - public AccessorParameterBinding(Integer parameterIndex, DataSourceAccessor dataSourceAccessor) { - this.parameterIndex = parameterIndex; - this.dataSourceAccessor = dataSourceAccessor; - } - - public Integer getParameterIndex() { - return parameterIndex; - } - - public DataSourceAccessor getDataSourceAccessor() { - return dataSourceAccessor; - } - -} diff --git a/src/main/java/org/ohdsi/webapi/shiro/management/datasource/DataSourceAccessParameterResolver.java b/src/main/java/org/ohdsi/webapi/shiro/management/datasource/DataSourceAccessParameterResolver.java deleted file mode 100644 index eccb9c767..000000000 --- a/src/main/java/org/ohdsi/webapi/shiro/management/datasource/DataSourceAccessParameterResolver.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.ohdsi.webapi.shiro.management.datasource; - -import org.ohdsi.webapi.shiro.annotations.SourceId; -import org.ohdsi.webapi.shiro.annotations.SourceKey; -import org.ohdsi.webapi.source.Source; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Objects; - -@Component -public class DataSourceAccessParameterResolver { - - @Autowired - private SourceKeyAccessor sourceKeyAccessor; - - @Autowired - private SourceIdAccessor sourceIdAccessor; - - @Autowired - private SourceAccessor sourceAccessor; - - public AccessorParameterBinding resolveParameterBinding(Method method){ - Annotation[][] annotations = method.getParameterAnnotations(); - for(int i = 0; i < annotations.length; i++) { - DataSourceAccessor result = null; - if (isAnnotated(annotations[i], SourceKey.class)) { - result = sourceKeyAccessor; - } else if (isAnnotated(annotations[i], SourceId.class)) { - result = sourceIdAccessor; - } - if (Objects.nonNull(result)) { - return new AccessorParameterBinding(i, result); - } - } - Class[] parameterTypes = method.getParameterTypes(); - for(int i = 0; i < parameterTypes.length; i++) { - if (parameterTypes[i].isAssignableFrom(Source.class)) { - return new AccessorParameterBinding(i, sourceAccessor); - } - } - return null; - } - - private boolean isAnnotated(Annotation[] annotations, Class annotation) { - return Arrays.stream(annotations).anyMatch(annotation::isInstance); - } - -} diff --git a/src/main/java/org/ohdsi/webapi/source/SourceService.java b/src/main/java/org/ohdsi/webapi/source/SourceService.java index 6fddf4e07..b5d332b2f 100644 --- a/src/main/java/org/ohdsi/webapi/source/SourceService.java +++ b/src/main/java/org/ohdsi/webapi/source/SourceService.java @@ -35,8 +35,10 @@ import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; -import jakarta.annotation.PostConstruct; import jakarta.persistence.PersistenceException; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import javax.cache.CacheManager; import org.springframework.context.annotation.Lazy; import javax.cache.configuration.MutableConfiguration; @@ -108,8 +110,8 @@ public SourceService(SourceRepository sourceRepository, this.publisher = publisher; } - @PostConstruct - private void postConstruct() { + @EventListener(ApplicationReadyEvent.class) + public void postConstruct() { ensureSourceEncrypted(); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 2bee6eb95..355cc5223 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -84,14 +84,6 @@ jasypt: password: "" jdbc: suppressInvalidApiException: true -jersey: - config: - server: - wadl: - disableWadl: true - resources: - root: - package: org.ohdsi.webapi kerberos: configPath: /etc/krb5.conf kinitPath: "" @@ -99,8 +91,6 @@ kerberos: logging: level: org: - apache: - shiro: warn hibernate: info ohdsi: info springframework: @@ -294,6 +284,8 @@ source: sparql: endpoint: http://virtuoso.ohdsi.org:8890/sparql?default-graph-uri=&query= spring: + main: + lazy-initialization: true autoconfigure: exclude: org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration batch: