summaryrefslogtreecommitdiff
path: root/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
blob: 01e8a9927354babdfdb1cc4026adb5446feb7ee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package eu.mulk.mulkcms2.benki.bookmarks;

import eu.mulk.mulkcms2.benki.posts.Post;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Table;
import java.util.Set;
import javax.annotation.CheckForNull;

@Entity
@Table(name = "bookmarks", schema = "benki")
public class Bookmark extends Post<BookmarkText> {

  @Column(name = "uri", nullable = false, length = -1)
  public String uri;

  @ElementCollection(fetch = FetchType.LAZY)
  @CollectionTable(
      name = "bookmark_tags",
      schema = "benki",
      joinColumns = @JoinColumn(name = "bookmark"))
  @Column(name = "tag")
  public Set<String> tags;

  @CheckForNull
  private String getDescription() {
    var text = getText();
    return text == null ? null : text.description;
  }

  @CheckForNull
  @Override
  public String getUri() {
    return uri;
  }

  @CheckForNull
  @Override
  public String getTitle() {
    var text = getText();
    return text == null ? null : text.title;
  }

  @Override
  public boolean isBookmark() {
    return true;
  }

  @Override
  public boolean isLazychatMessage() {
    return false;
  }

  public void setTitle(String x) {
    var text = getText();
    if (text == null) {
      text = new BookmarkText();
      text.post = this;
      text.language = "";
      texts.put(text.language, text);
    }

    text.title = x;
  }

  public void setDescription(String x) {
    var text = getText();
    if (text == null) {
      text = new BookmarkText();
      text.post = this;
      text.language = "";
      texts.put(text.language, text);
    }

    text.description = x;
    text.cachedDescriptionHtml = null;
  }
}