1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.event.comment;
23
24 import static org.opencastproject.util.RequireUtil.notEmpty;
25 import static org.opencastproject.util.RequireUtil.notNull;
26
27 import org.opencastproject.security.api.User;
28 import org.opencastproject.util.DateTimeSupport;
29 import org.opencastproject.util.EqualsUtil;
30 import org.opencastproject.util.Jsons;
31 import org.opencastproject.util.Jsons.Obj;
32 import org.opencastproject.util.Jsons.Val;
33 import org.opencastproject.util.data.Option;
34
35 import org.apache.commons.lang3.StringUtils;
36
37 import java.util.Date;
38
39
40
41
42 public final class EventCommentReply {
43
44
45 private Option<Long> id;
46
47
48 private String text;
49
50
51 private Date creationDate;
52
53
54 private Date modificationDate;
55
56
57 private User author;
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public static EventCommentReply create(Option<Long> id, String text, User author) {
72 Date creationDate = new Date();
73 return create(id, text, author, creationDate, creationDate);
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 public static EventCommentReply create(
93 Option<Long> id,
94 String text,
95 User author,
96 Date creationDate,
97 Date modificationDate
98 ) {
99 return new EventCommentReply(id, text, author, creationDate, modificationDate);
100 }
101
102 private EventCommentReply(Option<Long> id, String text, User author, Date creationDate, Date modificationDate) {
103 this.id = notNull(id, "id");
104 this.text = notEmpty(text, "text");
105 this.author = notNull(author, "author");
106 this.creationDate = notNull(creationDate, "creationDate");
107 this.modificationDate = notNull(modificationDate, "modificationDate");
108 }
109
110
111
112
113
114
115 public Option<Long> getId() {
116 return id;
117 }
118
119
120
121
122
123
124 public String getText() {
125 return text;
126 }
127
128
129
130
131
132
133 public Date getCreationDate() {
134 return creationDate;
135 }
136
137
138
139
140
141
142 public Date getModificationDate() {
143 return modificationDate;
144 }
145
146
147
148
149
150
151 public User getAuthor() {
152 return author;
153 }
154
155 @Override
156 public boolean equals(Object o) {
157 if (this == o) {
158 return true;
159 }
160 if (o == null || getClass() != o.getClass()) {
161 return false;
162 }
163 EventCommentReply reply = (EventCommentReply) o;
164 return text.equals(reply.getText()) && creationDate.equals(reply.getCreationDate())
165 && modificationDate.equals(reply.getModificationDate()) && author.equals(reply.getAuthor());
166 }
167
168 @Override
169 public int hashCode() {
170 return EqualsUtil.hash(text, creationDate, modificationDate, author);
171 }
172
173 @Override
174 public String toString() {
175 return "Comment reply:" + id + "|" + StringUtils.abbreviate(text, 25);
176 }
177
178 public Obj toJson() {
179 Obj authorObj = Jsons.obj(Jsons.p("name", author.getName()), Jsons.p("username", author.getUsername()),
180 Jsons.p("email", author.getEmail()));
181
182 Val idValue = Jsons.ZERO_VAL;
183 if (id.isSome()) {
184 idValue = Jsons.v(id.get());
185 }
186
187 return Jsons.obj(Jsons.p("id", idValue), Jsons.p("text", text), Jsons.p("author", authorObj),
188 Jsons.p("creationDate", DateTimeSupport.toUTC(creationDate.getTime())),
189 Jsons.p("modificationDate", DateTimeSupport.toUTC(modificationDate.getTime())));
190 }
191 }