diff --git a/Comment/_4u.cfe b/Comment/_4u.cfe new file mode 100644 index 0000000..bd8ee06 Binary files /dev/null and b/Comment/_4u.cfe differ diff --git a/Comment/_4u.cfs b/Comment/_4u.cfs new file mode 100644 index 0000000..1439beb Binary files /dev/null and b/Comment/_4u.cfs differ diff --git a/Comment/_4u.si b/Comment/_4u.si new file mode 100644 index 0000000..52ba712 Binary files /dev/null and b/Comment/_4u.si differ diff --git a/Comment/_4v.cfe b/Comment/_4v.cfe new file mode 100644 index 0000000..f256ab2 Binary files /dev/null and b/Comment/_4v.cfe differ diff --git a/Comment/_4v.cfs b/Comment/_4v.cfs new file mode 100644 index 0000000..6f4c8f8 Binary files /dev/null and b/Comment/_4v.cfs differ diff --git a/Comment/_4v.si b/Comment/_4v.si new file mode 100644 index 0000000..d2d718f Binary files /dev/null and b/Comment/_4v.si differ diff --git a/Comment/_4y.cfe b/Comment/_4y.cfe new file mode 100644 index 0000000..e3bb6ae Binary files /dev/null and b/Comment/_4y.cfe differ diff --git a/Comment/_4y.cfs b/Comment/_4y.cfs new file mode 100644 index 0000000..8b588bb Binary files /dev/null and b/Comment/_4y.cfs differ diff --git a/Comment/_4y.si b/Comment/_4y.si new file mode 100644 index 0000000..551da31 Binary files /dev/null and b/Comment/_4y.si differ diff --git a/Comment/_4z.fdm b/Comment/_4z.fdm new file mode 100644 index 0000000..f73ab7a Binary files /dev/null and b/Comment/_4z.fdm differ diff --git a/Comment/_4z.fdt b/Comment/_4z.fdt new file mode 100644 index 0000000..aa3393c Binary files /dev/null and b/Comment/_4z.fdt differ diff --git a/Comment/_4z.fdx b/Comment/_4z.fdx new file mode 100644 index 0000000..ed41f3d Binary files /dev/null and b/Comment/_4z.fdx differ diff --git a/Comment/_4z.fnm b/Comment/_4z.fnm new file mode 100644 index 0000000..a112a98 Binary files /dev/null and b/Comment/_4z.fnm differ diff --git a/Comment/_4z.nvd b/Comment/_4z.nvd new file mode 100644 index 0000000..c23bff0 Binary files /dev/null and b/Comment/_4z.nvd differ diff --git a/Comment/_4z.nvm b/Comment/_4z.nvm new file mode 100644 index 0000000..23e83b9 Binary files /dev/null and b/Comment/_4z.nvm differ diff --git a/Comment/_4z.si b/Comment/_4z.si new file mode 100644 index 0000000..a2cc560 Binary files /dev/null and b/Comment/_4z.si differ diff --git a/Comment/_4z_Lucene80_0.dvd b/Comment/_4z_Lucene80_0.dvd new file mode 100644 index 0000000..82df1d1 Binary files /dev/null and b/Comment/_4z_Lucene80_0.dvd differ diff --git a/Comment/_4z_Lucene80_0.dvm b/Comment/_4z_Lucene80_0.dvm new file mode 100644 index 0000000..9916e2b Binary files /dev/null and b/Comment/_4z_Lucene80_0.dvm differ diff --git a/Comment/_4z_Lucene84_0.doc b/Comment/_4z_Lucene84_0.doc new file mode 100644 index 0000000..16f5ca7 Binary files /dev/null and b/Comment/_4z_Lucene84_0.doc differ diff --git a/Comment/_4z_Lucene84_0.pos b/Comment/_4z_Lucene84_0.pos new file mode 100644 index 0000000..54379d8 Binary files /dev/null and b/Comment/_4z_Lucene84_0.pos differ diff --git a/Comment/_4z_Lucene84_0.tim b/Comment/_4z_Lucene84_0.tim new file mode 100644 index 0000000..0f55b01 Binary files /dev/null and b/Comment/_4z_Lucene84_0.tim differ diff --git a/Comment/_4z_Lucene84_0.tip b/Comment/_4z_Lucene84_0.tip new file mode 100644 index 0000000..8398ace Binary files /dev/null and b/Comment/_4z_Lucene84_0.tip differ diff --git a/Comment/_4z_Lucene84_0.tmd b/Comment/_4z_Lucene84_0.tmd new file mode 100644 index 0000000..cc682ce Binary files /dev/null and b/Comment/_4z_Lucene84_0.tmd differ diff --git a/Comment/segments_1d b/Comment/segments_1d new file mode 100644 index 0000000..b2e7a64 Binary files /dev/null and b/Comment/segments_1d differ diff --git a/Comment/write.lock b/Comment/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/Entry/_4d.cfe b/Entry/_4d.cfe new file mode 100644 index 0000000..f21e641 Binary files /dev/null and b/Entry/_4d.cfe differ diff --git a/Entry/_4d.cfs b/Entry/_4d.cfs new file mode 100644 index 0000000..f19e276 Binary files /dev/null and b/Entry/_4d.cfs differ diff --git a/Entry/_4d.si b/Entry/_4d.si new file mode 100644 index 0000000..52b4015 Binary files /dev/null and b/Entry/_4d.si differ diff --git a/Entry/_4h.cfe b/Entry/_4h.cfe new file mode 100644 index 0000000..f66dda4 Binary files /dev/null and b/Entry/_4h.cfe differ diff --git a/Entry/_4h.cfs b/Entry/_4h.cfs new file mode 100644 index 0000000..007ec6b Binary files /dev/null and b/Entry/_4h.cfs differ diff --git a/Entry/_4h.si b/Entry/_4h.si new file mode 100644 index 0000000..a26bbe1 Binary files /dev/null and b/Entry/_4h.si differ diff --git a/Entry/_4k.fdm b/Entry/_4k.fdm new file mode 100644 index 0000000..bd0bebc Binary files /dev/null and b/Entry/_4k.fdm differ diff --git a/Entry/_4k.fdt b/Entry/_4k.fdt new file mode 100644 index 0000000..b8f6a30 Binary files /dev/null and b/Entry/_4k.fdt differ diff --git a/Entry/_4k.fdx b/Entry/_4k.fdx new file mode 100644 index 0000000..9afd155 Binary files /dev/null and b/Entry/_4k.fdx differ diff --git a/Entry/_4k.fnm b/Entry/_4k.fnm new file mode 100644 index 0000000..a051f44 Binary files /dev/null and b/Entry/_4k.fnm differ diff --git a/Entry/_4k.nvd b/Entry/_4k.nvd new file mode 100644 index 0000000..817da3b Binary files /dev/null and b/Entry/_4k.nvd differ diff --git a/Entry/_4k.nvm b/Entry/_4k.nvm new file mode 100644 index 0000000..bcef35d Binary files /dev/null and b/Entry/_4k.nvm differ diff --git a/Entry/_4k.si b/Entry/_4k.si new file mode 100644 index 0000000..4f9900b Binary files /dev/null and b/Entry/_4k.si differ diff --git a/Entry/_4k_Lucene80_0.dvd b/Entry/_4k_Lucene80_0.dvd new file mode 100644 index 0000000..2859534 Binary files /dev/null and b/Entry/_4k_Lucene80_0.dvd differ diff --git a/Entry/_4k_Lucene80_0.dvm b/Entry/_4k_Lucene80_0.dvm new file mode 100644 index 0000000..0a28a08 Binary files /dev/null and b/Entry/_4k_Lucene80_0.dvm differ diff --git a/Entry/_4k_Lucene84_0.doc b/Entry/_4k_Lucene84_0.doc new file mode 100644 index 0000000..e53cb47 Binary files /dev/null and b/Entry/_4k_Lucene84_0.doc differ diff --git a/Entry/_4k_Lucene84_0.pos b/Entry/_4k_Lucene84_0.pos new file mode 100644 index 0000000..a3c932d Binary files /dev/null and b/Entry/_4k_Lucene84_0.pos differ diff --git a/Entry/_4k_Lucene84_0.tim b/Entry/_4k_Lucene84_0.tim new file mode 100644 index 0000000..dd8e732 Binary files /dev/null and b/Entry/_4k_Lucene84_0.tim differ diff --git a/Entry/_4k_Lucene84_0.tip b/Entry/_4k_Lucene84_0.tip new file mode 100644 index 0000000..f78288a Binary files /dev/null and b/Entry/_4k_Lucene84_0.tip differ diff --git a/Entry/_4k_Lucene84_0.tmd b/Entry/_4k_Lucene84_0.tmd new file mode 100644 index 0000000..e3fd854 Binary files /dev/null and b/Entry/_4k_Lucene84_0.tmd differ diff --git a/Entry/segments_19 b/Entry/segments_19 new file mode 100644 index 0000000..a8075f7 Binary files /dev/null and b/Entry/segments_19 differ diff --git a/Entry/write.lock b/Entry/write.lock new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml index 6a37175..24e410f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ UTF-8 11 - 1.2.0 + 1.3.0 @@ -57,6 +57,19 @@ spring-session-jdbc + + + org.hibernate.search + hibernate-search-mapper-orm + 6.0.7.Final + + + + org.hibernate.search + hibernate-search-backend-lucene + 6.0.7.Final + + com.querydsl diff --git a/src/main/java/de/bstly/board/businesslogic/CommentManager.java b/src/main/java/de/bstly/board/businesslogic/CommentManager.java index dea020f..3a583cb 100644 --- a/src/main/java/de/bstly/board/businesslogic/CommentManager.java +++ b/src/main/java/de/bstly/board/businesslogic/CommentManager.java @@ -19,13 +19,13 @@ import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import de.bstly.board.model.Comment; -import de.bstly.board.model.FlaggedStatus; import de.bstly.board.model.QComment; import de.bstly.board.model.QEntry; import de.bstly.board.model.QFlag; import de.bstly.board.model.QVote; -import de.bstly.board.model.Types; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; import de.bstly.board.repository.CommentRepository; import de.bstly.board.repository.VoteRepository; diff --git a/src/main/java/de/bstly/board/businesslogic/EntryManager.java b/src/main/java/de/bstly/board/businesslogic/EntryManager.java index a81f5b8..af403c1 100644 --- a/src/main/java/de/bstly/board/businesslogic/EntryManager.java +++ b/src/main/java/de/bstly/board/businesslogic/EntryManager.java @@ -27,12 +27,12 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import de.bstly.board.controller.model.EntryFilter; import de.bstly.board.model.Bookmarks; import de.bstly.board.model.Entry; -import de.bstly.board.model.FlaggedStatus; import de.bstly.board.model.QEntry; import de.bstly.board.model.QFlag; import de.bstly.board.model.QVote; -import de.bstly.board.model.Types; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; import de.bstly.board.repository.EntryRepository; import de.bstly.board.repository.VoteRepository; @@ -104,7 +104,7 @@ public class EntryManager { * @param asc the asc * @return the page */ - public Page fetchByRanking(String username, EntryFilter filter, double gravity, int page, + public Page fetchByRanking(String username, EntryFilter filter, float gravity, int page, int size, boolean asc) { Query query = createEntryQuery(RANK_CALCULATION_QUERY, username, filter, asc ? "ranking ASC, entry.created ASC" : "ranking DESC, entry.created DESC"); @@ -152,7 +152,7 @@ public class EntryManager { * @param asc the asc * @return the page */ - public Page fetchByComments(String username, EntryFilter filter, double gravity, + public Page fetchByComments(String username, EntryFilter filter, float gravity, int page, int size, boolean asc) { Query query = createEntryQuery(COMMENT_CALCULATION_QUERY, username, filter, asc ? "ranking ASC, entry.created ASC" : "ranking DESC, entry.created DESC"); @@ -247,6 +247,24 @@ public class EntryManager { + tagsString + ")"; } + + String fixedTagsString = ""; + if (filter.getFixedTags() != null && !filter.getFixedTags().isEmpty()) { + for (int index = 0; index < filter.getFixedTags().size(); index++) { + fixedTagsString += "'" + + filter.getFixedTags().get(index) + + "'"; + if (index < filter.getFixedTags().size() - 1) { + fixedTagsString += ","; + } + } + } + + if (StringUtils.hasText(fixedTagsString)) { + filterString += " INNER JOIN tags as fixedTag ON entry.id = fixedTag.target AND fixedTag.tag IN (" + + fixedTagsString + + ")"; + } boolean author = false; if (filter.getDate() != null) { @@ -289,6 +307,24 @@ public class EntryManager { + excludedTagsString + "))"; } + + String fixedExcludedTagsString = ""; + if (filter.getFixedExcludedTags() != null && !filter.getFixedExcludedTags().isEmpty()) { + for (int index = 0; index < filter.getFixedExcludedTags().size(); index++) { + fixedExcludedTagsString += "'" + + filter.getFixedExcludedTags().get(index) + + "'"; + if (index < filter.getFixedExcludedTags().size() - 1) { + fixedExcludedTagsString += ","; + } + } + } + + if (StringUtils.hasText(fixedExcludedTagsString)) { + filterString += " AND NOT EXISTS (SELECT * FROM tags as fixedExcludedTag WHERE entry.id = fixedExcludedTag.target AND fixedExcludedTag.tag IN (" + + fixedExcludedTagsString + + "))"; + } if (StringUtils.hasText(orderBy)) { filterString += " ORDER BY " diff --git a/src/main/java/de/bstly/board/businesslogic/FlagManager.java b/src/main/java/de/bstly/board/businesslogic/FlagManager.java index 13555e4..7234d8e 100644 --- a/src/main/java/de/bstly/board/businesslogic/FlagManager.java +++ b/src/main/java/de/bstly/board/businesslogic/FlagManager.java @@ -10,10 +10,10 @@ import org.springframework.util.Assert; import de.bstly.board.model.Comment; import de.bstly.board.model.Entry; import de.bstly.board.model.Flag; -import de.bstly.board.model.FlaggedStatus; import de.bstly.board.model.QComment; import de.bstly.board.model.QFlag; -import de.bstly.board.model.Types; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.Types; import de.bstly.board.repository.CommentRepository; import de.bstly.board.repository.FlagRepository; diff --git a/src/main/java/de/bstly/board/businesslogic/SearchManager.java b/src/main/java/de/bstly/board/businesslogic/SearchManager.java new file mode 100644 index 0000000..c2b1ed8 --- /dev/null +++ b/src/main/java/de/bstly/board/businesslogic/SearchManager.java @@ -0,0 +1,113 @@ +/** + * + */ +package de.bstly.board.businesslogic; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.transaction.Transactional; + +import org.hibernate.search.engine.search.query.SearchResult; +import org.hibernate.search.mapper.orm.Search; +import org.hibernate.search.mapper.orm.massindexing.MassIndexer; +import org.hibernate.search.mapper.orm.session.SearchSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import com.google.common.collect.Lists; + +import de.bstly.board.model.Comment; +import de.bstly.board.model.Entry; +import de.bstly.board.model.support.Types; + +/** + * The Class SearchManager. + */ +@Component +public class SearchManager implements SmartInitializingSingleton { + + private Logger logger = LoggerFactory.getLogger(SearchManager.class); + + @Autowired + private EntityManager em; + @Autowired + private SettingsManager settingsManager; + private SearchSession searchSession; + + /* + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() + */ + /* + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() + */ + @Override + public void afterSingletonsInstantiated() { + searchSession = Search.session(em); + } + + /** + * On application event. + * + * @param event the event + */ + @EventListener(ContextRefreshedEvent.class) + @Transactional + public void onApplicationEvent(ContextRefreshedEvent event) { + MassIndexer indexer = searchSession.massIndexer().idFetchSize(150) + .batchSizeToLoadObjects(25).threadsToLoadObjects(12); + try { + logger.info("start indexing!"); + indexer.startAndWait(); + logger.info("finished indexing!"); + } catch (InterruptedException e) { + logger.error("error on indexing!", e); + Thread.currentThread().interrupt(); + } + } + + @Transactional + public SearchResult search(List types, String search, int page, int size, + boolean asc, boolean sortByDate) { + List> classes = Lists.newArrayList(); + for (Types type : types) { + switch (type) { + case comment: + classes.add(Comment.class); + break; + case entry: + classes.add(Entry.class); + break; + default: + break; + } + } + + if (classes.contains(Entry.class)) { + return searchSession.search(classes) + .where(f -> f.bool() + .should(f.match().field("title").matching(search) + .boost(settingsManager.getGravity())) + .should(f.match().field("text").matching(search))) + .sort(f -> sortByDate + ? (asc ? f.field("created").asc() : f.field("created").desc()) + : (asc ? f.score().asc() : f.score().desc())) + .fetch(page * size, size); + } else { + return searchSession.search(classes) + .where(f -> f.bool().should(f.match().field("text").matching(search))) + .sort(f -> sortByDate + ? (asc ? f.field("created").asc() : f.field("created").desc()) + : (asc ? f.score().asc() : f.score().desc())) + .fetch(page * size, size); + } + } + +} diff --git a/src/main/java/de/bstly/board/businesslogic/SettingsManager.java b/src/main/java/de/bstly/board/businesslogic/SettingsManager.java index 3e48865..cc72bb2 100644 --- a/src/main/java/de/bstly/board/businesslogic/SettingsManager.java +++ b/src/main/java/de/bstly/board/businesslogic/SettingsManager.java @@ -13,7 +13,7 @@ import org.springframework.stereotype.Component; public class SettingsManager { @Value("${bstly.board.ranking.gravity:1.2}") - private double GRAVITY; + private float GRAVITY; @Value("${bstly.board.size:30}") private int SIZE; @Value("${bstly.board.entry.changePeriod:1}") @@ -26,7 +26,7 @@ public class SettingsManager { private long FLAG_THRESH; @Value("${bstly.board.maxTags:3}") private int MAX_TAGS; - @Value("${bstly.board.maxUserPage:5}") + @Value("${bstly.board.maxUserPage:10}") private long MAX_USER_PAGES; /** @@ -34,7 +34,7 @@ public class SettingsManager { * * @return the gravity */ - public double getGravity() { + public float getGravity() { return GRAVITY; } diff --git a/src/main/java/de/bstly/board/businesslogic/UserManager.java b/src/main/java/de/bstly/board/businesslogic/UserManager.java index 219419d..17ea87e 100644 --- a/src/main/java/de/bstly/board/businesslogic/UserManager.java +++ b/src/main/java/de/bstly/board/businesslogic/UserManager.java @@ -140,6 +140,9 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet /* * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String) */ + /* + * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String) + */ /* * @see org.springframework.security.core.userdetails.UserDetailsService# * loadUserByUsername(java.lang.String) @@ -254,6 +257,9 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet /* * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() */ + /* + * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + */ /* * @see org.springframework.beans.factory.SmartInitializingSingleton# * afterSingletonsInstantiated() diff --git a/src/main/java/de/bstly/board/businesslogic/UserPageManager.java b/src/main/java/de/bstly/board/businesslogic/UserPageManager.java index cc29c05..ac3d951 100644 --- a/src/main/java/de/bstly/board/businesslogic/UserPageManager.java +++ b/src/main/java/de/bstly/board/businesslogic/UserPageManager.java @@ -8,11 +8,13 @@ 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; /** @@ -29,7 +31,7 @@ public class UserPageManager { * Exists. * * @param username the username - * @param name the name + * @param name the name * @return true, if successful */ public boolean exists(String username, String name) { @@ -51,7 +53,7 @@ public class UserPageManager { * Gets the. * * @param username the username - * @param name the name + * @param name the name * @return the user page */ public UserPage get(String username, String name) { @@ -74,16 +76,16 @@ public class UserPageManager { * 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 + * @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, String sortBy, - boolean desc) { + public Page getByUser(String username, int page, int size, boolean desc) { return userPageRepository.findAll(qUserPage.username.equalsIgnoreCase(username), - PageRequest.of(page, size, Sort.by(desc ? Direction.DESC : Direction.ASC, sortBy))); + PageRequest.of(page, size, desc ? Sort.by(Order.desc("index"), Order.desc("name")) + : Sort.by(Order.asc("index"), Order.asc("name")))); } /** @@ -100,10 +102,10 @@ public class UserPageManager { * Gets the public. * * @param username the username - * @param page the page - * @param size the size - * @param sortBy the sort by - * @param desc the desc + * @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, @@ -117,10 +119,46 @@ public class UserPageManager { * Delete. * * @param username the username - * @param name the name + * @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/VoteManager.java b/src/main/java/de/bstly/board/businesslogic/VoteManager.java index 2cd5128..12dc61f 100644 --- a/src/main/java/de/bstly/board/businesslogic/VoteManager.java +++ b/src/main/java/de/bstly/board/businesslogic/VoteManager.java @@ -7,9 +7,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import de.bstly.board.model.QVote; -import de.bstly.board.model.Types; import de.bstly.board.model.Vote; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; import de.bstly.board.repository.VoteRepository; /** diff --git a/src/main/java/de/bstly/board/controller/BaseController.java b/src/main/java/de/bstly/board/controller/BaseController.java index 8e8d4e9..cece545 100644 --- a/src/main/java/de/bstly/board/controller/BaseController.java +++ b/src/main/java/de/bstly/board/controller/BaseController.java @@ -80,13 +80,13 @@ public class BaseController { * * @return the gravity */ - protected double getGravity() { + protected float getGravity() { String username = getCurrentUsername(); if (username != null) { LocalUser localUser = userManager.getByUsername(username); if (localUser.getSettings() != null && localUser.getSettings().containsKey("gravity")) { try { - double gravity = Double.parseDouble(localUser.getSettings().get("gravity")); + float gravity = Float.parseFloat(localUser.getSettings().get("gravity")); if (gravity < 0) { return 0; } diff --git a/src/main/java/de/bstly/board/controller/CommentController.java b/src/main/java/de/bstly/board/controller/CommentController.java index 0e92d3b..cd8fed2 100644 --- a/src/main/java/de/bstly/board/controller/CommentController.java +++ b/src/main/java/de/bstly/board/controller/CommentController.java @@ -31,10 +31,10 @@ import de.bstly.board.controller.support.EntityResponseStatusException; import de.bstly.board.controller.support.RequestBodyErrors; import de.bstly.board.controller.validation.CommentValidator; import de.bstly.board.model.Comment; -import de.bstly.board.model.FlaggedStatus; -import de.bstly.board.model.Types; import de.bstly.board.model.Vote; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; /** * The Class CommentController. @@ -55,12 +55,12 @@ public class CommentController extends BaseController { /** * Fetch by date. * - * @param target the target - * @param parent the parent - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param descParameter the desc parameter + * @param target the target + * @param parent the parent + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param dateParameter the date parameter + * @param descParameter the desc parameter * @param ignoreParameter the ignore parameter * @return the page */ @@ -93,11 +93,11 @@ public class CommentController extends BaseController { /** * Fetch by username. * - * @param username the username - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param ascParameter the asc parameter + * @param username the username + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param dateParameter the date parameter + * @param ascParameter the asc parameter * @param ignoreParameter the ignore parameter * @return the page */ @@ -143,7 +143,7 @@ public class CommentController extends BaseController { /** * Gets the comment. * - * @param id the id + * @param id the id * @param ignoreParameter the ignore parameter * @return the comment */ @@ -165,7 +165,7 @@ public class CommentController extends BaseController { /** * Creates the comment. * - * @param comment the comment + * @param comment the comment * @param ignoreParameter the ignore parameter * @return the comment */ @@ -203,7 +203,7 @@ public class CommentController extends BaseController { /** * Update comment. * - * @param comment the comment + * @param comment the comment * @param ignoreParameter the ignore parameter * @return the comment */ diff --git a/src/main/java/de/bstly/board/controller/DebugController.java b/src/main/java/de/bstly/board/controller/DebugController.java index 2fc5caa..eacd947 100644 --- a/src/main/java/de/bstly/board/controller/DebugController.java +++ b/src/main/java/de/bstly/board/controller/DebugController.java @@ -21,18 +21,17 @@ import org.springframework.web.bind.annotation.RestController; import de.bstly.board.businesslogic.EntryManager; import de.bstly.board.model.Comment; import de.bstly.board.model.Entry; -import de.bstly.board.model.EntryStatus; -import de.bstly.board.model.EntryType; import de.bstly.board.model.LocalUser; import de.bstly.board.model.QLocalUser; -import de.bstly.board.model.Types; import de.bstly.board.model.Vote; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.EntryStatus; +import de.bstly.board.model.support.EntryType; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; import de.bstly.board.repository.CommentRepository; import de.bstly.board.repository.LocalUserRepository; import de.bstly.board.repository.VoteRepository; - /** * The Class DebugController. */ @@ -40,78 +39,59 @@ import de.bstly.board.repository.VoteRepository; @RequestMapping("/debug") public class DebugController extends BaseController { - private Logger logger = LogManager.getLogger(DebugController.class); - @Autowired private PasswordEncoder passwordEncoder; - - + @Autowired private LocalUserRepository localUserRepository; - - + @Autowired private CommentRepository commentRepository; - - + @Autowired private VoteRepository voteRepository; - - + @Autowired private EntryManager entryManager; - @Value("${debug.random.users:0}") private int users; - - + @Value("${debug.random.minEntries:0}") private int minEntries; - - + @Value("${debug.random.maxEntries:10}") private int maxEntries; - - + @Value("${debug.random.entryAge:63115200}") private long entryAge; - - + @Value("${debug.random.minComments:0}") private int minComments; - - + @Value("${debug.random.maxComments:10}") private int maxComments; - - + @Value("${debug.random.subCommentsFactor:0.5}") - private double subCommentsFactor; - - + private float subCommentsFactor; + @Value("${debug.random.subCommentsThresh:0.3}") - private double subCommentsThresh; - - + private float subCommentsThresh; + @Value("${debug.random.subCommentsDepth:2}") private int subCommentsDepth; - - + @Value("${debug.random.minUpvotes:5}") private int minUpvotes; - - + @Value("${debug.random.maxUpvotes:10}") private int maxUpvotes; - - + @Value("${debug.random.minDownvotes:0}") private int minDownvotes; - - + @Value("${debug.random.maxDownvotes:10}") private int maxDownvotes; @@ -153,7 +133,7 @@ public class DebugController extends BaseController { /** * Entries. * - * @param username the username + * @param username the username * @param userCount the user count */ protected void entries(String username, long userCount) { @@ -184,8 +164,8 @@ public class DebugController extends BaseController { /** * Comments. * - * @param target the target - * @param date the date + * @param target the target + * @param date the date * @param userCount the user count */ protected void comments(Long target, Instant date, long userCount) { @@ -217,17 +197,17 @@ public class DebugController extends BaseController { /** * Sub comments. * - * @param target the target - * @param parent the parent - * @param date the date - * @param factor the factor - * @param thresh the thresh - * @param depth the depth + * @param target the target + * @param parent the parent + * @param date the date + * @param factor the factor + * @param thresh the thresh + * @param depth the depth * @param userCount the user count */ - protected void subComments(Long target, Long parent, Instant date, double factor, double thresh, + protected void subComments(Long target, Long parent, Instant date, float factor, float thresh, int depth, long userCount) { - if (depth < subCommentsDepth && RandomUtils.nextDouble(0, 1) < thresh) { + if (depth < subCommentsDepth && RandomUtils.nextFloat(0, 1) < thresh) { long numSubComments = RandomUtils.nextLong(0, Math.round(maxComments * factor)); logger.debug("Create " + numSubComments @@ -249,8 +229,8 @@ public class DebugController extends BaseController { logger.trace("Created subComment: '" + comment.getId() + "'"); - subComments(target, comment.getId(), comment.getCreated(), factor * 0.5, - thresh * 0.5, depth++, userCount); + subComments(target, comment.getId(), comment.getCreated(), factor * 0.5f, + thresh * 0.5f, depth++, userCount); } } } @@ -258,9 +238,9 @@ public class DebugController extends BaseController { /** * Votes. * - * @param target the target + * @param target the target * @param targetType the target type - * @param userCount the user count + * @param userCount the user count */ protected void votes(Long target, Types targetType, long userCount) { long numUpvotes = RandomUtils.nextLong(minUpvotes, maxUpvotes); diff --git a/src/main/java/de/bstly/board/controller/EntryController.java b/src/main/java/de/bstly/board/controller/EntryController.java index 9657e9d..53c1f02 100644 --- a/src/main/java/de/bstly/board/controller/EntryController.java +++ b/src/main/java/de/bstly/board/controller/EntryController.java @@ -39,13 +39,13 @@ 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.EntryStatus; -import de.bstly.board.model.EntryType; -import de.bstly.board.model.FlaggedStatus; -import de.bstly.board.model.Types; import de.bstly.board.model.UserPage; import de.bstly.board.model.Vote; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.EntryStatus; +import de.bstly.board.model.support.EntryType; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; /** * The Class EntryController. @@ -67,261 +67,28 @@ public class EntryController extends BaseController { @Autowired private UserPageManager userPageManager; - /** - * Fetch by ranking. - * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param tagsParameter the tags parameter - * @param excludedTagsParameter the excluded tags parameter - * @param typeParameter the type parameter - * @param gravityParameter the gravity parameter - * @param ascParameter the asc parameter - * @param ignoreParameter the ignore parameter - * @return the page - */ - @PreAuthorize("isAuthenticated()") - @GetMapping() - public Page fetchByRanking(@RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("date") Optional dateParameter, - @RequestParam("tags") Optional> tagsParameter, - @RequestParam("excludedTags") Optional> excludedTagsParameter, - @RequestParam("type") Optional typeParameter, - @RequestParam("gravity") Optional gravityParameter, - @RequestParam("asc") Optional ascParameter, - @RequestParam("ignore") Optional> ignoreParameter) { - - if (sizeParameter.isPresent() && sizeParameter.get() > 100) { - sizeParameter = Optional.of(100); - } - - if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { - dateParameter = Optional.of(Instant.now()); - } - - if (gravityParameter.isPresent() && gravityParameter.get() > 2) { - gravityParameter = Optional.of(2.0); - } - - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); - - Page entries = entryManager.fetchByRanking(getCurrentUsername(), filter, - gravityParameter.orElse(getGravity()), pageParameter.orElse(0), - sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); - - List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entries.getContent(), ignore); - return entries; - } - - /** - * Fetch by date. - * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param tagsParameter the tags parameter - * @param excludedTagsParameter the excluded tags parameter - * @param typeParameter the type parameter - * @param ascParameter the asc parameter - * @param ignoreParameter the ignore parameter - * @return the page - */ - @PreAuthorize("isAuthenticated()") - @GetMapping("/new") - public Page fetchByDate(@RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("date") Optional dateParameter, - @RequestParam("tags") Optional> tagsParameter, - @RequestParam("excludedTags") Optional> excludedTagsParameter, - @RequestParam("type") Optional typeParameter, - @RequestParam("asc") Optional ascParameter, - @RequestParam("ignore") Optional> ignoreParameter) { - - if (sizeParameter.isPresent() && sizeParameter.get() > 100) { - sizeParameter = Optional.of(100); - } - - if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { - dateParameter = Optional.of(Instant.now()); - } - - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); - - Page entries = entryManager.fetchByDate(getCurrentUsername(), filter, - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); - List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entries.getContent(), ignore); - return entries; - } - - /** - * Fetch by comments. - * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param tagsParameter the tags parameter - * @param excludedTagsParameter the excluded tags parameter - * @param typeParameter the type parameter - * @param gravityParameter the gravity parameter - * @param ascParameter the asc parameter - * @param ignoreParameter the ignore parameter - * @return the page - */ - @PreAuthorize("isAuthenticated()") - @GetMapping("/comments") - public Page fetchByComments(@RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("date") Optional dateParameter, - @RequestParam("tags") Optional> tagsParameter, - @RequestParam("excludedTags") Optional> excludedTagsParameter, - @RequestParam("type") Optional typeParameter, - @RequestParam("gravity") Optional gravityParameter, - @RequestParam("asc") Optional ascParameter, - @RequestParam("ignore") Optional> ignoreParameter) { - - if (sizeParameter.isPresent() && sizeParameter.get() > 100) { - sizeParameter = Optional.of(100); - } - - if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { - dateParameter = Optional.of(Instant.now()); - } - - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); - - Page entries = entryManager.fetchByComments(getCurrentUsername(), filter, - gravityParameter.orElse(getGravity()), pageParameter.orElse(0), - sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); - - List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entries.getContent(), ignore); - return entries; - } - - /** - * Fetch by last. - * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param tagsParameter the tags parameter - * @param excludedTagsParameter the excluded tags parameter - * @param typeParameter the type parameter - * @param ascParameter the asc parameter - * @param ignoreParameter the ignore parameter - * @return the page - */ - @PreAuthorize("isAuthenticated()") - @GetMapping("/last") - public Page fetchByLast(@RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("date") Optional dateParameter, - @RequestParam("tags") Optional> tagsParameter, - @RequestParam("excludedTags") Optional> excludedTagsParameter, - @RequestParam("type") Optional typeParameter, - @RequestParam("asc") Optional ascParameter, - @RequestParam("ignore") Optional> ignoreParameter) { - - if (sizeParameter.isPresent() && sizeParameter.get() > 100) { - sizeParameter = Optional.of(100); - } - - if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { - dateParameter = Optional.of(Instant.now()); - } - - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); - - Page entries = entryManager.fetchByLastComment(getCurrentUsername(), filter, - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); - - List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entries.getContent(), ignore); - return entries; - } - - /** - * Fetch by user. - * - * @param username the username - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param dateParameter the date parameter - * @param tagsParameter the tags parameter - * @param excludedTagsParameter the excluded tags parameter - * @param typeParameter the type parameter - * @param ascParameter the asc parameter - * @param ignoreParameter the ignore parameter - * @return the page - */ - @PreAuthorize("isAuthenticated()") - @GetMapping("/byuser/{username}") - public Page fetchByUser(@PathVariable("username") String username, - @RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("date") Optional dateParameter, - @RequestParam("tags") Optional> tagsParameter, - @RequestParam("excludedTags") Optional> excludedTagsParameter, - @RequestParam("type") Optional typeParameter, - @RequestParam("asc") Optional ascParameter, - @RequestParam("ignore") Optional> ignoreParameter) { - - if (sizeParameter.isPresent() && sizeParameter.get() > 100) { - sizeParameter = Optional.of(100); - } - - if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { - dateParameter = Optional.of(Instant.now()); - } - - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); - - Page entries = entryManager.fetchByUser(getCurrentUsername(), username, filter, - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); - List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entries.getContent(), ignore); - return entries; - } - /** * Fetch by user page. * - * @param name the name + * @param name the name * @param usernameParameter the username parameter - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param ascParameter the asc parameter - * @param ignoreParameter the ignore parameter + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param ascParameter the asc parameter + * @param ignoreParameter the ignore parameter * @return the page */ @PreAuthorize("isAuthenticated()") - @GetMapping("/userpage/{name}") + @GetMapping("/{name}") public Page fetchByUserPage(@PathVariable("name") String name, @RequestParam("user") Optional usernameParameter, @RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, + @RequestParam("date") Optional dateParameter, + @RequestParam("tags") Optional> tagsParameter, + @RequestParam("excludedTags") Optional> excludedTagsParameter, + @RequestParam("type") Optional typeParameter, + @RequestParam("gravity") Optional gravityParameter, @RequestParam("asc") Optional ascParameter, @RequestParam("ignore") Optional> ignoreParameter) { @@ -336,11 +103,12 @@ public class EntryController extends BaseController { sizeParameter = Optional.of(100); } - EntryFilter filter = new EntryFilter(); + EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, + tagsParameter.orElse(null), excludedTagsParameter.orElse(null), + typeParameter.orElse(null)); - filter.setEntryType(userPage.getEntryType()); - filter.setTags(userPage.getTags()); - filter.setExcludedTags(userPage.getExcludedTags()); + filter.setFixedTags(userPage.getTags()); + filter.setFixedExcludedTags(userPage.getExcludedTags()); Page entries = null; @@ -377,14 +145,61 @@ public class EntryController extends BaseController { return entries; } + /** + * Fetch by user. + * + * @param username the username + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param dateParameter the date parameter + * @param tagsParameter the tags parameter + * @param excludedTagsParameter the excluded tags parameter + * @param typeParameter the type parameter + * @param ascParameter the asc parameter + * @param ignoreParameter the ignore parameter + * @return the page + */ + @PreAuthorize("isAuthenticated()") + @GetMapping("/byuser/{username}") + public Page fetchByUser(@PathVariable("username") String username, + @RequestParam("page") Optional pageParameter, + @RequestParam("size") Optional sizeParameter, + @RequestParam("date") Optional dateParameter, + @RequestParam("tags") Optional> tagsParameter, + @RequestParam("excludedTags") Optional> excludedTagsParameter, + @RequestParam("type") Optional typeParameter, + @RequestParam("asc") Optional ascParameter, + @RequestParam("ignore") Optional> ignoreParameter) { + + if (sizeParameter.isPresent() && sizeParameter.get() > 100) { + sizeParameter = Optional.of(100); + } + + if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { + dateParameter = Optional.of(Instant.now()); + } + + EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, + tagsParameter.orElse(null), excludedTagsParameter.orElse(null), + typeParameter.orElse(null)); + + Page entries = entryManager.fetchByUser(getCurrentUsername(), username, filter, + pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), + ascParameter.orElse(false)); + List ignore = ignoreParameter.orElse(Lists.newArrayList()); + entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), + entries.getContent(), ignore); + return entries; + } + /** * Builds the filter. * - * @param date the date + * @param date the date * @param flaggedStatus the flagged status - * @param tags the tags - * @param excludedTags the excluded tags - * @param type the type + * @param tags the tags + * @param excludedTags the excluded tags + * @param type the type * @return the entry filter */ protected EntryFilter buildFilter(Instant date, FlaggedStatus flaggedStatus, List tags, @@ -401,7 +216,7 @@ public class EntryController extends BaseController { /** * Gets the entry. * - * @param id the id + * @param id the id * @param ignoreParameter the ignore parameter * @return the entry */ @@ -425,7 +240,7 @@ public class EntryController extends BaseController { /** * Creates the entry. * - * @param entry the entry + * @param entry the entry * @param ignoreParameter the ignore parameter * @return the entry */ @@ -466,7 +281,7 @@ public class EntryController extends BaseController { /** * Update entry. * - * @param entry the entry + * @param entry the entry * @param ignoreParameter the ignore parameter * @return the entry */ diff --git a/src/main/java/de/bstly/board/controller/FlagController.java b/src/main/java/de/bstly/board/controller/FlagController.java index fe5da49..782a65b 100644 --- a/src/main/java/de/bstly/board/controller/FlagController.java +++ b/src/main/java/de/bstly/board/controller/FlagController.java @@ -17,7 +17,7 @@ import de.bstly.board.businesslogic.EntryManager; import de.bstly.board.businesslogic.FlagManager; import de.bstly.board.controller.support.EntityResponseStatusException; import de.bstly.board.model.Flag; -import de.bstly.board.model.Types; +import de.bstly.board.model.support.Types; /** * The Class FlagController. diff --git a/src/main/java/de/bstly/board/controller/ModerationController.java b/src/main/java/de/bstly/board/controller/ModerationController.java index 3142747..06b1f4f 100644 --- a/src/main/java/de/bstly/board/controller/ModerationController.java +++ b/src/main/java/de/bstly/board/controller/ModerationController.java @@ -29,7 +29,7 @@ import de.bstly.board.controller.support.EntityResponseStatusException; import de.bstly.board.model.Comment; import de.bstly.board.model.Entry; import de.bstly.board.model.LocalUser; -import de.bstly.board.model.Types; +import de.bstly.board.model.support.Types; /** * The Class ModerationController. diff --git a/src/main/java/de/bstly/board/controller/SearchController.java b/src/main/java/de/bstly/board/controller/SearchController.java new file mode 100644 index 0000000..d42a953 --- /dev/null +++ b/src/main/java/de/bstly/board/controller/SearchController.java @@ -0,0 +1,115 @@ +/** + * + */ +package de.bstly.board.controller; + +import java.util.List; +import java.util.Optional; + +import org.hibernate.search.engine.search.query.SearchResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.google.common.collect.Lists; + +import de.bstly.board.businesslogic.CommentManager; +import de.bstly.board.businesslogic.EntryManager; +import de.bstly.board.businesslogic.SearchManager; +import de.bstly.board.businesslogic.SettingsManager; +import de.bstly.board.businesslogic.UserManager; +import de.bstly.board.model.Comment; +import de.bstly.board.model.Entry; +import de.bstly.board.model.support.Types; + +/** + * @author _bastler@bstly.de + * + */ +@RestController +@RequestMapping("/search") +public class SearchController extends BaseController { + + @Autowired + private SearchManager searchManager; + @Autowired + private SettingsManager settingsManager; + @Autowired + private EntryManager entryManager; + @Autowired + private UserManager userManager; + @Autowired + private CommentManager commentManager; + + /** + * Search. + * + * @param searchParameter the search parameter + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param byDateParameter the by date parameter + * @param ascParameter the asc parameter + * @param ignoreParameter the ignore parameter + * @return the page + */ + @PreAuthorize("isAuthenticated()") + @GetMapping + public Page search(@RequestParam("q") String searchParameter, + @RequestParam("type") Optional typeParameter, + @RequestParam("page") Optional pageParameter, + @RequestParam("size") Optional sizeParameter, + @RequestParam("byDate") Optional byDateParameter, + @RequestParam("asc") Optional ascParameter, + @RequestParam("ignore") Optional> ignoreParameter) { + + if (sizeParameter.isPresent() && sizeParameter.get() > 100) { + sizeParameter = Optional.of(100); + } + + String type = typeParameter.orElse(Types.entry.toString()); + + List types = Lists.newArrayList(); + + switch (type) { + case "entry": + types.add(Types.entry); + break; + case "comment": + types.add(Types.comment); + break; + case "all": + types.add(Types.comment); + types.add(Types.entry); + break; + } + + SearchResult result = searchManager.search(types, searchParameter, + pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), + ascParameter.orElse(false), byDateParameter.orElse(false)); + + Page objects = new PageImpl(result.hits(), + PageRequest.of(pageParameter.orElse(0), + sizeParameter.orElse(settingsManager.getPageSize())), + result.total().hitCount()); + + List ignore = ignoreParameter.orElse(Lists.newArrayList()); + + for (Object object : objects) { + if (object instanceof Entry) { + entryManager.applyMetadata(getCurrentUsername(), + userManager.getKarma(getCurrentUsername()), (Entry) object, ignore); + } else if (object instanceof Comment) { + commentManager.applyMetadata(getCurrentUsername(), (Comment) object, ignore); + } + } + + return objects; + } + +} diff --git a/src/main/java/de/bstly/board/controller/UserPageController.java b/src/main/java/de/bstly/board/controller/UserPageController.java index bab37f7..c5899b5 100644 --- a/src/main/java/de/bstly/board/controller/UserPageController.java +++ b/src/main/java/de/bstly/board/controller/UserPageController.java @@ -52,9 +52,13 @@ public class UserPageController extends BaseController { public Page getUserPages(@RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, @RequestParam("desc") Optional descParameter) { + + if (userPageManager.countByUser(getCurrentUsername()) == 0L) { + userPageManager.createDefault(getCurrentUsername()); + } + return userPageManager.getByUser(getCurrentUsername(), pageParameter.orElse(0), - sizeParameter.orElse(settingsManager.getPageSize()), "name", - descParameter.orElse(false)); + sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false)); } /** @@ -83,11 +87,13 @@ public class UserPageController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping("/userpage/{name}") - public UserPage getUserPage(@PathVariable("name") String name) { - UserPage userPage = userPageManager.get(getCurrentUsername(), name); + public UserPage getUserPage(@PathVariable("name") String name, + @RequestParam("user") Optional usernameParameter) { + UserPage userPage = userPageManager.get(usernameParameter.orElse(getCurrentUsername()), + name); - if (userPage == null) { - throw new EntityResponseStatusException(HttpStatus.NOT_FOUND); + if (userPage == null || usernameParameter.isPresent() && !userPage.isPublicPage()) { + throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); } return userPage; diff --git a/src/main/java/de/bstly/board/controller/VoteController.java b/src/main/java/de/bstly/board/controller/VoteController.java index 2819503..3b85038 100644 --- a/src/main/java/de/bstly/board/controller/VoteController.java +++ b/src/main/java/de/bstly/board/controller/VoteController.java @@ -19,9 +19,9 @@ import de.bstly.board.businesslogic.SettingsManager; import de.bstly.board.businesslogic.UserManager; import de.bstly.board.businesslogic.VoteManager; import de.bstly.board.controller.support.EntityResponseStatusException; -import de.bstly.board.model.Types; import de.bstly.board.model.Vote; -import de.bstly.board.model.VoteType; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; /** * The Class VoteController. diff --git a/src/main/java/de/bstly/board/controller/model/EntryFilter.java b/src/main/java/de/bstly/board/controller/model/EntryFilter.java index 236b160..6f41553 100644 --- a/src/main/java/de/bstly/board/controller/model/EntryFilter.java +++ b/src/main/java/de/bstly/board/controller/model/EntryFilter.java @@ -6,8 +6,8 @@ package de.bstly.board.controller.model; import java.time.Instant; import java.util.List; -import de.bstly.board.model.EntryType; -import de.bstly.board.model.FlaggedStatus; +import de.bstly.board.model.support.EntryType; +import de.bstly.board.model.support.FlaggedStatus; /** * The Class EntryFilter. @@ -18,6 +18,8 @@ public class EntryFilter { private FlaggedStatus flaggedStatus; private List tags; private List excludedTags; + private List fixedTags; + private List fixedExcludedTags; private EntryType entryType; private String additional; @@ -93,6 +95,34 @@ public class EntryFilter { this.excludedTags = excludedTags; } + /** + * @return the fixedTags + */ + public List getFixedTags() { + return fixedTags; + } + + /** + * @param fixedTags the fixedTags to set + */ + public void setFixedTags(List fixedTags) { + this.fixedTags = fixedTags; + } + + /** + * @return the fixedExcludedTags + */ + public List getFixedExcludedTags() { + return fixedExcludedTags; + } + + /** + * @param fixedExcludedTags the fixedExcludedTags to set + */ + public void setFixedExcludedTags(List fixedExcludedTags) { + this.fixedExcludedTags = fixedExcludedTags; + } + /** * Gets the entry type. * diff --git a/src/main/java/de/bstly/board/controller/validation/EntryValidator.java b/src/main/java/de/bstly/board/controller/validation/EntryValidator.java index 0cb9b30..59993f0 100644 --- a/src/main/java/de/bstly/board/controller/validation/EntryValidator.java +++ b/src/main/java/de/bstly/board/controller/validation/EntryValidator.java @@ -10,7 +10,7 @@ import org.springframework.validation.Errors; import org.springframework.validation.Validator; import de.bstly.board.model.Entry; -import de.bstly.board.model.EntryType; +import de.bstly.board.model.support.EntryType; /** * The Class EntryValidator. diff --git a/src/main/java/de/bstly/board/model/Comment.java b/src/main/java/de/bstly/board/model/Comment.java index 88987f9..43e4b03 100644 --- a/src/main/java/de/bstly/board/model/Comment.java +++ b/src/main/java/de/bstly/board/model/Comment.java @@ -18,16 +18,27 @@ import javax.persistence.Lob; import javax.persistence.Table; import javax.persistence.Transient; +import org.hibernate.search.engine.backend.types.Projectable; +import org.hibernate.search.engine.backend.types.Sortable; +import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBridgeRef; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import com.google.common.collect.Maps; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.InstantValueBridge; +import de.bstly.board.model.support.Types; + /** * The Class Comment. */ @Entity @Table(name = "comments") @EntityListeners({ AuditingEntityListener.class }) +@Indexed public class Comment { @Id @@ -37,6 +48,7 @@ public class Comment { @Column(name = "author", nullable = false) private String author; @Column(name = "created", nullable = false) + @KeywordField(name = "created", valueBridge = @ValueBridgeRef(type = InstantValueBridge.class), projectable = Projectable.YES, sortable = Sortable.YES) private Instant created; @Column(name = "target", nullable = false) private Long target; @@ -44,12 +56,15 @@ public class Comment { private Long parent; @Lob @Column(name = "text", nullable = false) + @FullTextField private String text; @Enumerated(EnumType.STRING) @Column(name = "flagged_status", nullable = false, columnDefinition = "varchar(255) default 'NORMAL'") private FlaggedStatus flaggedStatus; @Transient private Map metadata; + @Transient + private final Types type = Types.comment; /** * Gets the id. @@ -199,4 +214,11 @@ public class Comment { this.metadata = metadata; } + /** + * @return the type + */ + public Types getType() { + return type; + } + } diff --git a/src/main/java/de/bstly/board/model/Entry.java b/src/main/java/de/bstly/board/model/Entry.java index a486831..9fa4b88 100644 --- a/src/main/java/de/bstly/board/model/Entry.java +++ b/src/main/java/de/bstly/board/model/Entry.java @@ -19,25 +19,41 @@ import javax.persistence.Lob; import javax.persistence.Table; import javax.persistence.Transient; +import org.hibernate.search.engine.backend.types.Projectable; +import org.hibernate.search.engine.backend.types.Sortable; +import org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBridgeRef; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import com.google.common.collect.Maps; +import de.bstly.board.model.support.EntryStatus; +import de.bstly.board.model.support.EntryType; +import de.bstly.board.model.support.FlaggedStatus; +import de.bstly.board.model.support.InstantValueBridge; +import de.bstly.board.model.support.Types; + /** * The Class Entry. */ @Entity @Table(name = "entries") @EntityListeners({ AuditingEntityListener.class }) +@Indexed public class Entry { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", nullable = false) + @DocumentId private Long id; @Column(name = "author", nullable = false) private String author; @Column(name = "created", nullable = false) + @KeywordField(name = "created", valueBridge = @ValueBridgeRef(type = InstantValueBridge.class), projectable = Projectable.YES, sortable = Sortable.YES) private Instant created; @Enumerated(EnumType.STRING) @Column(name = "entry_type", nullable = false) @@ -51,18 +67,22 @@ public class Entry { @Column(name = "url") private String url; @Column(name = "title", nullable = false) + @FullTextField(name = "title") private String title; @Lob @Column(name = "text") + @FullTextField(name = "text") private String text; @Transient private List tags; @Transient - private Double ranking; + private Float ranking; @Transient private Long points; @Transient private Map metadata; + @Transient + private final Types type = Types.entry; /** * Gets the id. @@ -249,7 +269,7 @@ public class Entry { * * @return the ranking */ - public Double getRanking() { + public Float getRanking() { return ranking; } @@ -258,7 +278,7 @@ public class Entry { * * @param ranking the new ranking */ - public void setRanking(Double ranking) { + public void setRanking(Float ranking) { this.ranking = ranking; } @@ -301,4 +321,11 @@ public class Entry { this.metadata = metadata; } + /** + * @return the type + */ + public Types getType() { + return type; + } + } diff --git a/src/main/java/de/bstly/board/model/Flag.java b/src/main/java/de/bstly/board/model/Flag.java index aed42a5..26361dd 100644 --- a/src/main/java/de/bstly/board/model/Flag.java +++ b/src/main/java/de/bstly/board/model/Flag.java @@ -13,6 +13,8 @@ import javax.persistence.Table; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import de.bstly.board.model.support.Types; + /** * The Class Flag. */ diff --git a/src/main/java/de/bstly/board/model/LocalUser.java b/src/main/java/de/bstly/board/model/LocalUser.java index c6735c3..9edb592 100644 --- a/src/main/java/de/bstly/board/model/LocalUser.java +++ b/src/main/java/de/bstly/board/model/LocalUser.java @@ -23,6 +23,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.google.common.collect.Maps; +import de.bstly.board.model.support.Types; + /** * The Class LocalUser. */ @@ -58,6 +60,8 @@ public class LocalUser { private Map settings; @Transient private Map metadata; + @Transient + private final Types type = Types.user; /** * Gets the username. @@ -242,4 +246,11 @@ public class LocalUser { this.metadata = metadata; } + /** + * @return the type + */ + public Types getType() { + return type; + } + } diff --git a/src/main/java/de/bstly/board/model/UserPage.java b/src/main/java/de/bstly/board/model/UserPage.java index 13bfc69..50b9161 100644 --- a/src/main/java/de/bstly/board/model/UserPage.java +++ b/src/main/java/de/bstly/board/model/UserPage.java @@ -21,6 +21,9 @@ import org.hibernate.annotations.LazyCollection; 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; + /** * The Class UserPage. */ @@ -40,9 +43,11 @@ public class UserPage { @Enumerated(EnumType.STRING) @Column(name = "sorting", nullable = false) private UserPageSorting sorting; + @Column(name = "indexNumber") + private int index = 99; @ElementCollection @LazyCollection(LazyCollectionOption.FALSE) - @CollectionTable(name = "users_page_tags") + @CollectionTable(name = "user_pages_tags") private List tags; @ElementCollection @LazyCollection(LazyCollectionOption.FALSE) @@ -52,6 +57,8 @@ public class UserPage { private EntryType entryType; @Column(name = "public", columnDefinition = "boolean default false") private boolean publicPage; + @Column(name = "divider", columnDefinition = "boolean default false") + private boolean divider; /** * Gets the id. @@ -125,6 +132,20 @@ public class UserPage { this.sorting = sorting; } + /** + * @return the index + */ + public int getIndex() { + return index; + } + + /** + * @param index the index to set + */ + public void setIndex(int index) { + this.index = index; + } + /** * Gets the tags. * @@ -197,4 +218,18 @@ public class UserPage { this.publicPage = publicPage; } + /** + * @return the divider + */ + public boolean isDivider() { + return divider; + } + + /** + * @param divider the divider to set + */ + public void setDivider(boolean divider) { + this.divider = divider; + } + } diff --git a/src/main/java/de/bstly/board/model/Vote.java b/src/main/java/de/bstly/board/model/Vote.java index 86e0459..83ca0e0 100644 --- a/src/main/java/de/bstly/board/model/Vote.java +++ b/src/main/java/de/bstly/board/model/Vote.java @@ -13,6 +13,9 @@ import javax.persistence.Table; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import de.bstly.board.model.support.Types; +import de.bstly.board.model.support.VoteType; + /** * The Class Vote. diff --git a/src/main/java/de/bstly/board/model/EntryStatus.java b/src/main/java/de/bstly/board/model/support/EntryStatus.java similarity index 71% rename from src/main/java/de/bstly/board/model/EntryStatus.java rename to src/main/java/de/bstly/board/model/support/EntryStatus.java index f0ccdfa..e7b3b83 100644 --- a/src/main/java/de/bstly/board/model/EntryStatus.java +++ b/src/main/java/de/bstly/board/model/support/EntryStatus.java @@ -1,7 +1,7 @@ /** * */ -package de.bstly.board.model; +package de.bstly.board.model.support; /** * The Enum EntryStatus. diff --git a/src/main/java/de/bstly/board/model/EntryType.java b/src/main/java/de/bstly/board/model/support/EntryType.java similarity index 73% rename from src/main/java/de/bstly/board/model/EntryType.java rename to src/main/java/de/bstly/board/model/support/EntryType.java index 9d7a7b0..4399cac 100644 --- a/src/main/java/de/bstly/board/model/EntryType.java +++ b/src/main/java/de/bstly/board/model/support/EntryType.java @@ -1,7 +1,7 @@ /** * */ -package de.bstly.board.model; +package de.bstly.board.model.support; /** * The Enum EntryType. diff --git a/src/main/java/de/bstly/board/model/FlaggedStatus.java b/src/main/java/de/bstly/board/model/support/FlaggedStatus.java similarity index 73% rename from src/main/java/de/bstly/board/model/FlaggedStatus.java rename to src/main/java/de/bstly/board/model/support/FlaggedStatus.java index 257a72e..703a982 100644 --- a/src/main/java/de/bstly/board/model/FlaggedStatus.java +++ b/src/main/java/de/bstly/board/model/support/FlaggedStatus.java @@ -1,7 +1,7 @@ /** * */ -package de.bstly.board.model; +package de.bstly.board.model.support; /** * The Enum FlaggedStatus. diff --git a/src/main/java/de/bstly/board/model/support/InstantValueBridge.java b/src/main/java/de/bstly/board/model/support/InstantValueBridge.java new file mode 100644 index 0000000..fe77e3d --- /dev/null +++ b/src/main/java/de/bstly/board/model/support/InstantValueBridge.java @@ -0,0 +1,33 @@ +/** + * + */ +package de.bstly.board.model.support; + +import java.time.Instant; + +import org.hibernate.search.mapper.pojo.bridge.ValueBridge; +import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeFromIndexedValueContext; +import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext; + +/** + * The Class InstantValueBridge. + */ +public class InstantValueBridge implements ValueBridge { + + /* + * @see org.hibernate.search.mapper.pojo.bridge.ValueBridge#toIndexedValue(java.lang.Object, org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValueContext) + */ + @Override + public String toIndexedValue(Instant value, ValueBridgeToIndexedValueContext context) { + return value.toString(); + } + + /* + * @see org.hibernate.search.mapper.pojo.bridge.ValueBridge#fromIndexedValue(java.lang.Object, org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeFromIndexedValueContext) + */ + @Override + public Instant fromIndexedValue(String value, ValueBridgeFromIndexedValueContext context) { + return value == null ? null : Instant.parse(value); + } + +} diff --git a/src/main/java/de/bstly/board/model/Types.java b/src/main/java/de/bstly/board/model/support/Types.java similarity index 69% rename from src/main/java/de/bstly/board/model/Types.java rename to src/main/java/de/bstly/board/model/support/Types.java index ece618b..be4fa89 100644 --- a/src/main/java/de/bstly/board/model/Types.java +++ b/src/main/java/de/bstly/board/model/support/Types.java @@ -1,7 +1,7 @@ /** * */ -package de.bstly.board.model; +package de.bstly.board.model.support; /** * The Enum Types. diff --git a/src/main/java/de/bstly/board/model/UserPageSorting.java b/src/main/java/de/bstly/board/model/support/UserPageSorting.java similarity index 73% rename from src/main/java/de/bstly/board/model/UserPageSorting.java rename to src/main/java/de/bstly/board/model/support/UserPageSorting.java index 0c0e92f..2357362 100644 --- a/src/main/java/de/bstly/board/model/UserPageSorting.java +++ b/src/main/java/de/bstly/board/model/support/UserPageSorting.java @@ -1,7 +1,7 @@ /** * */ -package de.bstly.board.model; +package de.bstly.board.model.support; /** * The Enum UserPageSorting. diff --git a/src/main/java/de/bstly/board/model/VoteType.java b/src/main/java/de/bstly/board/model/support/VoteType.java similarity index 67% rename from src/main/java/de/bstly/board/model/VoteType.java rename to src/main/java/de/bstly/board/model/support/VoteType.java index 719b926..2122d44 100644 --- a/src/main/java/de/bstly/board/model/VoteType.java +++ b/src/main/java/de/bstly/board/model/support/VoteType.java @@ -1,7 +1,7 @@ /** * */ -package de.bstly.board.model; +package de.bstly.board.model.support; /** * The Enum VoteType. diff --git a/src/main/java/de/bstly/board/repository/CommentRepository.java b/src/main/java/de/bstly/board/repository/CommentRepository.java index 7a4ac3b..281562a 100644 --- a/src/main/java/de/bstly/board/repository/CommentRepository.java +++ b/src/main/java/de/bstly/board/repository/CommentRepository.java @@ -15,58 +15,4 @@ import de.bstly.board.model.Comment; @Repository public interface CommentRepository extends JpaRepository, QuerydslPredicateExecutor { - -// /** -// * Find all by ranking and parent. -// * -// * @param target the target -// * @param date the date -// * @param gravity the gravity -// * @return the list -// */ -// @Query(value = "SELECT comment.*, ranked.ranking FROM comments AS comment LEFT JOIN (SELECT comment.id, (IFNULL(upvote.count,0) - IFNULL(downvote.count,0)) / POW(TIMESTAMPDIFF(HOUR, comment.created, :date)+2,:gravity) AS ranking FROM comments AS comment LEFT JOIN (SELECT upvote.target,COUNT(upvote.id) AS count FROM votes as upvote WHERE upvote.type = 0 AND upvote.target_type = 0 GROUP BY upvote.target) AS upvote ON upvote.target = comment.id LEFT JOIN (SELECT downvote.target,COUNT(downvote.id) AS count FROM votes as downvote WHERE downvote.type = 1 GROUP BY downvote.target) AS downvote ON downvote.target = comment.id) as ranked on ranked.id = comment.id WHERE comment.target = :target AND parent IS NULL AND comment.created < :date ORDER BY ranked.ranking DESC, comment.created DESC", countQuery = "SELECT count(*) FROM comments as comment WHERE comment.target = :target AND parent IS NULL AND comment.created < :date", nativeQuery = true) -// List findAllByRankingAndParent(@Param("target") Long target, -// @Param("date") Instant date, @Param("gravity") double gravity); -// -// /** -// * Find all by ranking and parent. -// * -// * @param target the target -// * @param parent the parent -// * @param date the date -// * @param gravity the gravity -// * @return the list -// */ -// @Query(value = "SELECT comment.*, ranked.ranking FROM comments AS comment LEFT JOIN (SELECT comment.id, (IFNULL(upvote.count,0) - IFNULL(downvote.count,0)) / POW(TIMESTAMPDIFF(HOUR, comment.created, :date)+2,:gravity) AS ranking FROM comments AS comment LEFT JOIN (SELECT upvote.target,COUNT(upvote.id) AS count FROM votes as upvote WHERE upvote.type = 0 AND upvote.target_type = 0 GROUP BY upvote.target) AS upvote ON upvote.target = comment.id LEFT JOIN (SELECT downvote.target,COUNT(downvote.id) AS count FROM votes as downvote WHERE downvote.type = 1 GROUP BY downvote.target) AS downvote ON downvote.target = comment.id) as ranked on ranked.id = comment.id WHERE comment.target = :target AND parent = :parent AND comment.created < :date ORDER BY ranked.ranking DESC, comment.created DESC", countQuery = "SELECT count(*) FROM comments as comment WHERE comment.target = :target AND parent = :parent AND comment.created < :date", nativeQuery = true) -// List findAllByRankingAndParent(@Param("target") Long target, -// @Param("parent") Long parent, @Param("date") Instant date, -// @Param("gravity") double gravity); -// -// /** -// * Find all by ranking and parent. -// * -// * @param target the target -// * @param date the date -// * @param gravity the gravity -// * @param pageable the pageable -// * @return the page -// */ -// @Query(value = "SELECT comment.*, ranked.ranking FROM comments AS comment LEFT JOIN (SELECT comment.id, (IFNULL(upvote.count,0) - IFNULL(downvote.count,0)) / POW(TIMESTAMPDIFF(HOUR, comment.created, :date)+2,:gravity) AS ranking FROM comments AS comment LEFT JOIN (SELECT upvote.target,COUNT(upvote.id) AS count FROM votes as upvote WHERE upvote.type = 0 AND upvote.target_type = 0 GROUP BY upvote.target) AS upvote ON upvote.target = comment.id LEFT JOIN (SELECT downvote.target,COUNT(downvote.id) AS count FROM votes as downvote WHERE downvote.type = 1 GROUP BY downvote.target) AS downvote ON downvote.target = comment.id) as ranked on ranked.id = comment.id WHERE comment.target = :target AND parent IS NULL AND comment.created < :date ORDER BY ranked.ranking DESC, comment.created DESC", countQuery = "SELECT count(*) FROM comments as comment WHERE comment.target = :target AND parent IS NULL AND comment.created < :date", nativeQuery = true) -// Page findAllByRankingAndParent(@Param("target") Long target, -// @Param("date") Instant date, @Param("gravity") double gravity, Pageable pageable); -// -// /** -// * Find all by ranking and parent. -// * -// * @param target the target -// * @param parent the parent -// * @param date the date -// * @param gravity the gravity -// * @param pageable the pageable -// * @return the page -// */ -// @Query(value = "SELECT comment.*, ranked.ranking FROM comments AS comment LEFT JOIN (SELECT comment.id, (IFNULL(upvote.count,0) - IFNULL(downvote.count,0)) / POW(TIMESTAMPDIFF(HOUR, comment.created, :date)+2,:gravity) AS ranking FROM comments AS comment LEFT JOIN (SELECT upvote.target,COUNT(upvote.id) AS count FROM votes as upvote WHERE upvote.type = 0 AND upvote.target_type = 0 GROUP BY upvote.target) AS upvote ON upvote.target = comment.id LEFT JOIN (SELECT downvote.target,COUNT(downvote.id) AS count FROM votes as downvote WHERE downvote.type = 1 GROUP BY downvote.target) AS downvote ON downvote.target = comment.id) as ranked on ranked.id = comment.id WHERE comment.target = :target AND parent = :parent AND comment.created < :date ORDER BY ranked.ranking DESC, comment.created DESC", countQuery = "SELECT count(*) FROM comments as comment WHERE comment.target = :target AND parent = :parent AND comment.created < :date", nativeQuery = true) -// Page findAllByRankingAndParent(@Param("target") Long target, -// @Param("parent") Long parent, @Param("date") Instant date, -// @Param("gravity") double gravity, Pageable pageable); }