Correct transaction processing in multitenant server (#1884)

* Correct transaction processing in multitenant server

* # d codethe npm registry for updates every day (weekdays)
This commit is contained in:
James Agnew 2020-06-03 10:37:47 -04:00 committed by GitHub
parent 0487727fb1
commit 86ef0ec0e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 1 deletions

12
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,12 @@
# Basic dependabot.yml file with
# minimum configuration for two package managers
version: 2
updates:
# Enable version updates for Maven
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "daily"

View File

@ -2057,7 +2057,7 @@ public enum Pointcut {
return myParameterTypes;
}
private class UnknownType {
private static class UnknownType {
}
private static class ExceptionHandlingSpec {

View File

@ -48,6 +48,7 @@ import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Observation;
@ -641,6 +642,49 @@ public class PartitioningR4Test extends BaseJpaR4SystemTest {
}
@Test
public void testCreateInTransaction_ServerId_WithPartition() {
createUniqueCompositeSp();
createRequestId();
addCreatePartition(myPartitionId, myPartitionDate);
addCreatePartition(myPartitionId, myPartitionDate);
Bundle input = new Bundle();
input.setType(Bundle.BundleType.TRANSACTION);
Organization org = new Organization();
org.setId(IdType.newRandomUuid());
org.setName("org");
input.addEntry()
.setFullUrl(org.getId())
.setResource(org)
.getRequest().setUrl("Organization").setMethod(Bundle.HTTPVerb.POST);
Patient p = new Patient();
p.getMeta().addTag("http://system", "code", "diisplay");
p.addName().setFamily("FAM");
p.addIdentifier().setSystem("system").setValue("value");
p.setBirthDate(new Date());
p.getManagingOrganization().setReference(org.getId());
input.addEntry()
.setFullUrl(p.getId())
.setResource(p)
.getRequest().setUrl("Patient").setMethod(Bundle.HTTPVerb.POST);
Bundle output = mySystemDao.transaction(mySrd, input);
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(output));
Long patientId = new IdType(output.getEntry().get(1).getResponse().getLocation()).getIdPartAsLong();
runInTransaction(() -> {
// HFJ_RESOURCE
ResourceTable resourceTable = myResourceTableDao.findById(patientId).orElseThrow(IllegalArgumentException::new);
assertEquals(myPartitionId, resourceTable.getPartitionId().getPartitionId().intValue());
assertEquals(myPartitionDate, resourceTable.getPartitionId().getPartitionDate());
});
}
@Test
public void testUpdateResourceWithPartition() {
createRequestId();

View File

@ -4,12 +4,18 @@ import ca.uhn.fhir.jpa.util.TestUtil;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.test.utilities.ITestDataBuilder;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CapabilityStatement;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.junit.AfterClass;
import org.junit.Test;
import java.util.Date;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.in;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@ -66,6 +72,34 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Te
}
@Test
public void testTransaction() {
Bundle input = new Bundle();
input.setType(Bundle.BundleType.TRANSACTION);
Organization org = new Organization();
org.setId(IdType.newRandomUuid());
org.setName("org");
input.addEntry()
.setFullUrl(org.getId())
.setResource(org)
.getRequest().setUrl("Organization").setMethod(Bundle.HTTPVerb.POST);
Patient p = new Patient();
p.getMeta().addTag("http://system", "code", "diisplay");
p.addName().setFamily("FAM");
p.addIdentifier().setSystem("system").setValue("value");
p.setBirthDate(new Date());
p.getManagingOrganization().setReference(org.getId());
input.addEntry()
.setFullUrl(p.getId())
.setResource(p)
.getRequest().setUrl("Patient").setMethod(Bundle.HTTPVerb.POST);
myTenantClientInterceptor.setTenantId(TENANT_A);
Bundle response = ourClient.transaction().withBundle(input).execute();
}
@AfterClass
public static void afterClassClearContext() {

View File

@ -556,6 +556,10 @@ public abstract class RequestDetails {
@Override
public Object callHooksAndReturnObject(Pointcut thePointcut, HookParams theParams) {
if (!thePointcut.getReturnType().equals(void.class)) {
return myWrap.callHooksAndReturnObject(thePointcut, theParams);
}
myDeferredTasks.add(() -> myWrap.callHooksAndReturnObject(thePointcut, theParams));
return null;
}