camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jp...@apache.org
Subject [camel] 02/02: camel-fhir refactor Read API
Date Mon, 01 Oct 2018 14:52:03 GMT
This is an automated email from the ASF dual-hosted git repository.

jpoth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5738127f3e30dbab1ced31359d45cc68e1090326
Author: jpoth <poth.john@gmail.com>
AuthorDate: Mon Sep 24 10:26:40 2018 +0200

    camel-fhir refactor Read API
---
 .../apache/camel/component/fhir/api/FhirRead.java  | 67 ++++++++++------------
 components/camel-fhir/camel-fhir-component/pom.xml |  1 +
 .../apache/camel/component/fhir/FhirReadIT.java    |  4 +-
 3 files changed, 34 insertions(+), 38 deletions(-)

diff --git a/components/camel-fhir/camel-fhir-api/src/main/java/org/apache/camel/component/fhir/api/FhirRead.java
b/components/camel-fhir/camel-fhir-api/src/main/java/org/apache/camel/component/fhir/api/FhirRead.java
index f01292b..605f3f1 100644
--- a/components/camel-fhir/camel-fhir-api/src/main/java/org/apache/camel/component/fhir/api/FhirRead.java
+++ b/components/camel-fhir/camel-fhir-api/src/main/java/org/apache/camel/component/fhir/api/FhirRead.java
@@ -20,6 +20,7 @@ import java.util.Map;
 import ca.uhn.fhir.rest.client.api.IGenericClient;
 import ca.uhn.fhir.rest.gclient.IReadExecutable;
 import ca.uhn.fhir.rest.gclient.IReadIfNoneMatch;
+import ca.uhn.fhir.rest.gclient.IReadTyped;
 import org.hl7.fhir.instance.model.api.IBaseResource;
 import org.hl7.fhir.instance.model.api.IIdType;
 import org.slf4j.Logger;
@@ -39,7 +40,7 @@ public class FhirRead {
     }
 
 
