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.persistence;
23
24 import org.opencastproject.event.comment.EventCommentReply;
25 import org.opencastproject.security.api.User;
26 import org.opencastproject.security.api.UserDirectoryService;
27 import org.opencastproject.util.data.Option;
28
29 import java.util.Date;
30
31 import javax.persistence.Access;
32 import javax.persistence.AccessType;
33 import javax.persistence.Column;
34 import javax.persistence.Entity;
35 import javax.persistence.GeneratedValue;
36 import javax.persistence.Id;
37 import javax.persistence.JoinColumn;
38 import javax.persistence.Lob;
39 import javax.persistence.ManyToOne;
40 import javax.persistence.NamedQueries;
41 import javax.persistence.NamedQuery;
42 import javax.persistence.Table;
43 import javax.persistence.Temporal;
44 import javax.persistence.TemporalType;
45
46
47
48
49 @Entity(name = "EventCommentReply")
50 @Access(AccessType.FIELD)
51 @Table(name = "oc_event_comment_reply")
52 @NamedQueries({ @NamedQuery(name = "EventCommentReply.findAll", query = "SELECT c FROM EventCommentReply c"),
53 @NamedQuery(name = "EventCommentReply.clear", query = "DELETE FROM EventCommentReply") })
54 public class EventCommentReplyDto {
55
56 @Id
57 @GeneratedValue
58 @Column(name = "id")
59 private long id;
60
61 @ManyToOne(targetEntity = EventCommentDto.class)
62 @JoinColumn(name = "event_comment_id", referencedColumnName = "id", nullable = false)
63 private EventCommentDto eventComment;
64
65 @Lob
66 @Column(name = "text", nullable = false)
67 private String text;
68
69 @Column(name = "creation_date", nullable = false)
70 @Temporal(TemporalType.TIMESTAMP)
71 private Date creationDate;
72
73 @Column(name = "modification_date", nullable = false)
74 @Temporal(TemporalType.TIMESTAMP)
75 private Date modificationDate;
76
77 @Column(name = "author", nullable = false)
78 private String author;
79
80
81
82
83 public EventCommentReplyDto() {
84 }
85
86 public static EventCommentReplyDto from(EventCommentReply reply) {
87 EventCommentReplyDto dto = new EventCommentReplyDto();
88 if (reply.getId().isSome()) {
89 dto.id = reply.getId().get().longValue();
90 }
91 dto.text = reply.getText();
92 dto.creationDate = reply.getCreationDate();
93 dto.modificationDate = reply.getModificationDate();
94 dto.author = reply.getAuthor().getUsername();
95
96 return dto;
97 }
98
99
100
101
102
103
104 public long getId() {
105 return id;
106 }
107
108 EventCommentDto getEventComment() {
109 return eventComment;
110 }
111
112 void setEventComment(EventCommentDto eventComment) {
113 this.eventComment = eventComment;
114 }
115
116
117
118
119
120
121
122 public void setText(String text) {
123 this.text = text;
124 }
125
126
127
128
129
130
131 public String getText() {
132 return text;
133 }
134
135
136
137
138
139
140
141 public void setCreationDate(Date creationDate) {
142 this.creationDate = creationDate;
143 }
144
145
146
147
148
149
150 public Date getCreationDate() {
151 return creationDate;
152 }
153
154
155
156
157
158
159
160 public void setModificationDate(Date modificationDate) {
161 this.modificationDate = modificationDate;
162 }
163
164
165
166
167
168
169 public Date getModificationDate() {
170 return modificationDate;
171 }
172
173
174
175
176
177
178
179 public void setAuthor(String author) {
180 this.author = author;
181 }
182
183
184
185
186
187
188 public String getAuthor() {
189 return author;
190 }
191
192
193
194
195
196
197 public EventCommentReply toCommentReply(UserDirectoryService userDirectoryService) {
198 User user = userDirectoryService.loadUser(author);
199 return EventCommentReply.create(Option.option(id), text, user, creationDate, modificationDate);
200 }
201
202 }