From 5ce9d444e9979af3211edc911e2a558fd1980850 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 18 Jan 2019 09:04:45 -0500 Subject: [PATCH] Work on interceptors --- .../ca/uhn/fhir/hapi-version.properties | 1 - .../ca/uhn/fhir/jpa/config/TestR4Config.java | 3 +- .../provider/r4/ResourceProviderR4Test.java | 13 ++++ .../module/CanonicalSubscription.java | 67 ++++++++++++++++++- ...scriptionDeliveringRestHookSubscriber.java | 23 ++----- 5 files changed, 85 insertions(+), 22 deletions(-) delete mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/hapi-version.properties diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/hapi-version.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/hapi-version.properties deleted file mode 100644 index e5683df88cb..00000000000 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/hapi-version.properties +++ /dev/null @@ -1 +0,0 @@ -version=${project.version} \ No newline at end of file diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java index d9fcc5773cf..fc67daa6729 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.config; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.validation.ResultSeverityEnum; import net.ttddyy.dsproxy.listener.SingleQueryCountHolder; +import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel; import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; import org.apache.commons.dbcp2.BasicDataSource; import org.springframework.context.annotation.Bean; @@ -96,7 +97,7 @@ public class TestR4Config extends BaseJavaConfigR4 { DataSource dataSource = ProxyDataSourceBuilder .create(retVal) -// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") + .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") // .logSlowQueryBySlf4j(10, TimeUnit.SECONDS) // .countQuery(new ThreadQueryCountHolder()) .beforeQuery(new BlockLargeNumbersOfParamsListener()) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index ec5c4fcd125..72f422b8a8b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -945,6 +945,19 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } } + + @Test + @Ignore + public void testQuery() throws IOException { + ourLog.info("** Performing Search"); + HttpGet read = new HttpGet(ourServerBase + "/MedicationRequest?category=community&identifier=urn:oid:2.16.840.1.113883.3.7418.12.3%7C&intent=order&medication.code:text=calcitriol,hectorol,Zemplar,rocaltrol,vectical,vitamin%20D,doxercalciferol,paricalcitol&status=active,completed"); + try (CloseableHttpResponse response = ourHttpClient.execute(read)) { + ourLog.info(response.toString()); + } + ourLog.info("** DONE Performing Search"); + + } + @Test public void testDeleteResourceConditional1() throws IOException { String methodName = "testDeleteResourceConditional1"; diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java index 86e45ff8829..7b30f1abe15 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscription.java @@ -31,6 +31,7 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.EventDefinition; import org.hl7.fhir.r4.model.Subscription; +import javax.annotation.Nonnull; import java.io.Serializable; import java.util.*; @@ -65,6 +66,39 @@ public class CanonicalSubscription implements Serializable { @JsonProperty("extensions") private Map myChannelExtensions; + /** + * Constructor + */ + public CanonicalSubscription() { + super(); + } + + /** + * Copy Constructor + */ + public CanonicalSubscription(CanonicalSubscription theSubscription) { + myChannelExtensions = new HashMap<>(theSubscription.getChannelExtensions()); + myChannelType = theSubscription.getChannelType(); + myCriteriaString = theSubscription.getCriteriaString(); + if (theSubscription.getEmailDetails() != null) { + myEmailDetails = new EmailDetails(theSubscription.getEmailDetails()); + } + if (theSubscription.getRestHookDetails() != null) { + myRestHookDetails = new RestHookDetails(theSubscription.getRestHookDetails()); + } + myHeaders = new ArrayList<>(theSubscription.getHeaders()); + myEndpointUrl = theSubscription.getEndpointUrl(); + myIdElement = theSubscription.getIdElementString(); + myPayloadString = theSubscription.getPayloadString(); + myStatus = theSubscription.getStatus(); + // FIXME: is this constructor needed +// my + } + + private Map getChannelExtensions() { + return myChannelExtensions != null ? myChannelExtensions : Collections.emptyMap(); + } + /** * For now we're using the R4 TriggerDefinition, but this * may change in the future when things stabilize @@ -105,8 +139,9 @@ public class CanonicalSubscription implements Serializable { myEndpointUrl = theEndpointUrl; } + @Nonnull public List getHeaders() { - return Collections.unmodifiableList(myHeaders); + return myHeaders != null ? Collections.unmodifiableList(myHeaders) : Collections.emptyList(); } public void setHeaders(List> theHeader) { @@ -236,6 +271,21 @@ public class CanonicalSubscription implements Serializable { @JsonProperty("subjectTemplate") private String mySubjectTemplate; + /** + * Construcor + */ + public EmailDetails() { + super(); + } + + /** + * Copy Constructor + */ + public EmailDetails(EmailDetails theEmailDetails) { + myFrom = theEmailDetails.getFrom(); + mySubjectTemplate = theEmailDetails.getSubjectTemplate(); + } + public String getFrom() { return myFrom; } @@ -261,6 +311,21 @@ public class CanonicalSubscription implements Serializable { @JsonProperty("deliverLatestVersion") private boolean myDeliverLatestVersion; + /** + * Constructor + */ + public RestHookDetails() { + super(); + } + + /** + * Copy constructor + */ + public RestHookDetails(RestHookDetails theRestHookDetails) { + myDeliverLatestVersion = theRestHookDetails.isDeliverLatestVersion(); + myStripVersionId = theRestHookDetails.isStripVersionId(); + } + public boolean isDeliverLatestVersion() { return myDeliverLatestVersion; } diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java index b2d9e803053..cd945e8f845 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionDeliveringRestHookSubscriber.java @@ -55,7 +55,9 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe protected void deliverPayload(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, EncodingEnum thePayloadType, IGenericClient theClient) { IBaseResource payloadResource = getAndMassagePayload(theMsg, theSubscription); - if (payloadResource == null) return; + if (payloadResource == null) { + return; + } doDelivery(theMsg, theSubscription, thePayloadType, theClient, payloadResource); } @@ -64,22 +66,6 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe IClientExecutable operation; switch (theMsg.getOperationType()) { case CREATE: - if (thePayloadResource == null || thePayloadResource.isEmpty()) { - if (thePayloadType != null ) { - operation = theClient.create().resource(thePayloadResource); - } else { - sendNotification(theMsg); - return; - } - } else { - if (thePayloadType != null ) { - operation = theClient.update().resource(thePayloadResource); - } else { - sendNotification(theMsg); - return; - } - } - break; case UPDATE: if (thePayloadResource == null || thePayloadResource.isEmpty()) { if (thePayloadType != null ) { @@ -179,10 +165,9 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionDe /** * Sends a POST notification without a payload - * @param theMsg */ protected void sendNotification(ResourceDeliveryMessage theMsg) { - Map> params = new HashMap(); + Map> params = new HashMap<>(); List
headers = new ArrayList<>(); StringBuilder url = new StringBuilder(theMsg.getSubscription().getEndpointUrl()); IHttpClient client = myFhirContext.getRestfulClientFactory().getHttpClient(url, params, "", RequestTypeEnum.POST, headers);