ready for rereview

This commit is contained in:
Ken Stevens 2019-10-22 09:29:18 -04:00
parent d85e73c6fd
commit 2e532e4e98
2 changed files with 30 additions and 4 deletions

View File

@ -119,6 +119,10 @@ public class BinaryStorageInterceptor {
} }
private void extractLargeBinaries(ServletRequestDetails theRequestDetails, IBaseResource theResource, Pointcut thePoincut) throws IOException { private void extractLargeBinaries(ServletRequestDetails theRequestDetails, IBaseResource theResource, Pointcut thePoincut) throws IOException {
if (theRequestDetails == null) {
// RequestDetails will only be null for internal HAPI events. If externalization is required for them it will need to be done in a different way.
return;
}
IIdType resourceId = theResource.getIdElement(); IIdType resourceId = theResource.getIdElement();
if (!resourceId.hasResourceType() && resourceId.hasIdPart()) { if (!resourceId.hasResourceType() && resourceId.hasIdPart()) {
String resourceType = myCtx.getResourceDefinition(theResource).getName(); String resourceType = myCtx.getResourceDefinition(theResource).getName();
@ -145,7 +149,7 @@ public class BinaryStorageInterceptor {
newBlobId = myBinaryStorageSvc.newBlobId(); newBlobId = myBinaryStorageSvc.newBlobId();
List<DeferredBinaryTarget> deferredBinaryTargets = getOrCreateDeferredBinaryStorageMap(theRequestDetails); List<DeferredBinaryTarget> deferredBinaryTargets = getOrCreateDeferredBinaryStorageMap(theRequestDetails);
DeferredBinaryTarget newDeferredBinaryTarget = new DeferredBinaryTarget(newBlobId, nextTarget, data); DeferredBinaryTarget newDeferredBinaryTarget = new DeferredBinaryTarget(newBlobId, nextTarget, data);
deferredBinaryTargets.add(newDeferredBinaryTarget); deferredBinaryTargets.add(newDeferredBinaryTarget);
} }
myBinaryAccessProvider.replaceDataWithExtension(nextTarget, newBlobId); myBinaryAccessProvider.replaceDataWithExtension(nextTarget, newBlobId);
@ -159,9 +163,9 @@ public class BinaryStorageInterceptor {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<DeferredBinaryTarget> getOrCreateDeferredBinaryStorageMap(ServletRequestDetails theRequestDetails) { private List<DeferredBinaryTarget> getOrCreateDeferredBinaryStorageMap(ServletRequestDetails theRequestDetails) {
List<DeferredBinaryTarget> deferredBinaryTargets = (List<DeferredBinaryTarget>) theRequestDetails.getUserData().get(getDeferredListKey()); List<DeferredBinaryTarget> deferredBinaryTargets = (List<DeferredBinaryTarget>) theRequestDetails.getUserData().get(getDeferredListKey());
if (deferredBinaryTargets == null) { if (deferredBinaryTargets == null) {
deferredBinaryTargets = new ArrayList<>(); deferredBinaryTargets = new ArrayList<>();
theRequestDetails.getUserData().put(getDeferredListKey(), deferredBinaryTargets); theRequestDetails.getUserData().put(getDeferredListKey(), deferredBinaryTargets);
} }
return deferredBinaryTargets; return deferredBinaryTargets;
} }

View File

@ -75,6 +75,28 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test {
} }
@Test
public void testCreateAndRetrieveBinary_ServerAssignedId_ExternalizedBinary_NullServletRequest() {
// Create a resource with a big enough binary
Binary binary = new Binary();
binary.setContentType("application/octet-stream");
binary.setData(SOME_BYTES);
DaoMethodOutcome outcome = myBinaryDao.create(binary);
// Make sure it was externalized
IIdType id = outcome.getId().toUnqualifiedVersionless();
String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getResource());
ourLog.info("Encoded: {}", encoded);
assertThat(encoded, not(containsString(JpaConstants.EXT_EXTERNALIZED_BINARY_ID)));
assertThat(encoded, containsString("\"data\""));
Binary output = myBinaryDao.read(id);
assertEquals("application/octet-stream", output.getContentType());
assertArrayEquals(SOME_BYTES, output.getData());
}
@Test @Test
public void testCreateAndRetrieveBinary_ServerAssignedId_NonExternalizedBinary() { public void testCreateAndRetrieveBinary_ServerAssignedId_NonExternalizedBinary() {