From e4539c0a0f77c88ea0f398cec48e345d87704fc8 Mon Sep 17 00:00:00 2001 From: Rob Hausam Date: Fri, 18 Aug 2017 09:59:36 -0500 Subject: [PATCH 1/4] Add imports for org.slf4j.Logger and org.slf4j.LoggerFactory. --- .../src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index 043dc031af5..ae8830b5c4f 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -3,6 +3,8 @@ package ca.uhn.fhir.jpa.demo; import java.util.Collection; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.servlet.ServletException; From 83171292df72fab99627798409e9b4076c0753e6 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 22 Aug 2017 08:44:35 -0400 Subject: [PATCH 2/4] Try to get tests passing --- .../provider/dstu3/ResourceProviderInterceptorDstu3Test.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java index fb0642bae18..e243fe1cc0c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java @@ -79,6 +79,7 @@ public class ResourceProviderInterceptorDstu3Test extends BaseResourceProviderDs private void resetServerInterceptor() throws ServletException, IOException { reset(myServerInterceptor); + reset(myDaoInterceptor); when(myServerInterceptor.handleException(any(RequestDetails.class), any(BaseServerResponseException.class), any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn(true); when(myServerInterceptor.incomingRequestPostProcessed(any(RequestDetails.class), any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn(true); when(myServerInterceptor.incomingRequestPreProcessed(any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn(true); @@ -95,6 +96,7 @@ public class ResourceProviderInterceptorDstu3Test extends BaseResourceProviderDs String resource = myFhirCtx.newXmlParser().encodeResourceToString(pt); verify(myServerInterceptor, never()).incomingRequestPreHandled(any(RestOperationTypeEnum.class), any(ActionRequestDetails.class)); + verify(myDaoInterceptor, never()).incomingRequestPreHandled(any(RestOperationTypeEnum.class), any(ActionRequestDetails.class)); HttpPost post = new HttpPost(ourServerBase + "/Patient"); post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); From 4ed1e588b2ef555ebb5268874f961791ae7dc1bd Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 22 Aug 2017 08:46:46 -0400 Subject: [PATCH 3/4] Credit for #712 --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 3f23f72d316..8eedd207397 100644 --- a/pom.xml +++ b/pom.xml @@ -358,6 +358,10 @@ InfiniteLoop90 Clayton Bodendein + + rhausam + Rob Hausam + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8c5f223bff2..89c665c9dc6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -328,6 +328,10 @@ specified, regardless of whether the source event was a create or an update + + Add appropriate import statements for logging to JPA demo code. Thanks to + Rob Hausam for the pull request! + From 1ec14f4a31bc2fd3035480c5256299004c55a0e3 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 24 Aug 2017 13:06:47 -0400 Subject: [PATCH 4/4] Small perf improvement for JPA terminology --- .../data/ITermConceptParentChildLinkDao.java | 4 +- .../fhir/jpa/term/BaseHapiTerminologySvc.java | 8 +-- .../derby_maintenance.txt | 1 + .../ResponseHighlighterInterceptor.java | 26 ++++----- .../ResponseHighlightingInterceptorTest.java | 1 + .../ServerActionInterceptorTest.java | 54 +++++++++---------- 6 files changed, 48 insertions(+), 46 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java index d4d315a3c4f..6cfc3e44127 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermConceptParentChildLinkDao.java @@ -35,7 +35,7 @@ public interface ITermConceptParentChildLinkDao extends JpaRepository findAllWithChild(@Param("child_pid") Long theConceptPid); + @Query("SELECT t.myParentPid FROM TermConceptParentChildLink t WHERE t.myChildPid = :child_pid") + Collection findAllWithChild(@Param("child_pid") Long theConceptPid); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvc.java index 6db49a0e40b..16b686dee4a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseHapiTerminologySvc.java @@ -357,13 +357,14 @@ public abstract class BaseHapiTerminologySvc implements IHapiTerminologySvc { if (parents.contains(-1L)) { return; } else if (parents.isEmpty()) { - Collection parentLinks = myConceptParentChildLinkDao.findAllWithChild(theConceptPid); + ourLog.info("Loading parent concepts of concept {}", theConceptPid); + Collection parentLinks = myConceptParentChildLinkDao.findAllWithChild(theConceptPid); if (parentLinks.isEmpty()) { myChildToParentPidCache.put(theConceptPid, -1L); return; } else { - for (TermConceptParentChildLink next : parentLinks) { - myChildToParentPidCache.put(theConceptPid, next.getParentPid()); + for (Long next : parentLinks) { + myChildToParentPidCache.put(theConceptPid, next); } } } @@ -382,6 +383,7 @@ public abstract class BaseHapiTerminologySvc implements IHapiTerminologySvc { int maxResult = 1000; Page concepts = myConceptDao.findResourcesRequiringReindexing(new PageRequest(0, maxResult)); if (concepts.hasContent() == false) { + ourLog.info("Clearing parent concept cache"); myNextReindexPass = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE; myChildToParentPidCache = null; return; diff --git a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt index ad0baae566f..f62f740f5dd 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt +++ b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt @@ -11,6 +11,7 @@ curl -H "Authorization: Bearer " "http://fhirtest.uhn.ca/baseDstu3/\$mark-all-re # Delete all errored resources update hfj_res_ver set forced_id_pid = null where res_id in (select res_id from hfj_resource where sp_index_status = 2); update hfj_resource set forced_id_pid = null where res_id in (select res_id from hfj_resource where sp_index_status = 2); +delete from hfj_history_tag where res_id in (select res_id from hfj_resource where sp_index_status = 2); delete from hfj_res_ver where res_id in (select res_id from hfj_resource where sp_index_status = 2); delete from hfj_forced_id where resource_pid in (select res_id from hfj_resource where sp_index_status = 2); delete from hfj_res_link where src_resource_id in (select res_id from hfj_resource where sp_index_status = 2); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlighterInterceptor.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlighterInterceptor.java index 6be6783e19e..7745f9536de 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlighterInterceptor.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlighterInterceptor.java @@ -351,6 +351,7 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter { * * @return Returns a reference to this for easy method chaining */ + @SuppressWarnings("UnusedReturnValue") public ResponseHighlighterInterceptor setShowRequestHeaders(boolean theShowRequestHeaders) { myShowRequestHeaders = theShowRequestHeaders; return this; @@ -362,6 +363,7 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter { * * @return Returns a reference to this for easy method chaining */ + @SuppressWarnings("UnusedReturnValue") public ResponseHighlighterInterceptor setShowResponseHeaders(boolean theShowResponseHeaders) { myShowResponseHeaders = theShowResponseHeaders; return this; @@ -415,7 +417,7 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter { } } if (prettyPrintResponse) { - p.setPrettyPrint(prettyPrintResponse); + p.setPrettyPrint(true); } EncodingEnum encoding = p.getEncoding(); @@ -558,18 +560,16 @@ public class ResponseHighlighterInterceptor extends InterceptorAdapter { b.append("\n"); b.append("\n"); - if (true) { - try { - if (isShowRequestHeaders()) { - streamRequestHeaders(theServletRequest, b); - } - if (isShowResponseHeaders()) { - streamResponseHeaders(theRequestDetails, theServletResponse, b); - } - } catch (Throwable t) { - // ignore (this will hit if we're running in a servlet 2.5 environment) - } - } + try { + if (isShowRequestHeaders()) { + streamRequestHeaders(theServletRequest, b); + } + if (isShowResponseHeaders()) { + streamResponseHeaders(theRequestDetails, theServletResponse, b); + } + } catch (Throwable t) { + // ignore (this will hit if we're running in a servlet 2.5 environment) + } StringBuilder target = new StringBuilder(); int linesCount = format(encoded, target, encoding); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java index 1cf89d9c2eb..1191c40df0e 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java @@ -761,6 +761,7 @@ public class ResponseHighlightingInterceptorTest { @BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); + ourLog.info("Using port: {}", ourPort); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java index 9fd167c4aa9..1472dbf3044 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java @@ -1,33 +1,5 @@ package ca.uhn.fhir.rest.server.interceptor; -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.IOUtils; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; -import org.mockito.ArgumentCaptor; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.dstu2.resource.Observation; @@ -44,6 +16,32 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.ArgumentCaptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; public class ServerActionInterceptorTest {