jm wrong bundle entry url (#4213)

* Bug test

* here you go

* Generate relative URIs for bundle entry.request.url, as specified

* Point jira issue in changelog

* Adjust tests to fixes

Co-authored-by: juan.marchionatto <juan.marchionatto@smilecdr.com>
Co-authored-by: Tadgh <garygrantgraham@gmail.com>
This commit is contained in:
jmarchionatto 2022-10-28 16:55:39 -04:00 committed by GitHub
parent 7a39f8cbaf
commit c6c095219d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 102 additions and 22 deletions

View File

@ -2234,7 +2234,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
return new TransactionExecutable<>(theResources);
}
}
private class UpdateInternal extends BaseSearch<IUpdateExecutable, IUpdateWithQueryTyped, MethodOutcome>

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 4210
jira: SMILE-4685
title: "Generating Bundle with resources was setting `entry.request.url` as absolute url when it should be relative. This has been fixed"

View File

@ -4,11 +4,13 @@ import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.CapabilityStatement;
import org.hl7.fhir.dstu3.model.CarePlan;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.PrimitiveType;
import org.hl7.fhir.dstu3.model.StringType;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -56,7 +58,27 @@ public class ResourceProviderDstu3BundleTest extends BaseResourceProviderDstu3Te
assertTrue(searchInclude.stream().map(PrimitiveType::getValue).anyMatch(stringRevIncludes -> stringRevIncludes.equals("Patient:general-practitioner")));
assertEquals(searchInclude.size(), 4);
}
}
@Test
void testTransactionBundleEntryUri() {
CarePlan carePlan = new CarePlan();
carePlan.getText().setDivAsString("A CarePlan");
carePlan.setId("ACarePlan");
ourClient.create().resource(carePlan).execute();
// GET CarePlans from server
Bundle bundle = ourClient.search()
.byUrl(ourServerBase + "/CarePlan")
.returnBundle(Bundle.class).execute();
// Create and populate list of CarePlans
List<CarePlan> carePlans = new ArrayList<>();
bundle.getEntry().forEach(entry -> carePlans.add((CarePlan) entry.getResource()));
// Post CarePlans should not get: HAPI-2006: Unable to perform PUT, URL provided is invalid...
ourClient.transaction().withResources(carePlans).execute();
}
}

View File

@ -5,7 +5,6 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
import ca.uhn.fhir.jpa.entity.Search;
import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.util.QueryParameterUtils;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.model.primitive.InstantDt;
@ -17,7 +16,6 @@ import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SearchTotalModeEnum;
import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.IHttpRequest;
@ -30,7 +28,6 @@ import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
@ -107,7 +104,6 @@ import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Parameters;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Period;
import org.hl7.fhir.dstu3.model.Person;
import org.hl7.fhir.dstu3.model.PlanDefinition;
import org.hl7.fhir.dstu3.model.Practitioner;
import org.hl7.fhir.dstu3.model.ProcedureRequest;
@ -2354,7 +2350,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
assertEquals(1, ((Patient) history.getEntry().get(0).getResource()).getName().size());
assertEquals(HTTPVerb.DELETE, history.getEntry().get(1).getRequest().getMethodElement().getValue());
assertEquals("http://localhost:" + ourPort + "/fhir/context/Patient/" + id.getIdPart() + "/_history/2", history.getEntry().get(1).getRequest().getUrl());
assertEquals("Patient/" + id.getIdPart() + "/_history/2", history.getEntry().get(1).getRequest().getUrl());
assertEquals(null, history.getEntry().get(1).getResource());
assertEquals(id.withVersion("1").getValue(), history.getEntry().get(2).getResource().getId());

View File

@ -10,6 +10,7 @@ import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CarePlan;
import org.hl7.fhir.r4.model.Condition;
import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.r4.model.OperationOutcome;
@ -331,4 +332,25 @@ public class ResourceProviderR4BundleTest extends BaseResourceProviderR4Test {
return ids;
}
@Test
void testTransactionBundleEntryUri() {
CarePlan carePlan = new CarePlan();
carePlan.getText().setDivAsString("A CarePlan");
carePlan.setId("ACarePlan");
myClient.create().resource(carePlan).execute();
// GET CarePlans from server
Bundle bundle = myClient.search()
.byUrl(ourServerBase + "/CarePlan")
.returnBundle(Bundle.class).execute();
// Create and populate list of CarePlans
List<CarePlan> carePlans = new ArrayList<>();
bundle.getEntry().forEach(entry -> carePlans.add((CarePlan) entry.getResource()));
// Post CarePlans should not get: HAPI-2006: Unable to perform PUT, URL provided is invalid...
myClient.transaction().withResources(carePlans).execute();
}
}

View File

@ -10,7 +10,6 @@ import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.model.util.UcumServiceUtil;
import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.term.ZipCollectionBuilder;
import ca.uhn.fhir.jpa.test.config.TestR4Config;
import ca.uhn.fhir.jpa.util.QueryParameterUtils;
@ -25,7 +24,6 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.SearchTotalModeEnum;
import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.client.apache.ResourceEntity;
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
import ca.uhn.fhir.rest.client.api.IGenericClient;
@ -41,7 +39,6 @@ import ca.uhn.fhir.rest.param.ParamPrefixEnum;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
@ -71,7 +68,6 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.jena.rdf.model.ModelCon;
import org.hamcrest.Matchers;
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator;
import org.hl7.fhir.instance.model.api.IAnyResource;
@ -132,7 +128,6 @@ import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Period;
import org.hl7.fhir.r4.model.Person;
import org.hl7.fhir.r4.model.Practitioner;
import org.hl7.fhir.r4.model.Procedure;
import org.hl7.fhir.r4.model.Quantity;
@ -3285,7 +3280,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
assertEquals(1, ((Patient) history.getEntry().get(0).getResource()).getName().size());
assertEquals(HTTPVerb.DELETE, history.getEntry().get(1).getRequest().getMethodElement().getValue());
assertEquals("http://localhost:" + ourPort + "/fhir/context/Patient/" + id.getIdPart() + "/_history/2", history.getEntry().get(1).getRequest().getUrl());
assertEquals("Patient/" + id.getIdPart() + "/_history/2", history.getEntry().get(1).getRequest().getUrl());
assertEquals(null, history.getEntry().get(1).getResource());
assertEquals(id.withVersion("1").getValue(), history.getEntry().get(2).getResource().getId());

