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.search.impl.persistence;
23  
24  import org.opencastproject.security.api.Organization;
25  import org.opencastproject.security.impl.jpa.JpaOrganization;
26  
27  import java.util.Date;
28  
29  import javax.persistence.Column;
30  import javax.persistence.Entity;
31  import javax.persistence.Id;
32  import javax.persistence.Index;
33  import javax.persistence.JoinColumn;
34  import javax.persistence.Lob;
35  import javax.persistence.NamedQueries;
36  import javax.persistence.NamedQuery;
37  import javax.persistence.OneToOne;
38  import javax.persistence.Table;
39  import javax.persistence.Temporal;
40  import javax.persistence.TemporalType;
41  
42  /**
43   * Entity object for storing search in persistence storage. Media package id is stored as primary key.
44   */
45  @Entity(name = "SearchEntity")
46  @Table(name = "oc_search",
47      indexes = {
48          @Index(name = "IX_oc_search_series", columnList = ("series_id")),
49          @Index(name = "IX_oc_search_organization", columnList = ("organization"))
50      }
51  )
52  @NamedQueries({
53      @NamedQuery(name = "Search.findAll", query = "SELECT s FROM SearchEntity s"),
54      @NamedQuery(name = "Search.getCount", query = "SELECT COUNT(s) FROM SearchEntity s"),
55      @NamedQuery(
56          name = "Search.findById",
57          query = "SELECT s FROM SearchEntity s WHERE s.mediaPackageId=:mediaPackageId"
58      ),
59      @NamedQuery(
60          name = "Search.findBySeriesId",
61          query = "SELECT s FROM SearchEntity s WHERE s.seriesId=:seriesId and s.deletionDate is null"
62      ),
63      @NamedQuery(name = "Search.getNoSeries", query = "SELECT s FROM SearchEntity s WHERE s.seriesId IS NULL")
64  })
65  public class SearchEntity {
66  
67    /** media package id, primary key */
68    @Id
69    @Column(name = "id", length = 128)
70    private String mediaPackageId;
71  
72    @Column(name = "series_id", length = 128)
73    protected String seriesId;
74  
75    /** Organization id */
76    @OneToOne(targetEntity = JpaOrganization.class)
77    @JoinColumn(name = "organization", referencedColumnName = "id")
78    protected JpaOrganization organization;
79  
80    /** The media package deleted */
81    @Column(name = "deletion_date")
82    @Temporal(TemporalType.TIMESTAMP)
83    private Date deletionDate;
84  
85    /** The media package deleted */
86    @Column(name = "modification_date")
87    @Temporal(TemporalType.TIMESTAMP)
88    private Date modificationDate;
89  
90    /** Serialized media package */
91    @Lob
92    @Column(name = "mediapackage_xml", length = 65535)
93    private String mediaPackageXML;
94  
95    /** Serialized access control */
96    @Lob
97    @Column(name = "access_control", length = 65535)
98    protected String accessControl;
99  
100   /**
101    * Default constructor without any import.
102    */
103   public SearchEntity() {
104   }
105 
106   /**
107    * Returns media package id.
108    *
109    * @return media package id
110    */
111   public String getMediaPackageId() {
112     return mediaPackageId;
113   }
114 
115   /**
116    * Sets media package id. Id length limit is 128 charachters.
117    *
118    * @param mediaPackageId
119    */
120   public void setMediaPackageId(String mediaPackageId) {
121     this.mediaPackageId = mediaPackageId;
122   }
123 
124   /**
125    * Returns serialized media package.
126    *
127    * @return serialized media package
128    */
129   public String getMediaPackageXML() {
130     return mediaPackageXML;
131   }
132 
133   /**
134    * Sets serialized media package
135    *
136    * @param mediaPackageXML
137    */
138   public void setMediaPackageXML(String mediaPackageXML) {
139     this.mediaPackageXML = mediaPackageXML;
140   }
141 
142   /**
143    * Returns serialized access control
144    *
145    * @return serialized access control
146    */
147   public String getAccessControl() {
148     return accessControl;
149   }
150 
151   /**
152    * Sets serialized access control.
153    *
154    * @param accessControl
155    *          serialized access control
156    */
157   public void setAccessControl(String accessControl) {
158     this.accessControl = accessControl;
159   }
160 
161   /**
162    * @return the organization
163    */
164   public JpaOrganization getOrganization() {
165     return organization;
166   }
167 
168   /**
169    * @param organization
170    *          the organization to set
171    */
172   public void setOrganization(Organization organization) {
173     if (organization instanceof JpaOrganization) {
174       this.organization = (JpaOrganization) organization;
175     } else {
176       this.organization = new JpaOrganization(organization.getId(), organization.getName(), organization.getServers(),
177           organization.getAdminRole(), organization.getAnonymousRole(), organization.getProperties());
178     }
179   }
180 
181   /**
182    * @return the deletion date
183    */
184   public Date getDeletionDate() {
185     return deletionDate;
186   }
187 
188   /**
189    * Sets the deletion date
190    *
191    * @param deletionDate
192    *          the deletion date
193    */
194   public void setDeletionDate(Date deletionDate) {
195     this.deletionDate = deletionDate;
196   }
197 
198   /**
199    * @return the modification date
200    */
201   public Date getModificationDate() {
202     return modificationDate;
203   }
204 
205   /**
206    * Sets the modification date
207    *
208    * @param modificationDate
209    *          the modification date
210    */
211   public void setModificationDate(Date modificationDate) {
212     this.modificationDate = modificationDate;
213   }
214 
215   /**
216    * @return the series Id for this search entry
217    */
218   public String getSeriesId() {
219     return seriesId;
220   }
221 
222   /**
223    * Sets the series ID
224    *
225    * @param seriesId
226    *          the series ID
227    */
228   public void setSeriesId(String seriesId) {
229     this.seriesId = seriesId;
230   }
231 }