From eeba5812cbd0e885398183aaba00dc04616fb022 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 8 May 2015 17:15:50 -0400 Subject: [PATCH] Finalize 1.0 release --- .../rest/method/TransactionParamBinder.java | 4 +- .../fhir/jpa/provider/SystemProviderTest.java | 10 + .../grahame-transaction-with-bad.xml | 446 ++++++++++++++++++ .../test/resources/grahame-transaction.xml | 285 +++++++++++ .../ca/uhn/fhir/model/dstu2/FhirDstu2.java | 2 +- .../uhn/fhir/model/dstu2/composite/AgeDt.java | 2 +- .../composite/BoundCodeableConceptDt.java | 2 +- .../model/dstu2/composite/ContainedDt.java | 2 +- .../fhir/model/dstu2/composite/CountDt.java | 2 +- .../model/dstu2/composite/DistanceDt.java | 2 +- .../model/dstu2/composite/DurationDt.java | 2 +- .../fhir/model/dstu2/composite/MoneyDt.java | 2 +- .../model/dstu2/composite/NarrativeDt.java | 2 +- .../dstu2/composite/ResourceReferenceDt.java | 2 +- .../model/dstu2/resource/BaseResource.java | 2 +- .../provider/dstu2/Dstu2BundleFactory.java | 2 +- .../dstu2/ServerConformanceProvider.java | 2 +- .../provider/dstu2/ServerProfileProvider.java | 2 +- ...ransactionWithBundleResourceParamTest.java | 53 ++- src/changes/changes.xml | 6 +- 20 files changed, 813 insertions(+), 19 deletions(-) create mode 100644 hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction-with-bad.xml create mode 100644 hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction.xml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/TransactionParamBinder.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/TransactionParamBinder.java index 4d769e650931..eccd462c0e20 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/TransactionParamBinder.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/TransactionParamBinder.java @@ -98,7 +98,9 @@ public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Obj @Override public Object translateQueryParametersIntoServerArgument(Request theRequest, Object theRequestContents) throws InternalErrorException, InvalidRequestException { - EncodingEnum encoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequest.getServer(), theRequest.getServletRequest()); + // TODO: don't use a default encoding, just fail! + EncodingEnum encoding = RestfulServerUtils.determineRequestEncoding(theRequest); + IParser parser = encoding.newParser(myContext); BufferedReader reader; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTest.java index ee449458d3ee..0032706bccc2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTest.java @@ -45,6 +45,16 @@ public void testTransactionFromBundle() throws Exception { ourLog.info(response); } + // TODO: enable! +// @Test + public void testTransactionFromBundle3() throws Exception { + + InputStream bundleRes = SystemProviderTest.class.getResourceAsStream("/grahame-transaction.xml"); + String bundle = IOUtils.toString(bundleRes); + String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + ourLog.info(response); + } + @Test public void testTransactionFromBundle2() throws Exception { diff --git a/hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction-with-bad.xml b/hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction-with-bad.xml new file mode 100644 index 000000000000..1bded386d931 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction-with-bad.xml @@ -0,0 +1,446 @@ + + + + + + + + + + + + +
Make sure links are updated: Patient +
+
+ + + + + + + +
+
+ + + + +
+ + + + + + + +
Snipped for brevity
+
+ + + + + + + + + + +
+
+ + + + + +
+ + + + + + +
Snipped for brevity
+
+ + + + + + + + + + +
+
+ + + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + + +
+ + + + + + +
Snipped
+
+ + + + + + + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + + + + + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Snipped for brevity
+
+ + + + + + + + + + +
+
+ + + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + + +
+ + + + + + +
Snipped
+
+ + + + + + + + + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Snipped
+
+ + + + + + + + +
+
+ + + + +
+
\ No newline at end of file diff --git a/hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction.xml b/hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction.xml new file mode 100644 index 000000000000..d3baf5b5aa88 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/resources/grahame-transaction.xml @@ -0,0 +1,285 @@ + + + + + + + + + + + + +
Make sure links are updated: Patient +
+
+ + + + + + + +
+
+ + + + +
+ + + + + + + +
Snipped for brevity
+
+ + + + + + + + + + +
+
+ + + + + +
+ + + + + + +
Snipped for brevity
+
+ + + + + + + + + + +
+
+ + + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + +
+
+ + + + + +
+ + + + + + +
Snipped
+
+ + + + + + + + + +
+
+ + + + +
+ + + + + + + +
Snipped
+
+ + + + + + + + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java index a4210031bb28..0582cf11a4e0 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/AgeDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/AgeDt.java index dea05376cd84..9c431063e1cd 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/AgeDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/AgeDt.java @@ -5,7 +5,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/BoundCodeableConceptDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/BoundCodeableConceptDt.java index 56b925bae7a6..10d03059c5a0 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/BoundCodeableConceptDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/BoundCodeableConceptDt.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ContainedDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ContainedDt.java index 7a743dd88018..79fbda49295e 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ContainedDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ContainedDt.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/CountDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/CountDt.java index e2cdc77bad8d..eca7cead03c3 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/CountDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/CountDt.java @@ -5,7 +5,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DistanceDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DistanceDt.java index f0ba234ec520..a29726319319 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DistanceDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DistanceDt.java @@ -5,7 +5,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DurationDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DurationDt.java index 2adbe8079287..7afd82cd2a93 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DurationDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/DurationDt.java @@ -5,7 +5,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/MoneyDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/MoneyDt.java index a5c7f645a094..21e9f337af6b 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/MoneyDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/MoneyDt.java @@ -5,7 +5,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/NarrativeDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/NarrativeDt.java index de18356fc42b..4e48daa240ad 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/NarrativeDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/NarrativeDt.java @@ -18,7 +18,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ResourceReferenceDt.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ResourceReferenceDt.java index 73e4d99bd644..1ad905822a46 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ResourceReferenceDt.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/composite/ResourceReferenceDt.java @@ -18,7 +18,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java index da7969555f60..48f320d0ce0e 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/resource/BaseResource.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java index 433b161b0925..c69b9733c5b5 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactory.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerConformanceProvider.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerConformanceProvider.java index e74d73967c50..ec1f8aaea0fa 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerConformanceProvider.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerConformanceProvider.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerProfileProvider.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerProfileProvider.java index f272e5100eec..5749d4a583c4 100644 --- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerProfileProvider.java +++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2/ServerProfileProvider.java @@ -2,7 +2,7 @@ /* * #%L - * HAPI FHIR Structures - DSTU2 (FHIR v0.4.0) + * HAPI FHIR Structures - DSTU2 (FHIR v0.5.0) * %% * Copyright (C) 2014 - 2015 University Health Network * %% diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java index 8c67b58fca7e..dce0d9c8bcb5 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java @@ -55,7 +55,7 @@ public void before() { } @Test - public void testTransaction() throws Exception { + public void testTransactionWithXmlRequest() throws Exception { Bundle b = new Bundle(); InstantDt nowInstant = InstantDt.withCurrentTime(); @@ -79,8 +79,55 @@ public void testTransaction() throws Exception { ourLog.info(bundleString); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); - httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true"); - httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_ATOM_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + HttpResponse status = ourClient.execute(httpPost); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + ourLog.info(responseContent); + + Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); + assertEquals(3, bundle.getEntry().size()); + + Entry entry0 = bundle.getEntry().get(0); + assertEquals("Patient/81/_history/91", entry0.getTransactionResponse().getLocation()); + + Entry entry1 = bundle.getEntry().get(1); + assertEquals( "Patient/82/_history/92", entry1.getTransactionResponse().getLocation()); + + Entry entry2 = bundle.getEntry().get(2); + assertEquals("Patient/123/_history/93", entry2.getTransactionResponse().getLocation()); + } + + @Test + public void testTransactionWithJsonRequest() throws Exception { + Bundle b = new Bundle(); + InstantDt nowInstant = InstantDt.withCurrentTime(); + + Patient p1 = new Patient(); + p1.addName().addFamily("Family1"); + Entry entry = b.addEntry(); + p1.getId().setValue("1"); + entry.setResource(p1); + + Patient p2 = new Patient(); + p2.addName().addFamily("Family2"); + entry = b.addEntry(); + p2.getId().setValue("2"); + entry.setResource(p2); + + Entry deletedEntry = b.addEntry(); + deletedEntry.getTransaction().setMethod(HTTPVerbEnum.DELETE); + deletedEntry.getTransaction().setUrl("http://base.com/Patient/123"); + + String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); + ourLog.info(bundleString); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); +// httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true"); + httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c129bdfc4484..50b79cc3bf4e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -195,7 +195,11 @@ Add support for :missing qualifier in JPA server. - + + Transaction server operations incorrectly used the "Accept" header instead of the "Content-Type" header to determine the + POST request encoding. Thanks to Rene Spronk for providing a test case! + + Support for DSTU2 features introduced: New resource definitions, Bundle resource,