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