Commit a33008b7 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-162-repository-folder-with-paged-loader' into 'master'

FolderDetails with Page<> data for subfolders and files

See merge request genesys-pgr/genesys-server!317
parents fd383165 24e838d0
......@@ -27,10 +27,6 @@ import org.springframework.data.domain.Sort.Direction;
*
* @author Matija Obreza
*/
/**
* @author Matija Obreza
*
*/
public class Pagination {
/** The default sort properties. */
......@@ -170,4 +166,15 @@ public class Pagination {
return new PageRequest(p == null ? 0 : p, Integer.min(l == null ? 100 : l, maxPageSize), getDirection(defaultDir), getSortProperties(defaultSort));
}
/**
* To page request.
*
* @param maxPageSize the max page size
* @param sort the sort
* @return the pageable
*/
public static Pageable toPageRequest(int maxPageSize, Sort sort) {
return new PageRequest(0, Integer.min(100, maxPageSize), sort);
}
}
......@@ -18,7 +18,6 @@ package org.genesys2.server.api.v1;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
......@@ -36,11 +35,13 @@ import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -252,6 +253,38 @@ public class RepositoryController {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return folderDetails(Paths.get(folderPath));
}
/**
* Gets the folder subfolders.
*
* @param request the request
* @param page the page
* @return the folder subfolders
* @throws InvalidRepositoryPathException the invalid repository path exception
*/
@GetMapping(value = "/folder/**", params = { "folders" })
@ApiOperation(nickname = "getSubfolders", value = "List subfolders of folder path")
@JsonView(JsonViews.Protected.class)
public Page<RepositoryFolder> getFolderSubfolders(final HttpServletRequest request, final Pagination page) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return repositoryService.listFolders(Paths.get(folderPath), page.toPageRequest(50));
}
/**
* Gets the folder files.
*
* @param request the request
* @param page the page
* @return the folder files
* @throws InvalidRepositoryPathException the invalid repository path exception
*/
@GetMapping(value = "/folder/**", params = { "files" })
@ApiOperation(nickname = "getSubfolders", value = "List subfolders of folder path")
@JsonView(JsonViews.Protected.class)
public Page<RepositoryFile> getFolderFiles(final HttpServletRequest request, final Pagination page) throws InvalidRepositoryPathException {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return repositoryService.listFiles(Paths.get(folderPath), page.toPageRequest(50));
}
/**
* Gets folder details at specified path.
......@@ -281,11 +314,11 @@ public class RepositoryController {
private FolderDetails folderDetails(final Path path) throws InvalidRepositoryPathException {
FolderDetails fd = new FolderDetails();
fd.folder = repositoryService.getFolder(path);
fd.subFolders = repositoryService.getFolders(path, RepositoryFolder.DEFAULT_SORT);
fd.subFolders = repositoryService.listFolders(path, Pagination.toPageRequest(50, RepositoryFolder.DEFAULT_SORT));
if (fd.folder == null && !path.toAbsolutePath().toString().equals("/")) {
throw new ResourceNotFoundException("No such folder");
}
fd.files = repositoryService.getFiles(path, RepositoryFile.DEFAULT_SORT);
fd.files = repositoryService.listFiles(path, Pagination.toPageRequest(50, RepositoryFile.DEFAULT_SORT));
fd.gallery = imagegalleryService.loadImageGallery(path);
return fd;
}
......@@ -359,10 +392,10 @@ public class RepositoryController {
public RepositoryFolder folder;
/** Subfolders */
public List<RepositoryFolder> subFolders;
public Page<RepositoryFolder> subFolders;
/** The files. */
public List<RepositoryFile> files;
public Page<RepositoryFile> files;
/** The gallery. */
public ImageGallery gallery;
......
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