Binary storage prefix during update (#5334)

* wip

* Changelog

* Fix tests
This commit is contained in:
Tadgh 2023-09-22 17:55:23 -07:00 committed by GitHub
parent 6a0b2794eb
commit 10d9d9628c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 5 deletions

View File

@ -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."

View File

@ -117,6 +117,8 @@ public class BulkExportUseCaseTest extends BaseResourceProviderR4Test {
public class SpecConformanceTests {
@Test
public void testBulkExportJobsAreMetaTaggedWithJobIdAndExportId() throws IOException {
//Given a patient exists

View File

@ -10,6 +10,7 @@ import ca.uhn.fhir.jpa.binary.interceptor.BinaryStorageInterceptor;
import ca.uhn.fhir.jpa.binstore.MemoryBinaryStorageSvcImpl;
import ca.uhn.fhir.jpa.model.entity.StorageSettings;
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.client.api.IClientInterceptor;
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.util.HapiExtensions;
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.IIdType;
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.Test;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -103,8 +108,10 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test {
return "prefix-" + extensionValus + "-";
}
}
@Test
public void testCreatingExternalizedBinaryTriggersPointcut() {
@ParameterizedTest
@EnumSource(value = RestOperationTypeEnum.class, names = {"CREATE", "UPDATE"})
public void testCreatingExternalizedBinaryAppliesPrefix(RestOperationTypeEnum theOperationType) {
BinaryFilePrefixingInterceptor interceptor = new BinaryFilePrefixingInterceptor();
myInterceptorRegistry.registerInterceptor(interceptor);
// Create a resource with two metadata extensions on the binary
@ -119,15 +126,27 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test {
ext2.setValue(new StringType("bar2"));
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();
String encoded = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getResource());
ourLog.info("Encoded: {}", encoded);
assertThat(encoded, containsString(HapiExtensions.EXT_EXTERNALIZED_BINARY_ID));
// Then: Make sure the prefix was applied
assertThat(encoded, (containsString("prefix-bar-bar2-")));
myInterceptorRegistry.unregisterInterceptor(interceptor);
}
private static class BinaryBlobIdPrefixInterceptor {

View File

@ -55,6 +55,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -235,7 +236,7 @@ public class BinaryStorageInterceptor<T extends IPrimitiveType<byte[]>> {
if (shouldStoreBlob) {
String newBlobId;
if (resourceId.hasIdPart()) {
if (thePointcut == Pointcut.STORAGE_PRESTORAGE_RESOURCE_UPDATED) {
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
StoredDetails storedDetails = myBinaryStorageSvc.storeBlob(
resourceId, null, nextContentType, inputStream, theRequestDetails);