Commit d514b734 authored by Matija Obreza's avatar Matija Obreza

Fix: Thumbnail generation

- ImageGallery aspects fire before bytes are stored
parent eeb3df10
Pipeline #7268 passed with stage
in 2 minutes and 27 seconds
......@@ -250,10 +250,10 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
for (int thumbSize: thumbnailSizes) {
ensureThumbnail(thumbSize, thumbSize, repositoryImage, () -> {
if (cache[0] != null) {
LOG.warn("Using cached image bytes for {}", repositoryImage.getPath());
LOG.debug("Using cached image bytes for {}", repositoryImage.getStoragePath());
return cache[0];
} else {
LOG.warn("Must load image bytes for {}", repositoryImage.getPath());
LOG.info("Must load image bytes for {}", repositoryImage.getStoragePath());
return cache[0] = bytesStorageService.get(repositoryImage.storagePath());
}
});
......
......@@ -232,8 +232,11 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
repositoryImage.setContentType(contentType);
fillImageProperties(repositoryImage, bytes);
repositoryImage = repositoryImagePersistence.save(repositoryImage);
// We need the UUID before we save bytes
if (repositoryImage.getUuid() == null) {
repositoryImage.setUuid(UUID.randomUUID());
}
try {
bytesStorageService.upsert(repositoryImage.storagePath(), bytes);
......@@ -244,7 +247,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
throw e;
}
return repositoryImage;
return repositoryImagePersistence.save(repositoryImage);
}
/**
......@@ -591,7 +594,7 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
try {
List<String> thumbnails = bytesStorageService.listFiles(path);
for (String thumb : thumbnails) {
System.err.println("Should remove " + thumb + " from " + path.resolve(thumb));
LOG.debug("Removing thumbnail at {}", path.resolve(thumb));
try {
bytesStorageService.remove(path.resolve(thumb));
} catch (IOException e) {
......
......@@ -116,11 +116,11 @@ public class ImageGalleryThumbnailsTest extends RepositoryServiceTest {
@Test
public void testThumbnails1() throws InvalidRepositoryPathException, InvalidRepositoryFileDataException, NoSuchRepositoryFileException, IOException {
final ImageGallery imageGallery = imageGalleryService.createImageGallery(initialPath, DEFAULT_GALLERY_TITLE, DEFAULT_GALLERY_DESCRIPTION);
imageGalleryService.createImageGallery(initialPath, DEFAULT_GALLERY_TITLE, DEFAULT_GALLERY_DESCRIPTION);
final TestImage image1 = new TestImage("maize.jpg", "image/jpg");
final RepositoryImage repoImage1 = fileRepoService.addImage(initialPath, image1.getOriginalFilename(), image1.getContentType(), image1.getImageBytes(), null);
final byte[] thumbBytes1 = bytesStorageService.get(Paths.get(ImageGalleryService.THUMB_PATH, repoImage1.getThumbnailPath(), "200x200" + ".png"));
assertThat("Thumbnail must not be null", thumbBytes1, notNullValue());
......
Markdown is supported
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