Commit 822f08c8 authored by Matija Obreza's avatar Matija Obreza

Added listFolders, listFiles with pagination

parent b567e8d4
Pipeline #8285 passed with stage
in 2 minutes and 40 seconds
......@@ -32,6 +32,8 @@ import org.genesys.filerepository.metadata.ImageMetadata;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.model.RepositoryImage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
/**
......@@ -129,6 +131,16 @@ public interface RepositoryService {
*/
List<RepositoryFile> getFiles(Path folderPath, Sort sort) throws InvalidRepositoryPathException;
/**
* List files at the specified repository path.
*
* @param folderPath the folder path
* @param page the page
* @return the files
* @throws InvalidRepositoryPathException if path is not a valid repository path
*/
Page<RepositoryFile> listFiles(Path folderPath, Pageable page) throws InvalidRepositoryPathException;
/**
* Stream file info at the specified repository path.
*
......@@ -332,4 +344,14 @@ public interface RepositoryService {
*/
List<RepositoryFolder> getFolders(Path root, Sort sort) throws InvalidRepositoryPathException;
/**
* Get subfolders of root.
*
* @param root the root
* @param page the page
* @return the page
* @throws InvalidRepositoryPathException if path is not a valid repository path
*/
Page<RepositoryFolder> listFolders(Path root, Pageable page) throws InvalidRepositoryPathException;
}
......@@ -56,6 +56,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PostAuthorize;
......@@ -391,6 +394,18 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
}
return (List<RepositoryFile>) repositoryFilePersistence.findAll(QRepositoryFile.repositoryFile.folder.eq(folder), sort);
}
/* (non-Javadoc)
* @see org.genesys.filerepository.service.RepositoryService#listFiles(java.nio.file.Path, org.springframework.data.domain.Pageable)
*/
@Override
public Page<RepositoryFile> listFiles(Path folderPath, Pageable page) throws InvalidRepositoryPathException {
RepositoryFolder folder = getFolder(folderPath);
if (folder == null) {
return new PageImpl<>(Collections.emptyList(), page, 0);
}
return repositoryFilePersistence.findAll(QRepositoryFile.repositoryFile.folder.eq(folder), page);
}
/*
* (non-Javadoc)
......@@ -410,6 +425,22 @@ public class RepositoryServiceImpl implements RepositoryService, InitializingBea
(List<RepositoryFolder>) folderRepository.findAll(QRepositoryFolder.repositoryFolder.parent.eq(parent), sort);
}
}
/* (non-Javadoc)
* @see org.genesys.filerepository.service.RepositoryService#listFolders(java.nio.file.Path, org.springframework.data.domain.Pageable)
*/
@Override
public Page<RepositoryFolder> listFolders(Path root, Pageable page) throws InvalidRepositoryPathException {
PathValidator.checkValidPath(root);
if (root == null || "/".equals(root.normalize().toAbsolutePath().toString())) {
return folderRepository.findAll(QRepositoryFolder.repositoryFolder.parent.isNull(), page);
} else {
RepositoryFolder parent = getFolder(root);
return parent == null ? new PageImpl<>(Collections.emptyList(), page, 0) :
// Load child folders
folderRepository.findAll(QRepositoryFolder.repositoryFolder.parent.eq(parent), page);
}
}
@Override
public RepositoryFolder getFolder(UUID uuid) {
......
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