#59 - Even more sorting out profile vs id problem
This commit is contained in:
parent
8865a77227
commit
4599ec1544
|
@ -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<String, Long> counts = mySystemDao.getResourceCounts();
|
||||
|
||||
FhirContext ctx = myRestfulServer.getFhirContext();
|
||||
|
||||
retVal = super.getServerConformance();
|
||||
retVal = super.getServerConformance(theRequest);
|
||||
for (Rest nextRest : retVal.getRest()) {
|
||||
for (RestResource nextResource : nextRest.getResource()) {
|
||||
|
||||
|
|
|
@ -65,17 +65,17 @@ public class ServerProfileProvider implements IResourceProvider {
|
|||
|
||||
@Search()
|
||||
public List<Profile> getAllProfiles(HttpServletRequest theRequest) {
|
||||
final String serverBase = getServerBase(theRequest);
|
||||
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
||||
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
||||
@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<Profile> retVal = new ArrayList<Profile>();
|
||||
for (RuntimeResourceDefinition next : defs) {
|
||||
retVal.add((Profile) next.toProfile(serverBase));
|
||||
|
|
|
@ -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<String> includes = new TreeSet<String>();
|
||||
|
||||
|
|
|
@ -66,17 +66,17 @@ public class ServerProfileProvider implements IResourceProvider {
|
|||
|
||||
@Search()
|
||||
public List<Profile> getAllProfiles(HttpServletRequest theRequest) {
|
||||
final String serverBase = getServerBase(theRequest);
|
||||
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
||||
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
||||
@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<Profile> retVal = new ArrayList<Profile>();
|
||||
for (RuntimeResourceDefinition next : defs) {
|
||||
retVal.add((Profile) next.toProfile(serverBase));
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<ResourceBinding> 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<ResourceBinding> 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);
|
||||
|
||||
|
@ -148,6 +153,20 @@ public class ServerConformanceProviderTest {
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue