Dont overwrite absolute IDs in the server

This commit is contained in:
James Agnew 2014-11-18 14:29:57 -05:00
parent 62ef60e096
commit 7ca4bc30d2
3 changed files with 77 additions and 35 deletions

View File

@ -117,7 +117,13 @@ public class Bundle extends BaseBundle /* implements IElement */{
entry.getTitle().setValue(def.getName() + " " + StringUtils.defaultString(theResource.getId().getValue(), "(no ID)"));
}
if (theResource.getId() != null && StringUtils.isNotBlank(theResource.getId().getValue())) {
if (theResource.getId() != null) {
if (theResource.getId().isAbsolute()) {
entry.getLinkSelf().setValue(theResource.getId().getValue());
entry.getId().setValue(theResource.getId().toVersionless().getValue());
} else if (StringUtils.isNotBlank(theResource.getId().getValue())) {
StringBuilder b = new StringBuilder();
b.append(theServerBase);
@ -168,6 +174,7 @@ public class Bundle extends BaseBundle /* implements IElement */{
}
}
}
InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource);
if (published == null) {

View File

@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
@ -223,6 +224,25 @@ public class ServerFeaturesTest {
}
@Test
public void testSearchReturnWithAbsoluteIdSpecified() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/?_query=findPatientsWithAbsoluteIdSpecified");
httpGet.addHeader("Accept", Constants.CT_FHIR_XML + "; pretty=true");
CloseableHttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
Bundle bundle = servlet.getFhirContext().newXmlParser().parseBundle(responseContent);
assertEquals(1,bundle.size());
assertEquals("http://absolute.com/Patient/123", bundle.getEntries().get(0).getId().getValue());
assertEquals("http://absolute.com/Patient/123/_history/22", bundle.getEntries().get(0).getLinkSelf().getValue());
}
@Test
public void testSearchWithWildcardRetVal() throws Exception {
@ -345,6 +365,15 @@ public class ServerFeaturesTest {
return Collections.singletonList(p);
}
@Search(queryName = "findPatientsWithAbsoluteIdSpecified")
public List<Patient> findPatientsWithAbsoluteIdSpecified() {
Patient p = new Patient();
p.addIdentifier().setSystem("foo");
p.setId("http://absolute.com/Patient/123/_history/22");
return Collections.singletonList(p);
}
@Override
public Class<Patient> getResourceType() {
return Patient.class;

View File

@ -120,6 +120,12 @@
DateDt left precision value as null in the constructor
<![CDATA[DateDt(Date)]]>.
</action>
<action type="fix">
RESTful server now doesn't overwrite resource IDs if they are absolute. In other words, if
a server's Resource Provider returns a resource with ID "Patient/123" it will be translated to
"[base url]/Patient/123" but if the RP returns ID "http://foo/Patient/123" the ID will be
returned exactly as is. Thanks to Bill de Beaubien for the suggestion!
</action>
</release>
<release version="0.7" date="2014-Oct-23">
<action type="add" issue="30">