View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
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   * Entity object for the comment replies.
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     * Default constructor
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    * Returns the id of this entity
101    *
102    * @return the id as long
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    * Sets the text
118    *
119    * @param text
120    *          the text
121    */
122   public void setText(String text) {
123     this.text = text;
124   }
125 
126   /**
127    * Returns the text
128    *
129    * @return the text
130    */
131   public String getText() {
132     return text;
133   }
134 
135   /**
136    * Sets the creation date
137    *
138    * @param creationDate
139    *          the creation date
140    */
141   public void setCreationDate(Date creationDate) {
142     this.creationDate = creationDate;
143   }
144 
145   /**
146    * Returns the creation date
147    *
148    * @return the creation date
149    */
150   public Date getCreationDate() {
151     return creationDate;
152   }
153 
154   /**
155    * Sets the modification date
156    *
157    * @param modificationDate
158    *          the modification date
159    */
160   public void setModificationDate(Date modificationDate) {
161     this.modificationDate = modificationDate;
162   }
163 
164   /**
165    * Returns the modification date
166    *
167    * @return the modification date
168    */
169   public Date getModificationDate() {
170     return modificationDate;
171   }
172 
173   /**
174    * Sets the author
175    *
176    * @param author
177    *          the author
178    */
179   public void setAuthor(String author) {
180     this.author = author;
181   }
182 
183   /**
184    * Returns the author
185    *
186    * @return the author
187    */
188   public String getAuthor() {
189     return author;
190   }
191 
192   /**
193    * Returns the business object of this comment reply
194    *
195    * @return the business object model of this comment reply
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 }