From 4122867cc3056a89cd348bfc570f82796f6e987e Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Fri, 12 Dec 2014 11:42:14 -0500 Subject: [PATCH 01/10] Start of sorting out profile vs id problem --- .../context/RuntimeResourceDefinition.java | 21 +++++++ .../uhn/fhir/rest/server/RestfulServer.java | 24 +++++--- .../RuntimeResourceDefinitionTest.java | 59 ++++++++++++++++--- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index f357bd32f97..42c8ce1532f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -30,6 +30,7 @@ import java.util.Map; import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.ResourceDef; +import com.phloc.commons.url.URLValidator; public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition { @@ -74,10 +75,30 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini return ChildTypeEnum.RESOURCE; } + @Deprecated public String getResourceProfile() { return myResourceProfile; } + public String getResourceProfile(String theServerBase) { + String profile; + if (!myResourceProfile.isEmpty()) { + profile = myResourceProfile; + } else if (!myId.isEmpty()) { + profile = myId; + } else { + return ""; + } + + if (!URLValidator.isValid(profile)) { + String profileWithUrl = theServerBase + "/Profile/" + profile; + if (URLValidator.isValid(profileWithUrl)) { + return profileWithUrl; + } + } + return profile; + } + public RuntimeSearchParam getSearchParam(String theName) { return myNameToSearchParam.get(theName); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index c8c448bd7e6..29bebcd146b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -469,11 +469,7 @@ public class RestfulServer extends HttpServlet { requestPath = requestPath.substring(1); } - fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest); - - if (fhirServerBase.endsWith("/")) { - fhirServerBase = fhirServerBase.substring(0, fhirServerBase.length() - 1); - } + fhirServerBase = determineServerBase(theRequest); String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString(); @@ -710,6 +706,16 @@ public class RestfulServer extends HttpServlet { } + private String determineServerBase(HttpServletRequest theRequest) { + String fhirServerBase; + fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest); + + if (fhirServerBase.endsWith("/")) { + fhirServerBase = fhirServerBase.substring(0, fhirServerBase.length() - 1); + } + return fhirServerBase; + } + /** * Initializes the server. Note that this method is final to avoid accidentally introducing bugs in implementations, but subclasses may put initialization code in {@link #initialize()}, which is * called immediately before beginning initialization of the restful server's internal init. @@ -944,7 +950,7 @@ public class RestfulServer extends HttpServlet { myInterceptors.remove(theInterceptor); } - private static void addProfileToBundleEntry(FhirContext theContext, IResource theResource) { + private static void addProfileToBundleEntry(FhirContext theContext, IResource theResource, String theServerBase) { TagList tl = ResourceMetadataKeyEnum.TAG_LIST.get(theResource); if (tl == null) { @@ -953,7 +959,7 @@ public class RestfulServer extends HttpServlet { } RuntimeResourceDefinition nextDef = theContext.getResourceDefinition(theResource); - String profile = nextDef.getResourceProfile(); + String profile = nextDef.getResourceProfile(theServerBase); if (isNotBlank(profile)) { tl.add(new Tag(Tag.HL7_ORG_PROFILE_TAG, profile, null)); } @@ -1017,7 +1023,7 @@ public class RestfulServer extends HttpServlet { for (IResource nextRes : resourceList) { RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(nextRes); if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) { - addProfileToBundleEntry(theServer.getFhirContext(), nextRes); + addProfileToBundleEntry(theServer.getFhirContext(), nextRes, theServerBase); } } } @@ -1336,7 +1342,7 @@ public class RestfulServer extends HttpServlet { if (theServer.getAddProfileTag() != AddProfileTagEnum.NEVER) { RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(theResource); if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) { - addProfileToBundleEntry(theServer.getFhirContext(), theResource); + addProfileToBundleEntry(theServer.getFhirContext(), theResource, theServerBase); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java index 68caf6d83fa..cb53f1a8df2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java @@ -1,11 +1,6 @@ package ca.uhn.fhir.context; -import static org.junit.Assert.*; - -import java.util.List; - -import org.junit.Test; - +import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.resource.Profile; import ca.uhn.fhir.model.dstu.resource.Profile.ExtensionDefn; @@ -13,6 +8,12 @@ import ca.uhn.fhir.model.dstu.resource.Profile.Structure; import ca.uhn.fhir.model.dstu.resource.Profile.StructureElement; import ca.uhn.fhir.model.dstu.resource.ValueSet; import ca.uhn.fhir.model.dstu.valueset.DataTypeEnum; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class RuntimeResourceDefinitionTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuntimeResourceDefinitionTest.class); @@ -58,7 +59,7 @@ public class RuntimeResourceDefinitionTest { Profile profile = (Profile) def.toProfile(); - ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(profile)); + ourLog.info(ctx.newXmlParser().encodeResourceToString(profile)); List element = profile.getStructure().get(0).getElement(); assertEquals(1, element.get(0).getDefinition().getType().size()); @@ -102,4 +103,48 @@ public class RuntimeResourceDefinitionTest { assertEquals("customobservation", profile.getId().toString()); } + @Test + public void whenResourceProfileNotSet_ProfileShouldBeConstructedFromServerBaseAndId() { + FhirContext ctx = new FhirContext(PatientSansProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientSansProfile.class); + assertEquals("http://foo.org/fhir/Profile/PatientSansProfile", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient", id = "PatientSansProfile") + class PatientSansProfile extends Patient { + } + + @Test + public void whenResourceProfileHasNoUrl_ProfileShouldBeConstructedFromServerBaseAndProfile() { + FhirContext ctx = new FhirContext(PatientWithShortProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithShortProfile.class); + assertEquals("http://foo.org/fhir/Profile/PatientWithShortProfile", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient", id = "PatientWithShortProfileId", profile="PatientWithShortProfile") + class PatientWithShortProfile extends Patient { + } + + @Test + public void whenResourceProfileHasUrl_ProfileShouldUseThat() { + FhirContext ctx = new FhirContext(PatientWithFullProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithFullProfile.class); + assertEquals("http://bar.org/Profile/PatientWithFullProfile", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient", id = "PatientWithFullProfileId", profile="http://bar.org/Profile/PatientWithFullProfile") + class PatientWithFullProfile extends Patient { + } + + @Test + public void whenProfileAndIdAreBlank_ProfileShouldBeBlank() { + FhirContext ctx = new FhirContext(PatientWithNoIdOrProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithNoIdOrProfile.class); + assertEquals("", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient") + class PatientWithNoIdOrProfile extends Patient { + } + } From 1501b3e278482188e86e1b40b8ff35a43cae6956 Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Fri, 12 Dec 2014 11:42:14 -0500 Subject: [PATCH 02/10] #59 - Start of sorting out profile vs id problem --- .../context/RuntimeResourceDefinition.java | 21 +++++++ .../uhn/fhir/rest/server/RestfulServer.java | 24 +++++--- .../RuntimeResourceDefinitionTest.java | 59 ++++++++++++++++--- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index f357bd32f97..42c8ce1532f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -30,6 +30,7 @@ import java.util.Map; import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.ResourceDef; +import com.phloc.commons.url.URLValidator; public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition { @@ -74,10 +75,30 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini return ChildTypeEnum.RESOURCE; } + @Deprecated public String getResourceProfile() { return myResourceProfile; } + public String getResourceProfile(String theServerBase) { + String profile; + if (!myResourceProfile.isEmpty()) { + profile = myResourceProfile; + } else if (!myId.isEmpty()) { + profile = myId; + } else { + return ""; + } + + if (!URLValidator.isValid(profile)) { + String profileWithUrl = theServerBase + "/Profile/" + profile; + if (URLValidator.isValid(profileWithUrl)) { + return profileWithUrl; + } + } + return profile; + } + public RuntimeSearchParam getSearchParam(String theName) { return myNameToSearchParam.get(theName); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index c8c448bd7e6..29bebcd146b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -469,11 +469,7 @@ public class RestfulServer extends HttpServlet { requestPath = requestPath.substring(1); } - fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest); - - if (fhirServerBase.endsWith("/")) { - fhirServerBase = fhirServerBase.substring(0, fhirServerBase.length() - 1); - } + fhirServerBase = determineServerBase(theRequest); String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString(); @@ -710,6 +706,16 @@ public class RestfulServer extends HttpServlet { } + private String determineServerBase(HttpServletRequest theRequest) { + String fhirServerBase; + fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest); + + if (fhirServerBase.endsWith("/")) { + fhirServerBase = fhirServerBase.substring(0, fhirServerBase.length() - 1); + } + return fhirServerBase; + } + /** * Initializes the server. Note that this method is final to avoid accidentally introducing bugs in implementations, but subclasses may put initialization code in {@link #initialize()}, which is * called immediately before beginning initialization of the restful server's internal init. @@ -944,7 +950,7 @@ public class RestfulServer extends HttpServlet { myInterceptors.remove(theInterceptor); } - private static void addProfileToBundleEntry(FhirContext theContext, IResource theResource) { + private static void addProfileToBundleEntry(FhirContext theContext, IResource theResource, String theServerBase) { TagList tl = ResourceMetadataKeyEnum.TAG_LIST.get(theResource); if (tl == null) { @@ -953,7 +959,7 @@ public class RestfulServer extends HttpServlet { } RuntimeResourceDefinition nextDef = theContext.getResourceDefinition(theResource); - String profile = nextDef.getResourceProfile(); + String profile = nextDef.getResourceProfile(theServerBase); if (isNotBlank(profile)) { tl.add(new Tag(Tag.HL7_ORG_PROFILE_TAG, profile, null)); } @@ -1017,7 +1023,7 @@ public class RestfulServer extends HttpServlet { for (IResource nextRes : resourceList) { RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(nextRes); if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) { - addProfileToBundleEntry(theServer.getFhirContext(), nextRes); + addProfileToBundleEntry(theServer.getFhirContext(), nextRes, theServerBase); } } } @@ -1336,7 +1342,7 @@ public class RestfulServer extends HttpServlet { if (theServer.getAddProfileTag() != AddProfileTagEnum.NEVER) { RuntimeResourceDefinition def = theServer.getFhirContext().getResourceDefinition(theResource); if (theServer.getAddProfileTag() == AddProfileTagEnum.ALWAYS || !def.isStandardProfile()) { - addProfileToBundleEntry(theServer.getFhirContext(), theResource); + addProfileToBundleEntry(theServer.getFhirContext(), theResource, theServerBase); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java index 68caf6d83fa..cb53f1a8df2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java @@ -1,11 +1,6 @@ package ca.uhn.fhir.context; -import static org.junit.Assert.*; - -import java.util.List; - -import org.junit.Test; - +import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.resource.Profile; import ca.uhn.fhir.model.dstu.resource.Profile.ExtensionDefn; @@ -13,6 +8,12 @@ import ca.uhn.fhir.model.dstu.resource.Profile.Structure; import ca.uhn.fhir.model.dstu.resource.Profile.StructureElement; import ca.uhn.fhir.model.dstu.resource.ValueSet; import ca.uhn.fhir.model.dstu.valueset.DataTypeEnum; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class RuntimeResourceDefinitionTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RuntimeResourceDefinitionTest.class); @@ -58,7 +59,7 @@ public class RuntimeResourceDefinitionTest { Profile profile = (Profile) def.toProfile(); - ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(profile)); + ourLog.info(ctx.newXmlParser().encodeResourceToString(profile)); List element = profile.getStructure().get(0).getElement(); assertEquals(1, element.get(0).getDefinition().getType().size()); @@ -102,4 +103,48 @@ public class RuntimeResourceDefinitionTest { assertEquals("customobservation", profile.getId().toString()); } + @Test + public void whenResourceProfileNotSet_ProfileShouldBeConstructedFromServerBaseAndId() { + FhirContext ctx = new FhirContext(PatientSansProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientSansProfile.class); + assertEquals("http://foo.org/fhir/Profile/PatientSansProfile", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient", id = "PatientSansProfile") + class PatientSansProfile extends Patient { + } + + @Test + public void whenResourceProfileHasNoUrl_ProfileShouldBeConstructedFromServerBaseAndProfile() { + FhirContext ctx = new FhirContext(PatientWithShortProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithShortProfile.class); + assertEquals("http://foo.org/fhir/Profile/PatientWithShortProfile", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient", id = "PatientWithShortProfileId", profile="PatientWithShortProfile") + class PatientWithShortProfile extends Patient { + } + + @Test + public void whenResourceProfileHasUrl_ProfileShouldUseThat() { + FhirContext ctx = new FhirContext(PatientWithFullProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithFullProfile.class); + assertEquals("http://bar.org/Profile/PatientWithFullProfile", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient", id = "PatientWithFullProfileId", profile="http://bar.org/Profile/PatientWithFullProfile") + class PatientWithFullProfile extends Patient { + } + + @Test + public void whenProfileAndIdAreBlank_ProfileShouldBeBlank() { + FhirContext ctx = new FhirContext(PatientWithNoIdOrProfile.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(PatientWithNoIdOrProfile.class); + assertEquals("", def.getResourceProfile("http://foo.org/fhir")); + } + + @ResourceDef(name = "Patient") + class PatientWithNoIdOrProfile extends Patient { + } + } From d0db838f45be3fcf7aa9c308231e7329976e7bb8 Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Tue, 16 Dec 2014 09:25:12 -0500 Subject: [PATCH 03/10] #59 - More sorting out profile vs id problem --- .../fhir/context/RuntimeResourceDefinition.java | 13 ++++++++++++- .../java/ca/uhn/fhir/model/api/IFhirVersion.java | 8 +++++--- .../java/ca/uhn/fhirtest/TestRestfulServer.java | 3 ++- .../main/java/ca/uhn/fhir/model/dev/FhirDev.java | 4 +++- .../provider/dev/ServerProfileProvider.java | 10 ++++++---- .../java/ca/uhn/fhir/model/dstu/FhirDstu1.java | 6 ++++-- .../server/provider/ServerProfileProvider.java | 15 +++++++++------ .../fhir/rest/server/RestfulServerMethodTest.java | 14 ++++++++++---- .../server/RestfulServerSelfReferenceTest.java | 2 +- .../java/ca/uhn/fhir/model/dstu/FhirDstu1.java | 4 +++- 10 files changed, 55 insertions(+), 24 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index 42c8ce1532f..af23c263a25 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -32,6 +32,8 @@ import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.ResourceDef; import com.phloc.commons.url.URLValidator; +import javax.servlet.http.HttpServletRequest; + public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition { private RuntimeResourceDefinition myBaseDefinition; @@ -136,17 +138,26 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini } while (target.equals(Object.class)==false); } + @Deprecated public synchronized IResource toProfile() { if (myProfileDef != null) { return myProfileDef; } - IResource retVal = myContext.getVersion().generateProfile(this); + IResource retVal = myContext.getVersion().generateProfile(this, null); myProfileDef = retVal; return retVal; } + public synchronized IResource toProfile(HttpServletRequest theRequest) { + if (myProfileDef != null) { + return myProfileDef; + } + IResource retVal = myContext.getVersion().generateProfile(this, theRequest); + myProfileDef = retVal; + return retVal; + } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java index a1b97f896a3..093f99549de 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java @@ -24,12 +24,14 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import javax.servlet.http.HttpServletRequest; + public interface IFhirVersion { - IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition); + IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest); Object createServerConformanceProvider(RestfulServer theServer); - IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer); - + IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer); + } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index 6ecd9709ed1..148ca56ad75 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -72,7 +72,8 @@ public class TestRestfulServer extends RestfulServer { String baseUrl = System.getProperty("fhir.baseurl"); if (StringUtils.isBlank(baseUrl)) { - throw new ServletException("Missing system property: fhir.baseurl"); + //throw new ServletException("Missing system property: fhir.baseurl"); + baseUrl = "http://localhost:8080/base"; } setServerAddressStrategy(new HardcodedServerAddressStrategy(baseUrl)); diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java index de6f79ef724..dc2680aff8c 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java @@ -32,6 +32,8 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.provider.dev.ServerConformanceProvider; import ca.uhn.fhir.rest.server.provider.dev.ServerProfileProvider; +import javax.servlet.http.HttpServletRequest; + public class FhirDev implements IFhirVersion { private String myId; @@ -42,7 +44,7 @@ public class FhirDev implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { Profile retVal = new Profile(); RuntimeResourceDefinition def = theRuntimeResourceDefinition; diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java index 1e11a5034fc..4c4321b98b1 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java @@ -35,6 +35,8 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.server.IResourceProvider; +import javax.servlet.http.HttpServletRequest; + public class ServerProfileProvider implements IResourceProvider { private FhirContext myContext; @@ -49,16 +51,16 @@ public class ServerProfileProvider implements IResourceProvider { } @Read() - public Profile getProfileById(@IdParam IdDt theId) { + public Profile getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) { RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getValue()); if (retVal==null) { return null; } - return (Profile) retVal.toProfile(); + return (Profile) retVal.toProfile(theRequest); } @Search() - public List getAllProfiles() { + public List getAllProfiles(HttpServletRequest theRequest) { List defs = new ArrayList(myContext.getResourceDefinitions()); Collections.sort(defs, new Comparator() { @Override @@ -71,7 +73,7 @@ public class ServerProfileProvider implements IResourceProvider { }}); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { - retVal.add((Profile) next.toProfile()); + retVal.add((Profile) next.toProfile(theRequest)); } return retVal; } diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index 4b88824e4dc..a1cc2fefc92 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -55,6 +55,8 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider; import ca.uhn.fhir.rest.server.provider.ServerProfileProvider; +import javax.servlet.http.HttpServletRequest; + public class FhirDstu1 implements IFhirVersion { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirDstu1.class); @@ -231,7 +233,7 @@ public class FhirDstu1 implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { Profile retVal = new Profile(); RuntimeResourceDefinition def = theRuntimeResourceDefinition; @@ -318,7 +320,7 @@ public class FhirDstu1 implements IFhirVersion { @Override public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) { - return new ServerProfileProvider(theRestfulServer.getFhirContext()); + return new ServerProfileProvider(theRestfulServer); } } diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java index 0bfaf1d1d22..113e0bbc5ba 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java @@ -34,13 +34,16 @@ import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.RestfulServer; + +import javax.servlet.http.HttpServletRequest; public class ServerProfileProvider implements IResourceProvider { private FhirContext myContext; - public ServerProfileProvider(FhirContext theCtx) { - myContext = theCtx; + public ServerProfileProvider(RestfulServer theServer) { + myContext = theServer.getFhirContext(); } @Override @@ -49,16 +52,16 @@ public class ServerProfileProvider implements IResourceProvider { } @Read() - public Profile getProfileById(@IdParam IdDt theId) { + public Profile getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) { RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart()); if (retVal==null) { return null; } - return (Profile) retVal.toProfile(); + return (Profile) retVal.toProfile(theRequest); } @Search() - public List getAllProfiles() { + public List getAllProfiles(HttpServletRequest theRequest) { List defs = new ArrayList(myContext.getResourceDefinitions()); Collections.sort(defs, new Comparator() { @Override @@ -71,7 +74,7 @@ public class ServerProfileProvider implements IResourceProvider { }}); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { - retVal.add((Profile) next.toProfile()); + retVal.add((Profile) next.toProfile(theRequest)); } return retVal; } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java index 9f48e00acc6..688cbe09a66 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java @@ -997,7 +997,7 @@ public class RestfulServerMethodTest { public void testServerProfileProviderFindsProfiles() { ServerProfileProvider profileProvider = (ServerProfileProvider)ourRestfulServer.getServerProfilesProvider(); IdDt id = new IdDt("Profile", "observation"); - Profile profile = profileProvider.getProfileById(id); + Profile profile = profileProvider.getProfileById(null, id); assertNotNull(profile); } @@ -1013,12 +1013,14 @@ public class RestfulServerMethodTest { ourCtx = new FhirContext(Patient.class); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); - ServerProfileProvider profProvider = new ServerProfileProvider(ourCtx); ourReportProvider = new DummyDiagnosticReportResourceProvider(); DummyAdverseReactionResourceProvider adv = new DummyAdverseReactionResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - ourRestfulServer =new DummyRestfulServer(patientProvider, profProvider, ourReportProvider, adv); + DummyRestfulServer dummyServer = new DummyRestfulServer(patientProvider, ourReportProvider, adv); + ourRestfulServer = dummyServer; + ServerProfileProvider profProvider = new ServerProfileProvider(ourRestfulServer); + dummyServer.addResourceProvider(profProvider); ServletHolder servletHolder = new ServletHolder(ourRestfulServer); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); @@ -1370,7 +1372,11 @@ public class RestfulServerMethodTest { private Collection myResourceProviders; public DummyRestfulServer(IResourceProvider... theResourceProviders) { - myResourceProviders = Arrays.asList(theResourceProviders); + myResourceProviders = new ArrayList(Arrays.asList(theResourceProviders)); + } + + public void addResourceProvider(IResourceProvider theResourceProvider) { + myResourceProviders.add(theResourceProvider); } @Override diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java index 8616ec7d97c..2a648b3441b 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java @@ -106,10 +106,10 @@ public class RestfulServerSelfReferenceTest { Server hServer = new Server(port); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); - ServerProfileProvider profProvider = new ServerProfileProvider(ourCtx); ServletHandler proxyHandler = new ServletHandler(); RestfulServer server = new RestfulServer(); + ServerProfileProvider profProvider = new ServerProfileProvider(server); server.setFhirContext(ourCtx); server.setResourceProviders(patientProvider, profProvider); ServletHolder servletHolder = new ServletHolder(server); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index 085b0f926d9..dcb0fb45bc2 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -6,6 +6,8 @@ import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import javax.servlet.http.HttpServletRequest; + public class FhirDstu1 implements IFhirVersion { @Override @@ -19,7 +21,7 @@ public class FhirDstu1 implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { throw new UnsupportedOperationException(); } From 8865a77227f6e8c5592ac6ca6e061e3b56b17790 Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Tue, 16 Dec 2014 11:25:57 -0500 Subject: [PATCH 04/10] #59 - More sorting out profile vs id problem --- .../context/RuntimeResourceDefinition.java | 4 ++-- .../ca/uhn/fhir/model/api/IFhirVersion.java | 2 +- .../ca/uhn/fhir/rest/server/RestfulServer.java | 5 ++--- .../java/ca/uhn/fhir/model/dev/FhirDev.java | 4 ++-- .../provider/dev/ServerProfileProvider.java | 18 +++++++++++++----- .../java/ca/uhn/fhir/model/dstu/FhirDstu1.java | 17 ++++++++--------- .../server/provider/ServerProfileProvider.java | 14 +++++++++++--- 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index af23c263a25..fe834f684ab 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -150,12 +150,12 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini return retVal; } - public synchronized IResource toProfile(HttpServletRequest theRequest) { + public synchronized IResource toProfile(String theServerBase) { if (myProfileDef != null) { return myProfileDef; } - IResource retVal = myContext.getVersion().generateProfile(this, theRequest); + IResource retVal = myContext.getVersion().generateProfile(this, theServerBase); myProfileDef = retVal; return retVal; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java index 093f99549de..24ec881c8dd 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java @@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletRequest; public interface IFhirVersion { - IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest); + IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase); Object createServerConformanceProvider(RestfulServer theServer); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 29bebcd146b..54eea9c63b1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -469,7 +469,7 @@ public class RestfulServer extends HttpServlet { requestPath = requestPath.substring(1); } - fhirServerBase = determineServerBase(theRequest); + fhirServerBase = getServerBaseForRequest(theRequest); String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString(); @@ -703,10 +703,9 @@ public class RestfulServer extends HttpServlet { theResponse.getWriter().close(); } - } - private String determineServerBase(HttpServletRequest theRequest) { + public String getServerBaseForRequest(HttpServletRequest theRequest) { String fhirServerBase; fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest); diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java index dc2680aff8c..d8741447285 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java @@ -44,7 +44,7 @@ public class FhirDev implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) { Profile retVal = new Profile(); RuntimeResourceDefinition def = theRuntimeResourceDefinition; @@ -60,7 +60,7 @@ public class FhirDev implements IFhirVersion { @Override public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) { - return new ServerProfileProvider(theRestfulServer.getFhirContext()); + return new ServerProfileProvider(theRestfulServer); } } diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java index 4c4321b98b1..226dba64953 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java @@ -34,15 +34,18 @@ import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.RestfulServer; import javax.servlet.http.HttpServletRequest; public class ServerProfileProvider implements IResourceProvider { - private FhirContext myContext; + private final FhirContext myContext; + private final RestfulServer myRestfulServer; - public ServerProfileProvider(FhirContext theCtx) { - myContext = theCtx; + public ServerProfileProvider(RestfulServer theServer) { + myContext = theServer.getFhirContext(); + myRestfulServer = theServer; } @Override @@ -56,7 +59,8 @@ public class ServerProfileProvider implements IResourceProvider { if (retVal==null) { return null; } - return (Profile) retVal.toProfile(theRequest); + String serverBase = getServerBase(theRequest); + return (Profile) retVal.toProfile(serverBase); } @Search() @@ -71,11 +75,15 @@ public class ServerProfileProvider implements IResourceProvider { } return cmp; }}); + String serverBase = getServerBase(theRequest); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { - retVal.add((Profile) next.toProfile(theRequest)); + retVal.add((Profile) next.toProfile(serverBase)); } return retVal; } + private String getServerBase(HttpServletRequest theHttpRequest) { + return myRestfulServer.getServerBaseForRequest(theHttpRequest); + } } diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index a1cc2fefc92..dffe8a137c8 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -130,7 +130,7 @@ public class FhirDstu1 implements IFhirVersion { } } - private void fillName(StructureElement elem, BaseRuntimeElementDefinition nextDef) { + private void fillName(StructureElement elem, BaseRuntimeElementDefinition nextDef, String theServerBase) { if (nextDef instanceof RuntimeResourceReferenceDefinition) { RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef; for (Class next : rr.getResourceTypes()) { @@ -139,7 +139,7 @@ public class FhirDstu1 implements IFhirVersion { if (next != IResource.class) { RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next); - type.getProfile().setValueAsString(resDef.getResourceProfile()); + type.getProfile().setValueAsString(resDef.getResourceProfile(theServerBase)); } } @@ -155,7 +155,7 @@ public class FhirDstu1 implements IFhirVersion { type.setCode(fromCodeString); } - private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition def, LinkedList path, BaseRuntimeDeclaredChildDefinition theChild) { + private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition def, LinkedList path, BaseRuntimeDeclaredChildDefinition theChild, String theServerBase) { fillBasics(theElement, def, path, theChild); @@ -203,7 +203,7 @@ public class FhirDstu1 implements IFhirVersion { if (child instanceof RuntimeChildResourceBlockDefinition) { RuntimeResourceBlockDefinition nextDef = (RuntimeResourceBlockDefinition) child.getSingleChildOrThrow(); - fillProfile(theStruct, elem, nextDef, path, child); + fillProfile(theStruct, elem, nextDef, path, child, theServerBase); } else if (child instanceof RuntimeChildContainedResources) { // ignore } else if (child instanceof RuntimeChildDeclaredExtensionDefinition) { @@ -214,10 +214,10 @@ public class FhirDstu1 implements IFhirVersion { String nextName = childNamesIter.next(); BaseRuntimeElementDefinition nextDef = child.getChildByName(nextName); fillBasics(elem, nextDef, path, child); - fillName(elem, nextDef); + fillName(elem, nextDef, theServerBase); while (childNamesIter.hasNext()) { nextDef = child.getChildByName(childNamesIter.next()); - fillName(elem, nextDef); + fillName(elem, nextDef, theServerBase); } path.pollLast(); } else { @@ -233,7 +233,7 @@ public class FhirDstu1 implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) { Profile retVal = new Profile(); RuntimeResourceDefinition def = theRuntimeResourceDefinition; @@ -262,8 +262,7 @@ public class FhirDstu1 implements IFhirVersion { StructureElement element = struct.addElement(); element.getDefinition().setMin(1); element.getDefinition().setMax("1"); - - fillProfile(struct, element, def, path, null); + fillProfile(struct, element, def, path, null, theServerBase); retVal.getStructure().get(0).getElement().get(0).getDefinition().addType().getCode().setValue("Resource"); diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java index 113e0bbc5ba..b41a8b4974d 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java @@ -35,15 +35,18 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import org.apache.http.HttpRequest; import javax.servlet.http.HttpServletRequest; public class ServerProfileProvider implements IResourceProvider { - private FhirContext myContext; + private final FhirContext myContext; + private final RestfulServer myRestfulServer; public ServerProfileProvider(RestfulServer theServer) { myContext = theServer.getFhirContext(); + myRestfulServer = theServer; } @Override @@ -57,7 +60,8 @@ public class ServerProfileProvider implements IResourceProvider { if (retVal==null) { return null; } - return (Profile) retVal.toProfile(theRequest); + String serverBase = getServerBase(theRequest); + return (Profile) retVal.toProfile(serverBase); } @Search() @@ -72,11 +76,15 @@ public class ServerProfileProvider implements IResourceProvider { } return cmp; }}); + String serverBase = getServerBase(theRequest); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { - retVal.add((Profile) next.toProfile(theRequest)); + retVal.add((Profile) next.toProfile(serverBase)); } return retVal; } + private String getServerBase(HttpServletRequest theHttpRequest) { + return myRestfulServer.getServerBaseForRequest(theHttpRequest); + } } From 3b5d4bfe5271234997737da2f3c7842f0f1e1309 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 16 Dec 2014 11:55:45 -0500 Subject: [PATCH 05/10] Fix accidental failed unit tests from #60 --- .../ca/uhn/fhir/rest/client/ClientTest.java | 2 + .../fhir/rest/client/GenericClientTest.java | 47 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java index 182b6947e17..896eaa2d835 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java @@ -147,6 +147,7 @@ public class ClientTest { HttpPost post = (HttpPost) capt.getValue(); assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString(" "; when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); client.create().resource(resourceText).withId("123").execute(); assertEquals("http://example.com/fhir/Patient/123", capt.getAllValues().get(2).getURI().toString()); assertEquals(resourceText, IOUtils.toString(((HttpPost) capt.getAllValues().get(2)).getEntity().getContent())); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); count++; } @@ -977,6 +976,8 @@ public class GenericClientTest { assertEquals("http://example.com/fhir", capt.getValue().getURI().toString()); assertEquals(bundle.getEntries().get(0).getId(), response.getEntries().get(0).getId()); + assertEquals(EncodingEnum.XML.getBundleContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(0).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + } @Test @@ -1042,25 +1043,25 @@ public class GenericClientTest { client.update().resource(p1).execute(); int count = 0; - + assertEquals(1, capt.getAllValues().size()); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.XML.getResourceContentType()+Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); count++; - + MethodOutcome outcome = client.update().resource(p1).execute(); assertEquals("44", outcome.getId().getIdPart()); assertEquals("22", outcome.getId().getVersionIdPart()); assertEquals(2, capt.getAllValues().size()); - + assertEquals("http://example.com/fhir/Patient/44", capt.getValue().getURI().toString()); assertEquals("PUT", capt.getValue().getMethod()); Header catH = capt.getValue().getFirstHeader("Category"); assertNotNull(Arrays.asList(capt.getValue().getAllHeaders()).toString(), catH); assertEquals("urn:happytag; label=\"This is a happy resource\"; scheme=\"http://hl7.org/fhir/tag\"", catH.getValue()); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.XML.getResourceContentType()+Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); /* * Try fluent options @@ -1098,29 +1099,29 @@ public class GenericClientTest { int count = 0; client.update().resource(myCtx.newXmlParser().encodeResourceToString(p1)).withId("1").execute(); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); assertThat(extractBody(capt, count), containsString("value=\"John\"")); count++; client.update().resource(myCtx.newJsonParser().encodeResourceToString(p1)).withId("1").execute(); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.JSON.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); assertThat(extractBody(capt, count), containsString("[\"John\"]")); count++; /* * e.g. Now try with reversed encoding (provide a string that's in JSON and ask the client to use XML) */ - + client.update().resource(myCtx.newXmlParser().encodeResourceToString(p1)).withId("1").encodedJson().execute(); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.JSON.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.JSON.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); assertThat(extractBody(capt, count), containsString("[\"John\"]")); count++; client.update().resource(myCtx.newJsonParser().encodeResourceToString(p1)).withId("1").encodedXml().execute(); assertEquals(1, capt.getAllValues().get(count).getHeaders(Constants.HEADER_CONTENT_TYPE).length); - assertEquals(EncodingEnum.XML.getResourceContentType(), capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); + assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(count).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue()); assertThat(extractBody(capt, count), containsString("value=\"John\"")); count++; } From 4599ec1544eb2e05b542079af51d3b2f8d36e9c8 Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Tue, 16 Dec 2014 13:48:59 -0500 Subject: [PATCH 06/10] #59 - Even more sorting out profile vs id problem --- .../jpa/provider/JpaConformanceProvider.java | 6 ++- .../provider/dev/ServerProfileProvider.java | 4 +- .../provider/ServerConformanceProvider.java | 6 ++- .../provider/ServerProfileProvider.java | 4 +- .../fhir/context/DuplicateExtensionTest.java | 4 +- .../ca/uhn/fhir/context/ExtensionTest.java | 2 +- .../RuntimeResourceDefinitionTest.java | 8 ++-- .../rest/server/RestfulServerMethodTest.java | 15 ++++++- .../server/ServerConformanceProviderTest.java | 39 ++++++++++++++----- 9 files changed, 62 insertions(+), 26 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java index d85d0c829da..e0fbd37b15d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/JpaConformanceProvider.java @@ -19,6 +19,8 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider; import ca.uhn.fhir.util.ExtensionConstants; +import javax.servlet.http.HttpServletRequest; + public class JpaConformanceProvider extends ServerConformanceProvider { private String myImplementationDescription; @@ -34,14 +36,14 @@ public class JpaConformanceProvider extends ServerConformanceProvider { } @Override - public Conformance getServerConformance() { + public Conformance getServerConformance(HttpServletRequest theRequest) { Conformance retVal = myCachedValue; Map counts = mySystemDao.getResourceCounts(); FhirContext ctx = myRestfulServer.getFhirContext(); - retVal = super.getServerConformance(); + retVal = super.getServerConformance(theRequest); for (Rest nextRest : retVal.getRest()) { for (RestResource nextResource : nextRest.getResource()) { diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java index 226dba64953..a3b2b730795 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java @@ -65,17 +65,17 @@ public class ServerProfileProvider implements IResourceProvider { @Search() public List getAllProfiles(HttpServletRequest theRequest) { + final String serverBase = getServerBase(theRequest); List defs = new ArrayList(myContext.getResourceDefinitions()); Collections.sort(defs, new Comparator() { @Override public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) { int cmp = theO1.getName().compareTo(theO2.getName()); if (cmp==0) { - cmp=theO1.getResourceProfile().compareTo(theO2.getResourceProfile()); + cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase)); } return cmp; }}); - String serverBase = getServerBase(theRequest); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { retVal.add((Profile) next.toProfile(serverBase)); diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java index 99e917cf8ea..c64742294df 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerConformanceProvider.java @@ -59,6 +59,8 @@ import ca.uhn.fhir.rest.server.ResourceBinding; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.util.ExtensionConstants; +import javax.servlet.http.HttpServletRequest; + /** * Server FHIR Provider which serves the conformance statement for a RESTful server implementation * @@ -95,7 +97,7 @@ public class ServerConformanceProvider { * See the class documentation for an important note if you are extending this class */ @Metadata - public Conformance getServerConformance() { + public Conformance getServerConformance(HttpServletRequest theRequest) { if (myConformance != null && myCache) { return myConformance; } @@ -134,7 +136,7 @@ public class ServerConformanceProvider { String resourceName = next.getResourceName(); RuntimeResourceDefinition def = myRestfulServer.getFhirContext().getResourceDefinition(resourceName); resource.getType().setValue(def.getName()); - resource.getProfile().setReference(new IdDt(def.getResourceProfile())); + resource.getProfile().setReference(new IdDt(def.getResourceProfile(myRestfulServer.getServerBaseForRequest(theRequest)))); TreeSet includes = new TreeSet(); diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java index b41a8b4974d..6c2bd4ad728 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java @@ -66,17 +66,17 @@ public class ServerProfileProvider implements IResourceProvider { @Search() public List getAllProfiles(HttpServletRequest theRequest) { + final String serverBase = getServerBase(theRequest); List defs = new ArrayList(myContext.getResourceDefinitions()); Collections.sort(defs, new Comparator() { @Override public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) { int cmp = theO1.getName().compareTo(theO2.getName()); if (cmp==0) { - cmp=theO1.getResourceProfile().compareTo(theO2.getResourceProfile()); + cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase)); } return cmp; }}); - String serverBase = getServerBase(theRequest); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { retVal.add((Profile) next.toProfile(serverBase)); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java index a391d4214c0..5c8474f7c5b 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java @@ -25,13 +25,13 @@ public class DuplicateExtensionTest extends TestCase { public void testScannerShouldAddProvidedResources() { FhirContext ctx = new FhirContext(); RuntimeResourceDefinition patientDef = ctx.getResourceDefinition(CustomPatient.class); - Profile profile = (Profile) patientDef.toProfile(); + Profile profile = (Profile) patientDef.toProfile("http://foo.org/fhir"); String res = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(profile); ourLog.info(res); RuntimeResourceDefinition observationDef = ctx.getResourceDefinition(CustomObservation.class); - profile = (Profile) observationDef.toProfile(); + profile = (Profile) observationDef.toProfile("http://foo.org/fhir"); } @ResourceDef(name = "Observation", id = "CustomObservation") diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java index afd83146fd6..706c2331bc7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java @@ -80,7 +80,7 @@ public class ExtensionTest { { FhirContext ctx2 = new FhirContext(); RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient); - System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile())); + System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile("http://foo.org/fhir"))); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java index cb53f1a8df2..5ad82284b37 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java @@ -23,7 +23,7 @@ public class RuntimeResourceDefinitionTest { FhirContext ctx = new FhirContext(Patient.class, Profile.class); RuntimeResourceDefinition def = ctx.getResourceDefinition(Patient.class); - Profile profile = (Profile) def.toProfile(); + Profile profile = (Profile) def.toProfile("http://foo.org/fhir"); ourLog.info(ctx.newXmlParser().encodeResourceToString(profile)); @@ -42,7 +42,7 @@ public class RuntimeResourceDefinitionTest { FhirContext ctx = new FhirContext(ValueSet.class, Profile.class); RuntimeResourceDefinition def = ctx.getResourceDefinition(ValueSet.class); - Profile profile = (Profile) def.toProfile(); + Profile profile = (Profile) def.toProfile("http://foo.org/fhir"); String encoded = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(profile); ourLog.info(encoded); @@ -57,7 +57,7 @@ public class RuntimeResourceDefinitionTest { FhirContext ctx = new FhirContext(ResourceWithExtensionsA.class, Profile.class); RuntimeResourceDefinition def = ctx.getResourceDefinition(ResourceWithExtensionsA.class); - Profile profile = (Profile) def.toProfile(); + Profile profile = (Profile) def.toProfile("http://foo.org/fhir"); ourLog.info(ctx.newXmlParser().encodeResourceToString(profile)); @@ -98,7 +98,7 @@ public class RuntimeResourceDefinitionTest { FhirContext ctx = new FhirContext(CustomObservation.class); RuntimeResourceDefinition def = ctx.getResourceDefinition(CustomObservation.class); - Profile profile = (Profile) def.toProfile(); + Profile profile = (Profile) def.toProfile("http://foo.org/fhir"); assertEquals("customobservation", profile.getId().toString()); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java index 688cbe09a66..589f70542bd 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java @@ -3,6 +3,8 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; @@ -72,6 +74,8 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.provider.ServerProfileProvider; import ca.uhn.fhir.util.PortUtil; +import javax.servlet.http.HttpServletRequest; + /** * Created by dsotnikov on 2/25/2014. */ @@ -997,10 +1001,19 @@ public class RestfulServerMethodTest { public void testServerProfileProviderFindsProfiles() { ServerProfileProvider profileProvider = (ServerProfileProvider)ourRestfulServer.getServerProfilesProvider(); IdDt id = new IdDt("Profile", "observation"); - Profile profile = profileProvider.getProfileById(null, id); + Profile profile = profileProvider.getProfileById(createHttpServletRequest(), id); assertNotNull(profile); } + private HttpServletRequest createHttpServletRequest() { + HttpServletRequest req = mock(HttpServletRequest.class); + when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search"); + when(req.getServletPath()).thenReturn("/fhir"); + when(req.getRequestURL()).thenReturn(new StringBuffer().append("http://fhirstorm.dyndns.org:8080/FhirStorm/fhir/Patient/_search")); + when(req.getContextPath()).thenReturn("/FhirStorm"); + return req; + } + @AfterClass public static void afterClass() throws Exception { ourServer.stop(); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java index 582e1d805a9..09eeaa570c9 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java @@ -4,6 +4,8 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.util.Collection; import java.util.List; @@ -33,6 +35,9 @@ import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider; +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServletRequest; + public class ServerConformanceProviderTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderTest.class); @@ -47,7 +52,7 @@ public class ServerConformanceProviderTest { ServerConformanceProvider sc = new ServerConformanceProvider(rs); rs.setServerConformanceProvider(sc); - rs.init(null); + rs.init(createServletConfig()); boolean found=false; Collection resourceBindings = rs.getResourceBindings(); @@ -61,7 +66,7 @@ public class ServerConformanceProviderTest { } } assertTrue(found); - Conformance conformance = sc.getServerConformance(); + Conformance conformance = sc.getServerConformance(createHttpServletRequest()); String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); @@ -81,9 +86,9 @@ public class ServerConformanceProviderTest { ServerConformanceProvider sc = new ServerConformanceProvider(rs); rs.setServerConformanceProvider(sc); - rs.init(null); + rs.init(createServletConfig()); - Conformance conformance = sc.getServerConformance(); + Conformance conformance = sc.getServerConformance(createHttpServletRequest()); myCtx.newValidator().validate(conformance); } @@ -99,7 +104,7 @@ public class ServerConformanceProviderTest { ServerConformanceProvider sc = new ServerConformanceProvider(rs); rs.setServerConformanceProvider(sc); - rs.init(null); + rs.init(createServletConfig()); boolean found=false; Collection resourceBindings = rs.getResourceBindings(); @@ -113,7 +118,7 @@ public class ServerConformanceProviderTest { } } assertTrue(found); - Conformance conformance = sc.getServerConformance(); + Conformance conformance = sc.getServerConformance(createHttpServletRequest()); String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); @@ -131,9 +136,9 @@ public class ServerConformanceProviderTest { ServerConformanceProvider sc = new ServerConformanceProvider(rs); rs.setServerConformanceProvider(sc); - rs.init(null); + rs.init(createServletConfig()); - Conformance conformance = sc.getServerConformance(); + Conformance conformance = sc.getServerConformance(createHttpServletRequest()); String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); @@ -147,8 +152,22 @@ public class ServerConformanceProviderTest { assertEquals(1,res.getSearchInclude().size()); assertEquals("DiagnosticReport.result", res.getSearchIncludeFirstRep().getValue()); } - - + + private HttpServletRequest createHttpServletRequest() { + HttpServletRequest req = mock(HttpServletRequest.class); + when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search"); + when(req.getServletPath()).thenReturn("/fhir"); + when(req.getRequestURL()).thenReturn(new StringBuffer().append("http://fhirstorm.dyndns.org:8080/FhirStorm/fhir/Patient/_search")); + when(req.getContextPath()).thenReturn("/FhirStorm"); + return req; + } + + private ServletConfig createServletConfig() { + ServletConfig sc = mock(ServletConfig.class); + when (sc.getServletContext()).thenReturn(null); + return sc; + } + /** * Created by dsotnikov on 2/25/2014. */ From 2d680b1c33e92102d03b57f7e5b9c79e8e05a511 Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Tue, 16 Dec 2014 15:09:55 -0500 Subject: [PATCH 07/10] #59 - Even more sorting out profile vs id problem --- .../src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index dcb0fb45bc2..d6dc6b220b3 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -21,7 +21,7 @@ public class FhirDstu1 implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) { throw new UnsupportedOperationException(); } From 8e6bb6333f3318c6f7f1aeeb5b5207b6a742c5dc Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 16 Dec 2014 16:27:00 -0500 Subject: [PATCH 08/10] Unit tests --- .../uhn/fhir/jpa/dao/SearchParameterMap.java | 10 +++++ .../test/CompleteResourceProviderTest.java | 39 +++++++++++++++++-- .../resources/vm/jpa_resource_provider.vm | 8 +++- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java index 4206516cfb1..ae15d54fd6a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchParameterMap.java @@ -19,6 +19,8 @@ public class SearchParameterMap extends HashMap myIncludes; private SortSpec mySort; @@ -66,6 +68,10 @@ public class SearchParameterMap extends HashMap getIncludes() { if (myIncludes == null) { myIncludes = new HashSet(); @@ -77,6 +83,10 @@ public class SearchParameterMap extends HashMap theIncludes) { myIncludes = theIncludes; } diff --git a/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java index 187ae836d8d..f81fa30f886 100644 --- a/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java +++ b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java @@ -3,7 +3,9 @@ package ca.uhn.fhir.jpa.test; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import org.apache.commons.io.IOUtils; import org.eclipse.jetty.server.Server; @@ -15,6 +17,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.provider.JpaSystemProvider; @@ -43,6 +46,7 @@ import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.gclient.StringClientParam; import ca.uhn.fhir.rest.gclient.TokenClientParam; +import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; @@ -67,6 +71,8 @@ public class CompleteResourceProviderTest { private static IFhirResourceDao ourQuestionnaireDao; private static Server ourServer; private static IFhirResourceDao ourOrganizationDao; + private static OrganizationResourceProvider ourOrganizationRp; + private static DaoConfig ourDaoConfig; // private static JpaConformanceProvider ourConfProvider; @@ -97,6 +103,29 @@ public class CompleteResourceProviderTest { } } + @Test + public void testCountParam() throws Exception { + // NB this does not get used- The paging provider has its own limits built in + ourDaoConfig.setHardSearchLimit(100); + + List resources = new ArrayList<>(); + for (int i = 0; i < 300; i++) { + Organization org = new Organization(); + org.setName("testCountParam_01"); + resources.add(org); + } + ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + + Bundle found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("testCountParam_01")).limitTo(10).execute(); + assertEquals(300, found.getTotalResults().getValue().intValue()); + assertEquals(10, found.getEntries().size()); + + found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("testCountParam_01")).limitTo(999).execute(); + assertEquals(300, found.getTotalResults().getValue().intValue()); + assertEquals(50, found.getEntries().size()); + + } + /** * See issue #52 */ @@ -452,6 +481,8 @@ public class CompleteResourceProviderTest { if (true) { ourAppCtx = new ClassPathXmlApplicationContext("fhir-spring-test-config.xml"); + ourDaoConfig = (DaoConfig)ourAppCtx.getBean(DaoConfig.class); + ourPatientDao = (IFhirResourceDao) ourAppCtx.getBean("myPatientDao", IFhirResourceDao.class); PatientResourceProvider patientRp = new PatientResourceProvider(); patientRp.setDao(ourPatientDao); @@ -473,8 +504,8 @@ public class CompleteResourceProviderTest { encounterRp.setDao(encounterDao); ourOrganizationDao = (IFhirResourceDao) ourAppCtx.getBean("myOrganizationDao", IFhirResourceDao.class); - OrganizationResourceProvider organizationRp = new OrganizationResourceProvider(); - organizationRp.setDao(ourOrganizationDao); + ourOrganizationRp = new OrganizationResourceProvider(); + ourOrganizationRp.setDao(ourOrganizationDao); IFhirResourceDao imagingStudyDao = (IFhirResourceDao) ourAppCtx.getBean("myImagingStudyDao", IFhirResourceDao.class); ImagingStudyResourceProvider imagingStudyRp = new ImagingStudyResourceProvider(); @@ -492,7 +523,7 @@ public class CompleteResourceProviderTest { DocumentReferenceResourceProvider documentReferenceRp = new DocumentReferenceResourceProvider(); documentReferenceRp.setDao(documentReferenceDao); - restServer.setResourceProviders(diagnosticOrderRp, documentManifestRp, documentReferenceRp, encounterRp, locationRp, patientRp, questionnaireRp, organizationRp, imagingStudyRp); + restServer.setResourceProviders(diagnosticOrderRp, documentManifestRp, documentReferenceRp, encounterRp, locationRp, patientRp, questionnaireRp, ourOrganizationRp, imagingStudyRp); restServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); IFhirSystemDao systemDao = (IFhirSystemDao) ourAppCtx.getBean("mySystemDao", IFhirSystemDao.class); @@ -502,6 +533,8 @@ public class CompleteResourceProviderTest { // ourConfProvider = new JpaConformanceProvider(restServer, systemDao, // Collections.singletonList((IFhirResourceDao)patientDao)); + restServer.setPagingProvider(new FifoMemoryPagingProvider(10)); + ourServer = new Server(port); ServletContextHandler proxyHandler = new ServletContextHandler(); diff --git a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm index f0f93ee42c2..43b16d103a6 100644 --- a/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm +++ b/hapi-tinder-plugin/src/main/resources/vm/jpa_resource_provider.vm @@ -73,7 +73,10 @@ public class ${className}ResourceProvider extends JpaResourceProvider<${classNam Set theIncludes, @Sort - SortSpec theSort + SortSpec theSort, + + @Count + Integer theCount ) { startRequest(theServletRequest); try { @@ -86,7 +89,8 @@ public class ${className}ResourceProvider extends JpaResourceProvider<${classNam paramMap.setIncludes(theIncludes); paramMap.setSort(theSort); - + paramMap.setCount(theCount); + ca.uhn.fhir.rest.server.IBundleProvider retVal = getDao().search(paramMap); return retVal; } finally { From a46183ddb8b6b80ef595f0c0076f7094a3b145a9 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 17 Dec 2014 12:40:22 -0500 Subject: [PATCH 09/10] Add some documentation for #59 --- .../fhir/model/api/annotation/ResourceDef.java | 16 +++++++++++++--- .../jpa/test/CompleteResourceProviderTest.java | 9 +++++---- .../.settings/org.eclipse.wst.common.component | 2 +- .../java/ca/uhn/fhirtest/TestRestfulServer.java | 3 +-- src/changes/changes.xml | 6 ++++++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java index 03daf573e32..418e6ff7f64 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java @@ -33,17 +33,27 @@ import java.lang.annotation.Target; public @interface ResourceDef { /** - * The name of the resource (e.g. "Patient" or "DiagnosticReport") + * The name of the resource (e.g. "Patient" or "DiagnosticReport"). If you are defining your + * own custom extension to a built-in FHIR resource definition type (e.g. you are extending + * the built-in Patient class) you do not need to supply a value for this property, as it + * will be inferred from the parent class. */ String name() default ""; /** - * if set, will be used as the id for any profiles generated for this resource + * if set, will be used as the id for any profiles generated for this resource. This property + * should be set for custom profile definition classes, and will be used as the resource ID + * for the generated profile exported by the server. For example, if you set this value to + * "hello" on a custom resource class, your server will automatically export a profile with the + * identity: http://localhost:8080/fhir/Profile/hello (the base URL will be whatever + * your server uses, not necessarily "http://localhost:8080/fhir") */ String id() default ""; /** - * The URL indicating the profile for this resource definition, if known + * The URL indicating the profile for this resource definition, if known. If this value is set + * on a custom profile definition class in a server, the profile is assumed to be external to + * the server, so the server will not export a profile for it. */ String profile() default ""; diff --git a/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java index f81fa30f886..3fa9d9e8565 100644 --- a/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java +++ b/hapi-fhir-jpaserver-test/src/test/java/ca/uhn/fhir/jpa/test/CompleteResourceProviderTest.java @@ -109,7 +109,7 @@ public class CompleteResourceProviderTest { ourDaoConfig.setHardSearchLimit(100); List resources = new ArrayList<>(); - for (int i = 0; i < 300; i++) { + for (int i = 0; i < 100; i++) { Organization org = new Organization(); org.setName("testCountParam_01"); resources.add(org); @@ -117,11 +117,11 @@ public class CompleteResourceProviderTest { ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); Bundle found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("testCountParam_01")).limitTo(10).execute(); - assertEquals(300, found.getTotalResults().getValue().intValue()); + assertEquals(100, found.getTotalResults().getValue().intValue()); assertEquals(10, found.getEntries().size()); found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("testCountParam_01")).limitTo(999).execute(); - assertEquals(300, found.getTotalResults().getValue().intValue()); + assertEquals(100, found.getTotalResults().getValue().intValue()); assertEquals(50, found.getEntries().size()); } @@ -241,7 +241,8 @@ public class CompleteResourceProviderTest { } Bundle history = ourClient.history(null, (String) null, null, null); - assertEquals(p1Id.getIdPart(), history.getEntries().get(0).getId().getIdPart()); + + assertEquals("Expected[" + p1Id.getIdPart() + "] but was " + history.getEntries().get(0).getId(), p1Id.getIdPart(), history.getEntries().get(0).getId().getIdPart()); assertNotNull(history.getEntries().get(0).getResource()); } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component b/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component index 6c40b81fe82..0a683f4735f 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component +++ b/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component @@ -15,7 +15,7 @@ uses - + consumes diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index 148ca56ad75..6ecd9709ed1 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -72,8 +72,7 @@ public class TestRestfulServer extends RestfulServer { String baseUrl = System.getProperty("fhir.baseurl"); if (StringUtils.isBlank(baseUrl)) { - //throw new ServletException("Missing system property: fhir.baseurl"); - baseUrl = "http://localhost:8080/base"; + throw new ServletException("Missing system property: fhir.baseurl"); } setServerAddressStrategy(new HardcodedServerAddressStrategy(baseUrl)); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b7c96731eb9..7ea132dc547 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -189,6 +189,12 @@ header, leading to servers incorrectly assuming ISO-8859/1. Thanks to shvoidlee for reporting! + + Clean up the way that Profile resources are automatically exported + by the server for custom resource profile classes. See the + @ResourceDef]]> + JavaDoc for information on how this works. + From 7e8f81293e1870a73eb1a4fc723b3c6dc8c3f367 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 17 Dec 2014 14:22:10 -0500 Subject: [PATCH 10/10] Tagging and deploying 0.8 --- examples/pom.xml | 6 +- hapi-deployable-pom/pom.xml | 2 +- hapi-deployable-pom/pom.xml.versionsBackup | 117 ++++++++++++++++++ hapi-fhir-base/pom.xml | 30 +---- hapi-fhir-base/testmindeps/pom.xml | 6 +- hapi-fhir-dist/pom.xml | 100 +++++++++++++++ .../src/assembly/hapi-fhir-all.xml | 9 +- hapi-fhir-jpaserver-base/pom.xml | 6 +- hapi-fhir-jpaserver-test/pom.xml | 8 +- hapi-fhir-jpaserver-uhnfhirtest/pom.xml | 14 +-- hapi-fhir-structures-dev/pom.xml | 8 +- hapi-fhir-structures-dstu/pom.xml | 6 +- hapi-fhir-testpage-overlay/pom.xml | 8 +- hapi-tinder-plugin/pom.xml | 4 +- hapi-tinder-test/pom.xml | 10 +- pom.xml | 3 +- restful-server-example-test/pom.xml | 6 +- restful-server-example/pom.xml | 6 +- src/changes/changes.xml | 2 +- src/site/xdoc/doc_upgrading.xml | 18 +-- src/site/xdoc/index.xml | 47 ++++++- 21 files changed, 318 insertions(+), 98 deletions(-) create mode 100644 hapi-deployable-pom/pom.xml.versionsBackup create mode 100644 hapi-fhir-dist/pom.xml rename {hapi-fhir-base => hapi-fhir-dist}/src/assembly/hapi-fhir-all.xml (80%) diff --git a/examples/pom.xml b/examples/pom.xml index 6f01017290a..c43a8bf80c4 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml @@ -17,12 +17,12 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 javax.servlet diff --git a/hapi-deployable-pom/pom.xml b/hapi-deployable-pom/pom.xml index c54c52212b4..a939fe3fd45 100644 --- a/hapi-deployable-pom/pom.xml +++ b/hapi-deployable-pom/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml diff --git a/hapi-deployable-pom/pom.xml.versionsBackup b/hapi-deployable-pom/pom.xml.versionsBackup new file mode 100644 index 00000000000..c54c52212b4 --- /dev/null +++ b/hapi-deployable-pom/pom.xml.versionsBackup @@ -0,0 +1,117 @@ + + 4.0.0 + + + ca.uhn.hapi.fhir + hapi-fhir + 0.8-SNAPSHOT + ../pom.xml + + + hapi-deployable-pom + pom + + HAPI FHIR - Deployable Artifact Parent POM + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + + scm + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven_javadoc_plugin_version} + + + default + + javadoc + + + + http://jamesagnew.github.io/hapi-fhir/apidocs/ + https://docs.oracle.com/javaee/7/api/ + + + + + + + + + + + DIST + + + + org.apache.maven.plugins + maven-javadoc-plugin + true + + 128m + 1g + true + false + false + + + + package + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven_source_plugin_version} + + + package + + jar-no-fork + + + + + + org.codehaus.mojo + license-maven-plugin + ${maven_license_plugin_version} + + + first + + update-file-header + + process-sources + + apache_v2 + true + true + + src/main/java + + + + + + + + + + + diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index ebef43721bc..df3204c4507 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-deployable-pom - 0.8-SNAPSHOT + 0.8 ../hapi-deployable-pom/pom.xml @@ -195,39 +195,13 @@ - - DIST - - - - maven-assembly-plugin - ${maven_assembly_plugin_version} - - - package - - single - - - false - - ${project.basedir}/src/assembly/hapi-fhir-all.xml - - - - - - - - - ANDROID ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-base/testmindeps/pom.xml b/hapi-fhir-base/testmindeps/pom.xml index 114863ed25f..abf236e0aff 100644 --- a/hapi-fhir-base/testmindeps/pom.xml +++ b/hapi-fhir-base/testmindeps/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../../pom.xml @@ -40,12 +40,12 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-dist/pom.xml b/hapi-fhir-dist/pom.xml new file mode 100644 index 00000000000..d67816e0dd6 --- /dev/null +++ b/hapi-fhir-dist/pom.xml @@ -0,0 +1,100 @@ + + 4.0.0 + + + ca.uhn.hapi.fhir + hapi-deployable-pom + 0.8 + ../pom.xml + + + hapi-fhir-structures-dstu + pom + + HAPI FHIR Structures - DSTU (FHIR 0.80) + + + + ca.uhn.hapi.fhir + hapi-fhir-base + 0.8 + + + ca.uhn.hapi.fhir + hapi-fhir-structures-dstu + 0.8 + + + ca.uhn.hapi.fhir + hapi-fhir-structures-dev + 0.8 + + + ch.qos.logback + logback-classic + ${logback_version} + + + org.ebaysf.web + cors-filter + ${ebay_cors_filter_version} + + + org.thymeleaf + thymeleaf + ${thymeleaf-version} + + + com.phloc + phloc-schematron + ${phloc_schematron_version} + + + com.phloc + phloc-commons + ${phloc_commons_version} + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + + + + DIST + + + + maven-assembly-plugin + ${maven_assembly_plugin_version} + + + package + + single + + + false + + ${project.basedir}/src/assembly/hapi-fhir-all.xml + + + + + + + + + + + diff --git a/hapi-fhir-base/src/assembly/hapi-fhir-all.xml b/hapi-fhir-dist/src/assembly/hapi-fhir-all.xml similarity index 80% rename from hapi-fhir-base/src/assembly/hapi-fhir-all.xml rename to hapi-fhir-dist/src/assembly/hapi-fhir-all.xml index f47dfeb810e..671f6d703b3 100644 --- a/hapi-fhir-base/src/assembly/hapi-fhir-all.xml +++ b/hapi-fhir-dist/src/assembly/hapi-fhir-all.xml @@ -20,18 +20,11 @@ NOTICE* - - ${project.build.directory} - /lib - - *.jar - - - /lib/dependency + /lib true false runtime diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index 36702050c3b..b8cebb3b1a9 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml @@ -35,7 +35,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 commons-logging @@ -46,7 +46,7 @@ ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-jpaserver-test/pom.xml b/hapi-fhir-jpaserver-test/pom.xml index b030f9f9c57..f9545a2c634 100644 --- a/hapi-fhir-jpaserver-test/pom.xml +++ b/hapi-fhir-jpaserver-test/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml @@ -17,7 +17,7 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-base - 0.8-SNAPSHOT + 0.8 org.thymeleaf @@ -127,7 +127,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.8-SNAPSHOT + 0.8 buildclient @@ -160,7 +160,7 @@ ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml index ea4f87258d9..a50ded1314b 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml @@ -16,17 +16,17 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-base - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - 0.8-SNAPSHOT + 0.8 war provided @@ -34,7 +34,7 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-test - 0.8-SNAPSHOT + 0.8 test @@ -190,7 +190,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.8-SNAPSHOT + 0.8 buildclient @@ -274,7 +274,7 @@ ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-structures-dev/pom.xml b/hapi-fhir-structures-dev/pom.xml index bbcf2fa83eb..0731b3af6a5 100644 --- a/hapi-fhir-structures-dev/pom.xml +++ b/hapi-fhir-structures-dev/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-deployable-pom - 0.8-SNAPSHOT + 0.8 ../hapi-deployable-pom/pom.xml @@ -18,7 +18,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 @@ -32,7 +32,7 @@ ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 test @@ -201,7 +201,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-structures-dstu/pom.xml b/hapi-fhir-structures-dstu/pom.xml index 609667bb495..73349b272a9 100644 --- a/hapi-fhir-structures-dstu/pom.xml +++ b/hapi-fhir-structures-dstu/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-deployable-pom - 0.8-SNAPSHOT + 0.8 ../hapi-deployable-pom/pom.xml @@ -18,7 +18,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 @@ -195,7 +195,7 @@ ca.uhn.hapi.fhir hapi-tinder-plugin - 0.8-SNAPSHOT + 0.8 diff --git a/hapi-fhir-testpage-overlay/pom.xml b/hapi-fhir-testpage-overlay/pom.xml index 36604cc760b..cb63eb9394a 100644 --- a/hapi-fhir-testpage-overlay/pom.xml +++ b/hapi-fhir-testpage-overlay/pom.xml @@ -4,7 +4,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml @@ -27,12 +27,12 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 org.thymeleaf @@ -55,7 +55,7 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-test - 0.8-SNAPSHOT + 0.8 test diff --git a/hapi-tinder-plugin/pom.xml b/hapi-tinder-plugin/pom.xml index e9f510b3eb7..0d41091016f 100644 --- a/hapi-tinder-plugin/pom.xml +++ b/hapi-tinder-plugin/pom.xml @@ -5,7 +5,7 @@ ca.uhn.hapi.fhir hapi-fhir - 0.8-SNAPSHOT + 0.8 ../pom.xml @@ -19,7 +19,7 @@ ca.uhn.hapi.fhir hapi-fhir-base - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-structures-dstu - 0.8-SNAPSHOT + 0.8 ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - 0.8-SNAPSHOT + 0.8 war provided diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7ea132dc547..3c54cdf50db 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -6,7 +6,7 @@ HAPI FHIR Changelog - + API CHANGE:]]> The "FHIR structures" for DSTU1 (the classes which model the resources and composite datatypes) have been moved out of the core JAR into their diff --git a/src/site/xdoc/doc_upgrading.xml b/src/site/xdoc/doc_upgrading.xml index c6811c33ed6..8d68b1f5e10 100644 --- a/src/site/xdoc/doc_upgrading.xml +++ b/src/site/xdoc/doc_upgrading.xml @@ -13,20 +13,9 @@ - - -

