diff --git a/Comment/_4u.cfe b/Comment/_4u.cfe deleted file mode 100644 index bd8ee06..0000000 Binary files a/Comment/_4u.cfe and /dev/null differ diff --git a/Comment/_4u.cfs b/Comment/_4u.cfs deleted file mode 100644 index 1439beb..0000000 Binary files a/Comment/_4u.cfs and /dev/null differ diff --git a/Comment/_4v.cfe b/Comment/_4v.cfe deleted file mode 100644 index f256ab2..0000000 Binary files a/Comment/_4v.cfe and /dev/null differ diff --git a/Comment/_4v.cfs b/Comment/_4v.cfs deleted file mode 100644 index 6f4c8f8..0000000 Binary files a/Comment/_4v.cfs and /dev/null differ diff --git a/Comment/_4y.cfe b/Comment/_4y.cfe deleted file mode 100644 index e3bb6ae..0000000 Binary files a/Comment/_4y.cfe and /dev/null differ diff --git a/Comment/_4y.cfs b/Comment/_4y.cfs deleted file mode 100644 index 8b588bb..0000000 Binary files a/Comment/_4y.cfs and /dev/null differ diff --git a/Comment/_4z.fdm b/Comment/_4z.fdm deleted file mode 100644 index f73ab7a..0000000 Binary files a/Comment/_4z.fdm and /dev/null differ diff --git a/Comment/_4z.fdt b/Comment/_4z.fdt deleted file mode 100644 index aa3393c..0000000 Binary files a/Comment/_4z.fdt and /dev/null differ diff --git a/Comment/_4z.fdx b/Comment/_4z.fdx deleted file mode 100644 index ed41f3d..0000000 Binary files a/Comment/_4z.fdx and /dev/null differ diff --git a/Comment/_4z.fnm b/Comment/_4z.fnm deleted file mode 100644 index a112a98..0000000 Binary files a/Comment/_4z.fnm and /dev/null differ diff --git a/Comment/_4z.nvd b/Comment/_4z.nvd deleted file mode 100644 index c23bff0..0000000 Binary files a/Comment/_4z.nvd and /dev/null differ diff --git a/Comment/_4z.nvm b/Comment/_4z.nvm deleted file mode 100644 index 23e83b9..0000000 Binary files a/Comment/_4z.nvm and /dev/null differ diff --git a/Comment/_4z.si b/Comment/_4z.si deleted file mode 100644 index a2cc560..0000000 Binary files a/Comment/_4z.si and /dev/null differ diff --git a/Comment/_4z_Lucene80_0.dvd b/Comment/_4z_Lucene80_0.dvd deleted file mode 100644 index 82df1d1..0000000 Binary files a/Comment/_4z_Lucene80_0.dvd and /dev/null differ diff --git a/Comment/_4z_Lucene80_0.dvm b/Comment/_4z_Lucene80_0.dvm deleted file mode 100644 index 9916e2b..0000000 Binary files a/Comment/_4z_Lucene80_0.dvm and /dev/null differ diff --git a/Comment/_4z_Lucene84_0.doc b/Comment/_4z_Lucene84_0.doc deleted file mode 100644 index 16f5ca7..0000000 Binary files a/Comment/_4z_Lucene84_0.doc and /dev/null differ diff --git a/Comment/_4z_Lucene84_0.pos b/Comment/_4z_Lucene84_0.pos deleted file mode 100644 index 54379d8..0000000 Binary files a/Comment/_4z_Lucene84_0.pos and /dev/null differ diff --git a/Comment/_4z_Lucene84_0.tim b/Comment/_4z_Lucene84_0.tim deleted file mode 100644 index 0f55b01..0000000 Binary files a/Comment/_4z_Lucene84_0.tim and /dev/null differ diff --git a/Comment/_4z_Lucene84_0.tip b/Comment/_4z_Lucene84_0.tip deleted file mode 100644 index 8398ace..0000000 Binary files a/Comment/_4z_Lucene84_0.tip and /dev/null differ diff --git a/Comment/_4z_Lucene84_0.tmd b/Comment/_4z_Lucene84_0.tmd deleted file mode 100644 index cc682ce..0000000 Binary files a/Comment/_4z_Lucene84_0.tmd and /dev/null differ diff --git a/Comment/_58.cfe b/Comment/_58.cfe new file mode 100644 index 0000000..f9402f5 Binary files /dev/null and b/Comment/_58.cfe differ diff --git a/Comment/_58.cfs b/Comment/_58.cfs new file mode 100644 index 0000000..dc8bf70 Binary files /dev/null and b/Comment/_58.cfs differ diff --git a/Comment/_58.si b/Comment/_58.si new file mode 100644 index 0000000..312064f Binary files /dev/null and b/Comment/_58.si differ diff --git a/Comment/_59.cfe b/Comment/_59.cfe new file mode 100644 index 0000000..3d53581 Binary files /dev/null and b/Comment/_59.cfe differ diff --git a/Comment/_59.cfs b/Comment/_59.cfs new file mode 100644 index 0000000..405ba9c Binary files /dev/null and b/Comment/_59.cfs differ diff --git a/Comment/_59.si b/Comment/_59.si new file mode 100644 index 0000000..c0b245d Binary files /dev/null and b/Comment/_59.si differ diff --git a/Comment/_5a.cfe b/Comment/_5a.cfe new file mode 100644 index 0000000..1a8dd25 Binary files /dev/null and b/Comment/_5a.cfe differ diff --git a/Comment/_5a.cfs b/Comment/_5a.cfs new file mode 100644 index 0000000..abef8be Binary files /dev/null and b/Comment/_5a.cfs differ diff --git a/Comment/_5a.si b/Comment/_5a.si new file mode 100644 index 0000000..8887671 Binary files /dev/null and b/Comment/_5a.si differ diff --git a/Comment/_5b.cfe b/Comment/_5b.cfe new file mode 100644 index 0000000..7e8e966 Binary files /dev/null and b/Comment/_5b.cfe differ diff --git a/Comment/_5b.cfs b/Comment/_5b.cfs new file mode 100644 index 0000000..65f46e0 Binary files /dev/null and b/Comment/_5b.cfs differ diff --git a/Comment/_5b.si b/Comment/_5b.si new file mode 100644 index 0000000..9bc567c Binary files /dev/null and b/Comment/_5b.si differ diff --git a/Comment/_5c.cfe b/Comment/_5c.cfe new file mode 100644 index 0000000..b45dcd6 Binary files /dev/null and b/Comment/_5c.cfe differ diff --git a/Comment/_5c.cfs b/Comment/_5c.cfs new file mode 100644 index 0000000..376f65d Binary files /dev/null and b/Comment/_5c.cfs differ diff --git a/Comment/_5c.si b/Comment/_5c.si new file mode 100644 index 0000000..7d89600 Binary files /dev/null and b/Comment/_5c.si differ diff --git a/Comment/_5d.cfe b/Comment/_5d.cfe new file mode 100644 index 0000000..d1ba8f5 Binary files /dev/null and b/Comment/_5d.cfe differ diff --git a/Comment/_5d.cfs b/Comment/_5d.cfs new file mode 100644 index 0000000..ebbc816 Binary files /dev/null and b/Comment/_5d.cfs differ diff --git a/Comment/_5d.si b/Comment/_5d.si new file mode 100644 index 0000000..61e7f9c Binary files /dev/null and b/Comment/_5d.si differ diff --git a/Comment/_5e.cfe b/Comment/_5e.cfe new file mode 100644 index 0000000..697445c Binary files /dev/null and b/Comment/_5e.cfe differ diff --git a/Comment/_5e.cfs b/Comment/_5e.cfs new file mode 100644 index 0000000..ff30f35 Binary files /dev/null and b/Comment/_5e.cfs differ diff --git a/Comment/_5e.si b/Comment/_5e.si new file mode 100644 index 0000000..a971e4b Binary files /dev/null and b/Comment/_5e.si differ diff --git a/Comment/_5f.cfe b/Comment/_5f.cfe new file mode 100644 index 0000000..53bdd37 Binary files /dev/null and b/Comment/_5f.cfe differ diff --git a/Comment/_5f.cfs b/Comment/_5f.cfs new file mode 100644 index 0000000..8df8e55 Binary files /dev/null and b/Comment/_5f.cfs differ diff --git a/Comment/_5f.si b/Comment/_5f.si new file mode 100644 index 0000000..8da232e Binary files /dev/null and b/Comment/_5f.si differ diff --git a/Comment/segments_1d b/Comment/segments_1d deleted file mode 100644 index b2e7a64..0000000 Binary files a/Comment/segments_1d and /dev/null differ diff --git a/Comment/segments_1h b/Comment/segments_1h new file mode 100644 index 0000000..526ac12 Binary files /dev/null and b/Comment/segments_1h differ diff --git a/Entry/_4d.cfe b/Entry/_4d.cfe deleted file mode 100644 index f21e641..0000000 Binary files a/Entry/_4d.cfe and /dev/null differ diff --git a/Entry/_4d.cfs b/Entry/_4d.cfs deleted file mode 100644 index f19e276..0000000 Binary files a/Entry/_4d.cfs and /dev/null differ diff --git a/Entry/_4d.si b/Entry/_4d.si deleted file mode 100644 index 52b4015..0000000 Binary files a/Entry/_4d.si and /dev/null differ diff --git a/Entry/_4h.cfe b/Entry/_4h.cfe deleted file mode 100644 index f66dda4..0000000 Binary files a/Entry/_4h.cfe and /dev/null differ diff --git a/Entry/_4h.cfs b/Entry/_4h.cfs deleted file mode 100644 index 007ec6b..0000000 Binary files a/Entry/_4h.cfs and /dev/null differ diff --git a/Entry/_4h.si b/Entry/_4h.si deleted file mode 100644 index a26bbe1..0000000 Binary files a/Entry/_4h.si and /dev/null differ diff --git a/Entry/_4k.fdm b/Entry/_4k.fdm deleted file mode 100644 index bd0bebc..0000000 Binary files a/Entry/_4k.fdm and /dev/null differ diff --git a/Entry/_4k.fdt b/Entry/_4k.fdt deleted file mode 100644 index b8f6a30..0000000 Binary files a/Entry/_4k.fdt and /dev/null differ diff --git a/Entry/_4k.fdx b/Entry/_4k.fdx deleted file mode 100644 index 9afd155..0000000 Binary files a/Entry/_4k.fdx and /dev/null differ diff --git a/Entry/_4k.fnm b/Entry/_4k.fnm deleted file mode 100644 index a051f44..0000000 Binary files a/Entry/_4k.fnm and /dev/null differ diff --git a/Entry/_4k.nvd b/Entry/_4k.nvd deleted file mode 100644 index 817da3b..0000000 Binary files a/Entry/_4k.nvd and /dev/null differ diff --git a/Entry/_4k.nvm b/Entry/_4k.nvm deleted file mode 100644 index bcef35d..0000000 Binary files a/Entry/_4k.nvm and /dev/null differ diff --git a/Entry/_4k.si b/Entry/_4k.si deleted file mode 100644 index 4f9900b..0000000 Binary files a/Entry/_4k.si and /dev/null differ diff --git a/Entry/_4k_Lucene80_0.dvd b/Entry/_4k_Lucene80_0.dvd deleted file mode 100644 index 2859534..0000000 Binary files a/Entry/_4k_Lucene80_0.dvd and /dev/null differ diff --git a/Entry/_4k_Lucene80_0.dvm b/Entry/_4k_Lucene80_0.dvm deleted file mode 100644 index 0a28a08..0000000 Binary files a/Entry/_4k_Lucene80_0.dvm and /dev/null differ diff --git a/Entry/_4k_Lucene84_0.doc b/Entry/_4k_Lucene84_0.doc deleted file mode 100644 index e53cb47..0000000 Binary files a/Entry/_4k_Lucene84_0.doc and /dev/null differ diff --git a/Entry/_4k_Lucene84_0.pos b/Entry/_4k_Lucene84_0.pos deleted file mode 100644 index a3c932d..0000000 Binary files a/Entry/_4k_Lucene84_0.pos and /dev/null differ diff --git a/Entry/_4k_Lucene84_0.tim b/Entry/_4k_Lucene84_0.tim deleted file mode 100644 index dd8e732..0000000 Binary files a/Entry/_4k_Lucene84_0.tim and /dev/null differ diff --git a/Entry/_4k_Lucene84_0.tip b/Entry/_4k_Lucene84_0.tip deleted file mode 100644 index f78288a..0000000 Binary files a/Entry/_4k_Lucene84_0.tip and /dev/null differ diff --git a/Entry/_4k_Lucene84_0.tmd b/Entry/_4k_Lucene84_0.tmd deleted file mode 100644 index e3fd854..0000000 Binary files a/Entry/_4k_Lucene84_0.tmd and /dev/null differ diff --git a/Entry/_4t.cfe b/Entry/_4t.cfe new file mode 100644 index 0000000..2858720 Binary files /dev/null and b/Entry/_4t.cfe differ diff --git a/Entry/_4t.cfs b/Entry/_4t.cfs new file mode 100644 index 0000000..5df1679 Binary files /dev/null and b/Entry/_4t.cfs differ diff --git a/Entry/_4t.si b/Entry/_4t.si new file mode 100644 index 0000000..18d68e2 Binary files /dev/null and b/Entry/_4t.si differ diff --git a/Entry/_4u.cfe b/Entry/_4u.cfe new file mode 100644 index 0000000..bb63b59 Binary files /dev/null and b/Entry/_4u.cfe differ diff --git a/Entry/_4u.cfs b/Entry/_4u.cfs new file mode 100644 index 0000000..6ef5c2e Binary files /dev/null and b/Entry/_4u.cfs differ diff --git a/Comment/_4u.si b/Entry/_4u.si similarity index 58% rename from Comment/_4u.si rename to Entry/_4u.si index 52ba712..31dd0c0 100644 Binary files a/Comment/_4u.si and b/Entry/_4u.si differ diff --git a/Entry/_4v.cfe b/Entry/_4v.cfe new file mode 100644 index 0000000..b209e8b Binary files /dev/null and b/Entry/_4v.cfe differ diff --git a/Entry/_4v.cfs b/Entry/_4v.cfs new file mode 100644 index 0000000..981b690 Binary files /dev/null and b/Entry/_4v.cfs differ diff --git a/Comment/_4v.si b/Entry/_4v.si similarity index 58% rename from Comment/_4v.si rename to Entry/_4v.si index d2d718f..ac90e99 100644 Binary files a/Comment/_4v.si and b/Entry/_4v.si differ diff --git a/Entry/_4w.cfe b/Entry/_4w.cfe new file mode 100644 index 0000000..2955f79 Binary files /dev/null and b/Entry/_4w.cfe differ diff --git a/Entry/_4w.cfs b/Entry/_4w.cfs new file mode 100644 index 0000000..773934a Binary files /dev/null and b/Entry/_4w.cfs differ diff --git a/Entry/_4w.si b/Entry/_4w.si new file mode 100644 index 0000000..0dbb667 Binary files /dev/null and b/Entry/_4w.si differ diff --git a/Entry/_4x.cfe b/Entry/_4x.cfe new file mode 100644 index 0000000..b8d4438 Binary files /dev/null and b/Entry/_4x.cfe differ diff --git a/Entry/_4x.cfs b/Entry/_4x.cfs new file mode 100644 index 0000000..1acbd66 Binary files /dev/null and b/Entry/_4x.cfs differ diff --git a/Entry/_4x.si b/Entry/_4x.si new file mode 100644 index 0000000..8e513da Binary files /dev/null and b/Entry/_4x.si differ diff --git a/Entry/_4y.cfe b/Entry/_4y.cfe new file mode 100644 index 0000000..bee6bdb Binary files /dev/null and b/Entry/_4y.cfe differ diff --git a/Entry/_4y.cfs b/Entry/_4y.cfs new file mode 100644 index 0000000..a05a2f2 Binary files /dev/null and b/Entry/_4y.cfs differ diff --git a/Comment/_4y.si b/Entry/_4y.si similarity index 58% rename from Comment/_4y.si rename to Entry/_4y.si index 551da31..e0651a8 100644 Binary files a/Comment/_4y.si and b/Entry/_4y.si differ diff --git a/Entry/_4z.cfe b/Entry/_4z.cfe new file mode 100644 index 0000000..059b255 Binary files /dev/null and b/Entry/_4z.cfe differ diff --git a/Entry/_4z.cfs b/Entry/_4z.cfs new file mode 100644 index 0000000..8d071ac Binary files /dev/null and b/Entry/_4z.cfs differ diff --git a/Entry/_4z.si b/Entry/_4z.si new file mode 100644 index 0000000..cc25b6d Binary files /dev/null and b/Entry/_4z.si differ diff --git a/Entry/_50.cfe b/Entry/_50.cfe new file mode 100644 index 0000000..54ea33e Binary files /dev/null and b/Entry/_50.cfe differ diff --git a/Entry/_50.cfs b/Entry/_50.cfs new file mode 100644 index 0000000..afa8575 Binary files /dev/null and b/Entry/_50.cfs differ diff --git a/Entry/_50.si b/Entry/_50.si new file mode 100644 index 0000000..a361630 Binary files /dev/null and b/Entry/_50.si differ diff --git a/Entry/segments_19 b/Entry/segments_19 deleted file mode 100644 index a8075f7..0000000 Binary files a/Entry/segments_19 and /dev/null differ diff --git a/Entry/segments_1d b/Entry/segments_1d new file mode 100644 index 0000000..398b6d4 Binary files /dev/null and b/Entry/segments_1d differ diff --git a/src/main/java/de/bstly/board/businesslogic/SettingsManager.java b/src/main/java/de/bstly/board/businesslogic/SettingsManager.java index cc72bb2..0be115e 100644 --- a/src/main/java/de/bstly/board/businesslogic/SettingsManager.java +++ b/src/main/java/de/bstly/board/businesslogic/SettingsManager.java @@ -26,8 +26,8 @@ public class SettingsManager { private long FLAG_THRESH; @Value("${bstly.board.maxTags:3}") private int MAX_TAGS; - @Value("${bstly.board.maxUserPage:10}") - private long MAX_USER_PAGES; + @Value("${bstly.board.maxViews:10}") + private long MAX_VIEWS; /** * Gets the gravity. @@ -97,7 +97,7 @@ public class SettingsManager { * * @return the max user pages */ - public long getMaxUserPages() { - return MAX_USER_PAGES; + public long getMaxViews() { + return MAX_VIEWS; } } diff --git a/src/main/java/de/bstly/board/businesslogic/UserPageManager.java b/src/main/java/de/bstly/board/businesslogic/UserPageManager.java deleted file mode 100644 index ac3d951..0000000 --- a/src/main/java/de/bstly/board/businesslogic/UserPageManager.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * - */ -package de.bstly.board.businesslogic; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.domain.Sort.Order; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import de.bstly.board.model.QUserPage; -import de.bstly.board.model.UserPage; -import de.bstly.board.model.support.UserPageSorting; -import de.bstly.board.repository.UserPageRepository; - -/** - * The Class UserPageManager. - */ -@Component -public class UserPageManager { - - @Autowired - private UserPageRepository userPageRepository; - private QUserPage qUserPage = QUserPage.userPage; - - /** - * Exists. - * - * @param username the username - * @param name the name - * @return true, if successful - */ - public boolean exists(String username, String name) { - return userPageRepository - .exists(qUserPage.username.equalsIgnoreCase(username).and(qUserPage.name.eq(name))); - } - - /** - * Gets the. - * - * @param id the id - * @return the user page - */ - public UserPage get(Long id) { - return userPageRepository.findById(id).orElse(null); - } - - /** - * Gets the. - * - * @param username the username - * @param name the name - * @return the user page - */ - public UserPage get(String username, String name) { - return userPageRepository - .findOne(qUserPage.username.equalsIgnoreCase(username).and(qUserPage.name.eq(name))) - .orElse(null); - } - - /** - * Save. - * - * @param userPage the user page - * @return the user page - */ - public UserPage save(UserPage userPage) { - return userPageRepository.save(userPage); - } - - /** - * Gets the by user. - * - * @param username the username - * @param page the page - * @param size the size - * @param sortBy the sort by - * @param desc the desc - * @return the by user - */ - public Page getByUser(String username, int page, int size, boolean desc) { - return userPageRepository.findAll(qUserPage.username.equalsIgnoreCase(username), - PageRequest.of(page, size, desc ? Sort.by(Order.desc("index"), Order.desc("name")) - : Sort.by(Order.asc("index"), Order.asc("name")))); - } - - /** - * Count by user. - * - * @param username the username - * @return the long - */ - public long countByUser(String username) { - return userPageRepository.count(qUserPage.username.equalsIgnoreCase(username)); - } - - /** - * Gets the public. - * - * @param username the username - * @param page the page - * @param size the size - * @param sortBy the sort by - * @param desc the desc - * @return the public - */ - public Page getPublic(String username, int page, int size, String sortBy, - boolean desc) { - return userPageRepository.findAll( - qUserPage.username.notEqualsIgnoreCase(username).and(qUserPage.publicPage.isTrue()), - PageRequest.of(page, size, Sort.by(desc ? Direction.DESC : Direction.ASC, sortBy))); - } - - /** - * Delete. - * - * @param username the username - * @param name the name - */ - public void delete(String username, String name) { - Assert.isTrue(exists(username, name), "UserPage not found!"); - userPageRepository.delete(get(username, name)); - } - - public void createDefault(String username) { - if (!exists(username, "TOP")) { - UserPage userPageTop = new UserPage(); - userPageTop.setName("TOP"); - userPageTop.setUsername(username); - userPageTop.setSorting(UserPageSorting.TOP); - userPageTop.setIndex(20); - save(userPageTop); - } - if (!exists(username, "NEW")) { - UserPage userPageNew = new UserPage(); - userPageNew.setName("NEW"); - userPageNew.setUsername(username); - userPageNew.setSorting(UserPageSorting.NEW); - userPageNew.setIndex(40); - save(userPageNew); - } - if (!exists(username, "HOT")) { - UserPage userPageHot = new UserPage(); - userPageHot.setName("HOT"); - userPageHot.setUsername(username); - userPageHot.setSorting(UserPageSorting.HOT); - userPageHot.setIndex(60); - userPageHot.setDivider(true); - save(userPageHot); - } - if (!exists(username, "LAST")) { - UserPage userPageLast = new UserPage(); - userPageLast.setName("LAST"); - userPageLast.setUsername(username); - userPageLast.setSorting(UserPageSorting.LAST); - userPageLast.setIndex(80); - save(userPageLast); - } - } -} diff --git a/src/main/java/de/bstly/board/businesslogic/ViewManager.java b/src/main/java/de/bstly/board/businesslogic/ViewManager.java new file mode 100644 index 0000000..e214f38 --- /dev/null +++ b/src/main/java/de/bstly/board/businesslogic/ViewManager.java @@ -0,0 +1,163 @@ +/** + * + */ +package de.bstly.board.businesslogic; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.domain.Sort.Order; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import de.bstly.board.model.QView; +import de.bstly.board.model.View; +import de.bstly.board.model.support.ViewSorting; +import de.bstly.board.repository.ViewRepository; + +/** + * The Class ViewManager. + */ +@Component +public class ViewManager { + + @Autowired + private ViewRepository viewRepository; + private QView qView = QView.view; + + /** + * Exists. + * + * @param username the username + * @param name the name + * @return true, if successful + */ + public boolean exists(String username, String name) { + return viewRepository + .exists(qView.username.equalsIgnoreCase(username).and(qView.name.eq(name))); + } + + /** + * Gets the. + * + * @param id the id + * @return the user page + */ + public View get(Long id) { + return viewRepository.findById(id).orElse(null); + } + + /** + * Gets the. + * + * @param username the username + * @param name the name + * @return the user page + */ + public View get(String username, String name) { + return viewRepository + .findOne(qView.username.equalsIgnoreCase(username).and(qView.name.eq(name))) + .orElse(null); + } + + /** + * Save. + * + * @param view the user page + * @return the user page + */ + public View save(View view) { + return viewRepository.save(view); + } + + /** + * Gets the by user. + * + * @param username the username + * @param page the page + * @param size the size + * @param sortBy the sort by + * @param desc the desc + * @return the by user + */ + public Page getByUser(String username, int page, int size, boolean desc) { + return viewRepository.findAll(qView.username.equalsIgnoreCase(username), + PageRequest.of(page, size, desc ? Sort.by(Order.desc("index"), Order.desc("name")) + : Sort.by(Order.asc("index"), Order.asc("name")))); + } + + /** + * Count by user. + * + * @param username the username + * @return the long + */ + public long countByUser(String username) { + return viewRepository.count(qView.username.equalsIgnoreCase(username)); + } + + /** + * Gets the public. + * + * @param username the username + * @param page the page + * @param size the size + * @param sortBy the sort by + * @param desc the desc + * @return the public + */ + public Page getPublic(String username, int page, int size, String sortBy, boolean desc) { + return viewRepository.findAll( + qView.username.notEqualsIgnoreCase(username).and(qView.publicView.isTrue()), + PageRequest.of(page, size, Sort.by(desc ? Direction.DESC : Direction.ASC, sortBy))); + } + + /** + * Delete. + * + * @param username the username + * @param name the name + */ + public void delete(String username, String name) { + Assert.isTrue(exists(username, name), "View not found!"); + viewRepository.delete(get(username, name)); + } + + public void createDefault(String username) { + if (!exists(username, "TOP")) { + View viewTop = new View(); + viewTop.setName("TOP"); + viewTop.setUsername(username); + viewTop.setSorting(ViewSorting.TOP); + viewTop.setIndex(20); + save(viewTop); + } + if (!exists(username, "NEW")) { + View viewNew = new View(); + viewNew.setName("NEW"); + viewNew.setUsername(username); + viewNew.setSorting(ViewSorting.NEW); + viewNew.setIndex(40); + save(viewNew); + } + if (!exists(username, "HOT")) { + View viewHot = new View(); + viewHot.setName("HOT"); + viewHot.setUsername(username); + viewHot.setSorting(ViewSorting.HOT); + viewHot.setIndex(60); + viewHot.setDivider(true); + save(viewHot); + } + if (!exists(username, "LAST")) { + View viewLast = new View(); + viewLast.setName("LAST"); + viewLast.setUsername(username); + viewLast.setSorting(ViewSorting.LAST); + viewLast.setIndex(80); + save(viewLast); + } + } +} diff --git a/src/main/java/de/bstly/board/controller/EntryController.java b/src/main/java/de/bstly/board/controller/EntryController.java index 53c1f02..25eda85 100644 --- a/src/main/java/de/bstly/board/controller/EntryController.java +++ b/src/main/java/de/bstly/board/controller/EntryController.java @@ -32,14 +32,14 @@ import com.google.common.collect.Lists; import de.bstly.board.businesslogic.EntryManager; import de.bstly.board.businesslogic.SettingsManager; import de.bstly.board.businesslogic.UserManager; -import de.bstly.board.businesslogic.UserPageManager; +import de.bstly.board.businesslogic.ViewManager; import de.bstly.board.businesslogic.VoteManager; import de.bstly.board.controller.model.EntryFilter; import de.bstly.board.controller.support.EntityResponseStatusException; import de.bstly.board.controller.support.RequestBodyErrors; import de.bstly.board.controller.validation.EntryValidator; import de.bstly.board.model.Entry; -import de.bstly.board.model.UserPage; +import de.bstly.board.model.View; import de.bstly.board.model.Vote; import de.bstly.board.model.support.EntryStatus; import de.bstly.board.model.support.EntryType; @@ -65,7 +65,7 @@ public class EntryController extends BaseController { @Autowired private SettingsManager settingsManager; @Autowired - private UserPageManager userPageManager; + private ViewManager viewManager; /** * Fetch by user page. @@ -80,7 +80,7 @@ public class EntryController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping("/{name}") - public Page fetchByUserPage(@PathVariable("name") String name, + public Page fetchByView(@PathVariable("name") String name, @RequestParam("user") Optional usernameParameter, @RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, @@ -92,10 +92,10 @@ public class EntryController extends BaseController { @RequestParam("asc") Optional ascParameter, @RequestParam("ignore") Optional> ignoreParameter) { - UserPage userPage = userPageManager.get(usernameParameter.orElse(getCurrentUsername()), + View view = viewManager.get(usernameParameter.orElse(getCurrentUsername()), name); - if (userPage == null || usernameParameter.isPresent() && !userPage.isPublicPage()) { + if (view == null || usernameParameter.isPresent() && !view.isPublicView()) { throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); } @@ -107,12 +107,12 @@ public class EntryController extends BaseController { tagsParameter.orElse(null), excludedTagsParameter.orElse(null), typeParameter.orElse(null)); - filter.setFixedTags(userPage.getTags()); - filter.setFixedExcludedTags(userPage.getExcludedTags()); + filter.setFixedTags(view.getTags()); + filter.setFixedExcludedTags(view.getExcludedTags()); Page entries = null; - switch (userPage.getSorting()) { + switch (view.getSorting()) { case TOP: entries = entryManager.fetchByRanking(getCurrentUsername(), filter, getGravity(), pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), diff --git a/src/main/java/de/bstly/board/controller/SettingsController.java b/src/main/java/de/bstly/board/controller/SettingsController.java index 04a1eaf..ee8b71e 100644 --- a/src/main/java/de/bstly/board/controller/SettingsController.java +++ b/src/main/java/de/bstly/board/controller/SettingsController.java @@ -37,7 +37,7 @@ public class SettingsController extends BaseController { settings.put("entryDelay", getEntryDelay()); settings.put("commentDelay", getCommentDelay()); settings.put("maxTags", settingsManager.getMaxTags()); - settings.put("maxUserPages", settingsManager.getMaxUserPages()); + settings.put("maxViews", settingsManager.getMaxViews()); settings.put("defaultGravity", settingsManager.getGravity()); settings.put("defaultPageSize", settingsManager.getPageSize()); settings.put("defaultEntryDelay", settingsManager.getEntryDelay()); diff --git a/src/main/java/de/bstly/board/controller/UserPageController.java b/src/main/java/de/bstly/board/controller/ViewController.java similarity index 60% rename from src/main/java/de/bstly/board/controller/UserPageController.java rename to src/main/java/de/bstly/board/controller/ViewController.java index c5899b5..6c5ab3c 100644 --- a/src/main/java/de/bstly/board/controller/UserPageController.java +++ b/src/main/java/de/bstly/board/controller/ViewController.java @@ -19,25 +19,25 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import de.bstly.board.businesslogic.SettingsManager; -import de.bstly.board.businesslogic.UserPageManager; +import de.bstly.board.businesslogic.ViewManager; import de.bstly.board.controller.support.EntityResponseStatusException; import de.bstly.board.controller.support.RequestBodyErrors; -import de.bstly.board.controller.validation.UserPageValidator; -import de.bstly.board.model.UserPage; +import de.bstly.board.controller.validation.ViewValidator; +import de.bstly.board.model.View; /** - * The Class UserPageController. + * The Class ViewController. */ @RestController -@RequestMapping("/userpages") -public class UserPageController extends BaseController { +@RequestMapping("/views") +public class ViewController extends BaseController { @Autowired - private UserPageManager userPageManager; + private ViewManager viewManager; @Autowired private SettingsManager settingsManager; @Autowired - private UserPageValidator userPageValidator; + private ViewValidator viewValidator; /** * Gets the user pages. @@ -49,15 +49,15 @@ public class UserPageController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping() - public Page getUserPages(@RequestParam("page") Optional pageParameter, + public Page getViews(@RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, @RequestParam("desc") Optional descParameter) { - if (userPageManager.countByUser(getCurrentUsername()) == 0L) { - userPageManager.createDefault(getCurrentUsername()); + if (viewManager.countByUser(getCurrentUsername()) == 0L) { + viewManager.createDefault(getCurrentUsername()); } - return userPageManager.getByUser(getCurrentUsername(), pageParameter.orElse(0), + return viewManager.getByUser(getCurrentUsername(), pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false)); } @@ -71,10 +71,10 @@ public class UserPageController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping("/public") - public Page getPublicUserPages(@RequestParam("page") Optional pageParameter, + public Page getPublicViews(@RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, @RequestParam("desc") Optional descParameter) { - return userPageManager.getPublic(getCurrentUsername(), pageParameter.orElse(0), + return viewManager.getPublic(getCurrentUsername(), pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), "name", descParameter.orElse(false)); } @@ -86,44 +86,43 @@ public class UserPageController extends BaseController { * @return the user page */ @PreAuthorize("isAuthenticated()") - @GetMapping("/userpage/{name}") - public UserPage getUserPage(@PathVariable("name") String name, + @GetMapping("/view/{name}") + public View getView(@PathVariable("name") String name, @RequestParam("user") Optional usernameParameter) { - UserPage userPage = userPageManager.get(usernameParameter.orElse(getCurrentUsername()), - name); + View view = viewManager.get(usernameParameter.orElse(getCurrentUsername()), name); - if (userPage == null || usernameParameter.isPresent() && !userPage.isPublicPage()) { + if (view == null || usernameParameter.isPresent() && !view.isPublicView()) { throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); } - return userPage; + return view; } /** * Creates the or update. * - * @param userPage the user page + * @param view the user page * @return the user page */ @PreAuthorize("isAuthenticated()") - @PostMapping("/userpage") - public UserPage createOrUpdate(@RequestBody UserPage userPage) { - userPage.setUsername(getCurrentUsername()); + @PostMapping("/view") + public View createOrUpdate(@RequestBody View view) { + view.setUsername(getCurrentUsername()); - RequestBodyErrors bindingResult = new RequestBodyErrors(userPage); - userPageValidator.validate(userPage, bindingResult); + RequestBodyErrors bindingResult = new RequestBodyErrors(view); + viewValidator.validate(view, bindingResult); if (bindingResult.hasErrors()) { throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } - if (!userPageManager.exists(getCurrentUsername(), userPage.getName()) && userPageManager - .countByUser(getCurrentUsername()) >= settingsManager.getMaxUserPages()) { + if (!viewManager.exists(getCurrentUsername(), view.getName()) + && viewManager.countByUser(getCurrentUsername()) >= settingsManager.getMaxViews()) { throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); } - return userPageManager.save(userPage); + return viewManager.save(view); } /** @@ -132,13 +131,13 @@ public class UserPageController extends BaseController { * @param name the name */ @PreAuthorize("isAuthenticated()") - @DeleteMapping("/userpage/{name}") - public void deleteUserPage(@PathVariable("name") String name) { - if (!userPageManager.exists(getCurrentUsername(), name)) { + @DeleteMapping("/view/{name}") + public void deleteView(@PathVariable("name") String name) { + if (!viewManager.exists(getCurrentUsername(), name)) { throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); } - userPageManager.delete(getCurrentUsername(), name); + viewManager.delete(getCurrentUsername(), name); } } diff --git a/src/main/java/de/bstly/board/controller/validation/UserPageValidator.java b/src/main/java/de/bstly/board/controller/validation/ViewValidator.java similarity index 56% rename from src/main/java/de/bstly/board/controller/validation/UserPageValidator.java rename to src/main/java/de/bstly/board/controller/validation/ViewValidator.java index 44a1b26..52a0982 100644 --- a/src/main/java/de/bstly/board/controller/validation/UserPageValidator.java +++ b/src/main/java/de/bstly/board/controller/validation/ViewValidator.java @@ -10,25 +10,25 @@ import org.springframework.util.StringUtils; import org.springframework.validation.Errors; import org.springframework.validation.Validator; -import de.bstly.board.businesslogic.UserPageManager; +import de.bstly.board.businesslogic.ViewManager; import de.bstly.board.controller.support.EntityResponseStatusException; -import de.bstly.board.model.UserPage; +import de.bstly.board.model.View; /** - * The Class UserPageValidator. + * The Class ViewValidator. */ @Component -public class UserPageValidator implements Validator { +public class ViewValidator implements Validator { @Autowired - private UserPageManager userPageManager; + private ViewManager viewManager; /* * @see org.springframework.validation.Validator#supports(java.lang.Class) */ @Override public boolean supports(Class clazz) { - return clazz.isAssignableFrom(UserPage.class); + return clazz.isAssignableFrom(View.class); } /* @@ -37,34 +37,34 @@ public class UserPageValidator implements Validator { */ @Override public void validate(Object target, Errors errors) { - UserPage userPage = (UserPage) target; + View view = (View) target; - if (!StringUtils.hasText(userPage.getName())) { + if (!StringUtils.hasText(view.getName())) { errors.rejectValue("name", "required"); } - if ((userPage.getId() == null || userPage.getId().equals(0L)) - && userPageManager.exists(userPage.getUsername(), userPage.getName())) { + if ((view.getId() == null || view.getId().equals(0L)) + && viewManager.exists(view.getUsername(), view.getName())) { errors.rejectValue("name", "ALREADY_EXISTS"); } - if (userPage.getId() != null) { - UserPage origUserPage = userPageManager.get(userPage.getId()); - if (origUserPage == null) { + if (view.getId() != null) { + View origView = viewManager.get(view.getId()); + if (origView == null) { errors.rejectValue("id", "INVALID"); } - if (!origUserPage.getUsername().equals(userPage.getUsername())) { + if (!origView.getUsername().equals(view.getUsername())) { throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); } - UserPage other = userPageManager.get(userPage.getUsername(), userPage.getName()); - if (other != null && !other.getId().equals(userPage.getId())) { + View other = viewManager.get(view.getUsername(), view.getName()); + if (other != null && !other.getId().equals(view.getId())) { errors.rejectValue("name", "ALREADY_EXISTS"); } } - if (userPage.getSorting() == null) { + if (view.getSorting() == null) { errors.rejectValue("sorting", "REQUIRED"); } diff --git a/src/main/java/de/bstly/board/model/UserPage.java b/src/main/java/de/bstly/board/model/View.java similarity index 85% rename from src/main/java/de/bstly/board/model/UserPage.java rename to src/main/java/de/bstly/board/model/View.java index 50b9161..af268d3 100644 --- a/src/main/java/de/bstly/board/model/UserPage.java +++ b/src/main/java/de/bstly/board/model/View.java @@ -22,15 +22,15 @@ import org.hibernate.annotations.LazyCollectionOption; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import de.bstly.board.model.support.EntryType; -import de.bstly.board.model.support.UserPageSorting; +import de.bstly.board.model.support.ViewSorting; /** - * The Class UserPage. + * The Class View. */ @Entity -@Table(name = "user_pages") +@Table(name = "views") @EntityListeners({ AuditingEntityListener.class }) -public class UserPage { +public class View { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -42,21 +42,21 @@ public class UserPage { private String username; @Enumerated(EnumType.STRING) @Column(name = "sorting", nullable = false) - private UserPageSorting sorting; + private ViewSorting sorting; @Column(name = "indexNumber") private int index = 99; @ElementCollection @LazyCollection(LazyCollectionOption.FALSE) - @CollectionTable(name = "user_pages_tags") + @CollectionTable(name = "views_tags") private List tags; @ElementCollection @LazyCollection(LazyCollectionOption.FALSE) - @CollectionTable(name = "user_pages_excluded_tags") + @CollectionTable(name = "views_excluded_tags") private List excludedTags; @Column(name = "entry_type", nullable = true) private EntryType entryType; @Column(name = "public", columnDefinition = "boolean default false") - private boolean publicPage; + private boolean publicView; @Column(name = "divider", columnDefinition = "boolean default false") private boolean divider; @@ -119,7 +119,7 @@ public class UserPage { * * @return the sorting */ - public UserPageSorting getSorting() { + public ViewSorting getSorting() { return sorting; } @@ -128,7 +128,7 @@ public class UserPage { * * @param sorting the new sorting */ - public void setSorting(UserPageSorting sorting) { + public void setSorting(ViewSorting sorting) { this.sorting = sorting; } @@ -201,21 +201,17 @@ public class UserPage { } /** - * Checks if is public page. - * - * @return true, if is public page + * @return the publicView */ - public boolean isPublicPage() { - return publicPage; + public boolean isPublicView() { + return publicView; } /** - * Sets the public page. - * - * @param publicPage the new public page + * @param publicView the publicView to set */ - public void setPublicPage(boolean publicPage) { - this.publicPage = publicPage; + public void setPublicView(boolean publicView) { + this.publicView = publicView; } /** diff --git a/src/main/java/de/bstly/board/model/support/UserPageSorting.java b/src/main/java/de/bstly/board/model/support/ViewSorting.java similarity index 58% rename from src/main/java/de/bstly/board/model/support/UserPageSorting.java rename to src/main/java/de/bstly/board/model/support/ViewSorting.java index 2357362..df7f41a 100644 --- a/src/main/java/de/bstly/board/model/support/UserPageSorting.java +++ b/src/main/java/de/bstly/board/model/support/ViewSorting.java @@ -4,9 +4,9 @@ package de.bstly.board.model.support; /** - * The Enum UserPageSorting. + * The Enum ViewSorting. */ -public enum UserPageSorting { +public enum ViewSorting { TOP, NEW, HOT, LAST } diff --git a/src/main/java/de/bstly/board/repository/UserPageRepository.java b/src/main/java/de/bstly/board/repository/ViewRepository.java similarity index 57% rename from src/main/java/de/bstly/board/repository/UserPageRepository.java rename to src/main/java/de/bstly/board/repository/ViewRepository.java index 49dfb1b..5f75cfd 100644 --- a/src/main/java/de/bstly/board/repository/UserPageRepository.java +++ b/src/main/java/de/bstly/board/repository/ViewRepository.java @@ -7,13 +7,13 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.springframework.stereotype.Repository; -import de.bstly.board.model.UserPage; +import de.bstly.board.model.View; /** - * The Interface UserPageRepository. + * The Interface ViewRepository. */ @Repository -public interface UserPageRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface ViewRepository + extends JpaRepository, QuerydslPredicateExecutor { }