From eeac5e6ac04fd3faca95da48bb94554881e390cd Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 16 Oct 2015 08:57:07 -0400 Subject: [PATCH] Java config almost working --- hapi-fhir-jpaserver-base/pom.xml | 2 + .../ca/uhn/fhir/jpa/config/BaseConfig.java | 47 ++++++++++++++++--- .../uhn/fhir/jpa/config/BaseDstu1Config.java | 8 ++++ .../uhn/fhir/jpa/config/BaseDstu2Config.java | 32 +++++++++---- .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 9 ++-- .../java/ca/uhn/fhir/jpa/dao/DaoConfig.java | 9 ++++ .../FhirResourceDaoSearchParameterDstu2.java | 6 ++- .../dao/FhirResourceDaoSubscriptionDstu2.java | 8 ++++ .../ca/uhn/fhir/jpa/dao/FhirSearchDao.java | 3 ++ .../main/java/ca/uhn/fhir/jpa/dao/IDao.java | 4 ++ .../dao/IFhirResourceDaoSearchParameter.java | 4 +- .../jpa/dao/IFhirResourceDaoSubscription.java | 2 + .../SubscriptionWebsocketHandler.java | 1 + .../uhn/fhir/jpa/config/TestDstu1Config.java | 1 - .../uhn/fhir/jpa/config/TestDstu2Config.java | 3 +- .../jpa/dao/FhirResourceDaoDstu1Test.java | 3 +- .../FhirResourceDaoDstu2SearchNoFtTest.java | 3 ++ .../FhirResourceDaoDstu2SubscriptionTest.java | 9 ++++ .../jpa/provider/SubscriptionsDstu2Test.java | 6 +++ .../fhir/tinder/TinderJpaRestServerMojo.java | 14 ++++-- .../resources/vm/jpa_spring_beans_java.vm | 19 +------- 21 files changed, 149 insertions(+), 44 deletions(-) diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index 3574d7ea8e9..6bc01618bdb 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -327,6 +327,7 @@ dstu + ca.uhn.fhir.jpa.config ca.uhn.fhir.jpa.rp.dstu hapi-fhir-server-resourceproviders-dstu1.xml @@ -339,6 +340,7 @@ dstu2 + ca.uhn.fhir.jpa.config ca.uhn.fhir.jpa.rp.dstu2 hapi-fhir-server-resourceproviders-dstu2.xml diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index 8fca233bfc8..383c5f1c5a3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -1,19 +1,33 @@ package ca.uhn.fhir.jpa.config; +import javax.annotation.Resource; + +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; import ca.uhn.fhir.context.FhirContext; @Configuration -public class BaseConfig { +@EnableScheduling +@EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data") +public class BaseConfig implements SchedulingConfigurer { private static FhirContext ourFhirContextDstu2; private static FhirContext ourFhirContextDstu1; private static FhirContext ourFhirContextDstu2Hl7Org; - @Bean(name="myFhirContextDstu2") + @Resource + private ApplicationContext myAppCtx; + + @Bean(name = "myFhirContextDstu2") @Lazy public FhirContext fhirContextDstu2() { if (ourFhirContextDstu2 == null) { @@ -21,8 +35,8 @@ public class BaseConfig { } return ourFhirContextDstu2; } - - @Bean(name="myFhirContextDstu1") + + @Bean(name = "myFhirContextDstu1") @Lazy public FhirContext fhirContextDstu1() { if (ourFhirContextDstu1 == null) { @@ -30,8 +44,8 @@ public class BaseConfig { } return ourFhirContextDstu1; } - - @Bean(name="myFhirContextDstu2Hl7Org") + + @Bean(name = "myFhirContextDstu2Hl7Org") @Lazy public FhirContext fhirContextDstu2Hl7Org() { if (ourFhirContextDstu2Hl7Org == null) { @@ -40,4 +54,25 @@ public class BaseConfig { return ourFhirContextDstu2Hl7Org; } + @Override + public void configureTasks(ScheduledTaskRegistrar theTaskRegistrar) { + theTaskRegistrar.setTaskScheduler(taskScheduler()); + } + + @Bean + public TaskScheduler taskScheduler() { + ThreadPoolTaskScheduler retVal = new ThreadPoolTaskScheduler(); + retVal.setPoolSize(5); + return retVal; + } + + // @PostConstruct + // public void wireResourceDaos() { + // Map daoBeans = myAppCtx.getBeansOfType(IDao.class); + // List bean = myAppCtx.getBean("myResourceProvidersDstu2", List.class); + // for (IDao next : daoBeans.values()) { + // next.setResourceDaos(bean); + // } + // } + } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu1Config.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu1Config.java index 1746a491d1c..78b24f7ec90 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu1Config.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu1Config.java @@ -5,12 +5,20 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @Configuration public class BaseDstu1Config extends BaseConfig { + @Bean + @Primary + public FhirContext defaultFhirContext() { + return fhirContextDstu1(); + } + @Bean(name = "mySystemDaoDstu1", autowire = Autowire.BY_NAME) public ca.uhn.fhir.jpa.dao.IFhirSystemDao> fhirSystemDaoDstu1() { ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu1 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu1(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java index 1a8202ec4f3..f9878a3cdb6 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseDstu2Config.java @@ -3,7 +3,9 @@ package ca.uhn.fhir.jpa.config; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.context.annotation.Primary; +import org.springframework.scheduling.TaskScheduler; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.config.annotation.EnableWebSocket; @@ -11,6 +13,7 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer; import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.dao.FhirSearchDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.ISearchDao; @@ -19,19 +22,24 @@ import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandler; @Configuration @EnableTransactionManagement @EnableWebSocket() -@EnableScheduling public class BaseDstu2Config extends BaseConfig implements WebSocketConfigurer { + @Bean + @Primary + public FhirContext defaultFhirContext() { + return fhirContextDstu2(); + } + @Bean(name = "mySystemDaoDstu2", autowire = Autowire.BY_NAME) - public IFhirSystemDao fhirSystemDaoDstu2() { + public IFhirSystemDao systemDaoDstu2() { ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2 retVal = new ca.uhn.fhir.jpa.dao.FhirSystemDaoDstu2(); return retVal; } @Bean(name = "mySystemProviderDstu2") - public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 systemDaoDstu2() { + public ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 systemProviderDstu2() { ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2 retVal = new ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2(); - retVal.setDao(fhirSystemDaoDstu2()); + retVal.setDao(systemDaoDstu2()); return retVal; } @@ -42,8 +50,8 @@ public class BaseDstu2Config extends BaseConfig implements WebSocketConfigurer { } @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(subscriptionWebSocketHandler(), "/websocket/dstu2").withSockJS(); + public void registerWebSocketHandlers(WebSocketHandlerRegistry theRegistry) { + theRegistry.addHandler(subscriptionWebSocketHandler(), "/websocket/dstu2"); } @Bean(autowire = Autowire.BY_TYPE) @@ -51,9 +59,17 @@ public class BaseDstu2Config extends BaseConfig implements WebSocketConfigurer { return new PerConnectionWebSocketHandler(SubscriptionWebsocketHandler.class); } + @Bean + public TaskScheduler websocketTaskScheduler() { + ThreadPoolTaskScheduler retVal = new ThreadPoolTaskScheduler(); + retVal.setPoolSize(5); + return retVal; + } + @Bean(autowire = Autowire.BY_TYPE) public ISearchDao searchDao() { - return new FhirSearchDao(); + FhirSearchDao searchDao = new FhirSearchDao(); + return searchDao; } //