#59 - More sorting out profile vs id problem
This commit is contained in:
parent
3358db974c
commit
d0db838f45
|
@ -32,6 +32,8 @@ import ca.uhn.fhir.model.api.IResource;
|
||||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
import com.phloc.commons.url.URLValidator;
|
import com.phloc.commons.url.URLValidator;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition<IResource> {
|
public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition<IResource> {
|
||||||
|
|
||||||
private RuntimeResourceDefinition myBaseDefinition;
|
private RuntimeResourceDefinition myBaseDefinition;
|
||||||
|
@ -136,17 +138,26 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
|
||||||
} while (target.equals(Object.class)==false);
|
} while (target.equals(Object.class)==false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public synchronized IResource toProfile() {
|
public synchronized IResource toProfile() {
|
||||||
if (myProfileDef != null) {
|
if (myProfileDef != null) {
|
||||||
return myProfileDef;
|
return myProfileDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
IResource retVal = myContext.getVersion().generateProfile(this);
|
IResource retVal = myContext.getVersion().generateProfile(this, null);
|
||||||
myProfileDef = retVal;
|
myProfileDef = retVal;
|
||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,14 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public interface IFhirVersion {
|
public interface IFhirVersion {
|
||||||
|
|
||||||
IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition);
|
IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest);
|
||||||
|
|
||||||
Object createServerConformanceProvider(RestfulServer theServer);
|
Object createServerConformanceProvider(RestfulServer theServer);
|
||||||
|
|
||||||
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
|
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,8 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
|
|
||||||
String baseUrl = System.getProperty("fhir.baseurl");
|
String baseUrl = System.getProperty("fhir.baseurl");
|
||||||
if (StringUtils.isBlank(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));
|
setServerAddressStrategy(new HardcodedServerAddressStrategy(baseUrl));
|
||||||
|
|
|
@ -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.ServerConformanceProvider;
|
||||||
import ca.uhn.fhir.rest.server.provider.dev.ServerProfileProvider;
|
import ca.uhn.fhir.rest.server.provider.dev.ServerProfileProvider;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class FhirDev implements IFhirVersion {
|
public class FhirDev implements IFhirVersion {
|
||||||
|
|
||||||
private String myId;
|
private String myId;
|
||||||
|
@ -42,7 +44,7 @@ public class FhirDev implements IFhirVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
|
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) {
|
||||||
Profile retVal = new Profile();
|
Profile retVal = new Profile();
|
||||||
|
|
||||||
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
|
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
|
||||||
|
|
|
@ -35,6 +35,8 @@ import ca.uhn.fhir.rest.annotation.Read;
|
||||||
import ca.uhn.fhir.rest.annotation.Search;
|
import ca.uhn.fhir.rest.annotation.Search;
|
||||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class ServerProfileProvider implements IResourceProvider {
|
public class ServerProfileProvider implements IResourceProvider {
|
||||||
|
|
||||||
private FhirContext myContext;
|
private FhirContext myContext;
|
||||||
|
@ -49,16 +51,16 @@ public class ServerProfileProvider implements IResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Read()
|
@Read()
|
||||||
public Profile getProfileById(@IdParam IdDt theId) {
|
public Profile getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) {
|
||||||
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getValue());
|
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getValue());
|
||||||
if (retVal==null) {
|
if (retVal==null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (Profile) retVal.toProfile();
|
return (Profile) retVal.toProfile(theRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Search()
|
@Search()
|
||||||
public List<Profile> getAllProfiles() {
|
public List<Profile> getAllProfiles(HttpServletRequest theRequest) {
|
||||||
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
||||||
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,7 +73,7 @@ public class ServerProfileProvider implements IResourceProvider {
|
||||||
}});
|
}});
|
||||||
ArrayList<Profile> retVal = new ArrayList<Profile>();
|
ArrayList<Profile> retVal = new ArrayList<Profile>();
|
||||||
for (RuntimeResourceDefinition next : defs) {
|
for (RuntimeResourceDefinition next : defs) {
|
||||||
retVal.add((Profile) next.toProfile());
|
retVal.add((Profile) next.toProfile(theRequest));
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ServerConformanceProvider;
|
||||||
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class FhirDstu1 implements IFhirVersion {
|
public class FhirDstu1 implements IFhirVersion {
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirDstu1.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirDstu1.class);
|
||||||
|
@ -231,7 +233,7 @@ public class FhirDstu1 implements IFhirVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
|
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) {
|
||||||
Profile retVal = new Profile();
|
Profile retVal = new Profile();
|
||||||
|
|
||||||
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
|
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
|
||||||
|
@ -318,7 +320,7 @@ public class FhirDstu1 implements IFhirVersion {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
|
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
|
||||||
return new ServerProfileProvider(theRestfulServer.getFhirContext());
|
return new ServerProfileProvider(theRestfulServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,16 @@ import ca.uhn.fhir.rest.annotation.IdParam;
|
||||||
import ca.uhn.fhir.rest.annotation.Read;
|
import ca.uhn.fhir.rest.annotation.Read;
|
||||||
import ca.uhn.fhir.rest.annotation.Search;
|
import ca.uhn.fhir.rest.annotation.Search;
|
||||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class ServerProfileProvider implements IResourceProvider {
|
public class ServerProfileProvider implements IResourceProvider {
|
||||||
|
|
||||||
private FhirContext myContext;
|
private FhirContext myContext;
|
||||||
|
|
||||||
public ServerProfileProvider(FhirContext theCtx) {
|
public ServerProfileProvider(RestfulServer theServer) {
|
||||||
myContext = theCtx;
|
myContext = theServer.getFhirContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,16 +52,16 @@ public class ServerProfileProvider implements IResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Read()
|
@Read()
|
||||||
public Profile getProfileById(@IdParam IdDt theId) {
|
public Profile getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) {
|
||||||
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
|
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
|
||||||
if (retVal==null) {
|
if (retVal==null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (Profile) retVal.toProfile();
|
return (Profile) retVal.toProfile(theRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Search()
|
@Search()
|
||||||
public List<Profile> getAllProfiles() {
|
public List<Profile> getAllProfiles(HttpServletRequest theRequest) {
|
||||||
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
|
||||||
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,7 +74,7 @@ public class ServerProfileProvider implements IResourceProvider {
|
||||||
}});
|
}});
|
||||||
ArrayList<Profile> retVal = new ArrayList<Profile>();
|
ArrayList<Profile> retVal = new ArrayList<Profile>();
|
||||||
for (RuntimeResourceDefinition next : defs) {
|
for (RuntimeResourceDefinition next : defs) {
|
||||||
retVal.add((Profile) next.toProfile());
|
retVal.add((Profile) next.toProfile(theRequest));
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -997,7 +997,7 @@ public class RestfulServerMethodTest {
|
||||||
public void testServerProfileProviderFindsProfiles() {
|
public void testServerProfileProviderFindsProfiles() {
|
||||||
ServerProfileProvider profileProvider = (ServerProfileProvider)ourRestfulServer.getServerProfilesProvider();
|
ServerProfileProvider profileProvider = (ServerProfileProvider)ourRestfulServer.getServerProfilesProvider();
|
||||||
IdDt id = new IdDt("Profile", "observation");
|
IdDt id = new IdDt("Profile", "observation");
|
||||||
Profile profile = profileProvider.getProfileById(id);
|
Profile profile = profileProvider.getProfileById(null, id);
|
||||||
assertNotNull(profile);
|
assertNotNull(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,12 +1013,14 @@ public class RestfulServerMethodTest {
|
||||||
ourCtx = new FhirContext(Patient.class);
|
ourCtx = new FhirContext(Patient.class);
|
||||||
|
|
||||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||||
ServerProfileProvider profProvider = new ServerProfileProvider(ourCtx);
|
|
||||||
ourReportProvider = new DummyDiagnosticReportResourceProvider();
|
ourReportProvider = new DummyDiagnosticReportResourceProvider();
|
||||||
DummyAdverseReactionResourceProvider adv = new DummyAdverseReactionResourceProvider();
|
DummyAdverseReactionResourceProvider adv = new DummyAdverseReactionResourceProvider();
|
||||||
|
|
||||||
ServletHandler proxyHandler = new ServletHandler();
|
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);
|
ServletHolder servletHolder = new ServletHolder(ourRestfulServer);
|
||||||
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
||||||
ourServer.setHandler(proxyHandler);
|
ourServer.setHandler(proxyHandler);
|
||||||
|
@ -1370,7 +1372,11 @@ public class RestfulServerMethodTest {
|
||||||
private Collection<IResourceProvider> myResourceProviders;
|
private Collection<IResourceProvider> myResourceProviders;
|
||||||
|
|
||||||
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
|
public DummyRestfulServer(IResourceProvider... theResourceProviders) {
|
||||||
myResourceProviders = Arrays.asList(theResourceProviders);
|
myResourceProviders = new ArrayList<IResourceProvider>(Arrays.asList(theResourceProviders));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addResourceProvider(IResourceProvider theResourceProvider) {
|
||||||
|
myResourceProviders.add(theResourceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -106,10 +106,10 @@ public class RestfulServerSelfReferenceTest {
|
||||||
Server hServer = new Server(port);
|
Server hServer = new Server(port);
|
||||||
|
|
||||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||||
ServerProfileProvider profProvider = new ServerProfileProvider(ourCtx);
|
|
||||||
|
|
||||||
ServletHandler proxyHandler = new ServletHandler();
|
ServletHandler proxyHandler = new ServletHandler();
|
||||||
RestfulServer server = new RestfulServer();
|
RestfulServer server = new RestfulServer();
|
||||||
|
ServerProfileProvider profProvider = new ServerProfileProvider(server);
|
||||||
server.setFhirContext(ourCtx);
|
server.setFhirContext(ourCtx);
|
||||||
server.setResourceProviders(patientProvider, profProvider);
|
server.setResourceProviders(patientProvider, profProvider);
|
||||||
ServletHolder servletHolder = new ServletHolder(server);
|
ServletHolder servletHolder = new ServletHolder(server);
|
||||||
|
|
|
@ -6,6 +6,8 @@ import ca.uhn.fhir.model.api.IResource;
|
||||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class FhirDstu1 implements IFhirVersion {
|
public class FhirDstu1 implements IFhirVersion {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +21,7 @@ public class FhirDstu1 implements IFhirVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition) {
|
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue