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.annotation.impl;
23  
24  import org.opencastproject.annotation.api.Annotation;
25  
26  import java.util.Date;
27  
28  import javax.persistence.Access;
29  import javax.persistence.AccessType;
30  import javax.persistence.Basic;
31  import javax.persistence.Column;
32  import javax.persistence.Entity;
33  import javax.persistence.GeneratedValue;
34  import javax.persistence.GenerationType;
35  import javax.persistence.Id;
36  import javax.persistence.Index;
37  import javax.persistence.Lob;
38  import javax.persistence.NamedQueries;
39  import javax.persistence.NamedQuery;
40  import javax.persistence.Table;
41  import javax.persistence.Temporal;
42  import javax.persistence.TemporalType;
43  import javax.xml.bind.annotation.XmlAccessType;
44  import javax.xml.bind.annotation.XmlAccessorType;
45  import javax.xml.bind.annotation.XmlElement;
46  import javax.xml.bind.annotation.XmlRootElement;
47  import javax.xml.bind.annotation.XmlType;
48  
49  /**
50   * A JAXB-annotated implementation of {@link Annotation}
51   */
52  @Entity(name = "Annotation")
53  @Access(AccessType.FIELD)
54  @Table(name = "oc_annotation", indexes = {
55      @Index(name = "IX_oc_annotation_created", columnList = "created"),
56      @Index(name = "IX_oc_annotation_inpoint", columnList = "inpoint"),
57      @Index(name = "IX_oc_annotation_outpoint", columnList = "outpoint"),
58      @Index(name = "IX_oc_annotation_mediapackage", columnList = "mediapackage"),
59      @Index(name = "IX_oc_annotation_private", columnList = "private"),
60      @Index(name = "IX_oc_annotation_user", columnList = "user_id"),
61      @Index(name = "IX_oc_annotation_session", columnList = "session"),
62      @Index(name = "IX_oc_annotation_type", columnList = "type")
63  })
64  @NamedQueries({
65      @NamedQuery(
66          name = "findAnnotations",
67          query = "SELECT a FROM Annotation a "
68              + "WHERE (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
69      ),
70      @NamedQuery(
71          name = "findAnnotationsByMediapackageId",
72          query = "SELECT a FROM Annotation a "
73              + "WHERE a.mediapackageId = :mediapackageId "
74              + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
75      ),
76      @NamedQuery(
77          name = "findAnnotationsByType",
78          query = "SELECT a FROM Annotation a "
79              + "WHERE a.type = :type "
80              + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
81      ),
82      @NamedQuery(
83          name = "findAnnotationsByTypeAndMediapackageId",
84          query = "SELECT a FROM Annotation a "
85              + "WHERE a.mediapackageId = :mediapackageId "
86              + "AND a.type = :type "
87              + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
88      ),
89      @NamedQuery(
90          name = "findAnnotationsByTypeAndMediapackageIdOrderByOutpointDESC",
91          query = "SELECT a FROM Annotation a "
92              + "WHERE a.mediapackageId = :mediapackageId "
93              + "AND a.type = :type "
94              + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE)) "
95              + "ORDER BY a.outpoint DESC"
96      ),
97      @NamedQuery(
98          name = "findAnnotationsByIntervall",
99          query = "SELECT a FROM Annotation a "
100             + "WHERE :begin <= a.created "
101             + "AND a.created <= :end "
102             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
103     ),
104     @NamedQuery(
105         name = "findAnnotationsByTypeAndIntervall",
106         query = "SELECT a FROM Annotation a "
107             + "WHERE :begin <= a.created "
108             + "AND a.created <= :end "
109             + "AND a.type = :type "
110             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
111     ),
112     @NamedQuery(
113         name = "findTotal",
114         query = "SELECT COUNT(a) FROM Annotation a "
115             + "WHERE (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
116     ),
117     @NamedQuery(
118         name = "findTotalByMediapackageId",
119         query = "SELECT COUNT(a) FROM Annotation a "
120             + "WHERE a.mediapackageId = :mediapackageId "
121             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
122     ),
123     @NamedQuery(
124         name = "findTotalByType",
125         query = "SELECT COUNT(a) FROM Annotation a "
126             + "WHERE a.type = :type "
127             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
128     ),
129     @NamedQuery(
130         name = "findTotalByTypeAndMediapackageId",
131         query = "SELECT COUNT(a) FROM Annotation a "
132             + "WHERE a.mediapackageId = :mediapackageId "
133             + "AND a.type = :type "
134             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
135     ),
136     @NamedQuery(
137         name = "findTotalByIntervall",
138         query = "SELECT COUNT(a) FROM Annotation a "
139             + "WHERE :begin <= a.created "
140             + "AND a.created <= :end "
141             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
142     ),
143     @NamedQuery(
144         name = "findDistinctEpisodeIdTotalByIntervall",
145         query = "SELECT COUNT(distinct a.mediapackageId) FROM Annotation a "
146             + "WHERE :begin <= a.created "
147             + "AND a.created <= :end "
148             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
149     ),
150     @NamedQuery(
151         name = "findTotalByTypeAndIntervall",
152         query = "SELECT COUNT(a) FROM Annotation a "
153             + "WHERE :begin <= a.created "
154             + "AND a.created <= :end "
155             + "AND a.type = :type "
156             + "AND (a.privateAnnotation = FALSE OR (a.userId = :userId AND a.privateAnnotation = TRUE))"
157     ),
158     @NamedQuery(
159         name = "updateAnnotation",
160         query = "UPDATE Annotation a SET a.value = :value "
161             + "WHERE a.annotationId = :annotationId"
162     ),
163 })
164 @XmlType(name = "annotation", namespace = "http://annotation.opencastproject.org")
165 @XmlRootElement(name = "annotation", namespace = "http://annotation.opencastproject.org")
166 @XmlAccessorType(XmlAccessType.FIELD)
167 public class AnnotationImpl implements Annotation {
168 
169   @Id
170   @Column(name = "id")
171   @GeneratedValue(strategy = GenerationType.AUTO)
172   @XmlElement(name = "annotationId")
173   private Long annotationId;
174 
175   @Column(name = "mediapackage", length = 128)
176   @XmlElement(name = "mediapackageId")
177   private String mediapackageId;
178 
179   @Column(name = "user_id")
180   @XmlElement(name = "userId")
181   private String userId;
182 
183   @Column(name = "session", length = 128)
184   @XmlElement(name = "sessionId")
185   private String sessionId;
186 
187   @Column(name = "inpoint")
188   @XmlElement(name = "inpoint")
189   private int inpoint;
190 
191   @Column(name = "outpoint")
192   @XmlElement(name = "outpoint")
193   private int outpoint;
194 
195   @Column(name = "length")
196   @XmlElement(name = "length")
197   private int length;
198 
199   @Column(name = "type", length = 128)
200   @XmlElement(name = "type")
201   private String type;
202 
203   @Column(name = "private")
204   @XmlElement(name = "isPrivate")
205   private Boolean privateAnnotation = false;
206 
207   @Lob
208   @Column(name = "value", length = 65535)
209   @XmlElement(name = "value")
210   private String value;
211 
212   @Basic(optional = false)
213   @Column(name = "created")
214   @Temporal(TemporalType.TIMESTAMP)
215   @XmlElement(name = "created")
216   private Date created = new Date();
217 
218   /**
219    * A no-arg constructor needed by JAXB
220    */
221   public AnnotationImpl() {
222   }
223 
224   @Override
225   public Long getAnnotationId() {
226     return annotationId;
227   }
228 
229   @Override
230   public void setAnnotationId(Long annotationId) {
231     this.annotationId = annotationId;
232   }
233 
234   @Override
235   public String getMediapackageId() {
236     return mediapackageId;
237   }
238 
239   @Override
240   public void setMediapackageId(String mediapackageId) {
241     this.mediapackageId = mediapackageId;
242   }
243 
244   @Override
245   public String getUserId() {
246     return userId;
247   }
248 
249   @Override
250   public void setUserId(String userId) {
251     this.userId = userId;
252   }
253 
254   @Override
255   public String getSessionId() {
256     return sessionId;
257   }
258 
259   @Override
260   public void setSessionId(String sessionId) {
261     this.sessionId = sessionId;
262   }
263 
264   @Override
265   public int getInpoint() {
266     return inpoint;
267   }
268 
269   @Override
270   public void setInpoint(int inpoint) {
271     this.inpoint = inpoint;
272     updateLength();
273   }
274 
275   @Override
276   public int getOutpoint() {
277     return outpoint;
278   }
279 
280   @Override
281   public void setOutpoint(int outpoint) {
282     this.outpoint = outpoint;
283     updateLength();
284   }
285 
286   @Override
287   public int getLength() {
288     return length;
289   }
290 
291   @Override
292   public String getType() {
293     return type;
294   }
295 
296   @Override
297   public void setType(String type) {
298     this.type = type;
299   }
300 
301   @Override
302   public String getValue() {
303     return value;
304   }
305 
306   @Override
307   public void setValue(String value) {
308     this.value = value;
309   }
310 
311   @Override
312   public Date getCreated() {
313     return created;
314   }
315 
316   @Override
317   public void setCreated(Date created) {
318     this.created = created;
319   }
320 
321   private void updateLength() {
322     this.length = this.outpoint - this.inpoint;
323   }
324 
325   @Override
326   public Boolean getPrivate() {
327     return this.privateAnnotation;
328   }
329 
330   @Override
331   public void setPrivate(Boolean isPrivate) {
332     this.privateAnnotation = isPrivate;
333   }
334 
335 }