Commit aba6dd32 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ensure-image-thumbs' into 'master'

Image thumbnail generation updated

See merge request genesys-pgr/genesys-server!267
parents f3500cf1 9b44ea1a
......@@ -304,7 +304,6 @@ public class RepositoryController {
public ImageGallery getGallery(final HttpServletRequest request) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/gallery").length());
ImageGallery imageGallery = imagegalleryService.loadImageGallery(Paths.get(folderPath));
imagegalleryService.ensureThumbnails(imageGallery, 200, 200);
return imageGallery;
}
......@@ -321,7 +320,7 @@ public class RepositoryController {
public ImageGallery createGallery(final HttpServletRequest request, @RequestBody ImageGallery metadata) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/gallery").length());
ImageGallery imageGallery = imagegalleryService.createImageGallery(Paths.get(folderPath), metadata.getTitle(), metadata.getDescription());
imagegalleryService.ensureThumbnails(imageGallery, 200, 200);
return imageGallery;
}
......
......@@ -205,7 +205,6 @@ public class AccessionController extends BaseController {
LOG.warn("Error loading image gallery for accession={}. {}", accession.getAccessionNumber(), e.getMessage());
}
if (imageGallery != null) {
imageGalleryService.ensureThumbnails(imageGallery, 200, 200);
model.addAttribute("thumbnailFormat", "200x200");
model.addAttribute("imageGallery", imageGallery);
}
......
......@@ -678,7 +678,6 @@ public class WiewsController extends BaseController {
throw new ResourceNotFoundException("No image gallery here!");
}
imageGalleryService.ensureThumbnails(imageGallery, 200, 200);
model.addAttribute("thumbnailFormat", "200x200");
model.addAttribute("galleryPath", galleryPath);
model.addAttribute("imageGallery", imageGallery);
......
......@@ -78,7 +78,6 @@ public class RepositoryGalleryController extends BaseController {
throw new ResourceNotFoundException("No image gallery here!");
}
imageGalleryService.ensureThumbnails(imageGallery, 200, 200);
model.addAttribute("thumbnailFormat", "200x200");
model.addAttribute("imageGallery", imageGallery);
......
......@@ -26,6 +26,8 @@ import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.model.BasicUser;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.persistence.UserRepository;
......@@ -40,6 +42,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Import;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
......@@ -66,6 +70,10 @@ public class ApplicationStartup implements InitializingBean, ApplicationListener
@Value("${default.oauthclient.clientSecret}")
private String defaultOAuthClientSecret;
@Value("${file.repository.image.thumbnailSizes}")
private int thumbnailSizes[];
@Autowired
private UserRepository userRepository;
......@@ -95,6 +103,8 @@ public class ApplicationStartup implements InitializingBean, ApplicationListener
}
startup();
ensureThumbnails();
}
/**
......@@ -177,4 +187,29 @@ public class ApplicationStartup implements InitializingBean, ApplicationListener
private void reindexElasticsearch() {
elasticsearch.reindexAll();
}
@Autowired
private ImageGalleryService imageGalleryService;
/**
* We want all thumbnails to exist
*/
private void ensureThumbnails() throws Exception {
asAdminInvoker.invoke(() -> {
int page = 0;
Page<ImageGallery> galleries = null;
do {
PageRequest p = new PageRequest(page++, 10);
galleries = imageGalleryService.listImageGalleries(p);
galleries.forEach(gallery -> {
LOG.warn("Ensuring all thumbnails for {}", gallery.getPath());
imageGalleryService.ensureThumbnails(gallery);
});
} while (galleries != null && galleries.hasNext());
return true;
});
}
}
......@@ -90,6 +90,10 @@ public class FileRepositoryConfig implements InitializingBean {
@Value("${repository.ftp.externalAddress}")
private String ftpServerExternalAddress;
@Value("${file.repository.image.thumbnailSizes}")
private int thumbnailSizes[];
/**
* File repository service.
*
......@@ -136,7 +140,9 @@ public class FileRepositoryConfig implements InitializingBean {
*/
@Bean
public ImageGalleryService imageGalleryService() {
return new ImageGalleryServiceImpl();
ImageGalleryServiceImpl galleryService = new ImageGalleryServiceImpl();
galleryService.setThumbnailSizes(this.thumbnailSizes);
return galleryService;
}
/**
......
......@@ -194,6 +194,7 @@ transifex.content.template=<html xmlns="http://www.w3.org/1999/xhtml">\
# File repository
file.repository.dir=${data.dir}/repository
file.repository.datasets.folder=/datasets
file.repository.image.thumbnailSizes=200,300,600,1024
# File repository S3 parameter values
s3.accessKey=
......
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