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.ArrayList;
38 import java.util.Date;
39 import java.util.List;
40
41
42
43
44 public final class EventComment {
45
46
47 public static final String REASON_NEEDS_CUTTING = "EVENTS.EVENTS.DETAILS.COMMENTS.REASONS.CUTTING";
48
49
50 private Option<Long> id;
51
52
53 private String eventId;
54
55
56 private String organization;
57
58
59 private String text;
60
61
62 private Date creationDate;
63
64
65 private Date modificationDate;
66
67
68 private User author;
69
70
71 private String reason;
72
73
74 private boolean resolvedStatus = false;
75
76
77 private List<EventCommentReply> replies = new ArrayList<EventCommentReply>();
78
79
80
81
82
83
84
85
86
87
88
89
90
91 public static EventComment create(Option<Long> id, String eventId, String organization, String text, User author) {
92 return create(id, eventId, organization, text, author, null, false);
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 public static EventComment create(
112 Option<Long> id,
113 String eventId,
114 String organization,
115 String text,
116 User author,
117 String reason,
118 boolean resolvedStatus
119 ) {
120 Date creationDate = new Date();
121 return create(
122 id, eventId, organization, text, author, reason, resolvedStatus,
123 creationDate, creationDate, new ArrayList<EventCommentReply>()
124 );
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 public static EventComment create(
150 Option<Long> id,
151 String eventId,
152 String organization,
153 String text,
154 User author,
155 String reason,
156 boolean resolvedStatus,
157 Date creationDate,
158 Date modificationDate
159 ) {
160 return new EventComment(
161 id, eventId, organization, text, author, reason, resolvedStatus,
162 creationDate, modificationDate, new ArrayList<EventCommentReply>());
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189 public static EventComment create(
190 Option<Long> id,
191 String eventId,
192 String organization,
193 String text,
194 User author,
195 String reason,
196 boolean resolvedStatus,
197 Date creationDate,
198 Date modificationDate,
199 List<EventCommentReply> replies
200 ) {
201 return new EventComment(id, eventId, organization, text, author, reason,
202 resolvedStatus, creationDate, modificationDate, replies);
203 }
204
205 private EventComment(
206 Option<Long> id,
207 String eventId,
208 String organization,
209 String text,
210 User author,
211 String reason,
212 boolean resolvedStatus,
213 Date creationDate,
214 Date modificationDate,
215 List<EventCommentReply> replies
216 ) {
217 this.id = notNull(id, "id");
218 this.eventId = notEmpty(eventId, "eventId");
219 this.organization = notEmpty(organization, "organization");
220 this.text = notEmpty(text, "text");
221 this.author = notNull(author, "author");
222 this.reason = reason;
223 this.resolvedStatus = resolvedStatus;
224 this.creationDate = notNull(creationDate, "creationDate");
225 this.modificationDate = notNull(modificationDate, "modificationDate");
226 this.replies = notNull(replies, "replies");
227 }
228
229
230
231
232
233
234 public Option<Long> getId() {
235 return id;
236 }
237
238 public String getEventId() {
239 return eventId;
240 }
241
242 public void setEventId(String eventId) {
243 this.eventId = eventId;
244 }
245
246 public String getOrganization() {
247 return organization;
248 }
249
250 public void setOrganization(String organization) {
251 this.organization = organization;
252 }
253
254
255
256
257
258
259 public String getText() {
260 return text;
261 }
262
263
264
265
266
267
268 public Date getCreationDate() {
269 return creationDate;
270 }
271
272
273
274
275
276
277 public Date getModificationDate() {
278 return modificationDate;
279 }
280
281
282
283
284
285
286 public User getAuthor() {
287 return author;
288 }
289
290
291
292
293
294
295 public String getReason() {
296 return reason;
297 }
298
299
300
301
302
303
304 public boolean isResolvedStatus() {
305 return resolvedStatus;
306 }
307
308
309
310
311
312
313 public List<EventCommentReply> getReplies() {
314 return replies;
315 }
316
317
318
319
320
321
322
323
324
325 public boolean addReply(EventCommentReply reply) {
326 return replies.add(notNull(reply, "reply"));
327 }
328
329
330
331
332
333
334
335
336
337 public boolean removeReply(EventCommentReply reply) {
338 return replies.remove(notNull(reply, "reply"));
339 }
340
341 @Override
342 public boolean equals(Object o) {
343 if (this == o) {
344 return true;
345 }
346 if (o == null || getClass() != o.getClass()) {
347 return false;
348 }
349 EventComment comment = (EventComment) o;
350
351 return text.equals(comment.getText()) && creationDate.equals(comment.getCreationDate())
352 && modificationDate.equals(comment.getModificationDate()) && author.equals(comment.getAuthor())
353 && (reason == null ? comment.getReason() == null : reason.equals(comment.getReason()))
354 && resolvedStatus == comment.isResolvedStatus();
355 }
356
357 @Override
358 public int hashCode() {
359 return EqualsUtil.hash(text, creationDate, modificationDate, author, reason, resolvedStatus);
360 }
361
362 @Override
363 public String toString() {
364 return "Comment:" + id + "|" + StringUtils.abbreviate(text, 25);
365 }
366
367 public Obj toJson() {
368 Obj authorObj = Jsons.obj(Jsons.p("name", author.getName()), Jsons.p("username", author.getUsername()),
369 Jsons.p("email", author.getEmail()));
370
371 List<Val> replyArr = new ArrayList<Val>();
372 for (EventCommentReply reply : replies) {
373 replyArr.add(reply.toJson());
374 }
375
376 Val idValue = Jsons.ZERO_VAL;
377 if (id.isSome()) {
378 idValue = Jsons.v(id.get());
379 }
380
381 return Jsons.obj(
382 Jsons.p("id", idValue),
383 Jsons.p("text", text),
384 Jsons.p("creationDate", DateTimeSupport.toUTC(creationDate.getTime())),
385 Jsons.p("modificationDate", DateTimeSupport.toUTC(modificationDate.getTime())),
386 Jsons.p("author", authorObj), Jsons.p("reason", reason), Jsons.p("resolvedStatus", resolvedStatus),
387 Jsons.p("replies", Jsons.arr(replyArr))
388 );
389 }
390
391 }