ThumbnailData thumbnail = thumbnailDirectory.getWithoutTx(key);
if (thumbnail == null) {
log.info("Generating and storing thumbnail for " + key);
ImageMetadata thumbDimensions = metadata.getThumbnail();
if (thumbDimensions == null) {
// TODO(danilatos): Provide a default thumbnail
throw NotFoundException.withInternalMessage("No thumbnail available for attachment " + id);
}
byte[] thumbnailBytes = rawService.getResizedImageBytes(key,
thumbDimensions.getWidth(), thumbDimensions.getHeight());
thumbnail = new ThumbnailData(key, thumbnailBytes);
if (thumbnailBytes.length > maxThumbnailSavedSizeBytes) {
log.warning("Thumbnail for " + key + " too large to store " +