From d3b2a95472f5efc3068a4acc93a4b2250c966b64 Mon Sep 17 00:00:00 2001 From: _Bastler Date: Wed, 13 Apr 2022 16:50:35 +0200 Subject: [PATCH] update dependencies, javadoc, formatting --- pom.xml | 6 +- .../java/de/bstly/board/LuceneConfig.java | 29 +-- .../board/businesslogic/BookmarksManager.java | 19 +- .../board/businesslogic/CommentManager.java | 120 +++++---- .../board/businesslogic/EntryManager.java | 227 +++++++----------- .../board/businesslogic/FlagManager.java | 36 ++- .../board/businesslogic/InstantHelper.java | 23 +- .../board/businesslogic/SearchManager.java | 41 ++-- .../board/businesslogic/SettingsManager.java | 4 +- .../bstly/board/businesslogic/TagManager.java | 13 +- .../board/businesslogic/UserManager.java | 190 +++++++++------ .../board/businesslogic/ViewManager.java | 24 +- .../board/businesslogic/VoteManager.java | 23 +- .../businesslogic/support/InstantHelper.java | 24 +- .../controller/AuthenticationController.java | 15 +- .../board/controller/BaseController.java | 9 +- .../board/controller/BookmarksController.java | 8 +- .../board/controller/CommentController.java | 25 +- .../board/controller/DebugController.java | 110 +++------ .../board/controller/EntryController.java | 92 +++---- .../controller/ModerationController.java | 21 +- .../board/controller/SearchController.java | 20 +- .../bstly/board/controller/TagController.java | 10 +- .../board/controller/UserController.java | 2 - .../board/controller/ViewController.java | 30 ++- .../board/controller/model/EntryFilter.java | 16 +- .../support/ControllerExceptionHandler.java | 7 +- .../EntityResponseStatusException.java | 11 +- .../JsonStringBodyControllerAdvice.java | 36 ++- .../controller/support/RequestBodyErrors.java | 7 +- .../validation/CommentValidator.java | 6 +- .../controller/validation/EntryValidator.java | 6 +- .../de/bstly/board/events/VotedEvent.java | 2 - .../board/i18n/businesslogic/I18nManager.java | 24 +- .../board/i18n/controller/I18nController.java | 13 +- .../java/de/bstly/board/i18n/model/I18n.java | 3 - .../board/i18n/repository/I18nRepository.java | 3 +- .../java/de/bstly/board/model/Comment.java | 2 + src/main/java/de/bstly/board/model/Entry.java | 2 + .../java/de/bstly/board/model/LocalUser.java | 2 + src/main/java/de/bstly/board/model/Tag.java | 2 +- src/main/java/de/bstly/board/model/View.java | 22 +- src/main/java/de/bstly/board/model/Vote.java | 3 +- .../model/support/InstantValueBridge.java | 10 +- .../board/repository/BookmarksRepository.java | 3 +- .../board/repository/CommentRepository.java | 3 +- .../board/repository/EntryRepository.java | 3 +- .../board/repository/LocalUserRepository.java | 3 +- .../board/repository/ViewRepository.java | 3 +- .../security/LocalRememberMeServices.java | 10 +- .../board/security/LocalUserDetails.java | 7 +- .../OAuth2AuthenticationSuccessHandler.java | 13 +- .../bstly/board/security/SecurityConfig.java | 21 +- 53 files changed, 636 insertions(+), 728 deletions(-) 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 search(List types, String search, int page, int size, - boolean asc, boolean sortByDate) { + 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) { @@ -91,26 +102,20 @@ public class SearchManager implements SmartInitializingSingleton { } 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("title_de").matching(search) - .boost(settingsManager.getGravity())) - .should(f.match().field("url").matching(search)) - .should(f.match().field("url_de").matching(search)) - .should(f.match().field("text").matching(search)) - .should(f.match().field("text_de").matching(search))) - .sort(f -> sortByDate - ? (asc ? f.field("created").asc() : f.field("created").desc()) + return searchSession.search(classes).where(f -> f.bool() + .should(f.match().field("title").matching(search).boost(settingsManager.getGravity())) + .should(f.match().field("title_de").matching(search).boost(settingsManager.getGravity())) + .should(f.match().field("url").matching(search)).should(f.match().field("url_de").matching(search)) + .should(f.match().field("text").matching(search)) + .should(f.match().field("text_de").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)) .should(f.match().field("text_de").matching(search))) - .sort(f -> sortByDate - ? (asc ? f.field("created").asc() : f.field("created").desc()) + .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 0be115e..015c447 100644 --- a/src/main/java/de/bstly/board/businesslogic/SettingsManager.java +++ b/src/main/java/de/bstly/board/businesslogic/SettingsManager.java @@ -93,9 +93,9 @@ public class SettingsManager { } /** - * Gets the max user pages. + * Gets the max views. * - * @return the max user pages + * @return the max views */ public long getMaxViews() { return MAX_VIEWS; diff --git a/src/main/java/de/bstly/board/businesslogic/TagManager.java b/src/main/java/de/bstly/board/businesslogic/TagManager.java index 99681d7..80a181c 100644 --- a/src/main/java/de/bstly/board/businesslogic/TagManager.java +++ b/src/main/java/de/bstly/board/businesslogic/TagManager.java @@ -29,7 +29,7 @@ public class TagManager { /** * Creates the. * - * @param tag the tag + * @param tag the tag * @param target the target * @return the tag */ @@ -40,7 +40,7 @@ public class TagManager { /** * Delete. * - * @param tag the tag + * @param tag the tag * @param target the target */ public void delete(String tag, Long target) { @@ -54,15 +54,14 @@ public class TagManager { * @return the for target */ public List getForTarget(Long target) { - return jpaQueryFactory.selectFrom(qTag).where(qTag.target.eq(target)).select(qTag.tag) - .fetch(); + return jpaQueryFactory.selectFrom(qTag).where(qTag.target.eq(target)).select(qTag.tag).fetch(); } /** * Sets the for target. * * @param target the target - * @param tags the tags + * @param tags the tags */ public void setForTarget(Long target, List tags) { deleteByTarget(target); @@ -89,8 +88,8 @@ public class TagManager { * @return the list */ public List search(String search) { - return jpaQueryFactory.selectFrom(qTag).where(qTag.tag.containsIgnoreCase(search)) - .distinct().limit(10).select(qTag.tag).fetch(); + return jpaQueryFactory.selectFrom(qTag).where(qTag.tag.containsIgnoreCase(search)).distinct().limit(10) + .select(qTag.tag).fetch(); } } diff --git a/src/main/java/de/bstly/board/businesslogic/UserManager.java b/src/main/java/de/bstly/board/businesslogic/UserManager.java index 17ea87e..2a0e82c 100644 --- a/src/main/java/de/bstly/board/businesslogic/UserManager.java +++ b/src/main/java/de/bstly/board/businesslogic/UserManager.java @@ -60,88 +60,116 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet * 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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* - * @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) + * @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) */ /* * @see org.springframework.security.core.userdetails.UserDetailsService# @@ -177,88 +205,116 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ /* * @see org.springframework.beans.factory.SmartInitializingSingleton# @@ -269,8 +325,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet if (!localUserRepository.exists(qLocalUser.roles.contains("ROLE_ADMIN"))) { if (!StringUtils.hasText(adminPassword)) { adminPassword = RandomStringUtils.random(24, true, true); - logger.error("password for 'admin': " - + adminPassword); + logger.error("password for 'admin': " + adminPassword); } LocalUser admin = new LocalUser(); admin.setUsername("admin"); @@ -288,8 +343,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet * @return the by username */ public LocalUser getByUsername(String username) { - return localUserRepository.findOne(qLocalUser.username.equalsIgnoreCase(username)) - .orElse(null); + return localUserRepository.findOne(qLocalUser.username.equalsIgnoreCase(username)).orElse(null); } /** @@ -315,9 +369,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet return getByUsername(token.getName()); } else if (authentication instanceof OAuth2AuthenticationToken) { OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) authentication; - String externalId = token.getAuthorizedClientRegistrationId() - + "-" - + token.getName(); + String externalId = token.getAuthorizedClientRegistrationId() + "-" + token.getName(); LocalUser localUser = getByExternalId(externalId); if (localUser == null) { localUser = new LocalUser(); @@ -334,11 +386,8 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet } int count = 1; String username = tmpUsername; - while (localUserRepository - .exists(qLocalUser.username.equalsIgnoreCase(username))) { - username = tmpUsername - + "-" - + count; + while (localUserRepository.exists(qLocalUser.username.equalsIgnoreCase(username))) { + username = tmpUsername + "-" + count; count++; } @@ -369,11 +418,10 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet * Apply metadata. * * @param username the username - * @param user the user + * @param user the user */ public void applyMetadata(String username, LocalUser user) { - if (user.getUsername().equalsIgnoreCase(username) - && !user.getMetadata().containsKey("self")) { + if (user.getUsername().equalsIgnoreCase(username) && !user.getMetadata().containsKey("self")) { user.getMetadata().put("self", true); } diff --git a/src/main/java/de/bstly/board/businesslogic/ViewManager.java b/src/main/java/de/bstly/board/businesslogic/ViewManager.java index e214f38..ebe5834 100644 --- a/src/main/java/de/bstly/board/businesslogic/ViewManager.java +++ b/src/main/java/de/bstly/board/businesslogic/ViewManager.java @@ -35,15 +35,14 @@ public class ViewManager { * @return true, if successful */ public boolean exists(String username, String name) { - return viewRepository - .exists(qView.username.equalsIgnoreCase(username).and(qView.name.eq(name))); + return viewRepository.exists(qView.username.equalsIgnoreCase(username).and(qView.name.eq(name))); } /** * Gets the. * * @param id the id - * @return the user page + * @return the view */ public View get(Long id) { return viewRepository.findById(id).orElse(null); @@ -54,19 +53,17 @@ public class ViewManager { * * @param username the username * @param name the name - * @return the user page + * @return the view */ public View get(String username, String name) { - return viewRepository - .findOne(qView.username.equalsIgnoreCase(username).and(qView.name.eq(name))) - .orElse(null); + return viewRepository.findOne(qView.username.equalsIgnoreCase(username).and(qView.name.eq(name))).orElse(null); } /** * Save. * - * @param view the user page - * @return the user page + * @param view the view + * @return the view */ public View save(View view) { return viewRepository.save(view); @@ -78,7 +75,6 @@ public class ViewManager { * @param username the username * @param page the page * @param size the size - * @param sortBy the sort by * @param desc the desc * @return the by user */ @@ -109,8 +105,7 @@ public class ViewManager { * @return the public */ public Page getPublic(String username, int page, int size, String sortBy, boolean desc) { - return viewRepository.findAll( - qView.username.notEqualsIgnoreCase(username).and(qView.publicView.isTrue()), + return viewRepository.findAll(qView.username.notEqualsIgnoreCase(username).and(qView.publicView.isTrue()), PageRequest.of(page, size, Sort.by(desc ? Direction.DESC : Direction.ASC, sortBy))); } @@ -125,6 +120,11 @@ public class ViewManager { viewRepository.delete(get(username, name)); } + /** + * Creates the default. + * + * @param username the username + */ public void createDefault(String username) { if (!exists(username, "TOP")) { View viewTop = new View(); diff --git a/src/main/java/de/bstly/board/businesslogic/VoteManager.java b/src/main/java/de/bstly/board/businesslogic/VoteManager.java index 12dc61f..48cf986 100644 --- a/src/main/java/de/bstly/board/businesslogic/VoteManager.java +++ b/src/main/java/de/bstly/board/businesslogic/VoteManager.java @@ -26,14 +26,15 @@ public class VoteManager { /** * 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 vote */ public Vote get(String author, Long target, Types targetType) { - return voteRepository.findOne(qVote.author.eq(author).and(qVote.targetType.eq(targetType)) - .and(qVote.target.eq(target))).orElse(null); + return voteRepository + .findOne(qVote.author.eq(author).and(qVote.targetType.eq(targetType)).and(qVote.target.eq(target))) + .orElse(null); } /** @@ -58,12 +59,11 @@ public class VoteManager { /** * Delete by target. * - * @param target the target + * @param target the target * @param targetType the target type */ public void deleteByTarget(Long target, Types targetType) { - for (Vote vote : voteRepository - .findAll(qVote.target.eq(target).and(qVote.targetType.eq(targetType)))) { + for (Vote vote : voteRepository.findAll(qVote.target.eq(target).and(qVote.targetType.eq(targetType)))) { delete(vote); } } @@ -71,16 +71,15 @@ public class VoteManager { /** * Gets the points. * - * @param target the target + * @param target the target * @param targetType the target type * @return the points */ public Long getPoints(Long target, Types targetType) { return voteRepository - .count(qVote.target.eq(target) - .and(qVote.targetType.eq(targetType).and(qVote.type.eq(VoteType.up)))) - - voteRepository.count(qVote.target.eq(target) - .and(qVote.targetType.eq(targetType).and(qVote.type.eq(VoteType.down)))); + .count(qVote.target.eq(target).and(qVote.targetType.eq(targetType).and(qVote.type.eq(VoteType.up)))) + - voteRepository.count( + qVote.target.eq(target).and(qVote.targetType.eq(targetType).and(qVote.type.eq(VoteType.down)))); } } diff --git a/src/main/java/de/bstly/board/businesslogic/support/InstantHelper.java b/src/main/java/de/bstly/board/businesslogic/support/InstantHelper.java index b187bdd..33de3d7 100644 --- a/src/main/java/de/bstly/board/businesslogic/support/InstantHelper.java +++ b/src/main/java/de/bstly/board/businesslogic/support/InstantHelper.java @@ -11,7 +11,6 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalUnit; - /** * The Class InstantHelper. */ @@ -21,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) { @@ -31,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) { @@ -44,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) { @@ -54,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/controller/AuthenticationController.java b/src/main/java/de/bstly/board/controller/AuthenticationController.java index f06dcd2..3da6e9e 100755 --- a/src/main/java/de/bstly/board/controller/AuthenticationController.java +++ b/src/main/java/de/bstly/board/controller/AuthenticationController.java @@ -58,18 +58,13 @@ public class AuthenticationController extends BaseController { public List getExternalLoginUrls() { List clients = Lists.newArrayList(); Iterable clientRegistrations = null; - ResolvableType type = ResolvableType.forInstance(clientRegistrationRepository) - .as(Iterable.class); - if (type != ResolvableType.NONE - && ClientRegistration.class.isAssignableFrom(type.resolveGenerics()[0])) { + ResolvableType type = ResolvableType.forInstance(clientRegistrationRepository).as(Iterable.class); + if (type != ResolvableType.NONE && ClientRegistration.class.isAssignableFrom(type.resolveGenerics()[0])) { clientRegistrations = (Iterable) clientRegistrationRepository; } - clientRegistrations - .forEach(registration -> clients.add(new Client(registration.getRegistrationId(), - authorizationRequestBaseUri - + "/" - + registration.getRegistrationId()))); + clientRegistrations.forEach(registration -> clients.add(new Client(registration.getRegistrationId(), + authorizationRequestBaseUri + "/" + registration.getRegistrationId()))); return clients; } @@ -86,7 +81,7 @@ public class AuthenticationController extends BaseController { /** * Instantiates a new client. * - * @param id the id + * @param id the id * @param loginUrl the login url */ public Client(String id, String loginUrl) { diff --git a/src/main/java/de/bstly/board/controller/BaseController.java b/src/main/java/de/bstly/board/controller/BaseController.java index cece545..870aaee 100644 --- a/src/main/java/de/bstly/board/controller/BaseController.java +++ b/src/main/java/de/bstly/board/controller/BaseController.java @@ -63,8 +63,7 @@ public class BaseController { String username = getCurrentUsername(); if (username != null) { LocalUser localUser = userManager.getByUsername(username); - if (localUser.getSettings() != null - && localUser.getSettings().containsKey("pageSize")) { + if (localUser.getSettings() != null && localUser.getSettings().containsKey("pageSize")) { try { return Integer.parseInt(localUser.getSettings().get("pageSize")); } catch (Exception e) { @@ -112,8 +111,7 @@ public class BaseController { String username = getCurrentUsername(); if (username != null) { LocalUser localUser = userManager.getByUsername(username); - if (localUser.getSettings() != null - && localUser.getSettings().containsKey("entryDelay")) { + if (localUser.getSettings() != null && localUser.getSettings().containsKey("entryDelay")) { try { long entryDelay = Long.parseLong(localUser.getSettings().get("entryDelay")); @@ -142,8 +140,7 @@ public class BaseController { String username = getCurrentUsername(); if (username != null) { LocalUser localUser = userManager.getByUsername(username); - if (localUser.getSettings() != null - && localUser.getSettings().containsKey("commentDelay")) { + if (localUser.getSettings() != null && localUser.getSettings().containsKey("commentDelay")) { try { long commentDelay = Long.parseLong(localUser.getSettings().get("commentDelay")); diff --git a/src/main/java/de/bstly/board/controller/BookmarksController.java b/src/main/java/de/bstly/board/controller/BookmarksController.java index ce40801..44a6f33 100644 --- a/src/main/java/de/bstly/board/controller/BookmarksController.java +++ b/src/main/java/de/bstly/board/controller/BookmarksController.java @@ -46,8 +46,8 @@ public class BookmarksController extends BaseController { /** * Gets the entries. * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter + * @param pageParameter the page parameter + * @param sizeParameter the size parameter * @param ignoreParameter the ignore parameter * @return the entries */ @@ -61,8 +61,8 @@ public class BookmarksController extends BaseController { sizeParameter = Optional.of(100); } - Page entries = entryManager.fetchByBookmarks(getCurrentUsername(), - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); + Page entries = entryManager.fetchByBookmarks(getCurrentUsername(), pageParameter.orElse(0), + sizeParameter.orElse(settingsManager.getPageSize())); List ignore = ignoreParameter.orElse(Lists.newArrayList()); entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), diff --git a/src/main/java/de/bstly/board/controller/CommentController.java b/src/main/java/de/bstly/board/controller/CommentController.java index cd8fed2..9cdb5ec 100644 --- a/src/main/java/de/bstly/board/controller/CommentController.java +++ b/src/main/java/de/bstly/board/controller/CommentController.java @@ -66,8 +66,7 @@ public class CommentController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping({ "/new/{target}", "/new/{target}/{parent}" }) - public Page fetchByDate(@PathVariable("target") Long target, - @PathVariable("parent") Optional parent, + public Page fetchByDate(@PathVariable("target") Long target, @PathVariable("parent") Optional parent, @RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, @RequestParam("date") Optional dateParameter, @@ -81,8 +80,8 @@ public class CommentController extends BaseController { if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) { dateParameter = Optional.of(Instant.now()); } - Page comments = commentManager.fetchByDate(getCurrentUsername(), target, - parent.orElse(null), dateParameter.orElse(Instant.now()), pageParameter.orElse(0), + Page comments = commentManager.fetchByDate(getCurrentUsername(), target, parent.orElse(null), + dateParameter.orElse(Instant.now()), pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false)); List ignore = ignoreParameter.orElse(Lists.newArrayList("entry")); @@ -106,8 +105,7 @@ public class CommentController extends BaseController { public Page fetchByUsername(@PathVariable("username") String username, @RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, - @RequestParam("date") Optional dateParameter, - @RequestParam("asc") Optional ascParameter, + @RequestParam("date") Optional dateParameter, @RequestParam("asc") Optional ascParameter, @RequestParam("ignore") Optional> ignoreParameter) { if (sizeParameter.isPresent() && sizeParameter.get() > 100) { @@ -118,9 +116,9 @@ public class CommentController extends BaseController { dateParameter = Optional.of(Instant.now()); } - Page comments = commentManager.fetchByUsername(username, - dateParameter.orElse(Instant.now()), pageParameter.orElse(0), - sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); + Page comments = commentManager.fetchByUsername(username, dateParameter.orElse(Instant.now()), + pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), + ascParameter.orElse(false)); List ignore = ignoreParameter.orElse(Lists.newArrayList()); commentManager.applyMetadata(getCurrentUsername(), comments.getContent(), ignore); return comments; @@ -135,8 +133,7 @@ public class CommentController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping({ "/count/{target}", "/count/{target}/{parent}" }) - public Long countComments(@PathVariable("target") Long target, - @PathVariable("parent") Optional parent) { + public Long countComments(@PathVariable("target") Long target, @PathVariable("parent") Optional parent) { return commentManager.count(target, parent.orElse(null)); } @@ -177,8 +174,7 @@ public class CommentController extends BaseController { commentValidator.validate(comment, bindingResult); if (bindingResult.hasErrors()) { - throw new EntityResponseStatusException(bindingResult.getAllErrors(), - HttpStatus.UNPROCESSABLE_ENTITY); + throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } comment.setCreated(Instant.now().plus(getCommentDelay(), ChronoUnit.MINUTES)); @@ -221,8 +217,7 @@ public class CommentController extends BaseController { commentValidator.validate(comment, bindingResult); if (bindingResult.hasErrors()) { - throw new EntityResponseStatusException(bindingResult.getAllErrors(), - HttpStatus.UNPROCESSABLE_ENTITY); + throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } orgComment.setText(comment.getText()); diff --git a/src/main/java/de/bstly/board/controller/DebugController.java b/src/main/java/de/bstly/board/controller/DebugController.java index 44e514c..8ea1877 100644 --- a/src/main/java/de/bstly/board/controller/DebugController.java +++ b/src/main/java/de/bstly/board/controller/DebugController.java @@ -38,7 +38,7 @@ import de.bstly.board.repository.VoteRepository; @RestController @RequestMapping("/debug") public class DebugController extends BaseController { - + private Logger logger = LoggerFactory.getLogger(DebugController.class); @Autowired @@ -103,28 +103,21 @@ public class DebugController extends BaseController { public void random() { logger.warn("start random generation"); - long userCount = localUserRepository - .count(QLocalUser.localUser.username.startsWith("user")); + long userCount = localUserRepository.count(QLocalUser.localUser.username.startsWith("user")); for (long i = userCount; i < userCount + users; i++) { LocalUser localUser = new LocalUser(); - String username = "user" - + i; + String username = "user" + i; localUser.setUsername(username); localUser.setPasswordHash(passwordEncoder.encode(username)); localUserRepository.save(localUser); - logger.trace("Created user: '" - + username - + "'"); + logger.trace("Created user: '" + username + "'"); } - logger.info("Created " - + users - + " users"); + logger.info("Created " + users + " users"); for (long id = 0; id <= userCount; id++) { - entries("user" - + id, userCount); + entries("user" + id, userCount); } logger.warn("finished random generation"); @@ -142,23 +135,16 @@ public class DebugController extends BaseController { Entry entry = new Entry(); entry.setEntryType(EntryType.INTERN); entry.setAuthor(username); - entry.setCreated( - Instant.now().minus(RandomUtils.nextLong(0, entryAge), ChronoUnit.SECONDS)); + entry.setCreated(Instant.now().minus(RandomUtils.nextLong(0, entryAge), ChronoUnit.SECONDS)); entry.setTitle(RandomStringUtils.randomAscii(RandomUtils.nextInt(10, 250))); entry.setText(RandomStringUtils.randomAscii(RandomUtils.nextInt(0, 2500))); entry.setEntryStatus(EntryStatus.NORMAL); entry = entryManager.save(entry); - logger.trace("Created entry: '" - + entry.getId() - + "'"); + logger.trace("Created entry: '" + entry.getId() + "'"); comments(entry.getId(), entry.getCreated(), userCount); votes(entry.getId(), Types.entry, userCount); } - logger.info("Created " - + numEntries - + " entries of '" - + username - + "'"); + logger.info("Created " + numEntries + " entries of '" + username + "'"); } /** @@ -170,27 +156,19 @@ public class DebugController extends BaseController { */ protected void comments(Long target, Instant date, long userCount) { long numComments = RandomUtils.nextLong(minComments, maxComments); - logger.debug("Create " - + numComments - + " comments for '" - + target - + "'"); + logger.debug("Create " + numComments + " comments for '" + target + "'"); for (int i = 0; i < numComments; i++) { Comment comment = new Comment(); comment.setTarget(target); - comment.setAuthor("user" - + RandomUtils.nextLong(0, userCount)); + comment.setAuthor("user" + RandomUtils.nextLong(0, userCount)); comment.setText(RandomStringUtils.randomAscii(RandomUtils.nextInt(0, 2500))); - comment.setCreated(Instant.now() - .minus(RandomUtils.nextLong(0, - (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), - ChronoUnit.SECONDS)); + comment.setCreated(Instant.now().minus( + RandomUtils.nextLong(0, (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), + ChronoUnit.SECONDS)); comment = commentRepository.save(comment); - logger.trace("Created comment: '" - + comment.getId() - + "'"); - subComments(target, comment.getId(), comment.getCreated(), subCommentsFactor, - subCommentsThresh, 0, userCount); + logger.trace("Created comment: '" + comment.getId() + "'"); + subComments(target, comment.getId(), comment.getCreated(), subCommentsFactor, subCommentsThresh, 0, + userCount); } } @@ -205,32 +183,24 @@ public class DebugController extends BaseController { * @param depth the depth * @param userCount the user count */ - protected void subComments(Long target, Long parent, Instant date, float factor, float thresh, - int depth, long userCount) { + protected void subComments(Long target, Long parent, Instant date, float factor, float thresh, int depth, + long userCount) { if (depth < subCommentsDepth && RandomUtils.nextFloat(0, 1) < thresh) { long numSubComments = RandomUtils.nextLong(0, Math.round(maxComments * factor)); - logger.debug("Create " - + numSubComments - + " subComments for '" - + parent - + "'"); + logger.debug("Create " + numSubComments + " subComments for '" + parent + "'"); for (int i = 0; i < numSubComments; i++) { Comment comment = new Comment(); comment.setTarget(target); comment.setParent(parent); - comment.setAuthor("user" - + RandomUtils.nextLong(0, userCount)); + comment.setAuthor("user" + RandomUtils.nextLong(0, userCount)); comment.setText(RandomStringUtils.randomAscii(RandomUtils.nextInt(0, 2500))); - comment.setCreated(Instant.now() - .minus(RandomUtils.nextLong(0, - (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), - ChronoUnit.SECONDS)); + comment.setCreated(Instant.now().minus( + RandomUtils.nextLong(0, (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), + ChronoUnit.SECONDS)); comment = commentRepository.save(comment); - logger.trace("Created subComment: '" - + comment.getId() - + "'"); - subComments(target, comment.getId(), comment.getCreated(), factor * 0.5f, - thresh * 0.5f, depth++, userCount); + logger.trace("Created subComment: '" + comment.getId() + "'"); + subComments(target, comment.getId(), comment.getCreated(), factor * 0.5f, thresh * 0.5f, depth++, + userCount); } } } @@ -244,41 +214,27 @@ public class DebugController extends BaseController { */ protected void votes(Long target, Types targetType, long userCount) { long numUpvotes = RandomUtils.nextLong(minUpvotes, maxUpvotes); - logger.debug("Create " - + numUpvotes - + " upvotes for '" - + target - + "'"); + logger.debug("Create " + numUpvotes + " upvotes for '" + target + "'"); for (int i = 0; i < numUpvotes; i++) { Vote upvote = new Vote(); upvote.setTarget(target); upvote.setType(VoteType.up); upvote.setTargetType(targetType); - upvote.setAuthor("user" - + RandomUtils.nextLong(0, userCount)); + upvote.setAuthor("user" + RandomUtils.nextLong(0, userCount)); upvote = voteRepository.save(upvote); - logger.trace("Created upvote: '" - + upvote.getId() - + "'"); + logger.trace("Created upvote: '" + upvote.getId() + "'"); } long numDownvotes = RandomUtils.nextLong(minDownvotes, maxDownvotes); - logger.debug("Create " - + numDownvotes - + " downvotes for '" - + target - + "'"); + logger.debug("Create " + numDownvotes + " downvotes for '" + target + "'"); for (int i = 0; i < numDownvotes; i++) { Vote downvote = new Vote(); downvote.setTarget(target); downvote.setType(VoteType.down); downvote.setTargetType(targetType); - downvote.setAuthor("user" - + RandomUtils.nextLong(0, userCount)); + downvote.setAuthor("user" + RandomUtils.nextLong(0, userCount)); downvote = voteRepository.save(downvote); - logger.trace("Created downvote: '" - + downvote.getId() - + "'"); + logger.trace("Created downvote: '" + downvote.getId() + "'"); } } diff --git a/src/main/java/de/bstly/board/controller/EntryController.java b/src/main/java/de/bstly/board/controller/EntryController.java index 25eda85..6bbedd8 100644 --- a/src/main/java/de/bstly/board/controller/EntryController.java +++ b/src/main/java/de/bstly/board/controller/EntryController.java @@ -68,14 +68,19 @@ public class EntryController extends BaseController { private ViewManager viewManager; /** - * Fetch by user page. + * Fetch by view. * - * @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 name the name + * @param usernameParameter the username parameter + * @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()") @@ -92,8 +97,7 @@ public class EntryController extends BaseController { @RequestParam("asc") Optional ascParameter, @RequestParam("ignore") Optional> ignoreParameter) { - View view = viewManager.get(usernameParameter.orElse(getCurrentUsername()), - name); + View view = viewManager.get(usernameParameter.orElse(getCurrentUsername()), name); if (view == null || usernameParameter.isPresent() && !view.isPublicView()) { throw new EntityResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY); @@ -103,9 +107,8 @@ public class EntryController extends BaseController { sizeParameter = Optional.of(100); } - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); + EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, tagsParameter.orElse(null), + excludedTagsParameter.orElse(null), typeParameter.orElse(null)); filter.setFixedTags(view.getTags()); filter.setFixedExcludedTags(view.getExcludedTags()); @@ -114,24 +117,20 @@ public class EntryController extends BaseController { switch (view.getSorting()) { case TOP: - entries = entryManager.fetchByRanking(getCurrentUsername(), filter, getGravity(), - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); + entries = entryManager.fetchByRanking(getCurrentUsername(), filter, getGravity(), pageParameter.orElse(0), + sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); break; case NEW: - entries = entryManager.fetchByDate(getCurrentUsername(), filter, - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); + entries = entryManager.fetchByDate(getCurrentUsername(), filter, pageParameter.orElse(0), + sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); break; case HOT: - entries = entryManager.fetchByComments(getCurrentUsername(), filter, getGravity(), - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); + entries = entryManager.fetchByComments(getCurrentUsername(), filter, getGravity(), pageParameter.orElse(0), + sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); break; case LAST: - entries = entryManager.fetchByLastComment(getCurrentUsername(), filter, - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false)); + entries = entryManager.fetchByLastComment(getCurrentUsername(), filter, pageParameter.orElse(0), + sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); break; } @@ -179,13 +178,11 @@ public class EntryController extends BaseController { dateParameter = Optional.of(Instant.now()); } - EntryFilter filter = buildFilter(dateParameter.orElse(null), FlaggedStatus.NORMAL, - tagsParameter.orElse(null), excludedTagsParameter.orElse(null), - typeParameter.orElse(null)); + 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)); + 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); @@ -222,8 +219,7 @@ public class EntryController extends BaseController { */ @PreAuthorize("isAuthenticated()") @GetMapping("/entry/{id}") - public Entry getEntry(@PathVariable("id") Long id, - @RequestParam("ignore") Optional> ignoreParameter) { + public Entry getEntry(@PathVariable("id") Long id, @RequestParam("ignore") Optional> ignoreParameter) { Entry entry = entryManager.get(id); if (entry == null) { @@ -231,8 +227,7 @@ public class EntryController extends BaseController { } List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entry, ignore); + entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), entry, ignore); return entry; } @@ -246,14 +241,12 @@ public class EntryController extends BaseController { */ @PreAuthorize("isAuthenticated()") @PostMapping() - public Entry createEntry(@RequestBody Entry entry, - @RequestParam("ignore") Optional> ignoreParameter) { + public Entry createEntry(@RequestBody Entry entry, @RequestParam("ignore") Optional> ignoreParameter) { RequestBodyErrors bindingResult = new RequestBodyErrors(entry); entryValidator.validate(entry, bindingResult); if (bindingResult.hasErrors()) { - throw new EntityResponseStatusException(bindingResult.getAllErrors(), - HttpStatus.UNPROCESSABLE_ENTITY); + throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } entry.setCreated(Instant.now().plus(getEntryDelay(), ChronoUnit.MINUTES)); @@ -272,8 +265,7 @@ public class EntryController extends BaseController { voteManager.save(vote); List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entry, ignore); + entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), entry, ignore); return entry; } @@ -287,11 +279,10 @@ public class EntryController extends BaseController { */ @PreAuthorize("isAuthenticated()") @PatchMapping - public Entry updateEntry(@RequestBody Entry entry, - @RequestParam("ignore") Optional> ignoreParameter) { + public Entry updateEntry(@RequestBody Entry entry, @RequestParam("ignore") Optional> ignoreParameter) { Entry orgEntry = entryManager.get(entry.getId()); - if (orgEntry == null || !orgEntry.getAuthor().equals(getCurrentUsername()) || orgEntry - .getCreated().plus(getEntryDelay(), ChronoUnit.MINUTES).isBefore(Instant.now())) { + if (orgEntry == null || !orgEntry.getAuthor().equals(getCurrentUsername()) + || orgEntry.getCreated().plus(getEntryDelay(), ChronoUnit.MINUTES).isBefore(Instant.now())) { throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); } @@ -299,8 +290,7 @@ public class EntryController extends BaseController { entryValidator.validate(entry, bindingResult); if (bindingResult.hasErrors()) { - throw new EntityResponseStatusException(bindingResult.getAllErrors(), - HttpStatus.UNPROCESSABLE_ENTITY); + throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } orgEntry.setUrl(entry.getUrl()); @@ -310,8 +300,7 @@ public class EntryController extends BaseController { orgEntry = entryManager.save(orgEntry); List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - orgEntry, ignore); + entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), orgEntry, ignore); return orgEntry; } @@ -324,8 +313,8 @@ public class EntryController extends BaseController { @DeleteMapping("{id}") public void deteleEntry(@PathVariable("id") Long id) { Entry orgEntry = entryManager.get(id); - if (orgEntry == null || !orgEntry.getAuthor().equals(getCurrentUsername()) || orgEntry - .getCreated().plus(getEntryDelay(), ChronoUnit.MINUTES).isBefore(Instant.now())) { + if (orgEntry == null || !orgEntry.getAuthor().equals(getCurrentUsername()) + || orgEntry.getCreated().plus(getEntryDelay(), ChronoUnit.MINUTES).isBefore(Instant.now())) { throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); } @@ -347,8 +336,7 @@ public class EntryController extends BaseController { response = new URL(URLDecoder.decode(url, "utf-8")).openStream(); scanner = new Scanner(response); String responseBody = scanner.useDelimiter("\\A").next(); - return responseBody.substring(responseBody.indexOf("") + 7, - responseBody.indexOf("")); + return responseBody.substring(responseBody.indexOf("") + 7, responseBody.indexOf("")); } catch (IOException ex) { } finally { try { diff --git a/src/main/java/de/bstly/board/controller/ModerationController.java b/src/main/java/de/bstly/board/controller/ModerationController.java index 06b1f4f..f9ec258 100644 --- a/src/main/java/de/bstly/board/controller/ModerationController.java +++ b/src/main/java/de/bstly/board/controller/ModerationController.java @@ -52,17 +52,16 @@ public class ModerationController extends BaseController { /** * Gets the flagged comments. * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param ascParameter the asc parameter + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param ascParameter the asc parameter * @param ignoreParameter the ignore parameter * @return the flagged comments */ @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_MOD')") @GetMapping("/flags/comments") public Page getFlaggedComments(@RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("asc") Optional ascParameter, + @RequestParam("size") Optional sizeParameter, @RequestParam("asc") Optional ascParameter, @RequestParam("ignore") Optional> ignoreParameter) { if (sizeParameter.isPresent() && sizeParameter.get() > 100) { sizeParameter = Optional.of(100); @@ -78,17 +77,16 @@ public class ModerationController extends BaseController { /** * Gets the flagged entries. * - * @param pageParameter the page parameter - * @param sizeParameter the size parameter - * @param ascParameter the asc parameter + * @param pageParameter the page parameter + * @param sizeParameter the size parameter + * @param ascParameter the asc parameter * @param ignoreParameter the ignore parameter * @return the flagged entries */ @PreAuthorize("hasRole('ROLE_ADMIN') || hasRole('ROLE_MOD')") @GetMapping("/flags/entries") public Page getFlaggedEntries(@RequestParam("page") Optional pageParameter, - @RequestParam("size") Optional sizeParameter, - @RequestParam("asc") Optional ascParameter, + @RequestParam("size") Optional sizeParameter, @RequestParam("asc") Optional ascParameter, @RequestParam("ignore") Optional> ignoreParameter) { if (sizeParameter.isPresent() && sizeParameter.get() > 100) { sizeParameter = Optional.of(100); @@ -96,7 +94,8 @@ public class ModerationController extends BaseController { Page entries = entryManager.fetchFlagged(pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); - List ignore = ignoreParameter.orElse(Lists.newArrayList("flag", "unflag", "bookmark", "removeBookmark")); + List ignore = ignoreParameter + .orElse(Lists.newArrayList("flag", "unflag", "bookmark", "removeBookmark")); entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), entries.getContent(), ignore); return entries; diff --git a/src/main/java/de/bstly/board/controller/SearchController.java b/src/main/java/de/bstly/board/controller/SearchController.java index d42a953..ed06d58 100644 --- a/src/main/java/de/bstly/board/controller/SearchController.java +++ b/src/main/java/de/bstly/board/controller/SearchController.java @@ -29,8 +29,7 @@ import de.bstly.board.model.Entry; import de.bstly.board.model.support.Types; /** - * @author _bastler@bstly.de - * + * The Class SearchController. */ @RestController @RequestMapping("/search") @@ -51,6 +50,7 @@ public class SearchController extends BaseController { * Search. * * @param searchParameter the search parameter + * @param typeParameter the type parameter * @param pageParameter the page parameter * @param sizeParameter the size parameter * @param byDateParameter the by date parameter @@ -61,8 +61,7 @@ public class SearchController extends BaseController { @PreAuthorize("isAuthenticated()") @GetMapping public Page search(@RequestParam("q") String searchParameter, - @RequestParam("type") Optional typeParameter, - @RequestParam("page") Optional pageParameter, + @RequestParam("type") Optional typeParameter, @RequestParam("page") Optional pageParameter, @RequestParam("size") Optional sizeParameter, @RequestParam("byDate") Optional byDateParameter, @RequestParam("asc") Optional ascParameter, @@ -89,21 +88,20 @@ public class SearchController extends BaseController { break; } - SearchResult result = searchManager.search(types, searchParameter, - pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()), - ascParameter.orElse(false), byDateParameter.orElse(false)); + 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())), + 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); + entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), + (Entry) object, ignore); } else if (object instanceof Comment) { commentManager.applyMetadata(getCurrentUsername(), (Comment) object, ignore); } diff --git a/src/main/java/de/bstly/board/controller/TagController.java b/src/main/java/de/bstly/board/controller/TagController.java index 8147600..9397064 100644 --- a/src/main/java/de/bstly/board/controller/TagController.java +++ b/src/main/java/de/bstly/board/controller/TagController.java @@ -58,8 +58,8 @@ public class TagController extends BaseController { /** * Sets the tags. * - * @param id the id - * @param tags the tags + * @param id the id + * @param tags the tags * @param ignoreParameter the ignore parameter * @return the entry */ @@ -78,15 +78,13 @@ public class TagController extends BaseController { entryValidator.validate(entry, bindingResult); if (bindingResult.hasErrors()) { - throw new EntityResponseStatusException(bindingResult.getAllErrors(), - HttpStatus.UNPROCESSABLE_ENTITY); + throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } entry = entryManager.save(entry); List ignore = ignoreParameter.orElse(Lists.newArrayList()); - entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), - entry, ignore); + entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), entry, ignore); return entry; } diff --git a/src/main/java/de/bstly/board/controller/UserController.java b/src/main/java/de/bstly/board/controller/UserController.java index 168cf04..a10e726 100644 --- a/src/main/java/de/bstly/board/controller/UserController.java +++ b/src/main/java/de/bstly/board/controller/UserController.java @@ -19,7 +19,6 @@ import de.bstly.board.businesslogic.UserManager; import de.bstly.board.controller.support.EntityResponseStatusException; import de.bstly.board.model.LocalUser; - /** * The Class UserController. */ @@ -27,7 +26,6 @@ import de.bstly.board.model.LocalUser; @RequestMapping("/users") public class UserController extends BaseController { - @Autowired private UserManager userManager; diff --git a/src/main/java/de/bstly/board/controller/ViewController.java b/src/main/java/de/bstly/board/controller/ViewController.java index 6c5ab3c..239d0bd 100644 --- a/src/main/java/de/bstly/board/controller/ViewController.java +++ b/src/main/java/de/bstly/board/controller/ViewController.java @@ -40,12 +40,12 @@ public class ViewController extends BaseController { private ViewValidator viewValidator; /** - * Gets the user pages. + * Gets the views. * * @param pageParameter the page parameter * @param sizeParameter the size parameter * @param descParameter the desc parameter - * @return the user pages + * @return the views */ @PreAuthorize("isAuthenticated()") @GetMapping() @@ -62,12 +62,12 @@ public class ViewController extends BaseController { } /** - * Gets the public user pages. + * Gets the public views. * * @param pageParameter the page parameter * @param sizeParameter the size parameter * @param descParameter the desc parameter - * @return the public user pages + * @return the public views */ @PreAuthorize("isAuthenticated()") @GetMapping("/public") @@ -75,20 +75,19 @@ public class ViewController extends BaseController { @RequestParam("size") Optional sizeParameter, @RequestParam("desc") Optional descParameter) { return viewManager.getPublic(getCurrentUsername(), pageParameter.orElse(0), - sizeParameter.orElse(settingsManager.getPageSize()), "name", - descParameter.orElse(false)); + sizeParameter.orElse(settingsManager.getPageSize()), "name", descParameter.orElse(false)); } /** - * Gets the user page. + * Gets the view. * - * @param name the name - * @return the user page + * @param name the name + * @param usernameParameter the username parameter + * @return the view */ @PreAuthorize("isAuthenticated()") @GetMapping("/view/{name}") - public View getView(@PathVariable("name") String name, - @RequestParam("user") Optional usernameParameter) { + public View getView(@PathVariable("name") String name, @RequestParam("user") Optional usernameParameter) { View view = viewManager.get(usernameParameter.orElse(getCurrentUsername()), name); if (view == null || usernameParameter.isPresent() && !view.isPublicView()) { @@ -101,8 +100,8 @@ public class ViewController extends BaseController { /** * Creates the or update. * - * @param view the user page - * @return the user page + * @param view the view + * @return the view */ @PreAuthorize("isAuthenticated()") @PostMapping("/view") @@ -113,8 +112,7 @@ public class ViewController extends BaseController { viewValidator.validate(view, bindingResult); if (bindingResult.hasErrors()) { - throw new EntityResponseStatusException(bindingResult.getAllErrors(), - HttpStatus.UNPROCESSABLE_ENTITY); + throw new EntityResponseStatusException(bindingResult.getAllErrors(), HttpStatus.UNPROCESSABLE_ENTITY); } if (!viewManager.exists(getCurrentUsername(), view.getName()) @@ -126,7 +124,7 @@ public class ViewController extends BaseController { } /** - * Delete user page. + * Delete view. * * @param name the name */ 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 6f41553..6580a2a 100644 --- a/src/main/java/de/bstly/board/controller/model/EntryFilter.java +++ b/src/main/java/de/bstly/board/controller/model/EntryFilter.java @@ -96,28 +96,36 @@ public class EntryFilter { } /** - * @return the fixedTags + * Gets the fixed tags. + * + * @return the fixed tags */ public List getFixedTags() { return fixedTags; } /** - * @param fixedTags the fixedTags to set + * Sets the fixed tags. + * + * @param fixedTags the new fixed tags */ public void setFixedTags(List fixedTags) { this.fixedTags = fixedTags; } /** - * @return the fixedExcludedTags + * Gets the fixed excluded tags. + * + * @return the fixed excluded tags */ public List getFixedExcludedTags() { return fixedExcludedTags; } /** - * @param fixedExcludedTags the fixedExcludedTags to set + * Sets the fixed excluded tags. + * + * @param fixedExcludedTags the new fixed excluded tags */ public void setFixedExcludedTags(List fixedExcludedTags) { this.fixedExcludedTags = fixedExcludedTags; diff --git a/src/main/java/de/bstly/board/controller/support/ControllerExceptionHandler.java b/src/main/java/de/bstly/board/controller/support/ControllerExceptionHandler.java index 1e80917..7b23cb5 100644 --- a/src/main/java/de/bstly/board/controller/support/ControllerExceptionHandler.java +++ b/src/main/java/de/bstly/board/controller/support/ControllerExceptionHandler.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; - /** * The Class ControllerExceptionHandler. */ @@ -21,15 +20,15 @@ public class ControllerExceptionHandler extends ResponseEntityExceptionHandler { * Handle response entity status exception. * * @param exception the exception - * @param request the request + * @param request the request * @return the response entity */ @ExceptionHandler(value = { EntityResponseStatusException.class }) protected ResponseEntity handleResponseEntityStatusException(RuntimeException exception, WebRequest request) { EntityResponseStatusException entityResponseStatusException = (EntityResponseStatusException) exception; - return handleExceptionInternal(exception, entityResponseStatusException.getBody(), - new HttpHeaders(), entityResponseStatusException.getStatus(), request); + return handleExceptionInternal(exception, entityResponseStatusException.getBody(), new HttpHeaders(), + entityResponseStatusException.getStatus(), request); } } diff --git a/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java b/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java index 75a3823..caab719 100644 --- a/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java +++ b/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java @@ -10,19 +10,15 @@ import org.springframework.core.NestedRuntimeException; import org.springframework.http.HttpStatus; import org.springframework.util.Assert; - /** * The Class EntityResponseStatusException. */ public class EntityResponseStatusException extends NestedRuntimeException { - private static final long serialVersionUID = 1L; - private final HttpStatus status; - @Nullable private final Object body; @@ -38,7 +34,7 @@ public class EntityResponseStatusException extends NestedRuntimeException { /** * Instantiates a new entity response status exception. * - * @param body the body + * @param body the body * @param status the status */ public EntityResponseStatusException(@Nullable Object body, HttpStatus status) { @@ -48,9 +44,9 @@ public class EntityResponseStatusException extends NestedRuntimeException { /** * Instantiates a new entity response status exception. * - * @param body the body + * @param body the body * @param status the status - * @param cause the cause + * @param cause the cause */ public EntityResponseStatusException(@Nullable Object body, HttpStatus status, @Nullable Throwable cause) { super(null, cause); @@ -78,7 +74,6 @@ public class EntityResponseStatusException extends NestedRuntimeException { return this.body; } - /* * @see org.springframework.core.NestedRuntimeException#getMessage() */ diff --git a/src/main/java/de/bstly/board/controller/support/JsonStringBodyControllerAdvice.java b/src/main/java/de/bstly/board/controller/support/JsonStringBodyControllerAdvice.java index f93b0bb..f650b45 100644 --- a/src/main/java/de/bstly/board/controller/support/JsonStringBodyControllerAdvice.java +++ b/src/main/java/de/bstly/board/controller/support/JsonStringBodyControllerAdvice.java @@ -29,9 +29,10 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon private Gson gson = new Gson(); - /* - * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice#supports(org.springframework.core.MethodParameter, java.lang.reflect.Type, java.lang.Class) + * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice# + * supports(org.springframework.core.MethodParameter, java.lang.reflect.Type, + * java.lang.Class) */ @Override public boolean supports(MethodParameter methodParameter, Type targetType, @@ -39,9 +40,11 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon return targetType instanceof Class && String.class.equals((Class) targetType); } - /* - * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice#beforeBodyRead(org.springframework.http.HttpInputMessage, org.springframework.core.MethodParameter, java.lang.reflect.Type, java.lang.Class) + * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice# + * beforeBodyRead(org.springframework.http.HttpInputMessage, + * org.springframework.core.MethodParameter, java.lang.reflect.Type, + * java.lang.Class) */ @Override public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, @@ -49,9 +52,11 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon return inputMessage; } - /* - * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice#afterBodyRead(java.lang.Object, org.springframework.http.HttpInputMessage, org.springframework.core.MethodParameter, java.lang.reflect.Type, java.lang.Class) + * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice# + * afterBodyRead(java.lang.Object, org.springframework.http.HttpInputMessage, + * org.springframework.core.MethodParameter, java.lang.reflect.Type, + * java.lang.Class) */ @Override public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, @@ -60,9 +65,11 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon return body; } - /* - * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice#handleEmptyBody(java.lang.Object, org.springframework.http.HttpInputMessage, org.springframework.core.MethodParameter, java.lang.reflect.Type, java.lang.Class) + * @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice# + * handleEmptyBody(java.lang.Object, org.springframework.http.HttpInputMessage, + * org.springframework.core.MethodParameter, java.lang.reflect.Type, + * java.lang.Class) */ @Override public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, @@ -70,18 +77,23 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon return body; } - /* - * @see org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice#supports(org.springframework.core.MethodParameter, java.lang.Class) + * @see + * org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice# + * supports(org.springframework.core.MethodParameter, java.lang.Class) */ @Override public boolean supports(MethodParameter returnType, Class> converterType) { return converterType == StringHttpMessageConverter.class; } - /* - * @see org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice#beforeBodyWrite(java.lang.Object, org.springframework.core.MethodParameter, org.springframework.http.MediaType, java.lang.Class, org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse) + * @see + * org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice# + * beforeBodyWrite(java.lang.Object, org.springframework.core.MethodParameter, + * org.springframework.http.MediaType, java.lang.Class, + * org.springframework.http.server.ServerHttpRequest, + * org.springframework.http.server.ServerHttpResponse) */ @Override public String beforeBodyWrite(String body, MethodParameter returnType, MediaType selectedContentType, diff --git a/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java b/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java index 841efdf..5757f73 100644 --- a/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java +++ b/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java @@ -6,14 +6,12 @@ package de.bstly.board.controller.support; import org.springframework.lang.Nullable; import org.springframework.validation.AbstractBindingResult; - /** * The Class RequestBodyErrors. */ @SuppressWarnings("serial") public class RequestBodyErrors extends AbstractBindingResult { - @Nullable private final Object target; @@ -35,9 +33,10 @@ public class RequestBodyErrors extends AbstractBindingResult { return target; } - /* - * @see org.springframework.validation.AbstractBindingResult#getActualFieldValue(java.lang.String) + * @see + * org.springframework.validation.AbstractBindingResult#getActualFieldValue(java + * .lang.String) */ @Override protected Object getActualFieldValue(String field) { diff --git a/src/main/java/de/bstly/board/controller/validation/CommentValidator.java b/src/main/java/de/bstly/board/controller/validation/CommentValidator.java index 5d83770..538204d 100644 --- a/src/main/java/de/bstly/board/controller/validation/CommentValidator.java +++ b/src/main/java/de/bstly/board/controller/validation/CommentValidator.java @@ -13,7 +13,6 @@ import de.bstly.board.businesslogic.CommentManager; import de.bstly.board.businesslogic.EntryManager; import de.bstly.board.model.Comment; - /** * The Class CommentValidator. */ @@ -25,7 +24,6 @@ public class CommentValidator implements Validator { @Autowired private EntryManager entryManager; - /* * @see org.springframework.validation.Validator#supports(java.lang.Class) */ @@ -34,9 +32,9 @@ public class CommentValidator implements Validator { return clazz.isAssignableFrom(Comment.class); } - /* - * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) + * @see org.springframework.validation.Validator#validate(java.lang.Object, + * org.springframework.validation.Errors) */ @Override public void validate(Object target, Errors errors) { 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 59993f0..af8f5b7 100644 --- a/src/main/java/de/bstly/board/controller/validation/EntryValidator.java +++ b/src/main/java/de/bstly/board/controller/validation/EntryValidator.java @@ -41,11 +41,9 @@ public class EntryValidator implements Validator { if (entry.getEntryType() == null) { errors.rejectValue("entrytype", "REQUIRED"); - } else if (EntryType.LINK.equals(entry.getEntryType()) - && !StringUtils.hasText(entry.getUrl())) { + } else if (EntryType.LINK.equals(entry.getEntryType()) && !StringUtils.hasText(entry.getUrl())) { errors.rejectValue("url", "REQUIRED"); - } else if (!EntryType.LINK.equals(entry.getEntryType()) - && !StringUtils.hasText(entry.getText())) { + } else if (!EntryType.LINK.equals(entry.getEntryType()) && !StringUtils.hasText(entry.getText())) { errors.rejectValue("text", "REQUIRED"); } diff --git a/src/main/java/de/bstly/board/events/VotedEvent.java b/src/main/java/de/bstly/board/events/VotedEvent.java index 16df668..8ca0fa6 100644 --- a/src/main/java/de/bstly/board/events/VotedEvent.java +++ b/src/main/java/de/bstly/board/events/VotedEvent.java @@ -7,13 +7,11 @@ import org.springframework.context.ApplicationEvent; import de.bstly.board.model.Vote; - /** * The Class VotedEvent. */ public class VotedEvent extends ApplicationEvent { - private static final long serialVersionUID = 1L; /** diff --git a/src/main/java/de/bstly/board/i18n/businesslogic/I18nManager.java b/src/main/java/de/bstly/board/i18n/businesslogic/I18nManager.java index 9ca14b4..a49c26c 100644 --- a/src/main/java/de/bstly/board/i18n/businesslogic/I18nManager.java +++ b/src/main/java/de/bstly/board/i18n/businesslogic/I18nManager.java @@ -28,25 +28,20 @@ import com.google.gson.JsonParser; import de.bstly.board.i18n.model.I18n; import de.bstly.board.i18n.repository.I18nRepository; - /** * The Class I18nManager. */ @Component public class I18nManager implements SmartInitializingSingleton { - - + private Logger logger = LoggerFactory.getLogger(I18nManager.class); - @Autowired private I18nRepository i18nRepository; - - + @Autowired private ResourceLoader resourceLoader; - - + private Gson gson = new Gson(); /** @@ -90,7 +85,7 @@ public class I18nManager implements SmartInitializingSingleton { * Extend json object. * * @param dest the dest - * @param src the src + * @param src the src */ protected void extendJsonObject(JsonObject dest, JsonObject src) { for (Entry srcEntry : src.entrySet()) { @@ -112,7 +107,7 @@ public class I18nManager implements SmartInitializingSingleton { /** * Adds the label. * - * @param locale the locale + * @param locale the locale * @param newLabel the new label * @return the i 18 n */ @@ -136,7 +131,7 @@ public class I18nManager implements SmartInitializingSingleton { * Sets the label. * * @param locale the locale - * @param label the label + * @param label the label * @return the i 18 n */ public I18n setLabel(String locale, JsonObject label) { @@ -158,9 +153,9 @@ public class I18nManager implements SmartInitializingSingleton { } } - /* - * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated() + * @see org.springframework.beans.factory.SmartInitializingSingleton# + * afterSingletonsInstantiated() */ @Override public void afterSingletonsInstantiated() { @@ -171,8 +166,7 @@ public class I18nManager implements SmartInitializingSingleton { File labelFolder = resource.getFile(); if (labelFolder.exists() && labelFolder.isDirectory()) { for (File labelFile : labelFolder.listFiles()) { - JsonObject label = JsonParser - .parseReader(new FileReader(labelFile, StandardCharsets.UTF_8)) + JsonObject label = JsonParser.parseReader(new FileReader(labelFile, StandardCharsets.UTF_8)) .getAsJsonObject(); String locale = labelFile.getName().replace(".json", ""); diff --git a/src/main/java/de/bstly/board/i18n/controller/I18nController.java b/src/main/java/de/bstly/board/i18n/controller/I18nController.java index aca3f2c..5d84bfd 100644 --- a/src/main/java/de/bstly/board/i18n/controller/I18nController.java +++ b/src/main/java/de/bstly/board/i18n/controller/I18nController.java @@ -27,7 +27,6 @@ import com.google.gson.JsonObject; import de.bstly.board.controller.BaseController; import de.bstly.board.i18n.businesslogic.I18nManager; - /** * The Class I18nController. */ @@ -35,11 +34,9 @@ import de.bstly.board.i18n.businesslogic.I18nManager; @RequestMapping("/i18n") public class I18nController extends BaseController { - @Autowired private I18nManager i18nManager; - - + private Gson gson = new Gson(); /** @@ -55,11 +52,11 @@ public class I18nController extends BaseController { /** * Gets the label. * - * @param locale the locale + * @param locale the locale * @param response the response * @return the label * @throws JsonIOException the json IO exception - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. */ @GetMapping("/{locale}") public void getLabel(@PathVariable("locale") String locale, HttpServletResponse response) @@ -75,7 +72,7 @@ public class I18nController extends BaseController { * Sets the label. * * @param locale the locale - * @param label the label + * @param label the label */ @PreAuthorize("hasRole('ROLE_ADMIN')") @PostMapping("/{locale}") @@ -91,7 +88,7 @@ public class I18nController extends BaseController { * Adds the label. * * @param locale the locale - * @param label the label + * @param label the label */ @PreAuthorize("hasRole('ROLE_ADMIN')") @PutMapping("/{locale}") diff --git a/src/main/java/de/bstly/board/i18n/model/I18n.java b/src/main/java/de/bstly/board/i18n/model/I18n.java index 4217661..15eb780 100644 --- a/src/main/java/de/bstly/board/i18n/model/I18n.java +++ b/src/main/java/de/bstly/board/i18n/model/I18n.java @@ -10,7 +10,6 @@ import javax.persistence.Lob; import javax.persistence.Table; import javax.persistence.UniqueConstraint; - /** * The Class I18n. */ @@ -18,12 +17,10 @@ import javax.persistence.UniqueConstraint; @Table(name = "i18n", uniqueConstraints = @UniqueConstraint(columnNames = { "locale" })) public class I18n { - @Id @Column(name = "locale", unique = true, nullable = false) private String locale; - @Lob @Column(name = "label") private String label; diff --git a/src/main/java/de/bstly/board/i18n/repository/I18nRepository.java b/src/main/java/de/bstly/board/i18n/repository/I18nRepository.java index 27c1fb4..c5e93d5 100644 --- a/src/main/java/de/bstly/board/i18n/repository/I18nRepository.java +++ b/src/main/java/de/bstly/board/i18n/repository/I18nRepository.java @@ -13,7 +13,6 @@ import de.bstly.board.i18n.model.I18n; * The Interface I18nRepository. */ @Repository -public interface I18nRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface I18nRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/src/main/java/de/bstly/board/model/Comment.java b/src/main/java/de/bstly/board/model/Comment.java index fbfcd18..10202bc 100644 --- a/src/main/java/de/bstly/board/model/Comment.java +++ b/src/main/java/de/bstly/board/model/Comment.java @@ -217,6 +217,8 @@ public class Comment { } /** + * Gets the type. + * * @return the type */ public Types getType() { diff --git a/src/main/java/de/bstly/board/model/Entry.java b/src/main/java/de/bstly/board/model/Entry.java index b6aab1a..569d8d3 100644 --- a/src/main/java/de/bstly/board/model/Entry.java +++ b/src/main/java/de/bstly/board/model/Entry.java @@ -327,6 +327,8 @@ public class Entry { } /** + * Gets the type. + * * @return the type */ public Types getType() { diff --git a/src/main/java/de/bstly/board/model/LocalUser.java b/src/main/java/de/bstly/board/model/LocalUser.java index 9edb592..6d946ae 100644 --- a/src/main/java/de/bstly/board/model/LocalUser.java +++ b/src/main/java/de/bstly/board/model/LocalUser.java @@ -247,6 +247,8 @@ public class LocalUser { } /** + * Gets the type. + * * @return the type */ public Types getType() { diff --git a/src/main/java/de/bstly/board/model/Tag.java b/src/main/java/de/bstly/board/model/Tag.java index ee111cb..9169948 100644 --- a/src/main/java/de/bstly/board/model/Tag.java +++ b/src/main/java/de/bstly/board/model/Tag.java @@ -41,7 +41,7 @@ public class Tag implements Serializable { /** * Instantiates a new tag. * - * @param tag the tag + * @param tag the tag * @param target the target */ public Tag(String tag, Long target) { diff --git a/src/main/java/de/bstly/board/model/View.java b/src/main/java/de/bstly/board/model/View.java index af268d3..cbde5b9 100644 --- a/src/main/java/de/bstly/board/model/View.java +++ b/src/main/java/de/bstly/board/model/View.java @@ -133,6 +133,8 @@ public class View { } /** + * Gets the index. + * * @return the index */ public int getIndex() { @@ -140,7 +142,9 @@ public class View { } /** - * @param index the index to set + * Sets the index. + * + * @param index the new index */ public void setIndex(int index) { this.index = index; @@ -201,28 +205,36 @@ public class View { } /** - * @return the publicView + * Checks if is public view. + * + * @return true, if is public view */ public boolean isPublicView() { return publicView; } /** - * @param publicView the publicView to set + * Sets the public view. + * + * @param publicView the new public view */ public void setPublicView(boolean publicView) { this.publicView = publicView; } /** - * @return the divider + * Checks if is divider. + * + * @return true, if is divider */ public boolean isDivider() { return divider; } /** - * @param divider the divider to set + * Sets the divider. + * + * @param divider the new divider */ 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 83ca0e0..130a4c9 100644 --- a/src/main/java/de/bstly/board/model/Vote.java +++ b/src/main/java/de/bstly/board/model/Vote.java @@ -16,7 +16,6 @@ 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. */ @@ -24,7 +23,7 @@ import de.bstly.board.model.support.VoteType; @Table(name = "votes") @EntityListeners({ AuditingEntityListener.class }) public class Vote { - + @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") diff --git a/src/main/java/de/bstly/board/model/support/InstantValueBridge.java b/src/main/java/de/bstly/board/model/support/InstantValueBridge.java index fe77e3d..cb9a452 100644 --- a/src/main/java/de/bstly/board/model/support/InstantValueBridge.java +++ b/src/main/java/de/bstly/board/model/support/InstantValueBridge.java @@ -15,7 +15,10 @@ import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValue 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) + * @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) { @@ -23,7 +26,10 @@ public class InstantValueBridge implements ValueBridge { } /* - * @see org.hibernate.search.mapper.pojo.bridge.ValueBridge#fromIndexedValue(java.lang.Object, org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeFromIndexedValueContext) + * @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) { diff --git a/src/main/java/de/bstly/board/repository/BookmarksRepository.java b/src/main/java/de/bstly/board/repository/BookmarksRepository.java index 295e266..69f5dc7 100644 --- a/src/main/java/de/bstly/board/repository/BookmarksRepository.java +++ b/src/main/java/de/bstly/board/repository/BookmarksRepository.java @@ -13,7 +13,6 @@ import de.bstly.board.model.Bookmarks; * The Interface BookmarksRepository. */ @Repository -public interface BookmarksRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface BookmarksRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/src/main/java/de/bstly/board/repository/CommentRepository.java b/src/main/java/de/bstly/board/repository/CommentRepository.java index 281562a..c9249a4 100644 --- a/src/main/java/de/bstly/board/repository/CommentRepository.java +++ b/src/main/java/de/bstly/board/repository/CommentRepository.java @@ -13,6 +13,5 @@ import de.bstly.board.model.Comment; * The Interface CommentRepository. */ @Repository -public interface CommentRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface CommentRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/src/main/java/de/bstly/board/repository/EntryRepository.java b/src/main/java/de/bstly/board/repository/EntryRepository.java index 805fd28..0f41a45 100644 --- a/src/main/java/de/bstly/board/repository/EntryRepository.java +++ b/src/main/java/de/bstly/board/repository/EntryRepository.java @@ -13,7 +13,6 @@ import de.bstly.board.model.Entry; * The Interface EntryRepository. */ @Repository -public interface EntryRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface EntryRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/src/main/java/de/bstly/board/repository/LocalUserRepository.java b/src/main/java/de/bstly/board/repository/LocalUserRepository.java index b499cb2..edf6456 100644 --- a/src/main/java/de/bstly/board/repository/LocalUserRepository.java +++ b/src/main/java/de/bstly/board/repository/LocalUserRepository.java @@ -13,7 +13,6 @@ import de.bstly.board.model.LocalUser; * The Interface LocalUserRepository. */ @Repository -public interface LocalUserRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface LocalUserRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/src/main/java/de/bstly/board/repository/ViewRepository.java b/src/main/java/de/bstly/board/repository/ViewRepository.java index 5f75cfd..7ca1983 100644 --- a/src/main/java/de/bstly/board/repository/ViewRepository.java +++ b/src/main/java/de/bstly/board/repository/ViewRepository.java @@ -13,7 +13,6 @@ import de.bstly.board.model.View; * The Interface ViewRepository. */ @Repository -public interface ViewRepository - extends JpaRepository, QuerydslPredicateExecutor { +public interface ViewRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/src/main/java/de/bstly/board/security/LocalRememberMeServices.java b/src/main/java/de/bstly/board/security/LocalRememberMeServices.java index c966312..2ee48ff 100644 --- a/src/main/java/de/bstly/board/security/LocalRememberMeServices.java +++ b/src/main/java/de/bstly/board/security/LocalRememberMeServices.java @@ -9,7 +9,6 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices; import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository; - /** * The Class LocalRememberMeServices. */ @@ -18,18 +17,19 @@ public class LocalRememberMeServices extends PersistentTokenBasedRememberMeServi /** * Instantiates a new local remember me services. * - * @param key the key + * @param key the key * @param userDetailsService the user details service - * @param tokenRepository the token repository + * @param tokenRepository the token repository */ public LocalRememberMeServices(String key, UserDetailsService userDetailsService, PersistentTokenRepository tokenRepository) { super(key, userDetailsService, tokenRepository); } - /* - * @see org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices#rememberMeRequested(javax.servlet.http.HttpServletRequest, java.lang.String) + * @see org.springframework.security.web.authentication.rememberme. + * AbstractRememberMeServices#rememberMeRequested(javax.servlet.http. + * HttpServletRequest, java.lang.String) */ @Override protected boolean rememberMeRequested(HttpServletRequest request, String parameter) { diff --git a/src/main/java/de/bstly/board/security/LocalUserDetails.java b/src/main/java/de/bstly/board/security/LocalUserDetails.java index df6ffe8..64e8668 100644 --- a/src/main/java/de/bstly/board/security/LocalUserDetails.java +++ b/src/main/java/de/bstly/board/security/LocalUserDetails.java @@ -21,12 +21,11 @@ public class LocalUserDetails extends User { /** * Instantiates a new local user details. * - * @param username the username - * @param password the password + * @param username the username + * @param password the password * @param authorities the authorities */ - public LocalUserDetails(String username, String password, - Collection authorities) { + public LocalUserDetails(String username, String password, Collection authorities) { super(username, password, authorities); } diff --git a/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java b/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java index 6565577..49222a2 100644 --- a/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java +++ b/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java @@ -29,17 +29,18 @@ import de.bstly.board.model.LocalUser; * The Class OAuth2AuthenticationSuccessHandler. */ @Component -public class OAuth2AuthenticationSuccessHandler - extends SavedRequestAwareAuthenticationSuccessHandler { +public class OAuth2AuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { @Autowired private UserManager localUserManager; private RememberMeServices rememberMeServices; - /* - * @see org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler#onAuthenticationSuccess(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.springframework.security.core.Authentication) + * @see org.springframework.security.web.authentication. + * SavedRequestAwareAuthenticationSuccessHandler#onAuthenticationSuccess(javax. + * servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, + * org.springframework.security.core.Authentication) */ @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, @@ -52,8 +53,8 @@ public class OAuth2AuthenticationSuccessHandler authorities.addAll(authentication.getAuthorities()); authorities.addAll(userDetails.getAuthorities()); - UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken( - userDetails, null, authorities); + UsernamePasswordAuthenticationToken newAuthentication = new UsernamePasswordAuthenticationToken(userDetails, + null, authorities); SecurityContextHolder.getContext().setAuthentication(newAuthentication); diff --git a/src/main/java/de/bstly/board/security/SecurityConfig.java b/src/main/java/de/bstly/board/security/SecurityConfig.java index fb31934..644b1b1 100755 --- a/src/main/java/de/bstly/board/security/SecurityConfig.java +++ b/src/main/java/de/bstly/board/security/SecurityConfig.java @@ -51,7 +51,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { private String loginTargetUrl; /* - * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) + * @see org.springframework.security.config.annotation.web.configuration. + * WebSecurityConfigurerAdapter#configure(org.springframework.security.config. + * annotation.web.builders.HttpSecurity) */ /* * @see org.springframework.security.config.annotation.web.configuration. @@ -73,25 +75,20 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .anonymous().disable() // login .formLogin().loginPage("/login").defaultSuccessUrl(loginTargetUrl) - .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl - + "?error")) - .and() + .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?error")).and() // remember me .rememberMe().rememberMeServices(rememberMeServices()).and() // logout .logout().logoutUrl("/logout") - .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)) - .and() + .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)).and() // exception .exceptionHandling() - .defaultAuthenticationEntryPointFor( - new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED), + .defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED), new AntPathRequestMatcher("/api/**")) .and() // oidc .oauth2Login().successHandler(oAuth2AuthenticationSuccessHandler) - .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl - + "?externalError")) + .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?externalError")) .loginPage("/login"); } @@ -124,8 +121,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { */ @Bean public RememberMeServices rememberMeServices() { - PersistentTokenBasedRememberMeServices rememberMeServices = new LocalRememberMeServices( - "remember-me", localUserManager, persistentTokenRepository()); + PersistentTokenBasedRememberMeServices rememberMeServices = new LocalRememberMeServices("remember-me", + localUserManager, persistentTokenRepository()); return rememberMeServices; }