summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-08-06 21:34:08 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-08-06 21:35:11 +0200
commit5326f5ef3027ed24666a82a4820a0f4ad3c4d280 (patch)
tree66e0d061927eb99b0e444bf6520b5aec54b9d4e1 /src
parent2b3aff0382643f8c58d183769818ec62acd498d8 (diff)
Revert "De-generics-ize Post, PostText."
This reverts commit 475bf006583288e6544374ba7c5d085f0b4235f2. Change-Id: I78bc6e061c3cd8ecc7c8794168596e26de1e6af8
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java7
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkText.java7
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java9
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessageText.java7
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/newsletter/Newsletter.java2
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java2
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java33
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java12
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java10
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java6
-rw-r--r--src/main/resources/templates/PostResource/postList.html2
11 files changed, 39 insertions, 58 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
index ecfe69c..01e8a99 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
@@ -13,7 +13,7 @@ import javax.annotation.CheckForNull;
@Entity
@Table(name = "bookmarks", schema = "benki")
-public class Bookmark extends Post {
+public class Bookmark extends Post<BookmarkText> {
@Column(name = "uri", nullable = false, length = -1)
public String uri;
@@ -79,9 +79,4 @@ public class Bookmark extends Post {
text.description = x;
text.cachedDescriptionHtml = null;
}
-
- @Override
- public BookmarkText getText() {
- return (BookmarkText) super.getText();
- }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkText.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkText.java
index 300484d..019dce5 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkText.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkText.java
@@ -9,7 +9,7 @@ import javax.annotation.CheckForNull;
@Entity
@Table(name = "bookmark_texts", schema = "benki")
-public class BookmarkText extends PostText {
+public class BookmarkText extends PostText<Bookmark> {
@Column(name = "title", nullable = true, length = -1)
@CheckForNull
@@ -24,9 +24,4 @@ public class BookmarkText extends PostText {
protected String getDescriptionMarkup() {
return description;
}
-
- @Override
- public Bookmark getPost() {
- return (Bookmark) super.getPost();
- }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
index a1d81d5..9181adf 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
@@ -12,7 +12,7 @@ import javax.annotation.CheckForNull;
@Entity
@Table(name = "lazychat_messages", schema = "benki")
-public class LazychatMessage extends Post {
+public class LazychatMessage extends Post<LazychatMessageText> {
@ManyToMany
@JoinTable(
@@ -21,7 +21,7 @@ public class LazychatMessage extends Post {
joinColumns = {@JoinColumn(name = "referrer")},
inverseJoinColumns = {@JoinColumn(name = "referee")})
@JsonbTransient
- public Collection<Post> referees;
+ public Collection<Post<?>> referees;
@CheckForNull
@Override
@@ -57,9 +57,4 @@ public class LazychatMessage extends Post {
text.cachedDescriptionHtml = null;
text.content = x;
}
-
- @Override
- public LazychatMessageText getText() {
- return (LazychatMessageText) super.getText();
- }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessageText.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessageText.java
index ace7529..1a84909 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessageText.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessageText.java
@@ -9,7 +9,7 @@ import javax.annotation.CheckForNull;
@Entity
@Table(name = "lazychat_message_texts", schema = "benki")
-public class LazychatMessageText extends PostText {
+public class LazychatMessageText extends PostText<LazychatMessage> {
@Column(name = "content", nullable = true, length = -1)
@CheckForNull
@@ -21,9 +21,4 @@ public class LazychatMessageText extends PostText {
protected String getDescriptionMarkup() {
return content;
}
-
- @Override
- public LazychatMessage getPost() {
- return (LazychatMessage) super.getPost();
- }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/Newsletter.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/Newsletter.java
index 9c21e69..aaac084 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/Newsletter.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/Newsletter.java
@@ -25,5 +25,5 @@ public class Newsletter extends PanacheEntityBase {
@OneToMany(mappedBy = "newsletter", fetch = FetchType.LAZY)
@OrderBy("date")
- public Collection<Post> posts;
+ public Collection<Post<?>> posts;
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
index 5f7937f..ae1ef9e 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
@@ -53,7 +53,7 @@ public class NewsletterSender {
void run() throws InterruptedException, TimeoutException, ExecutionException {
var session = em.unwrap(Session.class);
- List<Post> posts =
+ List<Post<?>> posts =
Post.find(
"""
SELECT DISTINCT p FROM Post p
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
index 20fcabe..b0aa615 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
@@ -44,6 +44,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.TimeZone;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.hibernate.annotations.Type;
@@ -52,7 +53,7 @@ import org.hibernate.annotations.Where;
@Entity
@Table(name = "posts", schema = "benki")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
-public abstract class Post extends PanacheEntityBase {
+public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
public enum Scope {
top_level,
@@ -118,11 +119,15 @@ public abstract class Post extends PanacheEntityBase {
@JsonbTransient
public Collection<LazychatMessage> comments;
- @OneToMany(mappedBy = "post", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ @OneToMany(
+ mappedBy = "post",
+ fetch = FetchType.LAZY,
+ cascade = CascadeType.ALL,
+ targetEntity = PostText.class)
@MapKey(name = "language")
- public Map<String, PostText> texts = new HashMap<>();
+ public Map<String, Text> texts = new HashMap<>();
- public Map<String, PostText> getTexts() {
+ public Map<String, Text> getTexts() {
return texts;
}
@@ -148,7 +153,7 @@ public abstract class Post extends PanacheEntityBase {
}
}
- protected static <T extends Post> CriteriaBuilder<T> queryViewable(
+ protected static <T extends Post<?>> CriteriaBuilder<T> queryViewable(
Class<T> entityClass,
@CheckForNull User reader,
@CheckForNull User owner,
@@ -241,7 +246,7 @@ public abstract class Post extends PanacheEntityBase {
return scope == Scope.top_level;
}
- public static class Day<T extends Post> {
+ public static class Day<T extends Post<? extends PostText<?>>> {
public final @CheckForNull LocalDate date;
public final List<T> posts;
@@ -257,12 +262,14 @@ public abstract class Post extends PanacheEntityBase {
}
}
- public static class PostPage<T extends Post> {
+ public static class PostPage<T extends Post<? extends PostText<?>>> {
public @CheckForNull final Integer prevCursor;
public @CheckForNull final Integer cursor;
public @CheckForNull final Integer nextCursor;
public final List<T> posts;
+ private static final TimeZone timeZone = TimeZone.getDefault();
+
public PostPage(
@CheckForNull Integer c0,
@CheckForNull Integer c1,
@@ -289,7 +296,7 @@ public abstract class Post extends PanacheEntityBase {
}
}
- public static PostPage<Post> findViewable(
+ public static PostPage<Post<? extends PostText<?>>> findViewable(
PostFilter postFilter,
EntityManager em,
CriteriaBuilderFactory cbf,
@@ -298,7 +305,7 @@ public abstract class Post extends PanacheEntityBase {
return findViewable(postFilter, em, cbf, viewer, owner, null, null, null);
}
- public static PostPage<Post> findViewable(
+ public static PostPage<Post<? extends PostText<?>>> findViewable(
PostFilter postFilter,
EntityManager em,
CriteriaBuilderFactory cbf,
@@ -321,7 +328,7 @@ public abstract class Post extends PanacheEntityBase {
return findViewable(entityClass, em, cbf, viewer, owner, cursor, count, searchQuery);
}
- protected static <T extends Post> PostPage<T> findViewable(
+ protected static <T extends Post<? extends PostText<?>>> PostPage<T> findViewable(
Class<? extends T> entityClass,
EntityManager em,
CriteriaBuilderFactory cbf,
@@ -372,7 +379,7 @@ public abstract class Post extends PanacheEntityBase {
return new PostPage<>(prevCursor, cursor, nextCursor, forwardResults);
}
- public static <T extends Post> void fetchTexts(Collection<T> posts) {
+ public static <T extends Post<?>> void fetchTexts(Collection<T> posts) {
var postIds = posts.stream().map(x -> x.id).collect(toList());
if (!postIds.isEmpty()) {
@@ -382,7 +389,7 @@ public abstract class Post extends PanacheEntityBase {
}
@CheckForNull
- public PostText getText() {
+ public Text getText() {
var texts = getTexts();
if (texts.isEmpty()) {
return null;
@@ -410,7 +417,7 @@ public abstract class Post extends PanacheEntityBase {
if (!(o instanceof Post)) {
return false;
}
- Post post = (Post) o;
+ Post<?> post = (Post<?>) o;
return Objects.equals(id, post.id);
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index 4f7a43e..db613ae 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -91,7 +91,7 @@ public abstract class PostResource {
@CheckedTemplate
static class Templates {
- public static native <P extends Post> TemplateInstance postList(
+ public static native <P extends Post<?>> TemplateInstance postList(
List<Post.Day<P>> postDays,
@CheckForNull String feedUri,
String pageTitle,
@@ -242,7 +242,7 @@ public abstract class PostResource {
@GET
@Produces(APPLICATION_JSON)
@Path("{id}")
- public Post getPostJson(@PathParam("id") int id) {
+ public Post<?> getPostJson(@PathParam("id") int id) {
return getPostIfVisible(id);
}
@@ -253,7 +253,7 @@ public abstract class PostResource {
var post = getPostIfVisible(id);
return Templates.postList(
- new PostPage<>(null, null, null, List.of(post)).days(),
+ new PostPage<Post<? extends PostText<?>>>(null, null, null, List.of(post)).days(),
null,
String.format("Post #%d", id),
false,
@@ -319,7 +319,7 @@ public abstract class PostResource {
Response.status(Status.BAD_REQUEST).entity("invalid hashcash").build());
}
- Post post = Post.findById(postId);
+ Post<?> post = Post.findById(postId);
var comment = new LazychatMessage();
comment.date = OffsetDateTime.now();
@@ -509,7 +509,7 @@ public abstract class PostResource {
return entityManager.unwrap(Session.class);
}
- protected static void assignPostTargets(Post.Visibility visibility, User user, Post post) {
+ protected static void assignPostTargets(Post.Visibility visibility, User user, Post<?> post) {
switch (visibility) {
case PUBLIC:
post.targets = Set.of(Role.getWorld());
@@ -525,7 +525,7 @@ public abstract class PostResource {
}
}
- protected final Post getPostIfVisible(int id) {
+ protected final Post<?> getPostIfVisible(int id) {
@CheckForNull var user = getCurrentUser();
var message = getSession().byId(Post.class).load(id);
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java
index 177c590..5bc94c8 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java
@@ -27,7 +27,7 @@ import org.hibernate.annotations.Type;
@Table(name = "post_texts", schema = "benki")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@IdClass(PostTextPK.class)
-public abstract class PostText extends PanacheEntityBase {
+public abstract class PostText<OwningPost extends Post<?>> extends PanacheEntityBase {
private static final int DESCRIPTION_CACHE_VERSION = 1;
@@ -52,14 +52,10 @@ public abstract class PostText extends PanacheEntityBase {
@Type(value = PostgreSQLTSVectorType.class)
public String searchTerms;
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(fetch = FetchType.LAZY, targetEntity = Post.class)
@JoinColumn(name = "post", referencedColumnName = "id", nullable = false)
@JsonbTransient
- public Post post;
-
- public Post getPost() {
- return post;
- }
+ public OwningPost post;
@CheckForNull
public final String getDescriptionHtml() {
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java
index b057ac5..74ad89e 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java
@@ -1,10 +1,7 @@
package eu.mulk.mulkcms2.benki.posts;
import jakarta.persistence.Column;
-import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
-import jakarta.persistence.JoinColumn;
-import jakarta.persistence.ManyToOne;
import java.io.Serializable;
import java.util.Objects;
@@ -43,7 +40,8 @@ public class PostTextPK implements Serializable {
return false;
}
PostTextPK that = (PostTextPK) o;
- return Objects.equals(getPostId(), that.getPostId()) && getLanguage().equals(that.getLanguage());
+ return Objects.equals(getPostId(), that.getPostId())
+ && getLanguage().equals(that.getLanguage());
}
@Override
diff --git a/src/main/resources/templates/PostResource/postList.html b/src/main/resources/templates/PostResource/postList.html
index 434c22a..89267a2 100644
--- a/src/main/resources/templates/PostResource/postList.html
+++ b/src/main/resources/templates/PostResource/postList.html
@@ -1,4 +1,4 @@
-{@java.util.List<eu.mulk.mulkcms2.benki.posts.Post$Day<eu.mulk.mulkcms2.benki.posts.Post>> postDays}
+{@java.util.List<eu.mulk.mulkcms2.benki.posts.Post$Day<eu.mulk.mulkcms2.benki.posts.Post<?>>> postDays}
{@java.lang.String feedUri}
{@java.lang.String pageTitle}
{@boolean showBookmarkForm}