From 16039af110ca3cf84fb569c2a4d5a02a79a212bb Mon Sep 17 00:00:00 2001 From: Tadgh Date: Fri, 26 Jun 2020 13:15:31 -0700 Subject: [PATCH] Fix up samlpe starters --- .../job/BulkExportJobParameterValidator.java | 1 - .../autoconfigure/FhirAutoConfiguration.java | 17 ++++++------ .../FhirAutoConfigurationTest.java | 26 +++++-------------- .../src/main/resources/application.yml | 5 ++++ 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/BulkExportJobParameterValidator.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/BulkExportJobParameterValidator.java index 67be46efa14..b65110c8fd2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/BulkExportJobParameterValidator.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/job/BulkExportJobParameterValidator.java @@ -49,7 +49,6 @@ public class BulkExportJobParameterValidator implements JobParametersValidator { Long readChunkSize = theJobParameters.getLong("readChunkSize"); if (readChunkSize == null || readChunkSize < 1) { errorBuilder.append("There must be a valid number for readChunkSize, which is at least 1. "); - } String jobUUID = theJobParameters.getString("jobUUID"); Optional oJob = myBulkExportJobDao.findByJobId(jobUUID); diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java index b75e62db531..51b42fd567a 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java @@ -90,14 +90,6 @@ import java.util.concurrent.ScheduledExecutorService; @EnableConfigurationProperties(FhirProperties.class) public class FhirAutoConfiguration { - @Autowired - private EntityManagerFactory emf; - - @Bean - @Primary - public PlatformTransactionManager hapiTransactionManager() { - return new JpaTransactionManager(emf); - } private final FhirProperties properties; @@ -191,6 +183,15 @@ public class FhirAutoConfiguration { }) static class FhirJpaDaoConfiguration { + @Autowired + private EntityManagerFactory emf; + + @Bean + @Primary + public PlatformTransactionManager hapiTransactionManager() { + return new JpaTransactionManager(emf); + } + @Bean @ConditionalOnMissingBean @ConfigurationProperties("hapi.fhir.jpa") diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java index 2f1189ea54d..5c8cbdf615a 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java @@ -16,7 +16,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.web.servlet.ServletRegistrationBean; @@ -25,8 +24,6 @@ import org.springframework.mock.env.MockEnvironment; import java.net.URL; import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -83,7 +80,11 @@ public class FhirAutoConfigurationTest { @Test public void withJpaServer() { - load("hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + load(Arrays.array(EmbeddedDataSourceConfiguration.class, + HibernateJpaAutoConfiguration.class, + FhirAutoConfiguration.class), + "hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1); assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1); } @@ -131,14 +132,11 @@ public class FhirAutoConfigurationTest { } private void load(String... environment) { - load(new Class[]{EmbeddedDataSourceConfiguration.class,HibernateJpaAutoConfiguration.class,PropertyPlaceholderAutoConfiguration.class, FhirAutoConfiguration.class}, null, environment); - - - + load(new Class[]{FhirAutoConfiguration.class}, null, environment); } private void load(ClassLoader classLoader, String... environment) { - load(new Class[]{EmbeddedDataSourceConfiguration.class,HibernateJpaAutoConfiguration.class,PropertyPlaceholderAutoConfiguration.class, FhirAutoConfiguration.class}, classLoader, environment); + load(new Class[]{FhirAutoConfiguration.class}, classLoader, environment); } private void load(Class[] configs, String... environment) { @@ -146,18 +144,8 @@ public class FhirAutoConfigurationTest { } private void load(Class[] configs, ClassLoader classLoader, String... environment) { - List baseEnv = new ArrayList<>(); - baseEnv.add("hapi.fhir.version:DSTU3"); - baseEnv.add("spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); - baseEnv.add("spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles"); - MockEnvironment env = new MockEnvironment(); - for (String next: baseEnv) { - String nextKey = next.substring(0, next.indexOf(':')); - String nextValue = next.substring(next.indexOf(':') + 1); - env.setProperty(nextKey, nextValue); - } for (String next : environment) { String nextKey = next.substring(0, next.indexOf(':')); String nextValue = next.substring(next.indexOf(':') + 1); diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/main/resources/application.yml b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/main/resources/application.yml index 441dd26f0af..b63b06bf401 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/main/resources/application.yml +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/main/resources/application.yml @@ -13,9 +13,14 @@ spring: hibernate.search.lucene_version: LUCENE_CURRENT hibernate.search.model_mapping: ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory + main: + allow-bean-definition-overriding: true h2: console: enabled: true + batch: + job: + enabled: false hapi: fhir: version: DSTU3