From 9d584d1b8348d977a02cbde4b28c22aa4bff7b8f Mon Sep 17 00:00:00 2001 From: jmarchionatto <60409882+jmarchionatto@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:15:21 -0500 Subject: [PATCH] Extend meta source length (#6532) * Add test * Extend field * Migration (aimed to backport) * Add migration for HFJ_RES_VER_PROV table --------- Co-authored-by: juan.marchionatto --- .../tasks/HapiFhirJpaMigrationTasks.java | 20 ++++ .../model/entity/ResourceHistoryTable.java | 2 +- .../uhn/fhir/jpa/entity/MetaSourceTest.java | 104 ++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/entity/MetaSourceTest.java diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java index c43ed2d4827..1fe997f35c3 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java @@ -125,6 +125,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { init700(); init720(); init740(); + init760(); init780(); } @@ -154,6 +155,25 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .withType(ColumnTypeEnum.STRING, 512); } + /** + * Built at 2024.11.02 to be backported to version 7.6 + */ + protected void init760() { + final Builder version = forVersion(VersionEnum.V7_6_0); + + version.onTable("HFJ_RES_VER") + .modifyColumn("20241102.10", "SOURCE_URI") + .nullable() + .withType(ColumnTypeEnum.STRING, 768) + .failureAllowed(); + + version.onTable("HFJ_RES_VER_PROV") + .modifyColumn("20241102.20", "SOURCE_URI") + .nullable() + .withType(ColumnTypeEnum.STRING, 768) + .failureAllowed(); + } + protected void init740() { // Start of migrations from 7.2 to 7.4 diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceHistoryTable.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceHistoryTable.java index d5fa5b0e4eb..e42c2d04e37 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceHistoryTable.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceHistoryTable.java @@ -65,7 +65,7 @@ import java.util.Collection; }) public class ResourceHistoryTable extends BaseHasResource implements Serializable { public static final String IDX_RESVER_ID_VER = "IDX_RESVER_ID_VER"; - public static final int SOURCE_URI_LENGTH = 100; + public static final int SOURCE_URI_LENGTH = ResourceIndexedSearchParamString.MAX_LENGTH; /** * @see ResourceEncodingEnum */ diff --git a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/entity/MetaSourceTest.java b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/entity/MetaSourceTest.java new file mode 100644 index 00000000000..dadc849abee --- /dev/null +++ b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/entity/MetaSourceTest.java @@ -0,0 +1,104 @@ +package ca.uhn.fhir.jpa.entity; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.rp.r4.PatientResourceProvider; +import ca.uhn.fhir.jpa.test.BaseJpaR4Test; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; +import ca.uhn.fhir.rest.client.interceptor.SimpleRequestHeaderInterceptor; +import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.test.utilities.JettyUtil; +import org.eclipse.jetty.ee10.servlet.ServletContextHandler; +import org.eclipse.jetty.ee10.servlet.ServletHolder; +import org.eclipse.jetty.server.Server; +import org.h2.util.StringUtils; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4.model.Meta; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MetaSourceTest extends BaseJpaR4Test { + + private static RestfulServer ourRestServer; + private static final FhirContext ourCtx = FhirContext.forR4Cached(); + private static Server ourServer; + private static String ourServerBase; + private IGenericClient myClient; + + @BeforeEach + void beforeStartServer() throws Exception { + if (ourRestServer == null) { + + PatientResourceProvider patientRp = new PatientResourceProvider(); + patientRp.setContext(ourCtx); + patientRp.setDao(myPatientDao); + + RestfulServer restServer = new RestfulServer(ourCtx); + restServer.setResourceProviders(patientRp); + + restServer.registerProviders(mySystemProvider); + + ourServer = new Server(0); + + ServletContextHandler proxyHandler = new ServletContextHandler(); + proxyHandler.setContextPath("/"); + + ServletHolder servletHolder = new ServletHolder(); + servletHolder.setServlet(restServer); + proxyHandler.addServlet(servletHolder, "/fhir/context/*"); + + restServer.setFhirContext(ourCtx); + + ourServer.setHandler(proxyHandler); + JettyUtil.startServer(ourServer); + int myPort = JettyUtil.getPortForStartedServer(ourServer); + ourServerBase = "http://localhost:" + myPort + "/fhir/context"; + + ourCtx.getRestfulClientFactory().setSocketTimeout(600 * 1_000); + ourRestServer = restServer; + } + + myClient = ourCtx.newRestfulGenericClient(ourServerBase); + SimpleRequestHeaderInterceptor simpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); + myClient.registerInterceptor(simpleHeaderInterceptor); + + ourRestServer.setDefaultResponseEncoding(EncodingEnum.XML); + ourRestServer.setPagingProvider(myPagingProvider); + + LoggingInterceptor loggingInterceptor = new LoggingInterceptor(); + loggingInterceptor.setLogRequestBody(true); + loggingInterceptor.setLogResponseBody(true); + } + + + @Test + void testMetaSourceSupportsMaxLength() { + int metaSourceLength = 700; + + Patient p1 = new Patient(); + p1.setActive(true); + + Meta meta = new Meta(); + String longSourceValue = StringUtils.pad("http://", metaSourceLength, "abc", true); + meta.setSource(longSourceValue); + p1.setMeta(meta); + IIdType patientId = myClient.create().resource(p1).execute().getId().toUnqualifiedVersionless(); + + // verify + Patient patient = myClient.read().resource(Patient.class).withId(patientId.getValueAsString()).execute(); + assertThat(patient.getMeta().getSource()).hasSizeGreaterThan(metaSourceLength); + } + + + + @AfterAll + public static void afterClassClearContext() throws Exception { + JettyUtil.closeServer(ourServer); + } + +}