View File

@ -13,20 +13,17 @@ import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4b.model.Bundle;
import org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4b.model.CarePlan;
import org.hl7.fhir.r4b.model.CodeableConcept;
import org.hl7.fhir.r4b.model.Condition;
import org.hl7.fhir.r4b.model.DateTimeType;
import org.hl7.fhir.r4b.model.MedicationRequest;
import org.hl7.fhir.r4b.model.Observation;
import org.hl7.fhir.r4b.model.Observation.ObservationComponentComponent;
import org.hl7.fhir.r4b.model.OperationOutcome;
import org.hl7.fhir.r4b.model.Organization;
import org.hl7.fhir.r4b.model.Parameters;
import org.hl7.fhir.r4b.model.Patient;
@ -464,6 +461,28 @@ public class ResourceProviderR4BTest extends BaseResourceProviderR4BTest {
assertThat(ids, Matchers.not(hasItem(o2Id)));
}
@Test
void testTransactionBundleEntryUri() {
CarePlan carePlan = new CarePlan();
carePlan.getText().setDivAsString("A CarePlan");
carePlan.setId("ACarePlan");
myClient.create().resource(carePlan).execute();
// GET CarePlans from server
Bundle bundle = myClient.search()
.byUrl(ourServerBase + "/CarePlan")
.returnBundle(Bundle.class).execute();
// Create and populate list of CarePlans
List<CarePlan> carePlans = new ArrayList<>();
bundle.getEntry().forEach(entry -> carePlans.add((CarePlan) entry.getResource()));
// Post CarePlans should not get: HAPI-2006: Unable to perform PUT, URL provided is invalid...
myClient.transaction().withResources(carePlans).execute();
}
private IIdType createOrganization(String methodName, String s) {
Organization o1 = new Organization();
o1.setName(methodName + s);

View File

@ -19,6 +19,7 @@ import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r5.model.CarePlan;
import org.hl7.fhir.r5.model.CodeableConcept;
import org.hl7.fhir.r5.model.Condition;
import org.hl7.fhir.r5.model.DateTimeType;
@ -481,6 +482,27 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test {
assertThat(ids, Matchers.not(hasItem(o2Id)));
}
@Test
void testTransactionBundleEntryUri() {
CarePlan carePlan = new CarePlan();
carePlan.getText().setDivAsString("A CarePlan");
carePlan.setId("ACarePlan");
myClient.create().resource(carePlan).execute();
// GET CarePlans from server
Bundle bundle = myClient.search()
.byUrl(ourServerBase + "/CarePlan")
.returnBundle(Bundle.class).execute();
// Create and populate list of CarePlans
List<CarePlan> carePlans = new ArrayList<>();
bundle.getEntry().forEach(entry -> carePlans.add((CarePlan) entry.getResource()));
// Post CarePlans should not get: HAPI-2006: Unable to perform PUT, URL provided is invalid...
myClient.transaction().withResources(carePlans).execute();
}
private IIdType createOrganization(String methodName, String s) {
Organization o1 = new Organization();
o1.setName(methodName + s);

View File

@ -136,7 +136,7 @@ public class Dstu3BundleFactory implements IVersionSpecificBundleFactory {
if (httpVerb != null) {
entry.getRequest().getMethodElement().setValueAsString(httpVerb);
if (id != null) {
entry.getRequest().setUrl(id.getValue());
entry.getRequest().setUrl(id.toUnqualified().getValue());
}
}
if ("DELETE".equals(httpVerb)) {

View File

@ -138,7 +138,7 @@ public class R4BundleFactory implements IVersionSpecificBundleFactory {
if (httpVerb != null) {
entry.getRequest().getMethodElement().setValueAsString(httpVerb);
if (id != null) {
entry.getRequest().setUrl(id.getValue());
entry.getRequest().setUrl(id.toUnqualified().getValue());
}
}
if ("DELETE".equals(httpVerb)) {

View File

@ -138,7 +138,7 @@ public class R4BBundleFactory implements IVersionSpecificBundleFactory {
if (httpVerb != null) {
entry.getRequest().getMethodElement().setValueAsString(httpVerb);
if (id != null) {
entry.getRequest().setUrl(id.getValue());
entry.getRequest().setUrl(id.toUnqualified().getValue());
}
}
if ("DELETE".equals(httpVerb)) {

View File

@ -138,7 +138,7 @@ public class R5BundleFactory implements IVersionSpecificBundleFactory {
if (httpVerb != null) {
entry.getRequest().getMethodElement().setValueAsString(httpVerb);
if (id != null) {
entry.getRequest().setUrl(id.getValue());
entry.getRequest().setUrl(id.toUnqualified().getValue());
}
}
if ("DELETE".equals(httpVerb)) {