- If you are using the "Tinder" Maven plugin to generate structure code, - you will need to add a structure dependency to the plugin configuration - itself in your project pom.xml. See the - Tinder Page for an example of - how to do this. -

- -
-
+

@@ -57,8 +46,9 @@ resources, or both depending on your needs. Note that using DEV resources may introduce incompatibilities with other frameworks however. If you are including this JAR, you must also include hapi-fhir-structures-dstu-[version].jar. - Hopefully by the time 0.8 is final this requirement will be relaxed, but for now it - is mandatory. + We are planning on removing the requirement to include + the DSTU structures in your application (so you can include only the + DEV ones) for HAPI-FHIR 0.9. diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 79f81336d5f..e6e4fb5b15a 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -39,6 +39,50 @@

+

+ Dec 17, 2014 - HAPI FHIR 0.8 Released - HAPI 0.8 has been released! + As always, thanks to everyone who contributed on this; this release includes + a lot of bug fixes and new features from around the world. +

+

+ See the changelog + for a complete list of what's new! +

+

+ In particular, this release marks the beginning of our push to separate the model + classes (e.g. Patient, Encounter, etc.) from the core API, so that you can use any + version of the structures you want in your application, or even combine versions if + you need to. As is the case with HAPI's HL7 v2 library, you now need to include at least + one new separate "structures" JAR with your application as of HAPI-FHIR 0.8. See the + Upgrading + and + Download + pages for more information. +

