diff --git a/pom.xml b/pom.xml
index 02244b3..87724b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,14 +10,14 @@
UTF-8
11
- 2.16.0
- 1.3.3
+ 2.17.2
+ 1.4.0
org.springframework.boot
spring-boot-starter-parent
- 2.5.5
+ 2.6.6
diff --git a/src/main/java/de/bstly/board/LuceneConfig.java b/src/main/java/de/bstly/board/LuceneConfig.java
index ec86821..b56de8e 100644
--- a/src/main/java/de/bstly/board/LuceneConfig.java
+++ b/src/main/java/de/bstly/board/LuceneConfig.java
@@ -13,8 +13,7 @@ import org.hibernate.search.backend.lucene.analysis.LuceneAnalysisConfigurer;
import org.springframework.context.annotation.Configuration;
/**
- * @author _bastler@bstly.de
- *
+ * The Class LuceneConfig.
*/
@Configuration
public class LuceneConfig implements LuceneAnalysisConfigurer {
@@ -27,28 +26,22 @@ public class LuceneConfig implements LuceneAnalysisConfigurer {
@Override
public void configure(LuceneAnalysisConfigurationContext context) {
context.analyzer("english").custom().tokenizer(StandardTokenizerFactory.class)
- .tokenFilter(LowerCaseFilterFactory.class)
- .tokenFilter(SnowballPorterFilterFactory.class).param("language", "English")
- .tokenFilter(ASCIIFoldingFilterFactory.class)
- .tokenFilter(EdgeNGramFilterFactory.class).param("minGramSize", "3")
- .param("maxGramSize", "7");
+ .tokenFilter(LowerCaseFilterFactory.class).tokenFilter(SnowballPorterFilterFactory.class)
+ .param("language", "English").tokenFilter(ASCIIFoldingFilterFactory.class)
+ .tokenFilter(EdgeNGramFilterFactory.class).param("minGramSize", "3").param("maxGramSize", "7");
context.analyzer("english_search").custom().tokenizer(StandardTokenizerFactory.class)
- .tokenFilter(LowerCaseFilterFactory.class)
- .tokenFilter(SnowballPorterFilterFactory.class).param("language", "English")
- .tokenFilter(ASCIIFoldingFilterFactory.class);
+ .tokenFilter(LowerCaseFilterFactory.class).tokenFilter(SnowballPorterFilterFactory.class)
+ .param("language", "English").tokenFilter(ASCIIFoldingFilterFactory.class);
context.analyzer("german").custom().tokenizer(StandardTokenizerFactory.class)
- .tokenFilter(LowerCaseFilterFactory.class)
- .tokenFilter(SnowballPorterFilterFactory.class).param("language", "German")
- .tokenFilter(ASCIIFoldingFilterFactory.class)
- .tokenFilter(EdgeNGramFilterFactory.class).param("minGramSize", "3")
- .param("maxGramSize", "7");
+ .tokenFilter(LowerCaseFilterFactory.class).tokenFilter(SnowballPorterFilterFactory.class)
+ .param("language", "German").tokenFilter(ASCIIFoldingFilterFactory.class)
+ .tokenFilter(EdgeNGramFilterFactory.class).param("minGramSize", "3").param("maxGramSize", "7");
context.analyzer("german_search").custom().tokenizer(StandardTokenizerFactory.class)
- .tokenFilter(LowerCaseFilterFactory.class)
- .tokenFilter(SnowballPorterFilterFactory.class).param("language", "German")
- .tokenFilter(ASCIIFoldingFilterFactory.class);
+ .tokenFilter(LowerCaseFilterFactory.class).tokenFilter(SnowballPorterFilterFactory.class)
+ .param("language", "German").tokenFilter(ASCIIFoldingFilterFactory.class);
}
diff --git a/src/main/java/de/bstly/board/businesslogic/BookmarksManager.java b/src/main/java/de/bstly/board/businesslogic/BookmarksManager.java
index 1d37a39..f6914d6 100644
--- a/src/main/java/de/bstly/board/businesslogic/BookmarksManager.java
+++ b/src/main/java/de/bstly/board/businesslogic/BookmarksManager.java
@@ -46,24 +46,23 @@ public class BookmarksManager {
* Checks for entry.
*
* @param username the username
- * @param entryId the entry id
+ * @param entryId the entry id
* @return true, if successful
*/
public boolean hasEntry(String username, Long entryId) {
- return bookmarksRepository.exists(qBookmarks.username.equalsIgnoreCase(username)
- .and(qBookmarks.entries.contains(entryId)));
+ return bookmarksRepository
+ .exists(qBookmarks.username.equalsIgnoreCase(username).and(qBookmarks.entries.contains(entryId)));
}
/**
* Adds the entry.
*
* @param username the username
- * @param entryId the entry id
+ * @param entryId the entry id
*/
public void addEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
- Assert.isTrue(localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username)),
- "Invalid username");
+ Assert.isTrue(localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username)), "Invalid username");
Bookmarks bookmarks = get(username);
if (bookmarks.getEntries() == null) {
@@ -80,12 +79,11 @@ public class BookmarksManager {
* Removes the entry.
*
* @param username the username
- * @param entryId the entry id
+ * @param entryId the entry id
*/
public void removeEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
- Assert.isTrue(localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username)),
- "Invalid username");
+ Assert.isTrue(localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username)), "Invalid username");
Bookmarks bookmarks = get(username);
@@ -105,8 +103,7 @@ public class BookmarksManager {
* @param entryId the entry id
*/
public void removeEntry(Long entryId) {
- for (Bookmarks bookmarks : bookmarksRepository
- .findAll(qBookmarks.entries.contains(entryId))) {
+ for (Bookmarks bookmarks : bookmarksRepository.findAll(qBookmarks.entries.contains(entryId))) {
bookmarks.getEntries().remove(entryId);
bookmarksRepository.save(bookmarks);
}
diff --git a/src/main/java/de/bstly/board/businesslogic/CommentManager.java b/src/main/java/de/bstly/board/businesslogic/CommentManager.java
index 3a583cb..7c700c3 100644
--- a/src/main/java/de/bstly/board/businesslogic/CommentManager.java
+++ b/src/main/java/de/bstly/board/businesslogic/CommentManager.java
@@ -55,30 +55,29 @@ public class CommentManager {
* Fetch by date.
*
* @param username the username
- * @param target the target
- * @param parent the parent
- * @param date the date
- * @param page the page
- * @param size the size
- * @param desc the desc
+ * @param target the target
+ * @param parent the parent
+ * @param date the date
+ * @param page the page
+ * @param size the size
+ * @param desc the desc
* @return the page
*/
- public Page fetchByDate(String username, Long target, Long parent, Instant date,
- int page, int size, boolean desc) {
+ public Page fetchByDate(String username, Long target, Long parent, Instant date, int page, int size,
+ boolean desc) {
Sort sort = Sort.by(desc ? Order.desc("created") : Order.asc("created"));
if (parent == null) {
- return commentRepository
- .findAll(
- qComment.target.eq(target).and(qComment.parent.isNull())
- .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
- .and(qComment.created.before(date)
- .or(qComment.author.eq(username))),
- PageRequest.of(page, size, sort));
+ return commentRepository.findAll(
+ qComment.target.eq(target).and(qComment.parent.isNull())
+ .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
+ .and(qComment.created.before(date).or(qComment.author.eq(username))),
+ PageRequest.of(page, size, sort));
}
- return commentRepository.findAll(qComment.target.eq(target).and(qComment.parent.eq(parent))
- .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
- .and(qComment.created.before(date)), PageRequest.of(page, size, sort));
+ return commentRepository.findAll(
+ qComment.target.eq(target).and(qComment.parent.eq(parent))
+ .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL)).and(qComment.created.before(date)),
+ PageRequest.of(page, size, sort));
}
/**
@@ -86,37 +85,37 @@ public class CommentManager {
*
* @param page the page
* @param size the size
- * @param asc the asc
+ * @param asc the asc
* @return the page
*/
public Page fetchFlagged(int page, int size, boolean asc) {
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
- JPAQuery query = jpaQueryFactory.selectFrom(qComment).leftJoin(qFlag)
- .on(qComment.id.eq(qFlag.target)).where(qFlag.targetType.eq(Types.comment))
- .groupBy(qFlag.target);
+ JPAQuery query = jpaQueryFactory.selectFrom(qComment).leftJoin(qFlag).on(qComment.id.eq(qFlag.target))
+ .where(qFlag.targetType.eq(Types.comment)).groupBy(qFlag.target);
+
+ JPAQuery countQuery = query.clone().select(qComment.id.countDistinct());
+
return new PageImpl(query
- .orderBy(new OrderSpecifier<>(asc ? com.querydsl.core.types.Order.ASC
- : com.querydsl.core.types.Order.DESC, qComment.created))
- .limit(size).offset(page * size).fetch(), PageRequest.of(page, size, sort),
- query.fetchCount());
+ .orderBy(new OrderSpecifier<>(
+ asc ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, qComment.created))
+ .limit(size).offset(page * size).fetch(), PageRequest.of(page, size, sort), countQuery.fetchOne());
}
/**
* Fetch by username.
*
* @param username the username
- * @param date the date
- * @param page the page
- * @param size the size
- * @param asc the asc
+ * @param date the date
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
* @return the page
*/
- public Page fetchByUsername(String username, Instant date, int page, int size,
- boolean asc) {
+ public Page fetchByUsername(String username, Instant date, int page, int size, boolean asc) {
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
return commentRepository.findAll(qComment.author.equalsIgnoreCase(username)
- .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
- .and(qComment.created.before(date)), PageRequest.of(page, size, sort));
+ .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL)).and(qComment.created.before(date)),
+ PageRequest.of(page, size, sort));
}
/**
@@ -132,8 +131,7 @@ public class CommentManager {
}
return commentRepository.count(qComment.target.eq(target).and(qComment.parent.eq(parent))
- .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
- .and(qComment.created.before(Instant.now())));
+ .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL)).and(qComment.created.before(Instant.now())));
}
/**
@@ -143,17 +141,16 @@ public class CommentManager {
* @return the long
*/
public Long count(Long target) {
- return commentRepository.count(
- qComment.target.eq(target).and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
- .and(qComment.created.before(Instant.now())));
+ return commentRepository.count(qComment.target.eq(target).and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL))
+ .and(qComment.created.before(Instant.now())));
}
/**
* Apply metadata.
*
* @param username the username
- * @param comment the comment
- * @param ignore the ignore
+ * @param comment the comment
+ * @param ignore the ignore
*/
public void applyMetadata(String username, Comment comment, List ignore) {
@@ -168,45 +165,36 @@ public class CommentManager {
}
if (!ignore.contains("points")) {
- comment.getMetadata().put("points",
- voteManager.getPoints(comment.getId(), Types.comment));
+ comment.getMetadata().put("points", voteManager.getPoints(comment.getId(), Types.comment));
}
if (!ignore.contains("upvoted")) {
comment.getMetadata().put("upvoted",
- voteRepository.exists(qVote.target.eq(comment.getId())
- .and(qVote.targetType.eq(Types.comment)).and(qVote.type.eq(VoteType.up))
- .and(qVote.author.equalsIgnoreCase(username))));
+ voteRepository.exists(qVote.target.eq(comment.getId()).and(qVote.targetType.eq(Types.comment))
+ .and(qVote.type.eq(VoteType.up)).and(qVote.author.equalsIgnoreCase(username))));
}
if (!ignore.contains("downvoted")) {
comment.getMetadata().put("downvoted",
- voteRepository.exists(
- qVote.target.eq(comment.getId()).and(qVote.targetType.eq(Types.comment))
- .and(qVote.type.eq(VoteType.down))
- .and(qVote.author.equalsIgnoreCase(username))));
+ voteRepository.exists(qVote.target.eq(comment.getId()).and(qVote.targetType.eq(Types.comment))
+ .and(qVote.type.eq(VoteType.down)).and(qVote.author.equalsIgnoreCase(username))));
}
if (!ignore.contains("unvote")) {
- comment.getMetadata().put("unvote",
- voteRepository.exists(
- qVote.target.eq(comment.getId()).and(qVote.targetType.eq(Types.comment))
- .and(qVote.author.equalsIgnoreCase(username))));
+ comment.getMetadata().put("unvote", voteRepository.exists(qVote.target.eq(comment.getId())
+ .and(qVote.targetType.eq(Types.comment)).and(qVote.author.equalsIgnoreCase(username))));
}
if (!username.equals(comment.getAuthor()) && !ignore.contains("flag")) {
- comment.getMetadata().put("flag",
- flagManager.get(username, comment.getId(), Types.comment) == null);
+ comment.getMetadata().put("flag", flagManager.get(username, comment.getId(), Types.comment) == null);
}
if (!username.equals(comment.getAuthor()) && !ignore.contains("unflag")) {
- comment.getMetadata().put("unflag",
- flagManager.get(username, comment.getId(), Types.comment) != null);
+ comment.getMetadata().put("unflag", flagManager.get(username, comment.getId(), Types.comment) != null);
}
if (!ignore.contains("flagged")) {
- comment.getMetadata().put("flagged",
- flagManager.getFlags(comment.getId(), Types.comment) > 0);
+ comment.getMetadata().put("flagged", flagManager.getFlags(comment.getId(), Types.comment) > 0);
}
if (!ignore.contains("entry")) {
@@ -219,8 +207,8 @@ public class CommentManager {
* Apply metadata.
*
* @param username the username
- * @param entries the entries
- * @param ignore the ignore
+ * @param entries the entries
+ * @param ignore the ignore
*/
public void applyMetadata(String username, List entries, List ignore) {
for (Comment comment : entries) {
@@ -265,10 +253,10 @@ public class CommentManager {
* @return the points
*/
public long getPoints(Long commentId) {
- long upvotes = voteRepository.count(qVote.targetType.eq(Types.comment)
- .and(qVote.type.eq(VoteType.up)).and(qVote.target.eq(commentId)));
- long downvotes = voteRepository.count(qVote.targetType.eq(Types.comment)
- .and(qVote.type.eq(VoteType.down)).and(qVote.target.eq(commentId)));
+ long upvotes = voteRepository.count(
+ qVote.targetType.eq(Types.comment).and(qVote.type.eq(VoteType.up)).and(qVote.target.eq(commentId)));
+ long downvotes = voteRepository.count(
+ qVote.targetType.eq(Types.comment).and(qVote.type.eq(VoteType.down)).and(qVote.target.eq(commentId)));
return upvotes - downvotes;
}
diff --git a/src/main/java/de/bstly/board/businesslogic/EntryManager.java b/src/main/java/de/bstly/board/businesslogic/EntryManager.java
index af403c1..a208066 100644
--- a/src/main/java/de/bstly/board/businesslogic/EntryManager.java
+++ b/src/main/java/de/bstly/board/businesslogic/EntryManager.java
@@ -74,9 +74,7 @@ public class EntryManager {
static final String COMMENTS_QUERY = "SELECT DISTINCT comment.target,MAX(comment.created) as last,COUNT(comment.id) AS count FROM comments as comment WHERE comment.flagged_status = :flag GROUP BY comment.target";
static final String RANK_CALCULATION_QUERY = "SELECT DISTINCT entry.*, (IFNULL(upvote.count,0) - IFNULL(downvote.count,0)) as points, (IFNULL(upvote.count,0) - IFNULL(downvote.count,0)) / IF(:gravity > 0, POW(TIMESTAMPDIFF(HOUR, entry.created, :before)+2,:gravity), 1) AS ranking FROM entries AS entry LEFT JOIN ("
- + UPVOTES_QUERY
- + ") AS upvote ON upvote.target = entry.id LEFT JOIN ("
- + DOWNVOTES_QUERY
+ + UPVOTES_QUERY + ") AS upvote ON upvote.target = entry.id LEFT JOIN (" + DOWNVOTES_QUERY
+ ") AS downvote ON downvote.target = entry.id %s";
static final String DATE_QUERY = "SELECT DISTINCT entry.* FROM entries AS entry %s";
@@ -84,12 +82,10 @@ public class EntryManager {
static final String USER_QUERY = "SELECT DISTINCT entry.* FROM entries AS entry %s ORDER BY entry.created :order";
static final String COMMENT_CALCULATION_QUERY = "SELECT DISTINCT entry.*, IFNULL(comment.count,0) as comments, IFNULL(comment.count,0) / IF(:gravity > 0, POW(TIMESTAMPDIFF(HOUR, comment.last, :before)+2,:gravity), 1) AS ranking FROM entries AS entry LEFT JOIN ("
- + COMMENTS_QUERY
- + ") AS comment ON comment.target = entry.id %s";
+ + COMMENTS_QUERY + ") AS comment ON comment.target = entry.id %s";
static final String LAST_COMMENT_QUERY = "SELECT DISTINCT entry.* FROM entries AS entry LEFT JOIN ("
- + COMMENTS_QUERY
- + ") AS comment ON comment.target = entry.id %s ";
+ + COMMENTS_QUERY + ") AS comment ON comment.target = entry.id %s ";
static final String COUNT_QUERY = "SELECT count(entry.id) FROM entries as entry %s";
@@ -97,15 +93,15 @@ public class EntryManager {
* Fetch by ranking.
*
* @param username the username
- * @param filter the filter
- * @param gravity the gravity
- * @param page the page
- * @param size the size
- * @param asc the asc
+ * @param filter the filter
+ * @param gravity the gravity
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
* @return the page
*/
- public Page fetchByRanking(String username, EntryFilter filter, float gravity, int page,
- int size, boolean asc) {
+ 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");
query.setParameter("gravity", gravity);
@@ -122,16 +118,14 @@ public class EntryManager {
* Fetch by date.
*
* @param username the username
- * @param filter the filter
- * @param page the page
- * @param size the size
- * @param asc the asc
+ * @param filter the filter
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
* @return the page
*/
- public Page fetchByDate(String username, EntryFilter filter, int page, int size,
- boolean asc) {
- Query query = createEntryQuery(DATE_QUERY, username, filter,
- asc ? "entry.created ASC" : "entry.created DESC");
+ public Page fetchByDate(String username, EntryFilter filter, int page, int size, boolean asc) {
+ Query query = createEntryQuery(DATE_QUERY, username, filter, asc ? "entry.created ASC" : "entry.created DESC");
query.setFirstResult((page) * size);
query.setMaxResults(size);
@SuppressWarnings("unchecked")
@@ -145,15 +139,15 @@ public class EntryManager {
* Fetch by comments.
*
* @param username the username
- * @param filter the filter
- * @param gravity the gravity
- * @param page the page
- * @param size the size
- * @param asc the asc
+ * @param filter the filter
+ * @param gravity the gravity
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
* @return the page
*/
- public Page fetchByComments(String username, EntryFilter filter, float gravity,
- int page, int size, boolean asc) {
+ 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");
query.setParameter("gravity", gravity);
@@ -170,17 +164,15 @@ public class EntryManager {
* Fetch by last comment.
*
* @param username the username
- * @param filter the filter
- * @param page the page
- * @param size the size
- * @param asc the asc
+ * @param filter the filter
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
* @return the page
*/
- public Page fetchByLastComment(String username, EntryFilter filter, int page, int size,
- boolean asc) {
+ public Page fetchByLastComment(String username, EntryFilter filter, int page, int size, boolean asc) {
Query query = createEntryQuery(LAST_COMMENT_QUERY, username, filter,
- asc ? "comment.last ASC, entry.created ASC"
- : "comment.last DESC, entry.created DESC");
+ asc ? "comment.last ASC, entry.created ASC" : "comment.last DESC, entry.created DESC");
query.setFirstResult((page) * size);
query.setMaxResults(size);
@SuppressWarnings("unchecked")
@@ -195,17 +187,16 @@ public class EntryManager {
*
* @param fromUser the from user
* @param username the username
- * @param filter the filter
- * @param page the page
- * @param size the size
- * @param asc the asc
+ * @param filter the filter
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
* @return the page
*/
- public Page fetchByUser(String fromUser, String username, EntryFilter filter, int page,
- int size, boolean asc) {
+ public Page fetchByUser(String fromUser, String username, EntryFilter filter, int page, int size,
+ boolean asc) {
filter.setAdditional("AND entry.author = :username");
- Query query = createEntryQuery(DATE_QUERY, username, filter,
- asc ? "entry.created ASC" : "entry.created DESC");
+ Query query = createEntryQuery(DATE_QUERY, username, filter, asc ? "entry.created ASC" : "entry.created DESC");
query.setParameter("username", username);
query.setFirstResult((page) * size);
query.setMaxResults(size);
@@ -222,20 +213,17 @@ public class EntryManager {
*
* @param rawQuery the raw query
* @param username the username
- * @param filter the filter
- * @param orderBy the order by
+ * @param filter the filter
+ * @param orderBy the order by
* @return the query
*/
- protected Query createEntryQuery(String rawQuery, String username, EntryFilter filter,
- String orderBy) {
+ protected Query createEntryQuery(String rawQuery, String username, EntryFilter filter, String orderBy) {
String filterString = "";
String tagsString = "";
if (filter.getTags() != null && !filter.getTags().isEmpty()) {
for (int index = 0; index < filter.getTags().size(); index++) {
- tagsString += "'"
- + filter.getTags().get(index)
- + "'";
+ tagsString += "'" + filter.getTags().get(index) + "'";
if (index < filter.getTags().size() - 1) {
tagsString += ",";
}
@@ -243,17 +231,13 @@ public class EntryManager {
}
if (StringUtils.hasText(tagsString)) {
- filterString += " INNER JOIN tags as tag ON entry.id = tag.target AND tag.tag IN ("
- + tagsString
- + ")";
+ filterString += " INNER JOIN tags as tag ON entry.id = tag.target AND tag.tag IN (" + tagsString + ")";
}
-
+
String fixedTagsString = "";
if (filter.getFixedTags() != null && !filter.getFixedTags().isEmpty()) {
for (int index = 0; index < filter.getFixedTags().size(); index++) {
- fixedTagsString += "'"
- + filter.getFixedTags().get(index)
- + "'";
+ fixedTagsString += "'" + filter.getFixedTags().get(index) + "'";
if (index < filter.getFixedTags().size() - 1) {
fixedTagsString += ",";
}
@@ -262,8 +246,7 @@ public class EntryManager {
if (StringUtils.hasText(fixedTagsString)) {
filterString += " INNER JOIN tags as fixedTag ON entry.id = fixedTag.target AND fixedTag.tag IN ("
- + fixedTagsString
- + ")";
+ + fixedTagsString + ")";
}
boolean author = false;
@@ -286,16 +269,13 @@ public class EntryManager {
}
if (StringUtils.hasText(filter.getAdditional())) {
- filterString += " "
- + filter.getAdditional();
+ filterString += " " + filter.getAdditional();
}
String excludedTagsString = "";
if (filter.getExcludedTags() != null && !filter.getExcludedTags().isEmpty()) {
for (int index = 0; index < filter.getExcludedTags().size(); index++) {
- excludedTagsString += "'"
- + filter.getExcludedTags().get(index)
- + "'";
+ excludedTagsString += "'" + filter.getExcludedTags().get(index) + "'";
if (index < filter.getExcludedTags().size() - 1) {
excludedTagsString += ",";
}
@@ -304,16 +284,13 @@ public class EntryManager {
if (StringUtils.hasText(excludedTagsString)) {
filterString += " AND NOT EXISTS (SELECT * FROM tags as excludedTag WHERE entry.id = excludedTag.target AND excludedTag.tag IN ("
- + excludedTagsString
- + "))";
+ + excludedTagsString + "))";
}
-
+
String fixedExcludedTagsString = "";
if (filter.getFixedExcludedTags() != null && !filter.getFixedExcludedTags().isEmpty()) {
for (int index = 0; index < filter.getFixedExcludedTags().size(); index++) {
- fixedExcludedTagsString += "'"
- + filter.getFixedExcludedTags().get(index)
- + "'";
+ fixedExcludedTagsString += "'" + filter.getFixedExcludedTags().get(index) + "'";
if (index < filter.getFixedExcludedTags().size() - 1) {
fixedExcludedTagsString += ",";
}
@@ -322,13 +299,11 @@ public class EntryManager {
if (StringUtils.hasText(fixedExcludedTagsString)) {
filterString += " AND NOT EXISTS (SELECT * FROM tags as fixedExcludedTag WHERE entry.id = fixedExcludedTag.target AND fixedExcludedTag.tag IN ("
- + fixedExcludedTagsString
- + "))";
+ + fixedExcludedTagsString + "))";
}
if (StringUtils.hasText(orderBy)) {
- filterString += " ORDER BY "
- + orderBy;
+ filterString += " ORDER BY " + orderBy;
}
Query query = em.createNativeQuery(String.format(rawQuery, filterString), Entry.class);
@@ -351,7 +326,7 @@ public class EntryManager {
*
* @param rawQuery the raw query
* @param username the username
- * @param filter the filter
+ * @param filter the filter
* @return the query
*/
protected Query createCountQuery(String rawQuery, String username, EntryFilter filter) {
@@ -360,9 +335,7 @@ public class EntryManager {
String tagsString = "";
if (filter.getTags() != null && !filter.getTags().isEmpty()) {
for (int index = 0; index < filter.getTags().size(); index++) {
- tagsString += "'"
- + filter.getTags().get(index)
- + "'";
+ tagsString += "'" + filter.getTags().get(index) + "'";
if (index < filter.getTags().size() - 1) {
tagsString += ",";
}
@@ -370,9 +343,7 @@ public class EntryManager {
}
if (StringUtils.hasText(tagsString)) {
- filterString += " INNER JOIN tags as tag ON entry.id = tag.target AND tag.tag IN ("
- + tagsString
- + ")";
+ filterString += " INNER JOIN tags as tag ON entry.id = tag.target AND tag.tag IN (" + tagsString + ")";
}
boolean author = false;
@@ -395,16 +366,13 @@ public class EntryManager {
}
if (StringUtils.hasText(filter.getAdditional())) {
- filterString += " "
- + filter.getAdditional();
+ filterString += " " + filter.getAdditional();
}
String excludedTagsString = "";
if (filter.getExcludedTags() != null && !filter.getExcludedTags().isEmpty()) {
for (int index = 0; index < filter.getExcludedTags().size(); index++) {
- excludedTagsString += "'"
- + filter.getExcludedTags().get(index)
- + "'";
+ excludedTagsString += "'" + filter.getExcludedTags().get(index) + "'";
if (index < filter.getExcludedTags().size() - 1) {
excludedTagsString += ",";
}
@@ -413,8 +381,7 @@ public class EntryManager {
if (StringUtils.hasText(excludedTagsString)) {
filterString += " AND NOT EXISTS (SELECT * FROM tags as excludedTag WHERE entry.id = excludedTag.target AND excludedTag.tag IN ("
- + excludedTagsString
- + "))";
+ + excludedTagsString + "))";
}
Query query = em.createNativeQuery(String.format(rawQuery, filterString));
@@ -437,27 +404,28 @@ public class EntryManager {
*
* @param page the page
* @param size the size
- * @param asc the asc
+ * @param asc the asc
* @return the page
*/
public Page fetchFlagged(int page, int size, boolean asc) {
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
- JPAQuery query = jpaQueryFactory.selectFrom(qEntry).leftJoin(qFlag)
- .on(qEntry.id.eq(qFlag.target)).where(qFlag.targetType.eq(Types.entry))
- .groupBy(qFlag.target);
+ JPAQuery query = jpaQueryFactory.selectFrom(qEntry).leftJoin(qFlag).on(qEntry.id.eq(qFlag.target))
+ .where(qFlag.targetType.eq(Types.entry)).groupBy(qFlag.target);
+
+ JPAQuery countQuery = query.clone().select(qEntry.id.countDistinct());
+
return new PageImpl(query
- .orderBy(new OrderSpecifier<>(asc ? com.querydsl.core.types.Order.ASC
- : com.querydsl.core.types.Order.DESC, qEntry.created))
- .limit(size).offset(page * size).fetch(), PageRequest.of(page, size, sort),
- query.fetchCount());
+ .orderBy(new OrderSpecifier<>(
+ asc ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, qEntry.created))
+ .limit(size).offset(page * size).fetch(), PageRequest.of(page, size, sort), countQuery.fetchOne());
}
/**
* Fetch by bookmarks.
*
* @param username the username
- * @param page the page
- * @param size the size
+ * @param page the page
+ * @param size the size
* @return the page
*/
public Page fetchByBookmarks(String username, int page, int size) {
@@ -475,9 +443,9 @@ public class EntryManager {
* Apply metadata.
*
* @param username the username
- * @param karma the karma
- * @param entry the entry
- * @param ignore the ignore
+ * @param karma the karma
+ * @param entry the entry
+ * @param ignore the ignore
*/
public void applyMetadata(String username, long karma, Entry entry, List ignore) {
@@ -490,8 +458,8 @@ public class EntryManager {
}
if (!ignore.contains("edit")) {
- entry.getMetadata().put("edit", entry.getAuthor().equals(username)
- && entry.getCreated().isAfter(Instant.now()));
+ entry.getMetadata().put("edit",
+ entry.getAuthor().equals(username) && entry.getCreated().isAfter(Instant.now()));
}
if (!ignore.contains("comments")) {
@@ -503,47 +471,39 @@ public class EntryManager {
}
if (!ignore.contains("bookmark")) {
- entry.getMetadata().put("bookmark",
- !bookmarksManager.hasEntry(username, entry.getId()));
+ entry.getMetadata().put("bookmark", !bookmarksManager.hasEntry(username, entry.getId()));
}
if (!ignore.contains("removeBookmark")) {
- entry.getMetadata().put("removeBookmark",
- bookmarksManager.hasEntry(username, entry.getId()));
+ entry.getMetadata().put("removeBookmark", bookmarksManager.hasEntry(username, entry.getId()));
}
if (!ignore.contains("upvoted")) {
entry.getMetadata().put("upvoted",
- voteRepository.exists(qVote.target.eq(entry.getId())
- .and(qVote.targetType.eq(Types.entry)).and(qVote.type.eq(VoteType.up))
- .and(qVote.author.equalsIgnoreCase(username))));
+ voteRepository.exists(qVote.target.eq(entry.getId()).and(qVote.targetType.eq(Types.entry))
+ .and(qVote.type.eq(VoteType.up)).and(qVote.author.equalsIgnoreCase(username))));
}
if (!ignore.contains("downvoted")) {
entry.getMetadata().put("downvoted",
- voteRepository.exists(qVote.target.eq(entry.getId())
- .and(qVote.targetType.eq(Types.entry)).and(qVote.type.eq(VoteType.down))
- .and(qVote.author.equalsIgnoreCase(username))));
+ voteRepository.exists(qVote.target.eq(entry.getId()).and(qVote.targetType.eq(Types.entry))
+ .and(qVote.type.eq(VoteType.down)).and(qVote.author.equalsIgnoreCase(username))));
}
if (!username.equals(entry.getAuthor()) && !ignore.contains("flag")) {
- entry.getMetadata().put("flag",
- flagManager.get(username, entry.getId(), Types.entry) == null);
+ entry.getMetadata().put("flag", flagManager.get(username, entry.getId(), Types.entry) == null);
}
if (!username.equals(entry.getAuthor()) && !ignore.contains("unflag")) {
- entry.getMetadata().put("unflag",
- flagManager.get(username, entry.getId(), Types.entry) != null);
+ entry.getMetadata().put("unflag", flagManager.get(username, entry.getId(), Types.entry) != null);
}
if (!ignore.contains("flagged")) {
- entry.getMetadata().put("flagged",
- flagManager.getFlags(entry.getId(), Types.entry) > 0);
+ entry.getMetadata().put("flagged", flagManager.getFlags(entry.getId(), Types.entry) > 0);
}
- if (voteRepository
- .exists(qVote.target.eq(entry.getId()).and(qVote.targetType.eq(Types.entry))
- .and(qVote.author.equalsIgnoreCase(username)))) {
+ if (voteRepository.exists(qVote.target.eq(entry.getId()).and(qVote.targetType.eq(Types.entry))
+ .and(qVote.author.equalsIgnoreCase(username)))) {
if (!ignore.contains("unvote")) {
entry.getMetadata().put("unvote", true);
}
@@ -562,12 +522,11 @@ public class EntryManager {
* Apply metadata.
*
* @param username the username
- * @param karma the karma
- * @param entries the entries
- * @param ignore the ignore
+ * @param karma the karma
+ * @param entries the entries
+ * @param ignore the ignore
*/
- public void applyMetadata(String username, long karma, List entries,
- List ignore) {
+ public void applyMetadata(String username, long karma, List entries, List ignore) {
for (Entry entry : entries) {
applyMetadata(username, karma, entry, ignore);
}
@@ -635,17 +594,17 @@ public class EntryManager {
* @return the points
*/
public long getPoints(Long entryId) {
- long upvotes = voteRepository.count(qVote.targetType.eq(Types.entry)
- .and(qVote.type.eq(VoteType.up)).and(qVote.target.eq(entryId)));
- long downvotes = voteRepository.count(qVote.targetType.eq(Types.entry)
- .and(qVote.type.eq(VoteType.down)).and(qVote.target.eq(entryId)));
+ long upvotes = voteRepository
+ .count(qVote.targetType.eq(Types.entry).and(qVote.type.eq(VoteType.up)).and(qVote.target.eq(entryId)));
+ long downvotes = voteRepository.count(
+ qVote.targetType.eq(Types.entry).and(qVote.type.eq(VoteType.down)).and(qVote.target.eq(entryId)));
return upvotes - downvotes;
}
/**
* Gets the user points.
*
- * @param entryId the entry id
+ * @param entryId the entry id
* @param username the username
* @return the user points
*/
diff --git a/src/main/java/de/bstly/board/businesslogic/FlagManager.java b/src/main/java/de/bstly/board/businesslogic/FlagManager.java
index 7234d8e..41129e5 100644
--- a/src/main/java/de/bstly/board/businesslogic/FlagManager.java
+++ b/src/main/java/de/bstly/board/businesslogic/FlagManager.java
@@ -40,14 +40,15 @@ public class FlagManager {
/**
* Gets the.
*
- * @param author the author
- * @param target the target
+ * @param author the author
+ * @param target the target
* @param targetType the target type
* @return the flag
*/
public Flag get(String author, Long target, Types targetType) {
- return flagRepository.findOne(qFlag.author.eq(author).and(qFlag.targetType.eq(targetType))
- .and(qFlag.target.eq(target))).orElse(null);
+ return flagRepository
+ .findOne(qFlag.author.eq(author).and(qFlag.targetType.eq(targetType)).and(qFlag.target.eq(target)))
+ .orElse(null);
}
/**
@@ -72,12 +73,11 @@ public class FlagManager {
/**
* Delete by target.
*
- * @param target the target
+ * @param target the target
* @param targetType the target type
*/
public void deleteByTarget(Long target, Types targetType) {
- for (Flag flag : flagRepository
- .findAll(qFlag.target.eq(target).and(qFlag.targetType.eq(targetType)))) {
+ for (Flag flag : flagRepository.findAll(qFlag.target.eq(target).and(qFlag.targetType.eq(targetType)))) {
delete(flag);
}
}
@@ -85,7 +85,7 @@ public class FlagManager {
/**
* Gets the flags.
*
- * @param target the target
+ * @param target the target
* @param targetType the target type
* @return the flags
*/
@@ -96,7 +96,7 @@ public class FlagManager {
/**
* Check flag status.
*
- * @param target the target
+ * @param target the target
* @param targetType the target type
*/
public void checkFlagStatus(Long target, Types targetType) {
@@ -120,9 +120,7 @@ public class FlagManager {
* @param target the target
*/
public void checkCommentFlagStatus(Long target) {
- Assert.isTrue(commentManager.exists(target), "Comment not exists: '"
- + target
- + "'!");
+ Assert.isTrue(commentManager.exists(target), "Comment not exists: '" + target + "'!");
Comment comment = commentManager.get(target);
if (getFlags(target, Types.comment) >= settingsManager.getFlahThresh()) {
@@ -151,8 +149,8 @@ public class FlagManager {
* @param comment the comment
*/
protected void hideSubcomments(Comment comment) {
- for (Comment subcomment : commentRepository.findAll(qComment.parent.eq(comment.getId())
- .and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL)))) {
+ for (Comment subcomment : commentRepository
+ .findAll(qComment.parent.eq(comment.getId()).and(qComment.flaggedStatus.eq(FlaggedStatus.NORMAL)))) {
subcomment.setFlaggedStatus(FlaggedStatus.HIDDEN);
subcomment = commentManager.save(subcomment);
hideSubcomments(subcomment);
@@ -176,8 +174,8 @@ public class FlagManager {
* @param comment the comment
*/
protected void unhideSubcomments(Comment comment) {
- for (Comment subcomment : commentRepository.findAll(qComment.parent.eq(comment.getId())
- .and(qComment.flaggedStatus.eq(FlaggedStatus.HIDDEN)))) {
+ for (Comment subcomment : commentRepository
+ .findAll(qComment.parent.eq(comment.getId()).and(qComment.flaggedStatus.eq(FlaggedStatus.HIDDEN)))) {
subcomment.setFlaggedStatus(FlaggedStatus.NORMAL);
subcomment = commentManager.save(subcomment);
hideSubcomments(subcomment);
@@ -190,9 +188,7 @@ public class FlagManager {
* @param target the target
*/
public void checkEntryFlagStatus(Long target) {
- Assert.isTrue(entryManager.exists(target), "Entry not exists: '"
- + target
- + "'!");
+ Assert.isTrue(entryManager.exists(target), "Entry not exists: '" + target + "'!");
Entry entry = entryManager.get(target);
if (getFlags(target, Types.entry) >= settingsManager.getFlahThresh()) {
if (!FlaggedStatus.FLAGGED.equals(entry.getFlaggedStatus())) {
@@ -208,7 +204,7 @@ public class FlagManager {
/**
* Unflag.
*
- * @param target the target
+ * @param target the target
* @param targetType the target type
*/
public void unflag(Long target, Types targetType) {
diff --git a/src/main/java/de/bstly/board/businesslogic/InstantHelper.java b/src/main/java/de/bstly/board/businesslogic/InstantHelper.java
index aba30cf..2ceeb86 100644
--- a/src/main/java/de/bstly/board/businesslogic/InstantHelper.java
+++ b/src/main/java/de/bstly/board/businesslogic/InstantHelper.java
@@ -20,7 +20,7 @@ public class InstantHelper {
* Plus.
*
* @param instant the instant
- * @param amount the amount
+ * @param amount the amount
* @return the instant
*/
public static Instant plus(Instant instant, TemporalAmount amount) {
@@ -30,9 +30,9 @@ public class InstantHelper {
/**
* Plus.
*
- * @param instant the instant
+ * @param instant the instant
* @param amountToAdd the amount to add
- * @param unit the unit
+ * @param unit the unit
* @return the instant
*/
public static Instant plus(Instant instant, long amountToAdd, TemporalUnit unit) {
@@ -43,7 +43,7 @@ public class InstantHelper {
* Minus.
*
* @param instant the instant
- * @param amount the amount
+ * @param amount the amount
* @return the instant
*/
public static Instant minus(Instant instant, TemporalAmount amount) {
@@ -53,32 +53,29 @@ public class InstantHelper {
/**
* Minus.
*
- * @param instant the instant
+ * @param instant the instant
* @param amountToAdd the amount to add
- * @param unit the unit
+ * @param unit the unit
* @return the instant
*/
public static Instant minus(Instant instant, long amountToAdd, TemporalUnit unit) {
- return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC).minus(amountToAdd, unit)
- .toInstant();
+ return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC).minus(amountToAdd, unit).toInstant();
}
/**
* Truncate.
*
* @param instant the instant
- * @param unit the unit
+ * @param unit the unit
* @return the instant
*/
public static Instant truncate(Instant instant, TemporalUnit unit) {
if (ChronoUnit.YEARS.equals(unit)) {
instant = instant.truncatedTo(ChronoUnit.DAYS);
- return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC)
- .with(ChronoField.DAY_OF_YEAR, 1L).toInstant();
+ return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC).with(ChronoField.DAY_OF_YEAR, 1L).toInstant();
} else if (ChronoUnit.MONTHS.equals(unit)) {
instant = instant.truncatedTo(ChronoUnit.DAYS);
- return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC)
- .with(ChronoField.DAY_OF_MONTH, 1L).toInstant();
+ return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC).with(ChronoField.DAY_OF_MONTH, 1L).toInstant();
}
return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC).truncatedTo(unit).toInstant();
diff --git a/src/main/java/de/bstly/board/businesslogic/SearchManager.java b/src/main/java/de/bstly/board/businesslogic/SearchManager.java
index 0e3ee0d..790fd6b 100644
--- a/src/main/java/de/bstly/board/businesslogic/SearchManager.java
+++ b/src/main/java/de/bstly/board/businesslogic/SearchManager.java
@@ -61,8 +61,8 @@ public class SearchManager implements SmartInitializingSingleton {
@EventListener(ContextRefreshedEvent.class)
@Transactional
public void onApplicationEvent(ContextRefreshedEvent event) {
- MassIndexer indexer = searchSession.massIndexer().idFetchSize(150)
- .batchSizeToLoadObjects(25).threadsToLoadObjects(12);
+ MassIndexer indexer = searchSession.massIndexer().idFetchSize(150).batchSizeToLoadObjects(25)
+ .threadsToLoadObjects(12);
try {
logger.info("start indexing!");
indexer.startAndWait();
@@ -73,9 +73,20 @@ public class SearchManager implements SmartInitializingSingleton {
}
}
+ /**
+ * Search.
+ *
+ * @param types the types
+ * @param search the search
+ * @param page the page
+ * @param size the size
+ * @param asc the asc
+ * @param sortByDate the sort by date
+ * @return the search result
+ */
@Transactional
- public SearchResult