#59 - More sorting out profile vs id problem
This commit is contained in:
parent
d0db838f45
commit
8865a77227
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Profile> retVal = new ArrayList<Profile>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<? extends IResource> 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<String> path, BaseRuntimeDeclaredChildDefinition theChild) {
|
||||
private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition<?> def, LinkedList<String> 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");
|
||||
|
||||
|
|
|
@ -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<Profile> retVal = new ArrayList<Profile>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue