Commit 7cde148e authored by Matija Obreza's avatar Matija Obreza

Merge branch 'new-method-to-load-galleries-list' into 'master'

New method to load galleries list

See merge request !36
parents 0506bd25 07ffb830
Pipeline #13082 failed with stage
in 2 minutes and 2 seconds
......@@ -17,6 +17,7 @@
package org.genesys.filerepository.service;
import java.nio.file.Path;
import java.util.List;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
......@@ -48,6 +49,15 @@ public interface ImageGalleryService {
*/
ImageGallery loadImageGallery(Path path) throws InvalidRepositoryPathException;
/**
* Loads galleries with the specified paths.
*
* @param paths Image gallery paths in the repository
* @return the list of ImageGalleries
* @throws InvalidRepositoryPathException if path is not a valid repository path
*/
List<ImageGallery> loadImageGalleries(final List<Path> paths) throws InvalidRepositoryPathException;
/**
* Get gallery with the specified folder. Use within existing transactions only.
*
......
......@@ -23,11 +23,13 @@ import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.QImageGallery;
import org.genesys.filerepository.model.QRepositoryFolder;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.model.RepositoryImage;
......@@ -45,6 +47,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -101,6 +104,21 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
final ImageGallery imageGallery = imageGalleryPersistence.findByFolder(repositoryService.getFolder(path));
return deepLoad(imageGallery);
}
@Override
@PostFilter("filterObject==null || hasRole('ADMINISTRATOR') || hasPermission(filterObject, 'read')")
public List<ImageGallery> loadImageGalleries(final List<Path> paths) throws InvalidRepositoryPathException {
List<String> normalizedPaths = new ArrayList<>(paths.size());
for (Path path : paths) {
PathValidator.checkValidPath(path);
normalizedPaths.add(path.normalize().toAbsolutePath().toString());
}
List<RepositoryFolder> folders = jpaQueryFactory.selectFrom(QRepositoryFolder.repositoryFolder).where(QRepositoryFolder.repositoryFolder.path.in(normalizedPaths)).fetch();
JPAQuery<ImageGallery> query = jpaQueryFactory.selectFrom(QImageGallery.imageGallery).where(QImageGallery.imageGallery.folder.in(folders));
return query.fetch().stream().map(this::deepLoad).collect(Collectors.toList());
}
@Override
@PostAuthorize("returnObject == null or hasRole('ADMINISTRATOR') or hasPermission(returnObject, 'read')")
......
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