From e5f6c35aeab8bbc056870a038e1862181049a020 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 30 Jul 2017 19:31:18 -0400 Subject: [PATCH] More work on getting legacy code cleaned up --- .../fhir/android/BuiltJarDstu2ShadeIT.java | 3 +- .../fhir/rest/annotation/VersionIdParam.java | 36 ----- .../ca/uhn/fhir/rest/param/ParameterUtil.java | 4 - hapi-fhir-client/pom.xml | 7 + ...indingWithResourceIdButNoResourceBody.java | 6 - .../fhir/rest/client/method/MethodUtil.java | 2 +- .../rest/client/method/ReadMethodBinding.java | 23 +-- hapi-fhir-jacoco/pom.xml | 34 +++-- hapi-fhir-jpaserver-example/pom.xml | 4 +- .../uhn/fhir/jpa/demo/JpaServerDemoDstu2.java | 4 +- .../ca/uhn/fhirtest/TestRestfulServer.java | 22 ++- .../uhn/fhirtest/config/FhirTesterConfig.java | 18 ++- .../uhn/fhirtest/config/TestDstu3Config.java | 2 - .../ca/uhn/fhirtest/config/TestR4Config.java | 143 ++++++++++++++++++ .../mvc/SubscriptionPlaygroundController.java | 5 +- .../src/main/webapp/WEB-INF/web.xml | 15 +- hapi-fhir-server/pom.xml | 7 + .../BaseAddOrDeleteTagsMethodBinding.java | 2 - ...indingWithResourceIdButNoResourceBody.java | 6 - .../fhir/rest/server/method/MethodUtil.java | 2 +- .../rest/server/method/ReadMethodBinding.java | 42 +---- 21 files changed, 233 insertions(+), 154 deletions(-) delete mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/VersionIdParam.java create mode 100644 hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestR4Config.java diff --git a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java index bc0a9a5a3a2..edb29a485e7 100644 --- a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java +++ b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java @@ -61,11 +61,12 @@ public class BuiltJarDstu2ShadeIT { * Disabled for now - TODO: add the old version of the apache client (the one that * android uses) and see if this passes */ + @Test public void testClient() { FhirContext ctx = FhirContext.forDstu2(); try { IGenericClient client = ctx.newRestfulGenericClient("http://127.0.0.1:44442/SomeBase"); - client.capabilities().ofType(Conformance.class).execute() + client.capabilities().ofType(Conformance.class).execute(); } catch (FhirClientConnectionException e) { // this is good } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/VersionIdParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/VersionIdParam.java deleted file mode 100644 index 555d2b42215..00000000000 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/annotation/VersionIdParam.java +++ /dev/null @@ -1,36 +0,0 @@ -package ca.uhn.fhir.rest.annotation; - -/* - * #%L - * HAPI FHIR - Core Library - * %% - * Copyright (C) 2014 - 2017 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @deprecated IdDt can now hold both an ID and a version ID, so a single parameter with the {@link IdParam} annotation may be used - */ -@Deprecated -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface VersionIdParam { - // just a marker -} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java index 6f393857cec..36083c33872 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java @@ -212,10 +212,6 @@ public class ParameterUtil { return findParamAnnotationIndex(theMethod, TagListParam.class); } - public static Integer findVersionIdParameterIndex(Method theMethod) { - return findParamAnnotationIndex(theMethod, VersionIdParam.class); - } - public static Object fromInteger(Class theType, IntegerDt theArgument) { if (theType.equals(IntegerDt.class)) { if (theArgument == null) { diff --git a/hapi-fhir-client/pom.xml b/hapi-fhir-client/pom.xml index cd8a6e4bf91..5d62a66d16c 100644 --- a/hapi-fhir-client/pom.xml +++ b/hapi-fhir-client/pom.xml @@ -62,6 +62,13 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + ${argLine} -Dfile.encoding=UTF-8 -Xmx712m + + diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java index 643b8b5393b..afefbe334fb 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java @@ -51,12 +51,6 @@ public abstract class BaseOutcomeReturningMethodBindingWithResourceIdButNoResour throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation"); } - Integer versionIdParameterIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); - if (versionIdParameterIndex != null) { - //TODO Use of a deprecated method should be resolved - throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has a parameter annotated with the @" + VersionIdParam.class.getSimpleName() + " annotation but delete methods may not have this annotation"); - } - } @Override diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java index d16e4e5d1ec..4fcc3f7d45d 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java @@ -313,7 +313,7 @@ public class MethodUtil { throw new ConfigurationException(b.toString()); } param = new ResourceParameter(parameterType); - } else if (nextAnnotation instanceof IdParam || nextAnnotation instanceof VersionIdParam) { + } else if (nextAnnotation instanceof IdParam) { param = new NullParameter(); } else if (nextAnnotation instanceof ServerBase) { param = new ServerBaseParamBinder(); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java index d41d25e8eb8..572b873e0b0 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java @@ -41,7 +41,6 @@ import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; public class ReadMethodBinding extends BaseResourceReturningMethodBinding implements IClientResponseHandlerHandlesBinary { private Integer myIdIndex; private boolean mySupportsVersion; - private Integer myVersionIdIndex; private Class myIdParameterType; @SuppressWarnings("unchecked") @@ -51,13 +50,11 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem Validate.notNull(theMethod, "Method must not be null"); Integer idIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); - Integer versionIdIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); Class[] parameterTypes = theMethod.getParameterTypes(); mySupportsVersion = theMethod.getAnnotation(Read.class).version(); myIdIndex = idIndex; - myVersionIdIndex = versionIdIndex; if (myIdIndex == null) { throw new ConfigurationException("@" + Read.class.getSimpleName() + " method " + theMethod.getName() + " on type \"" + theMethod.getDeclaringClass().getName() @@ -68,9 +65,6 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem if (!IIdType.class.isAssignableFrom(myIdParameterType)) { throw new ConfigurationException("ID parameter must be of type IdDt or IdType - Found: " + myIdParameterType); } - if (myVersionIdIndex != null && !IdDt.class.equals(parameterTypes[myVersionIdIndex])) { - throw new ConfigurationException("Version ID parameter must be of type: " + IdDt.class.getCanonicalName() + " - Found: " + parameterTypes[myVersionIdIndex]); - } } @@ -96,18 +90,11 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem public HttpGetClientInvocation invokeClient(Object[] theArgs) { HttpGetClientInvocation retVal; IIdType id = ((IIdType) theArgs[myIdIndex]); - if (myVersionIdIndex == null) { - String resourceName = getResourceName(); - if (id.hasVersionIdPart()) { - retVal = createVReadInvocation(getContext(), new IdDt(resourceName, id.getIdPart(), id.getVersionIdPart()), resourceName); - } else { - retVal = createReadInvocation(getContext(), id, resourceName); - } + String resourceName = getResourceName(); + if (id.hasVersionIdPart()) { + retVal = createVReadInvocation(getContext(), new IdDt(resourceName, id.getIdPart(), id.getVersionIdPart()), resourceName); } else { - IdDt vid = ((IdDt) theArgs[myVersionIdIndex]); - String resourceName = getResourceName(); - - retVal = createVReadInvocation(getContext(), new IdDt(resourceName, id.getIdPart(), vid.getVersionIdPart()), resourceName); + retVal = createReadInvocation(getContext(), id, resourceName); } for (int idx = 0; idx < theArgs.length; idx++) { @@ -146,7 +133,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem } public boolean isVread() { - return mySupportsVersion || myVersionIdIndex != null; + return mySupportsVersion; } public static HttpGetClientInvocation createAbsoluteReadInvocation(FhirContext theContext, IIdType theId) { diff --git a/hapi-fhir-jacoco/pom.xml b/hapi-fhir-jacoco/pom.xml index 5aed33ea23f..6597a529425 100644 --- a/hapi-fhir-jacoco/pom.xml +++ b/hapi-fhir-jacoco/pom.xml @@ -21,6 +21,16 @@ hapi-fhir-base ${project.version} + + ca.uhn.hapi.fhir + hapi-fhir-server + ${project.version} + + + ca.uhn.hapi.fhir + hapi-fhir-client + ${project.version} + ca.uhn.hapi.fhir hapi-fhir-structures-dstu2 @@ -31,6 +41,11 @@ hapi-fhir-structures-dstu3 ${project.version} + + ca.uhn.hapi.fhir + hapi-fhir-structures-r4 + ${project.version} + ca.uhn.hapi.fhir hapi-fhir-structures-hl7org-dstu2 @@ -265,9 +280,11 @@ hapi-fhir-structures-dstu2/target/jacoco.exec hapi-fhir-structures-hl7org-dstu2/target/jacoco.exec hapi-fhir-structures-dstu3/target/jacoco.exec + hapi-fhir-structures-r4/target/jacoco.exec hapi-fhir-jpaserver-base/target/jacoco.exec hapi-fhir-client-okhttp/target/jacoco.exec hapi-fhir-android/target/jacoco.exec + hapi-fhir-validation/target/jacoco.exec @@ -290,6 +307,7 @@ ../hapi-fhir-structures-dstu2/src/test/java ../hapi-fhir-structures-hl7org-dstu2/src/test/java ../hapi-fhir-structures-dstu3/src/test/java + ../hapi-fhir-structures-r4/src/test/java ../hapi-fhir-jpaserver-base/src/main/java ../hapi-fhir-client-okhttp/src/main/java @@ -359,22 +377,6 @@ - - org.codehaus.mojo - cobertura-maven-plugin - - - - cobertura - - - - true - - - - - org.apache.maven.plugins maven-project-info-reports-plugin diff --git a/hapi-fhir-jpaserver-example/pom.xml b/hapi-fhir-jpaserver-example/pom.xml index 893e22c7e2e..247d30ad6f6 100644 --- a/hapi-fhir-jpaserver-example/pom.xml +++ b/hapi-fhir-jpaserver-example/pom.xml @@ -239,8 +239,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.7 + 1.7 diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java index 0cfa22d9824..3147a776819 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java @@ -56,9 +56,7 @@ public class JpaServerDemoDstu2 extends RestfulServer { * contains bean definitions for a resource provider for each resource type */ String resourceProviderBeanName; - if (fhirVersion == FhirVersionEnum.DSTU1) { - resourceProviderBeanName = "myResourceProvidersDstu1"; - } else if (fhirVersion == FhirVersionEnum.DSTU2) { + if (fhirVersion == FhirVersionEnum.DSTU2) { resourceProviderBeanName = "myResourceProvidersDstu2"; } else if (fhirVersion == FhirVersionEnum.DSTU3) { resourceProviderBeanName = "myResourceProvidersDstu3"; diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index fba5fe04573..49628d572d2 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -15,11 +15,13 @@ import org.springframework.web.cors.CorsConfiguration; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.config.WebsocketDstu2DispatcherConfig; import ca.uhn.fhir.jpa.config.dstu3.WebsocketDstu3DispatcherConfig; +import ca.uhn.fhir.jpa.config.r4.WebsocketR4DispatcherConfig; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2; import ca.uhn.fhir.jpa.provider.dstu3.*; +import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.rest.api.EncodingEnum; @@ -29,7 +31,7 @@ import ca.uhn.fhirtest.config.*; public class TestRestfulServer extends RestfulServer { - public static final String FHIR_BASEURL_DSTU1 = "fhir.baseurl.dstu1"; + public static final String FHIR_BASEURL_R4 = "fhir.baseurl.r4"; public static final String FHIR_BASEURL_DSTU2 = "fhir.baseurl.dstu2"; public static final String FHIR_BASEURL_DSTU3 = "fhir.baseurl.dstu3"; public static final String FHIR_BASEURL_TDL2 = "fhir.baseurl.tdl2"; @@ -114,6 +116,24 @@ public class TestRestfulServer extends RestfulServer { plainProviders.add(myAppCtx.getBean(TerminologyUploaderProviderDstu3.class)); break; } + case "R4": { + myAppCtx = new AnnotationConfigWebApplicationContext(); + myAppCtx.setServletConfig(getServletConfig()); + myAppCtx.setParent(parentAppCtx); + myAppCtx.register(TestR4Config.class, WebsocketR4DispatcherConfig.class); + baseUrlProperty = FHIR_BASEURL_R4; + myAppCtx.refresh(); + setFhirContext(FhirContext.forR4()); + beans = myAppCtx.getBean("myResourceProvidersR4", List.class); + plainProviders.add(myAppCtx.getBean("mySystemProviderR4", JpaSystemProviderDstu3.class)); + systemDao = myAppCtx.getBean("mySystemDaoR4", IFhirSystemDao.class); + etagSupport = ETagSupportEnum.ENABLED; + JpaConformanceProviderDstu3 confProvider = new JpaConformanceProviderDstu3(this, systemDao, myAppCtx.getBean(DaoConfig.class)); + confProvider.setImplementationDescription(implDesc); + setServerConformanceProvider(confProvider); + plainProviders.add(myAppCtx.getBean(TerminologyUploaderProviderR4.class)); + break; + } default: throw new ServletException("Unknown FHIR version specified in init-param[FhirVersion]: " + fhirVersionParam); } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/FhirTesterConfig.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/FhirTesterConfig.java index 193a1bb2e0e..d4318ad9364 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/FhirTesterConfig.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/FhirTesterConfig.java @@ -1,10 +1,7 @@ package ca.uhn.fhirtest.config; import org.springframework.beans.factory.annotation.Autowire; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.*; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.to.FhirTesterMvcConfig; @@ -56,10 +53,10 @@ public class FhirTesterConfig { .withBaseUrl("http://fhirtest.uhn.ca/baseDstu2") .withName("UHN/HAPI Server (DSTU2 FHIR)") .addServer() - .withId("home") - .withFhirVersion(FhirVersionEnum.DSTU1) - .withBaseUrl("http://fhirtest.uhn.ca/baseDstu1") - .withName("UHN/HAPI Server (DSTU1 FHIR)") + .withId("home_r4") + .withFhirVersion(FhirVersionEnum.R4) + .withBaseUrl("http://fhirtest.uhn.ca/baseR4") + .withName("UHN/HAPI Server (R4 FHIR)") // .addServer() // .withId("tdl_d2") // .withFhirVersion(FhirVersionEnum.DSTU2) @@ -72,6 +69,11 @@ public class FhirTesterConfig { // .withBaseUrl("http://fhirtest.uhn.ca/testDataLibraryStu3") // .withName("Test Data Library (DSTU3 FHIR)") // .allowsApiKey() + .addServer() + .withId("hi4") + .withFhirVersion(FhirVersionEnum.DSTU3) + .withBaseUrl("http://test.fhir.org/r4") + .withName("Health Intersections (R4 FHIR)") .addServer() .withId("hi3") .withFhirVersion(FhirVersionEnum.DSTU3) diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java index 250a41d653b..1f743b92dd5 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java @@ -7,7 +7,6 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.lang3.time.DateUtils; -import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.dialect.PostgreSQL94Dialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Autowire; @@ -21,7 +20,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu3; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; -import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.validation.ResultSeverityEnum; diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestR4Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestR4Config.java new file mode 100644 index 00000000000..8a39b0be8d9 --- /dev/null +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestR4Config.java @@ -0,0 +1,143 @@ +package ca.uhn.fhirtest.config; + +import java.util.Properties; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.apache.commons.lang3.time.DateUtils; +import org.hibernate.dialect.PostgreSQL95Dialect; +import org.hibernate.jpa.HibernatePersistenceProvider; +import org.springframework.beans.factory.annotation.Autowire; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.*; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import ca.uhn.fhir.jpa.config.BaseJavaConfigR4; +import ca.uhn.fhir.jpa.dao.DaoConfig; +import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; +import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; +import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; +import ca.uhn.fhir.validation.ResultSeverityEnum; +import ca.uhn.fhirtest.interceptor.PublicSecurityInterceptor; + +@Configuration +@Import(CommonConfig.class) +@EnableTransactionManagement() +public class TestR4Config extends BaseJavaConfigR4 { + public static final String FHIR_DB_USERNAME = "${fhir.db.username}"; + public static final String FHIR_DB_PASSWORD = "${fhir.db.password}"; + public static final String FHIR_LUCENE_LOCATION_R4 = "${fhir.lucene.location.r4}"; + + @Value(TestR4Config.FHIR_DB_USERNAME) + private String myDbUsername; + + @Value(TestR4Config.FHIR_DB_PASSWORD) + private String myDbPassword; + + @Value(FHIR_LUCENE_LOCATION_R4) + private String myFhirLuceneLocation; + + @Bean() + public DaoConfig daoConfig() { + DaoConfig retVal = new DaoConfig(); + retVal.setSubscriptionEnabled(true); + retVal.setSubscriptionPollDelay(5000); + retVal.setSubscriptionPurgeInactiveAfterMillis(DateUtils.MILLIS_PER_HOUR); + retVal.setAllowMultipleDelete(true); + retVal.setAllowInlineMatchUrlReferences(true); + retVal.setAllowExternalReferences(true); + retVal.getTreatBaseUrlsAsLocal().add("http://fhirtest.uhn.ca/baseR4"); + retVal.getTreatBaseUrlsAsLocal().add("https://fhirtest.uhn.ca/baseR4"); + return retVal; + } + + @Override + @Bean(autowire = Autowire.BY_TYPE) + public DatabaseBackedPagingProvider databaseBackedPagingProvider() { + DatabaseBackedPagingProvider retVal = super.databaseBackedPagingProvider(); + retVal.setDefaultPageSize(20); + retVal.setMaximumPageSize(500); + return retVal; + } + + + @Bean + public IServerInterceptor securityInterceptor() { + return new PublicSecurityInterceptor(); + } + + @Bean(name = "myPersistenceDataSourceR4", destroyMethod = "close") + public DataSource dataSource() { + BasicDataSource retVal = new BasicDataSource(); + retVal.setDriver(new org.postgresql.Driver()); + retVal.setUrl("jdbc:postgresql://localhost/fhirtest_r4"); + retVal.setUsername(myDbUsername); + retVal.setPassword(myDbPassword); + return retVal; + } + + @Bean() + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean(); + retVal.setPersistenceUnitName("PU_HapiFhirJpaR4"); + retVal.setDataSource(dataSource()); + retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity"); + retVal.setPersistenceProvider(new HibernatePersistenceProvider()); + retVal.setJpaProperties(jpaProperties()); + return retVal; + } + + private Properties jpaProperties() { + Properties extraProperties = new Properties(); + extraProperties.put("hibernate.dialect", PostgreSQL95Dialect.class.getName()); + extraProperties.put("hibernate.format_sql", "false"); + extraProperties.put("hibernate.show_sql", "false"); + extraProperties.put("hibernate.hbm2ddl.auto", "update"); + extraProperties.put("hibernate.jdbc.batch_size", "20"); + extraProperties.put("hibernate.cache.use_query_cache", "false"); + extraProperties.put("hibernate.cache.use_second_level_cache", "false"); + extraProperties.put("hibernate.cache.use_structured_entries", "false"); + extraProperties.put("hibernate.cache.use_minimal_puts", "false"); + extraProperties.put("hibernate.search.default.directory_provider", "filesystem"); + extraProperties.put("hibernate.search.default.indexBase", myFhirLuceneLocation); + extraProperties.put("hibernate.search.lucene_version", "LUCENE_CURRENT"); + return extraProperties; + } + + /** + * Bean which validates incoming requests + */ + @Bean + @Lazy + public RequestValidatingInterceptor requestValidatingInterceptor() { + RequestValidatingInterceptor requestValidator = new RequestValidatingInterceptor(); + requestValidator.setFailOnSeverity(null); + requestValidator.setAddResponseHeaderOnSeverity(null); + requestValidator.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + requestValidator.addValidatorModule(instanceValidatorR4()); + requestValidator.setIgnoreValidatorExceptions(true); + + return requestValidator; + } + + + @Bean() + public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { + JpaTransactionManager retVal = new JpaTransactionManager(); + retVal.setEntityManagerFactory(entityManagerFactory); + return retVal; + } + + /** + * This lets the "@Value" fields reference properties from the properties file + */ + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } +} diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java index 22c92ab06c2..630004fc28e 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/mvc/SubscriptionPlaygroundController.java @@ -19,6 +19,7 @@ import ca.uhn.fhir.to.model.HomeRequest; public class SubscriptionPlaygroundController extends BaseController { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionPlaygroundController.class); + @SuppressWarnings("unchecked") @RequestMapping(value = { "/subscriptions" }) public String subscriptionsHome(final HttpServletRequest theServletRequest, HomeRequest theRequest, final ModelMap theModel) { addCommonParams(theServletRequest, theRequest, theModel); @@ -31,8 +32,7 @@ public class SubscriptionPlaygroundController extends BaseController { CaptureInterceptor interceptor = new CaptureInterceptor(); GenericClient client = theRequest.newClient(theServletRequest, getContext(theRequest), myConfig, interceptor); - //@formatter:off - Bundle resp = client + Bundle resp = (Bundle) client .search() .forResource(Subscription.class) // .where(Subscription.TYPE.exactly().code(SubscriptionChannelTypeEnum.WEBSOCKET.getCode())) @@ -41,7 +41,6 @@ public class SubscriptionPlaygroundController extends BaseController { .sort().ascending(Subscription.STATUS) .returnBundle(Bundle.class) .execute(); - //@formatter:off List subscriptions = new ArrayList(); for (Entry next : resp.getEntry()) { diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml index 55804d41d6e..fd02bc0ae4e 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/web.xml @@ -41,15 +41,15 @@ - fhirServletDstu1 + fhirServletR4 ca.uhn.fhirtest.TestRestfulServer ImplementationDescription - UHN Test Server (DSTU1 Resources) + UHN Test Server (R4 Resources) FhirVersion - DSTU1 + R4 1 @@ -112,13 +112,8 @@ --> - fhirServletDstu1 - /base/* - - - - fhirServletDstu1 - /baseDstu1/* + fhirServletR4 + /baseR4/* diff --git a/hapi-fhir-server/pom.xml b/hapi-fhir-server/pom.xml index b7a4c14dfde..58af562ca5a 100644 --- a/hapi-fhir-server/pom.xml +++ b/hapi-fhir-server/pom.xml @@ -87,6 +87,13 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + ${argLine} -Dfile.encoding=UTF-8 -Xmx712m + + diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseAddOrDeleteTagsMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseAddOrDeleteTagsMethodBinding.java index bc2968432cc..2bc494b55b5 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseAddOrDeleteTagsMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseAddOrDeleteTagsMethodBinding.java @@ -19,7 +19,6 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding private Class myType; private Integer myIdParamIndex; - private Integer myVersionIdParamIndex; private String myResourceName; private Integer myTagListParamIndex; @@ -40,7 +39,6 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding myResourceName = theContext.getResourceDefinition(myType).getName(); myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); - myVersionIdParamIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); myTagListParamIndex = ParameterUtil.findTagListParameterIndex(theMethod); if (myIdParamIndex == null) { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java index a7652751d7d..328e07216b7 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java @@ -57,12 +57,6 @@ public abstract class BaseOutcomeReturningMethodBindingWithResourceIdButNoResour throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation"); } - Integer versionIdParameterIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); - if (versionIdParameterIndex != null) { - //TODO Use of a deprecated method should be resolved - throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has a parameter annotated with the @" + VersionIdParam.class.getSimpleName() + " annotation but delete methods may not have this annotation"); - } - } @Override diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java index e25b5e4ba67..2e69f421a4d 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/MethodUtil.java @@ -149,7 +149,7 @@ public class MethodUtil { throw new ConfigurationException(b.toString()); } param = new ResourceParameter((Class) parameterType, theProvider, mode); - } else if (nextAnnotation instanceof IdParam || nextAnnotation instanceof VersionIdParam) { + } else if (nextAnnotation instanceof IdParam) { param = new NullParameter(); } else if (nextAnnotation instanceof ServerBase) { param = new ServerBaseParamBinder(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java index 1182d5d06b5..1f7b5dd164f 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java @@ -3,15 +3,11 @@ package ca.uhn.fhir.rest.server.method; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.IAnyResource; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.*; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -20,20 +16,12 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.annotation.Elements; -import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.annotation.Read; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.RequestTypeEnum; -import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.api.server.IRestfulServer; -import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.server.*; import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.ETagSupportEnum; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; +import ca.uhn.fhir.rest.server.exceptions.*; import ca.uhn.fhir.util.DateUtils; public class ReadMethodBinding extends BaseResourceReturningMethodBinding { @@ -41,7 +29,6 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding { private Integer myIdIndex; private boolean mySupportsVersion; - private Integer myVersionIdIndex; private Class myIdParameterType; @SuppressWarnings("unchecked") @@ -51,13 +38,11 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding { Validate.notNull(theMethod, "Method must not be null"); Integer idIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); - Integer versionIdIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); Class[] parameterTypes = theMethod.getParameterTypes(); mySupportsVersion = theMethod.getAnnotation(Read.class).version(); myIdIndex = idIndex; - myVersionIdIndex = versionIdIndex; if (myIdIndex == null) { throw new ConfigurationException("@" + Read.class.getSimpleName() + " method " + theMethod.getName() + " on type \"" + theMethod.getDeclaringClass().getName() + "\" does not have a parameter annotated with @" + IdParam.class.getSimpleName()); @@ -67,9 +52,6 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding { if (!IIdType.class.isAssignableFrom(myIdParameterType)) { throw new ConfigurationException("ID parameter must be of type IdDt or IdType - Found: " + myIdParameterType); } - if (myVersionIdIndex != null && !IdDt.class.equals(parameterTypes[myVersionIdIndex])) { - throw new ConfigurationException("Version ID parameter must be of type: " + IdDt.class.getCanonicalName() + " - Found: " + parameterTypes[myVersionIdIndex]); - } } @@ -125,7 +107,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding { return false; } if (Constants.PARAM_HISTORY.equals(theRequest.getOperation())) { - if (mySupportsVersion == false && myVersionIdIndex == null) { + if (mySupportsVersion == false) { return false; } if (theRequest.getId().hasVersionIdPart() == false) { @@ -141,9 +123,6 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding { @Override public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { theMethodParams[myIdIndex] = ParameterUtil.convertIdToType(theRequest.getId(), myIdParameterType); - if (myVersionIdIndex != null) { - theMethodParams[myVersionIdIndex] = new IdDt(theRequest.getId().getVersionIdPart()); - } Object response = invokeServerMethod(theServer, theRequest, theMethodParams); IBundleProvider retVal = toResourceList(response); @@ -193,13 +172,8 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding { return retVal; } -// @Override -// public boolean isBinary() { -// return "Binary".equals(getResourceName()); -// } - public boolean isVread() { - return mySupportsVersion || myVersionIdIndex != null; + return mySupportsVersion; } @Override