-    public IBaseResource resourceById(Class<IBaseResource> resource, IIdType id, String
ifVersionMatches,
+    public IBaseResource resourceById(Class<IBaseResource> resource, IIdType id,  String
ifVersionMatches,
                                       Boolean returnNull, IBaseResource returnResource, Boolean
throwError, Map<ExtraParameters, Object> extraParameters) {
         IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withId(id);
         ExtraParameters.process(extraParameters, readExecutable);
@@ -53,51 +54,53 @@ public class FhirRead {
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceByUrl(Class<IBaseResource> resource, IIdType iUrl,
String ifVersionMatches,
+    public IBaseResource  resourceById(Class<IBaseResource> resource, String stringId,
String version, String ifVersionMatches,
                                        Boolean returnNull, IBaseResource returnResource,
Boolean throwError, Map<ExtraParameters, Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withUrl(iUrl);
+        IReadTyped<IBaseResource> readTyped = client.read().resource(resource);
+        IReadExecutable<IBaseResource> readExecutable = readWithOptionalVersion(stringId,
readTyped, version);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceByUrl(String resourceClass, IIdType iUrl, String ifVersionMatches,
Boolean returnNull,
-                                       IBaseResource returnResource, Boolean throwError,
Map<ExtraParameters, Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withUrl(iUrl);
+    public IBaseResource resourceById(String resourceClass, String stringId, String ifVersionMatches,
String version,
+                                      Boolean returnNull, IBaseResource returnResource, Boolean
throwError, Map<ExtraParameters, Object> extraParameters) {
+        IReadTyped<IBaseResource> resource = client.read().resource(resourceClass);
+        IReadExecutable<IBaseResource> readExecutable = readWithOptionalVersion(stringId,
resource, version);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource  resourceById(Class<IBaseResource> resource, String stringId,
String ifVersionMatches,
-                                       Boolean returnNull, IBaseResource returnResource,
Boolean throwError, Map<ExtraParameters, Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withId(stringId);
+    public IBaseResource resourceById(Class<IBaseResource> resource, Long longId, String
ifVersionMatches,
+                                      Boolean returnNull, IBaseResource returnResource, Boolean
throwError, Map<ExtraParameters, Object> extraParameters) {
+        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withId(longId);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceByUrl(Class<IBaseResource> resource, String url, String
ifVersionMatches,
-                                       Boolean returnNull, IBaseResource returnResource,
Boolean throwError, Map<ExtraParameters, Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withUrl(url);
+    public IBaseResource resourceById(String resourceClass, Long longId, String ifVersionMatches,
Boolean returnNull,
+                                      IBaseResource returnResource, Boolean throwError, Map<ExtraParameters,
Object> extraParameters) {
+        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withId(longId);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceById(String resourceClass, String stringId, String ifVersionMatches,
-                                      Boolean returnNull, IBaseResource returnResource, Boolean
throwError, Map<ExtraParameters, Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withId(stringId);
+    public IBaseResource resourceByUrl(Class<IBaseResource> resource, IIdType iUrl,
String ifVersionMatches,
+                                       Boolean returnNull, IBaseResource returnResource,
Boolean throwError, Map<ExtraParameters, Object> extraParameters) {
+        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withUrl(iUrl);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceByIdAndVersion(String resourceClass, String stringId, String
version,
-                                                String ifVersionMatches, Boolean returnNull,
IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters)
{
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withIdAndVersion(stringId,
version);
+    public IBaseResource resourceByUrl(String resourceClass, IIdType iUrl, String ifVersionMatches,
Boolean returnNull,
+                                       IBaseResource returnResource, Boolean throwError,
Map<ExtraParameters, Object> extraParameters) {
+        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withUrl(iUrl);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceByIdAndVersion(Class<IBaseResource> resource, String
stringId, String version,
-                                                String ifVersionMatches, Boolean returnNull,
IBaseResource returnResource, Boolean throwError, Map<ExtraParameters, Object> extraParameters)
{
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withIdAndVersion(stringId,
version);
+    public IBaseResource resourceByUrl(Class<IBaseResource> resource, String url, String
ifVersionMatches,
+                                       Boolean returnNull, IBaseResource returnResource,
Boolean throwError, Map<ExtraParameters, Object> extraParameters) {
+        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withUrl(url);
         ExtraParameters.process(extraParameters, readExecutable);
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
@@ -109,21 +112,6 @@ public class FhirRead {
         return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
     }
 
-    public IBaseResource resourceById(Class<IBaseResource> resource, Long longId, String
ifVersionMatches,
-                                      Boolean returnNull, IBaseResource returnResource, Boolean
throwError, Map<ExtraParameters, Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resource).withId(longId);
-        ExtraParameters.process(extraParameters, readExecutable);
-        return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
-    }
-
-    public IBaseResource resourceById(String resourceClass, Long longId, String ifVersionMatches,
Boolean returnNull,
-                                      IBaseResource returnResource, Boolean throwError, Map<ExtraParameters,
Object> extraParameters) {
-        IReadExecutable<IBaseResource> readExecutable = client.read().resource(resourceClass).withId(longId);
-        ExtraParameters.process(extraParameters, readExecutable);
-        return processOptionalParams(ifVersionMatches, returnNull, returnResource, throwError,
readExecutable);
-    }
-
-
     private IBaseResource processOptionalParams(String ifVersionMatches, Boolean returnNull,
IBaseResource returnResource,
                                                 Boolean throwError, IReadExecutable<IBaseResource>
readExecutable) {
         if (ifVersionMatches != null) {
@@ -139,4 +127,11 @@ public class FhirRead {
         }
         return readExecutable.execute();
     }
+
+    private IReadExecutable<IBaseResource> readWithOptionalVersion(String stringId,
IReadTyped<IBaseResource> resource, String version) {
+        if (version != null) {
+            return resource.withIdAndVersion(stringId, version);
+        }
+        return resource.withId(stringId);
+    }
 }
diff --git a/components/camel-fhir/camel-fhir-component/pom.xml b/components/camel-fhir/camel-fhir-component/pom.xml
index d02e3e7..5e1d7c5 100644
--- a/components/camel-fhir/camel-fhir-component/pom.xml
+++ b/components/camel-fhir/camel-fhir-component/pom.xml
@@ -238,6 +238,7 @@
                     <nullableOption>returnResource</nullableOption>
                     <nullableOption>throwError</nullableOption>
                     <nullableOption>extraParameters</nullableOption>
+                    <nullableOption>version</nullableOption>
                   </nullableOptions>
                 </api>
                 <api>
diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirReadIT.java
b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirReadIT.java
index 42fc00c..67235b5 100644
--- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirReadIT.java
+++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirReadIT.java
@@ -247,11 +247,11 @@ public class FhirReadIT extends AbstractFhirTestSupport {
 
                 // test route for resourceById
                 from("direct://RESOURCE_BY_STRING_ID_AND_VERSION")
-                    .to("fhir://" + PATH_PREFIX + "/resourceByIdAndVersion");
+                    .to("fhir://" + PATH_PREFIX + "/resourceById");
 
                 // test route for resourceById
                 from("direct://RESOURCE_BY_STRING_ID_AND_VERSION_AND_STRING_RESOURCE")
-                    .to("fhir://" + PATH_PREFIX + "/resourceByIdAndVersion");
+                    .to("fhir://" + PATH_PREFIX + "/resourceById");
 
                 // test route for resourceByUrl
                 from("direct://RESOURCE_BY_IURL")


Mime
View raw message