Commit 98abaeb0 authored by Matija Obreza's avatar Matija Obreza
Browse files

Updated error handling for thumbnail generation

parent e7f887a7
......@@ -206,7 +206,9 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
@Override
@Transactional
public void ensureThumbnails(final ImageGallery imageGallery, final Integer width, final Integer height) {
final ImageGallery imageGallery2 = imageGalleryPersistence.findOne(imageGallery.getId());
if (CollectionUtils.isEmpty(imageGallery2.getImages())) {
LOG.debug("ImageGallery has no images, skipping thumbnail generation for path=" + imageGallery2.getPath());
return;
......@@ -217,6 +219,8 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
imageGallery2.getImages().forEach(repositoryImage -> {
try {
ensureThumbnail(thumbPath, width, height, repositoryImage);
} catch (final NullPointerException e) {
LOG.error("Error generating thumbnail for image={} message={}", repositoryImage, e.getMessage());
} catch (final Exception e) {
LOG.error("Error generating thumbnail for " + repositoryImage, e);
}
......
......@@ -48,6 +48,11 @@ public class ThumbnailGenerator1 implements ThumbnailGenerator {
@Override
public byte[] createThumbnail(final Integer width, final Integer height, final byte[] imageBytes)
throws IOException {
if (imageBytes == null) {
throw new NullPointerException("Cannot generate thumbnail with null bytes");
}
final InputStream inputStream = new ByteArrayInputStream(imageBytes);
final Builder<? extends InputStream> th = Thumbnails.of(inputStream);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment