fixed meta.source request append bug
This commit is contained in:
parent
f5788341f2
commit
0e90867a65
|
@ -47,12 +47,14 @@ import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||||
import ca.uhn.fhir.util.*;
|
import ca.uhn.fhir.util.CoverageIgnore;
|
||||||
|
import ca.uhn.fhir.util.MetaUtil;
|
||||||
|
import ca.uhn.fhir.util.StopWatch;
|
||||||
|
import ca.uhn.fhir.util.XmlUtil;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
@ -86,7 +88,6 @@ import javax.xml.stream.events.XMLEvent;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import static ca.uhn.fhir.jpa.model.util.JpaConstants.EXT_EXTERNALIZED_BINARY_ID;
|
|
||||||
import static org.apache.commons.lang3.StringUtils.*;
|
import static org.apache.commons.lang3.StringUtils.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -974,7 +975,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
|
||||||
|
|
||||||
// 6. Handle source (provenance)
|
// 6. Handle source (provenance)
|
||||||
if (isNotBlank(provenanceRequestId) || isNotBlank(provenanceSourceUri)) {
|
if (isNotBlank(provenanceRequestId) || isNotBlank(provenanceSourceUri)) {
|
||||||
String sourceString = defaultString(provenanceSourceUri)
|
String sourceString = cleanProvenanceSourceUri(provenanceSourceUri)
|
||||||
+ (isNotBlank(provenanceRequestId) ? "#" : "")
|
+ (isNotBlank(provenanceRequestId) ? "#" : "")
|
||||||
+ defaultString(provenanceRequestId);
|
+ defaultString(provenanceRequestId);
|
||||||
|
|
||||||
|
@ -992,6 +993,16 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao,
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String cleanProvenanceSourceUri(String theProvenanceSourceUri) {
|
||||||
|
if (isNotBlank(theProvenanceSourceUri)) {
|
||||||
|
int hashIndex = theProvenanceSourceUri.indexOf('#');
|
||||||
|
if (hashIndex != -1) {
|
||||||
|
theProvenanceSourceUri = theProvenanceSourceUri.substring(0, hashIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultString(theProvenanceSourceUri);
|
||||||
|
}
|
||||||
|
|
||||||
public String toResourceName(Class<? extends IBaseResource> theResourceType) {
|
public String toResourceName(Class<? extends IBaseResource> theResourceType) {
|
||||||
return myContext.getResourceDefinition(theResourceType).getName();
|
return myContext.getResourceDefinition(theResourceType).getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ca.uhn.fhir.jpa.dao;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class BaseHapiFhirDaoTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cleanProvenanceSourceUri() {
|
||||||
|
assertEquals("", BaseHapiFhirDao.cleanProvenanceSourceUri(null));
|
||||||
|
assertEquals("abc", BaseHapiFhirDao.cleanProvenanceSourceUri("abc"));
|
||||||
|
assertEquals("abc", BaseHapiFhirDao.cleanProvenanceSourceUri("abc#def"));
|
||||||
|
assertEquals("abc", BaseHapiFhirDao.cleanProvenanceSourceUri("abc#def#ghi"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.provider.dstu3;
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
||||||
import ca.uhn.fhir.jpa.entity.Search;
|
import ca.uhn.fhir.jpa.entity.Search;
|
||||||
|
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||||
import ca.uhn.fhir.jpa.provider.r4.ResourceProviderR4Test;
|
import ca.uhn.fhir.jpa.provider.r4.ResourceProviderR4Test;
|
||||||
import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
|
import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
|
@ -3913,6 +3914,31 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateWithSource() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setActive(false);
|
||||||
|
IIdType patientid = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
{
|
||||||
|
Patient readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute();
|
||||||
|
assertThat(readPatient.getMeta().getExtensionString(JpaConstants.EXT_META_SOURCE), matchesPattern("#[a-f0-9]+"));
|
||||||
|
}
|
||||||
|
|
||||||
|
patient.setId(patientid);
|
||||||
|
patient.setActive(true);
|
||||||
|
ourClient.update().resource(patient).execute();
|
||||||
|
{
|
||||||
|
Patient readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute();
|
||||||
|
assertThat(readPatient.getMeta().getExtensionString(JpaConstants.EXT_META_SOURCE), matchesPattern("#[a-f0-9]+"));
|
||||||
|
|
||||||
|
readPatient.addName().setFamily("testUpdateWithSource");
|
||||||
|
ourClient.update().resource(readPatient).execute();
|
||||||
|
readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute();
|
||||||
|
assertThat(readPatient.getMeta().getExtensionString(JpaConstants.EXT_META_SOURCE), matchesPattern("#[a-f0-9]+"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateWithETag() throws Exception {
|
public void testUpdateWithETag() throws Exception {
|
||||||
String methodName = "testUpdateWithETag";
|
String methodName = "testUpdateWithETag";
|
||||||
|
|
|
@ -5081,6 +5081,31 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateWithSource() {
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.setActive(false);
|
||||||
|
IIdType patientid = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
{
|
||||||
|
Patient readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute();
|
||||||
|
assertThat(readPatient.getMeta().getSource(), matchesPattern("#[a-f0-9]+"));
|
||||||
|
}
|
||||||
|
|
||||||
|
patient.setId(patientid);
|
||||||
|
patient.setActive(true);
|
||||||
|
ourClient.update().resource(patient).execute();
|
||||||
|
{
|
||||||
|
Patient readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute();
|
||||||
|
assertThat(readPatient.getMeta().getSource(), matchesPattern("#[a-f0-9]+"));
|
||||||
|
|
||||||
|
readPatient.addName().setFamily("testUpdateWithSource");
|
||||||
|
ourClient.update().resource(readPatient).execute();
|
||||||
|
readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute();
|
||||||
|
assertThat(readPatient.getMeta().getSource(), matchesPattern("#[a-f0-9]+"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateWithETag() throws Exception {
|
public void testUpdateWithETag() throws Exception {
|
||||||
String methodName = "testUpdateWithETag";
|
String methodName = "testUpdateWithETag";
|
||||||
|
|
|
@ -201,6 +201,11 @@
|
||||||
Some resource IDs and URLs for LOINC ValueSets and ConceptMaps were inconsistently populated by the
|
Some resource IDs and URLs for LOINC ValueSets and ConceptMaps were inconsistently populated by the
|
||||||
terminology uploader. This has been corrected.
|
terminology uploader. This has been corrected.
|
||||||
</action>
|
</action>
|
||||||
|
<action type="fix">
|
||||||
|
When a resource was updated with a meta.source containing a request id, the meta.source was getting appended
|
||||||
|
with the new request id, resulting in an ever growing source.meta value. E.g. after the first update, it looks
|
||||||
|
like "#9f0a901387128111#5f37835ee38a89e2" when it should only be "#5f37835ee38a89e2". This has been corrected.
|
||||||
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="4.0.3" date="2019-09-03" description="Igloo (Point Release)">
|
<release version="4.0.3" date="2019-09-03" description="Igloo (Point Release)">
|
||||||
<action type="fix">
|
<action type="fix">
|
||||||
|
|
Loading…
Reference in New Issue