Binary storage prefix during update (#5334)
* wip * Changelog * Fix tests
This commit is contained in:
parent
6a0b2794eb
commit
10d9d9628c
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 5333
|
||||||
|
jira: SMILE-7403
|
||||||
|
title: "A regression was introduced in 2023.08.R01 which caused binary storage prefixes to not be applied to exported binary blobs. This has been fixed."
|
|
@ -117,6 +117,8 @@ public class BulkExportUseCaseTest extends BaseResourceProviderR4Test {
|
||||||
public class SpecConformanceTests {
|
public class SpecConformanceTests {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBulkExportJobsAreMetaTaggedWithJobIdAndExportId() throws IOException {
|
public void testBulkExportJobsAreMetaTaggedWithJobIdAndExportId() throws IOException {
|
||||||
//Given a patient exists
|
//Given a patient exists
|
||||||
|
|
|
@ -10,6 +10,7 @@ import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor;
|
||||||
import ca.uhn.fhir.jpa.binstore.MemoryBinaryStorageSvcImpl;
|
import ca.uhn.fhir.jpa.binstore.MemoryBinaryStorageSvcImpl;
|
||||||
import ca.uhn.fhir.jpa.model.entity.StorageSettings;
|
import ca.uhn.fhir.jpa.model.entity.StorageSettings;
|
||||||
import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test;
|
import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test;
|
||||||
|
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
|
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
|
||||||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||||
|
@ -17,6 +18,7 @@ import ca.uhn.fhir.rest.client.api.IHttpResponse;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import ca.uhn.fhir.util.HapiExtensions;
|
import ca.uhn.fhir.util.HapiExtensions;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
import org.hl7.fhir.instance.model.api.IBaseHasExtensions;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.hl7.fhir.r4.model.Binary;
|
import org.hl7.fhir.r4.model.Binary;
|
||||||
|
@ -28,6 +30,9 @@ import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -103,8 +108,10 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test {
|
||||||
return "prefix-" + extensionValus + "-";
|
return "prefix-" + extensionValus + "-";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
|
||||||
public void testCreatingExternalizedBinaryTriggersPointcut() {
|
@ParameterizedTest
|
||||||
|
@EnumSource(value = RestOperationTypeEnum.class, names = {"CREATE", "UPDATE"})
|
||||||
|
public void testCreatingExternalizedBinaryAppliesPrefix(RestOperationTypeEnum theOperationType) {
|
||||||
BinaryFilePrefixingInterceptor interceptor = new BinaryFilePrefixingInterceptor();
|
BinaryFilePrefixingInterceptor interceptor = new BinaryFilePrefixingInterceptor();
|
||||||
myInterceptorRegistry.registerInterceptor(interceptor);
|
myInterceptorRegistry.registerInterceptor(interceptor);
|
||||||
// Create a resource with two metadata extensions on the binary
|
// Create a resource with two metadata extensions on the binary
|
||||||
|
@ -119,15 +126,27 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test {
|
||||||
ext2.setValue(new StringType("bar2"));
|
ext2.setValue(new StringType("bar2"));
|
||||||
|
|
||||||
binary.setData(SOME_BYTES);
|
binary.setData(SOME_BYTES);
|
||||||
DaoMethodOutcome outcome = myBinaryDao.create(binary, mySrd);
|
|
||||||
|
|
||||||
// Make sure it was externalized
|
DaoMethodOutcome outcome = null;
|
||||||
|
|
||||||
|
//Either CREATE or UPDATE
|
||||||
|
if (theOperationType == RestOperationTypeEnum.CREATE) {
|
||||||
|
outcome = myBinaryDao.create(binary, mySrd);
|
||||||
|
} else if (theOperationType == RestOperationTypeEnum.UPDATE) {
|
||||||
|
binary.setId("my-id");
|
||||||
|
outcome = myBinaryDao.update(binary, mySrd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then: Sure it was externalized
|
||||||
outcome.getId().toUnqualifiedVersionless();
|
outcome.getId().toUnqualifiedVersionless();
|
||||||
String encoded = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getResource());
|
String encoded = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getResource());
|
||||||
ourLog.info("Encoded: {}", encoded);
|
ourLog.info("Encoded: {}", encoded);
|
||||||
assertThat(encoded, containsString(HapiExtensions.EXT_EXTERNALIZED_BINARY_ID));
|
assertThat(encoded, containsString(HapiExtensions.EXT_EXTERNALIZED_BINARY_ID));
|
||||||
|
|
||||||
|
// Then: Make sure the prefix was applied
|
||||||
assertThat(encoded, (containsString("prefix-bar-bar2-")));
|
assertThat(encoded, (containsString("prefix-bar-bar2-")));
|
||||||
myInterceptorRegistry.unregisterInterceptor(interceptor);
|
myInterceptorRegistry.unregisterInterceptor(interceptor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BinaryBlobIdPrefixInterceptor {
|
private static class BinaryBlobIdPrefixInterceptor {
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -235,7 +236,7 @@ public class BinaryStorageInterceptor<T extends IPrimitiveType<byte[]>> {
|
||||||
if (shouldStoreBlob) {
|
if (shouldStoreBlob) {
|
||||||
|
|
||||||
String newBlobId;
|
String newBlobId;
|
||||||
if (resourceId.hasIdPart()) {
|
if (thePointcut == Pointcut.STORAGE_PRESTORAGE_RESOURCE_UPDATED) {
|
||||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
|
||||||
StoredDetails storedDetails = myBinaryStorageSvc.storeBlob(
|
StoredDetails storedDetails = myBinaryStorageSvc.storeBlob(
|
||||||
resourceId, null, nextContentType, inputStream, theRequestDetails);
|
resourceId, null, nextContentType, inputStream, theRequestDetails);
|
||||||
|
|
Loading…
Reference in New Issue