update dependencies, javadoc, formatting
This commit is contained in:
parent
628980db7f
commit
d3b2a95472
6
pom.xml
6
pom.xml
@ -10,14 +10,14 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>11</java.version>
|
||||
<log4j2.version>2.16.0</log4j2.version>
|
||||
<revision>1.3.3</revision>
|
||||
<log4j2.version>2.17.2</log4j2.version>
|
||||
<revision>1.4.0</revision>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.5.5</version>
|
||||
<version>2.6.6</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<Comment> fetchByDate(String username, Long target, Long parent, Instant date,
|
||||
int page, int size, boolean desc) {
|
||||
public Page<Comment> 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<Comment> fetchFlagged(int page, int size, boolean asc) {
|
||||
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
|
||||
JPAQuery<Comment> query = jpaQueryFactory.selectFrom(qComment).leftJoin(qFlag)
|
||||
.on(qComment.id.eq(qFlag.target)).where(qFlag.targetType.eq(Types.comment))
|
||||
.groupBy(qFlag.target);
|
||||
JPAQuery<Comment> query = jpaQueryFactory.selectFrom(qComment).leftJoin(qFlag).on(qComment.id.eq(qFlag.target))
|
||||
.where(qFlag.targetType.eq(Types.comment)).groupBy(qFlag.target);
|
||||
|
||||
JPAQuery<Long> countQuery = query.clone().select(qComment.id.countDistinct());
|
||||
|
||||
return new PageImpl<Comment>(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<Comment> fetchByUsername(String username, Instant date, int page, int size,
|
||||
boolean asc) {
|
||||
public Page<Comment> 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<String> 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<Comment> entries, List<String> 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;
|
||||
}
|
||||
|
||||
|
@ -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<Entry> fetchByRanking(String username, EntryFilter filter, float gravity, int page,
|
||||
int size, boolean asc) {
|
||||
public Page<Entry> 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<Entry> 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<Entry> 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<Entry> fetchByComments(String username, EntryFilter filter, float gravity,
|
||||
int page, int size, boolean asc) {
|
||||
public Page<Entry> 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<Entry> fetchByLastComment(String username, EntryFilter filter, int page, int size,
|
||||
boolean asc) {
|
||||
public Page<Entry> 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<Entry> fetchByUser(String fromUser, String username, EntryFilter filter, int page,
|
||||
int size, boolean asc) {
|
||||
public Page<Entry> 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<Entry> fetchFlagged(int page, int size, boolean asc) {
|
||||
Sort sort = Sort.by(asc ? Order.asc("created") : Order.desc("created"));
|
||||
JPAQuery<Entry> query = jpaQueryFactory.selectFrom(qEntry).leftJoin(qFlag)
|
||||
.on(qEntry.id.eq(qFlag.target)).where(qFlag.targetType.eq(Types.entry))
|
||||
.groupBy(qFlag.target);
|
||||
JPAQuery<Entry> query = jpaQueryFactory.selectFrom(qEntry).leftJoin(qFlag).on(qEntry.id.eq(qFlag.target))
|
||||
.where(qFlag.targetType.eq(Types.entry)).groupBy(qFlag.target);
|
||||
|
||||
JPAQuery<Long> countQuery = query.clone().select(qEntry.id.countDistinct());
|
||||
|
||||
return new PageImpl<Entry>(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<Entry> 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<String> 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<Entry> entries,
|
||||
List<String> ignore) {
|
||||
public void applyMetadata(String username, long karma, List<Entry> entries, List<String> 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
|
||||
*/
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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<Object> search(List<Types> types, String search, int page, int size,
|
||||
boolean asc, boolean sortByDate) {
|
||||
public SearchResult<Object> search(List<Types> types, String search, int page, int size, boolean asc,
|
||||
boolean sortByDate) {
|
||||
List<Class<? extends Object>> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<String> 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<String> tags) {
|
||||
deleteByTarget(target);
|
||||
@ -89,8 +88,8 @@ public class TagManager {
|
||||
* @return the list
|
||||
*/
|
||||
public List<String> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<View> 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();
|
||||
|
@ -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))));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -58,18 +58,13 @@ public class AuthenticationController extends BaseController {
|
||||
public List<Client> getExternalLoginUrls() {
|
||||
List<Client> clients = Lists.newArrayList();
|
||||
Iterable<ClientRegistration> 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<ClientRegistration>) 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) {
|
||||
|
@ -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"));
|
||||
|
||||
|
@ -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<Entry> entries = entryManager.fetchByBookmarks(getCurrentUsername(),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
|
||||
Page<Entry> entries = entryManager.fetchByBookmarks(getCurrentUsername(), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize()));
|
||||
|
||||
List<String> ignore = ignoreParameter.orElse(Lists.newArrayList());
|
||||
entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()),
|
||||
|
@ -66,8 +66,7 @@ public class CommentController extends BaseController {
|
||||
*/
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping({ "/new/{target}", "/new/{target}/{parent}" })
|
||||
public Page<Comment> fetchByDate(@PathVariable("target") Long target,
|
||||
@PathVariable("parent") Optional<Long> parent,
|
||||
public Page<Comment> fetchByDate(@PathVariable("target") Long target, @PathVariable("parent") Optional<Long> parent,
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("date") Optional<Instant> dateParameter,
|
||||
@ -81,8 +80,8 @@ public class CommentController extends BaseController {
|
||||
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
|
||||
dateParameter = Optional.of(Instant.now());
|
||||
}
|
||||
Page<Comment> comments = commentManager.fetchByDate(getCurrentUsername(), target,
|
||||
parent.orElse(null), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
|
||||
Page<Comment> comments = commentManager.fetchByDate(getCurrentUsername(), target, parent.orElse(null),
|
||||
dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false));
|
||||
|
||||
List<String> ignore = ignoreParameter.orElse(Lists.newArrayList("entry"));
|
||||
@ -106,8 +105,7 @@ public class CommentController extends BaseController {
|
||||
public Page<Comment> fetchByUsername(@PathVariable("username") String username,
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("date") Optional<Instant> dateParameter,
|
||||
@RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@RequestParam("ignore") Optional<List<String>> ignoreParameter) {
|
||||
|
||||
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
|
||||
@ -118,9 +116,9 @@ public class CommentController extends BaseController {
|
||||
dateParameter = Optional.of(Instant.now());
|
||||
}
|
||||
|
||||
Page<Comment> comments = commentManager.fetchByUsername(username,
|
||||
dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));
|
||||
Page<Comment> comments = commentManager.fetchByUsername(username, dateParameter.orElse(Instant.now()),
|
||||
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()),
|
||||
ascParameter.orElse(false));
|
||||
List<String> 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<Long> parent) {
|
||||
public Long countComments(@PathVariable("target") Long target, @PathVariable("parent") Optional<Long> 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());
|
||||
|
@ -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() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Boolean> ascParameter,
|
||||
@RequestParam("ignore") Optional<List<String>> 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<Entry> entries = entryManager.fetchByUser(getCurrentUsername(), username, filter,
|
||||
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()),
|
||||
ascParameter.orElse(false));
|
||||
Page<Entry> entries = entryManager.fetchByUser(getCurrentUsername(), username, filter, pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));
|
||||
List<String> 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<List<String>> ignoreParameter) {
|
||||
public Entry getEntry(@PathVariable("id") Long id, @RequestParam("ignore") Optional<List<String>> ignoreParameter) {
|
||||
Entry entry = entryManager.get(id);
|
||||
|
||||
if (entry == null) {
|
||||
@ -231,8 +227,7 @@ public class EntryController extends BaseController {
|
||||
}
|
||||
|
||||
List<String> 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<List<String>> ignoreParameter) {
|
||||
public Entry createEntry(@RequestBody Entry entry, @RequestParam("ignore") Optional<List<String>> 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<String> 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<List<String>> ignoreParameter) {
|
||||
public Entry updateEntry(@RequestBody Entry entry, @RequestParam("ignore") Optional<List<String>> 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<String> 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("<title>") + 7,
|
||||
responseBody.indexOf("</title>"));
|
||||
return responseBody.substring(responseBody.indexOf("<title>") + 7, responseBody.indexOf("</title>"));
|
||||
} catch (IOException ex) {
|
||||
} finally {
|
||||
try {
|
||||
|
@ -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<Comment> getFlaggedComments(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@RequestParam("ignore") Optional<List<String>> 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<Entry> getFlaggedEntries(@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter, @RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@RequestParam("ignore") Optional<List<String>> ignoreParameter) {
|
||||
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
|
||||
sizeParameter = Optional.of(100);
|
||||
@ -96,7 +94,8 @@ public class ModerationController extends BaseController {
|
||||
|
||||
Page<Entry> entries = entryManager.fetchFlagged(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));
|
||||
List<String> ignore = ignoreParameter.orElse(Lists.newArrayList("flag", "unflag", "bookmark", "removeBookmark"));
|
||||
List<String> ignore = ignoreParameter
|
||||
.orElse(Lists.newArrayList("flag", "unflag", "bookmark", "removeBookmark"));
|
||||
entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()),
|
||||
entries.getContent(), ignore);
|
||||
return entries;
|
||||
|
@ -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<Object> search(@RequestParam("q") String searchParameter,
|
||||
@RequestParam("type") Optional<String> typeParameter,
|
||||
@RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("type") Optional<String> typeParameter, @RequestParam("page") Optional<Integer> pageParameter,
|
||||
@RequestParam("size") Optional<Integer> sizeParameter,
|
||||
@RequestParam("byDate") Optional<Boolean> byDateParameter,
|
||||
@RequestParam("asc") Optional<Boolean> ascParameter,
|
||||
@ -89,21 +88,20 @@ public class SearchController extends BaseController {
|
||||
break;
|
||||
}
|
||||
|
||||
SearchResult<Object> result = searchManager.search(types, searchParameter,
|
||||
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()),
|
||||
ascParameter.orElse(false), byDateParameter.orElse(false));
|
||||
SearchResult<Object> result = searchManager.search(types, searchParameter, pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false),
|
||||
byDateParameter.orElse(false));
|
||||
|
||||
Page<Object> objects = new PageImpl<Object>(result.hits(),
|
||||
PageRequest.of(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(settingsManager.getPageSize())),
|
||||
PageRequest.of(pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())),
|
||||
result.total().hitCount());
|
||||
|
||||
List<String> 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);
|
||||
}
|
||||
|
@ -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<String> ignore = ignoreParameter.orElse(Lists.newArrayList());
|
||||
entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()),
|
||||
entry, ignore);
|
||||
entryManager.applyMetadata(getCurrentUsername(), userManager.getKarma(getCurrentUsername()), entry, ignore);
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Integer> sizeParameter,
|
||||
@RequestParam("desc") Optional<Boolean> 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<String> usernameParameter) {
|
||||
public View getView(@PathVariable("name") String name, @RequestParam("user") Optional<String> 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
|
||||
*/
|
||||
|
@ -96,28 +96,36 @@ public class EntryFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fixedTags
|
||||
* Gets the fixed tags.
|
||||
*
|
||||
* @return the fixed tags
|
||||
*/
|
||||
public List<String> getFixedTags() {
|
||||
return fixedTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fixedTags the fixedTags to set
|
||||
* Sets the fixed tags.
|
||||
*
|
||||
* @param fixedTags the new fixed tags
|
||||
*/
|
||||
public void setFixedTags(List<String> fixedTags) {
|
||||
this.fixedTags = fixedTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fixedExcludedTags
|
||||
* Gets the fixed excluded tags.
|
||||
*
|
||||
* @return the fixed excluded tags
|
||||
*/
|
||||
public List<String> 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<String> fixedExcludedTags) {
|
||||
this.fixedExcludedTags = fixedExcludedTags;
|
||||
|
@ -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<Object> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
*/
|
||||
|
@ -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<? extends HttpMessageConverter<?>> 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,
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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<String, JsonElement> 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", "");
|
||||
|
@ -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}")
|
||||
|
@ -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;
|
||||
|
@ -13,7 +13,6 @@ import de.bstly.board.i18n.model.I18n;
|
||||
* The Interface I18nRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface I18nRepository
|
||||
extends JpaRepository<I18n, String>, QuerydslPredicateExecutor<I18n> {
|
||||
public interface I18nRepository extends JpaRepository<I18n, String>, QuerydslPredicateExecutor<I18n> {
|
||||
|
||||
}
|
||||
|
@ -217,6 +217,8 @@ public class Comment {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public Types getType() {
|
||||
|
@ -327,6 +327,8 @@ public class Entry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public Types getType() {
|
||||
|
@ -247,6 +247,8 @@ public class LocalUser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public Types getType() {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -15,7 +15,10 @@ import org.hibernate.search.mapper.pojo.bridge.runtime.ValueBridgeToIndexedValue
|
||||
public class InstantValueBridge implements ValueBridge<Instant, String> {
|
||||
|
||||
/*
|
||||
* @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<Instant, String> {
|
||||
}
|
||||
|
||||
/*
|
||||
* @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) {
|
||||
|
@ -13,7 +13,6 @@ import de.bstly.board.model.Bookmarks;
|
||||
* The Interface BookmarksRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface BookmarksRepository
|
||||
extends JpaRepository<Bookmarks, String>, QuerydslPredicateExecutor<Bookmarks> {
|
||||
public interface BookmarksRepository extends JpaRepository<Bookmarks, String>, QuerydslPredicateExecutor<Bookmarks> {
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,5 @@ import de.bstly.board.model.Comment;
|
||||
* The Interface CommentRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface CommentRepository
|
||||
extends JpaRepository<Comment, Long>, QuerydslPredicateExecutor<Comment> {
|
||||
public interface CommentRepository extends JpaRepository<Comment, Long>, QuerydslPredicateExecutor<Comment> {
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import de.bstly.board.model.Entry;
|
||||
* The Interface EntryRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface EntryRepository
|
||||
extends JpaRepository<Entry, Long>, QuerydslPredicateExecutor<Entry> {
|
||||
public interface EntryRepository extends JpaRepository<Entry, Long>, QuerydslPredicateExecutor<Entry> {
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import de.bstly.board.model.LocalUser;
|
||||
* The Interface LocalUserRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface LocalUserRepository
|
||||
extends JpaRepository<LocalUser, String>, QuerydslPredicateExecutor<LocalUser> {
|
||||
public interface LocalUserRepository extends JpaRepository<LocalUser, String>, QuerydslPredicateExecutor<LocalUser> {
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import de.bstly.board.model.View;
|
||||
* The Interface ViewRepository.
|
||||
*/
|
||||
@Repository
|
||||
public interface ViewRepository
|
||||
extends JpaRepository<View, Long>, QuerydslPredicateExecutor<View> {
|
||||
public interface ViewRepository extends JpaRepository<View, Long>, QuerydslPredicateExecutor<View> {
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<? extends GrantedAuthority> authorities) {
|
||||
public LocalUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities) {
|
||||
super(username, password, authorities);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user