+

+ With the newly separated "structures" dependencies, we have also introduced + a separate "dev" version of the structures, which contains the current development + structure definitions, which are now close to being in their final DSTU2 state + (DSTU2 should be released in mid 2015 by HL7 although the date is not yet finalized). + DSTU2 contains a number of new and updated resource definitions, but it also makes + several infrastructure changes including a new Bundle format and a new encoding style + for extensions in JSON. These changes are not yet supported in HAPI-FHIR 0.8, but + will be included in HAPI-FHIR 0.9. We expect to deploy a working snapshot build of + HAPI-FHIR 0.9 within the next day or so, including all of these changes. +

+

+ One further note: We are currently working with Grahame Grieve on an initiative + to harmonize HAPI's model objects with the FHIR Java Reference Implementation. This + means that developers should in the future be able to use either the HAPI built-in + resource definitions or the ones shipped by HL7. The advantage to this is that + it will allow users of HAPI's API to take advantage of other tooling produced + by HL7 (such as profile validators). Please get in touch (either by email or + on the Google Group) if you would like to help test this. +

+

+ - James Agnew +

+

Oct 23, 2014 - HAPI FHIR 0.7 Released - HAPI 0.7 has been released! This release contains a number of contributions and bugfixes from all over @@ -68,6 +112,7 @@ - James Agnew

+