diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml
index bacb74272cd..11938a5952b 100644
--- a/hapi-fhir-jpaserver-base/pom.xml
+++ b/hapi-fhir-jpaserver-base/pom.xml
@@ -67,7 +67,6 @@
ch.qos.logback
logback-classic
- ${logback_version}
test
@@ -269,25 +268,21 @@
org.eclipse.jetty
jetty-servlets
- ${jetty_version}
test
org.eclipse.jetty
jetty-servlet
- ${jetty_version}
test
org.eclipse.jetty
jetty-server
- ${jetty_version}
test
org.eclipse.jetty
jetty-util
- ${jetty_version}
test
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java
index e347fea14f9..4ceacc36740 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoQuestionnaireResponseDstu2.java
@@ -1,30 +1,10 @@
package ca.uhn.fhir.jpa.dao;
-/*
- * #%L
- * HAPI FHIR JPA Server
- * %%
- * Copyright (C) 2014 - 2015 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 javax.annotation.PostConstruct;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.PlatformTransactionManager;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
@@ -41,12 +21,30 @@ import ca.uhn.fhir.validation.ValidationResult;
public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDstu2 {
- private FhirContext myRefImplCtx = FhirContext.forDstu2Hl7Org();
+ private FhirContext myRefImplCtx;
+ private Boolean myValidateResponses;
+ /**
+ * Initialize the bean
+ */
+ @PostConstruct
+ public void initialize() {
+ try {
+ Class.forName("org.hl7.fhir.instance.model.QuestionnaireResponse");
+ myValidateResponses = true;
+ myRefImplCtx = FhirContext.forDstu2Hl7Org();
+ } catch (ClassNotFoundException e) {
+ myValidateResponses = Boolean.FALSE;
+ }
+ }
+
@Override
protected void validateResourceForStorage(IResource theResource) {
super.validateResourceForStorage(theResource);
-
+ if (!myValidateResponses) {
+ return;
+ }
+
QuestionnaireResponse qa = (QuestionnaireResponse) theResource;
if (qa == null || qa.getQuestionnaire() == null || qa.getQuestionnaire().getReference() == null || qa.getQuestionnaire().getReference().isEmpty()) {
return;
@@ -73,7 +71,8 @@ public class FhirResourceDaoQuestionnaireResponseDstu2 extends FhirResourceDaoDs
public T load(Class theType, IIdType theId) throws ResourceNotFoundException {
/*
- * The QuestionnaireResponse validator uses RI structures, so for now we need to convert between that and HAPI structures. This is a bit hackish, but hopefully it will go away at some point.
+ * The QuestionnaireResponse validator uses RI structures, so for now we need to convert between that and HAPI
+ * structures. This is a bit hackish, but hopefully it will go away at some point.
*/
if ("ValueSet".equals(theType.getSimpleName())) {
IFhirResourceDao dao = getDao(ValueSet.class);
diff --git a/hapi-fhir-jpaserver-example/.classpath b/hapi-fhir-jpaserver-example/.classpath
index d4174742df1..2394f84cc44 100644
--- a/hapi-fhir-jpaserver-example/.classpath
+++ b/hapi-fhir-jpaserver-example/.classpath
@@ -1,12 +1,13 @@
-
+
-
+
+
diff --git a/hapi-fhir-jpaserver-example/pom.xml b/hapi-fhir-jpaserver-example/pom.xml
index 7ead7c6697e..2baf36f29a2 100644
--- a/hapi-fhir-jpaserver-example/pom.xml
+++ b/hapi-fhir-jpaserver-example/pom.xml
@@ -1,21 +1,18 @@
-
+
4.0.0
-
+
ca.uhn.hapi.fhir
hapi-fhir
1.2-SNAPSHOT
../pom.xml
-
+
ca.uhn.hapi.example
hapi-fhir-jpaserver-example
war
@@ -40,7 +37,7 @@
hapi-fhir-base
1.2-SNAPSHOT
-
+
ca.uhn.hapi.fhir
@@ -53,10 +50,8 @@
1.2-SNAPSHOT
-
+
ca.uhn.hapi.fhir
hapi-fhir-jpaserver-base
@@ -69,19 +64,16 @@
hapi-fhir-testpage-overlay
1.2-SNAPSHOT
war
- provided
+ provided
-
+
ch.qos.logback
logback-classic
- ${logback_version}
@@ -91,10 +83,8 @@
provided
-
+
org.thymeleaf
thymeleaf
@@ -113,11 +103,8 @@
-
-
+
+
org.springframework
spring-web
@@ -125,21 +112,17 @@
provided
-
+
org.apache.commons
commons-dbcp2
-
+
org.apache.derby
derby
@@ -153,31 +136,50 @@
derbyclient
-
- org.jboss.arquillian.junit
- arquillian-junit-container
+ junit
+ junit
+ test
+
+
+ org.eclipse.jetty
+ jetty-servlets
+ test
+
+
+ org.eclipse.jetty
+ jetty-servlet
+ test
+
+
+ org.eclipse.jetty
+ jetty-server
+ test
+
+
+ org.eclipse.jetty
+ jetty-util
+ test
+
+
+ org.eclipse.jetty
+ jetty-webapp
test
-
-
+
+
hapi-fhir-jpaserver-example
-
-
+
+
@@ -192,11 +194,9 @@
-
+
-
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -205,11 +205,9 @@
1.6
-
-
+
+
org.apache.maven.plugins
maven-war-plugin
@@ -222,11 +220,9 @@
-
-
+
+
org.apache.maven.plugins
maven-deploy-plugin
@@ -234,7 +230,7 @@
true
-
+
diff --git a/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml b/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml
index bd2a4f98b33..8466b030fbe 100644
--- a/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml
+++ b/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml
@@ -42,7 +42,7 @@
FhirVersion
- DSTU1
+ DSTU2
1
diff --git a/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/dao/RandomServerPortProvider.java b/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/dao/RandomServerPortProvider.java
new file mode 100644
index 00000000000..6fb23cb7a33
--- /dev/null
+++ b/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/dao/RandomServerPortProvider.java
@@ -0,0 +1,36 @@
+package ca.uhn.fhir.jpa.dao;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Provides server ports
+ */
+public class RandomServerPortProvider {
+
+ private static List ourPorts = new ArrayList();
+
+ public static int findFreePort() {
+ ServerSocket server;
+ try {
+ server = new ServerSocket(0);
+ int port = server.getLocalPort();
+ ourPorts.add(port);
+ server.close();
+ Thread.sleep(500);
+ return port;
+ } catch (IOException e) {
+ throw new Error(e);
+ } catch (InterruptedException e) {
+ throw new Error(e);
+ }
+ }
+
+ public static List list() {
+ return ourPorts;
+ }
+
+}
+
\ No newline at end of file
diff --git a/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/dao/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/dao/ResourceProviderDstu2Test.java
new file mode 100644
index 00000000000..ac842baba9a
--- /dev/null
+++ b/hapi-fhir-jpaserver-example/src/test/java/ca/uhn/fhir/jpa/dao/ResourceProviderDstu2Test.java
@@ -0,0 +1,66 @@
+package ca.uhn.fhir.jpa.dao;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.hl7.fhir.instance.model.api.IIdType;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.rest.client.IGenericClient;
+import ca.uhn.fhir.rest.client.ServerValidationModeEnum;
+import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
+
+public class ResourceProviderDstu2Test {
+
+ private static IGenericClient ourClient;
+ private static final FhirContext ourCtx = FhirContext.forDstu2();
+ private static int ourPort;
+
+ private static Server ourServer;
+
+ @Test
+ public void testCreateAndRead() throws IOException {
+ String methodName = "testCreateResourceConditional";
+
+ Patient pt = new Patient();
+ pt.addName().addFamily(methodName);
+ IIdType id = ourClient.create().resource(pt).execute().getId();
+
+ Patient pt2 = ourClient.read().resource(Patient.class).withId(id).execute();
+ assertEquals(methodName, pt2.getName().get(0).getFamily().get(0).getValue());
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ ourServer.stop();
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ ourPort = RandomServerPortProvider.findFreePort();
+ ourServer = new Server(ourPort);
+
+ WebAppContext webAppContext = new WebAppContext();
+ webAppContext.setContextPath("/");
+ webAppContext.setDescriptor("src/main/webapp/WEB-INF/web.xml");
+ webAppContext.setResourceBase("target/hapi-fhir-jpaserver-example");
+ webAppContext.setParentLoaderPriority(true);
+
+ ourServer.setHandler(webAppContext);
+ ourServer.start();
+
+ ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
+ ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
+ ourClient = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/base");
+ ourClient.registerInterceptor(new LoggingInterceptor(true));
+
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index e8fba856f41..f2cd24553a5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,12 +45,6 @@
-
- net.sourceforge.cobertura
- cobertura
- 2.1.1
- provided
-
@@ -231,6 +225,16 @@
javax.servlet-api
3.1.0
+
+ junit
+ junit
+ 4.12
+
+
+ net.sourceforge.cobertura
+ cobertura
+ 2.1.1
+
org.apache.commons
commons-dbcp2
@@ -252,10 +256,30 @@
${derby_version}
- org.jboss.arquillian.junit
- arquillian-junit-container
- 1.1.8.Final
-
+ org.eclipse.jetty
+ jetty-servlets
+ 9.2.6.v20141205
+
+
+ org.eclipse.jetty
+ jetty-servlet
+ 9.2.6.v20141205
+
+
+ org.eclipse.jetty
+ jetty-server
+ 9.2.6.v20141205
+
+
+ org.eclipse.jetty
+ jetty-util
+ 9.2.6.v20141205
+
+
+ org.eclipse.jetty
+ jetty-webapp
+ 9.2.6.v20141205
+
org.mockito
mockito-all
@@ -580,7 +604,7 @@
-
+
Fixing Checkstyle Report
@@ -609,7 +633,8 @@
]]>
-
+