Commit 24e838d0 authored by Matija Obreza's avatar Matija Obreza

FolderDetails with Page<> data for subfolders and files

parent fd383165
...@@ -27,10 +27,6 @@ import org.springframework.data.domain.Sort.Direction; ...@@ -27,10 +27,6 @@ import org.springframework.data.domain.Sort.Direction;
* *
* @author Matija Obreza * @author Matija Obreza
*/ */
/**
* @author Matija Obreza
*
*/
public class Pagination { public class Pagination {
/** The default sort properties. */ /** The default sort properties. */
...@@ -170,4 +166,15 @@ public class Pagination { ...@@ -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)); 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; ...@@ -18,7 +18,6 @@ package org.genesys2.server.api.v1;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -36,11 +35,13 @@ import org.genesys.filerepository.model.RepositoryFolder; ...@@ -36,11 +35,13 @@ import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.ImageGalleryService; import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService; import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.api.ApiBaseController; import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.Pagination;
import org.genesys2.server.exception.NotFoundElement; import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.spring.ResourceNotFoundException; import org.genesys2.spring.ResourceNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -252,6 +253,38 @@ public class RepositoryController { ...@@ -252,6 +253,38 @@ public class RepositoryController {
final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length()); final String folderPath = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).substring((CONTROLLER_URL + "/folder").length());
return folderDetails(Paths.get(folderPath)); 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. * Gets folder details at specified path.
...@@ -281,11 +314,11 @@ public class RepositoryController { ...@@ -281,11 +314,11 @@ public class RepositoryController {
private FolderDetails folderDetails(final Path path) throws InvalidRepositoryPathException { private FolderDetails folderDetails(final Path path) throws InvalidRepositoryPathException {
FolderDetails fd = new FolderDetails(); FolderDetails fd = new FolderDetails();
fd.folder = repositoryService.getFolder(path); 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("/")) { if (fd.folder == null && !path.toAbsolutePath().toString().equals("/")) {
throw new ResourceNotFoundException("No such folder"); 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); fd.gallery = imagegalleryService.loadImageGallery(path);
return fd; return fd;
} }
...@@ -359,10 +392,10 @@ public class RepositoryController { ...@@ -359,10 +392,10 @@ public class RepositoryController {
public RepositoryFolder folder; public RepositoryFolder folder;
/** Subfolders */ /** Subfolders */
public List<RepositoryFolder> subFolders; public Page<RepositoryFolder> subFolders;
/** The files. */ /** The files. */
public List<RepositoryFile> files; public Page<RepositoryFile> files;
/** The gallery. */ /** The gallery. */
public ImageGallery 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