4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
StoredDocument.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: StoredDocument.java
5  * Description: Class representing stored document
6  */
7 
8 /**
9  * @file StoredDocument.java
10  *
11  * @brief Class representing stored document
12  */
13 
14 package cz.vutbr.fit.knot.annotations.entity;
15 
17 import java.io.Serializable;
18 import java.util.Date;
19 import javax.persistence.Basic;
20 import javax.persistence.Column;
21 import javax.persistence.Entity;
22 import javax.persistence.GeneratedValue;
23 import javax.persistence.GenerationType;
24 import javax.persistence.Id;
25 import javax.persistence.JoinColumn;
26 import javax.persistence.Lob;
27 import javax.persistence.NamedQueries;
28 import javax.persistence.NamedQuery;
29 import javax.persistence.OneToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33 
34 /**
35  * Class representing stored document
36  *
37  * @brief Class representing stored document
38  * @author idytrych
39  */
40 @Entity
41 @Table(name = "storedDocument")
42 @NamedQueries({
43  @NamedQuery(name = "StoredDocument.findAll", query = "SELECT s FROM StoredDocument s"),
44  @NamedQuery(name = "StoredDocument.findById", query = "SELECT s FROM StoredDocument s WHERE s.id = :id"),
45  @NamedQuery(name = "StoredDocument.findByUri", query = "SELECT s FROM StoredDocument s WHERE s.uri = :uri"),
46  @NamedQuery(name = "StoredDocument.findByAdded", query = "SELECT s FROM StoredDocument s WHERE s.added = :added"),
47  @NamedQuery(name = "StoredDocument.findByOwnerId", query = "SELECT s FROM StoredDocument s WHERE s.ownerId = :ownerId"),
48  @NamedQuery(name = "StoredDocument.findByGroupId", query = "SELECT s FROM StoredDocument s WHERE s.groupId = :groupId")})
49 public class StoredDocument implements Serializable {
50  private static final long serialVersionUID = 1L;
51  /** Document id */
52  @Id
53  @GeneratedValue(strategy = GenerationType.IDENTITY)
54  @Basic(optional = false)
55  @Column(name = "id")
56  private Integer id;
57  /** URI of document */
58  @Basic(optional = false)
59  @Column(name = "uri")
60  private String uri;
61  /** File name of document */
62  @Basic(optional = false)
63  @Column(name = "name")
64  private String name;
65  /** File type of document */
66  @Basic(optional = false)
67  @Column(name = "type")
68  private String type;
69  /** Date of document addition */
70  @Basic(optional = false)
71  @Column(name = "added")
72  @Temporal(TemporalType.TIMESTAMP)
73  private Date added;
74  /** Id of document owner */
75  @Basic(optional = false)
76  @Column(name = "ownerId", insertable=false, updatable=false)
77  private int ownerId;
78  /** Id of user group to which this document belongs */
79  @Basic(optional = false)
80  @Column(name = "groupId", insertable=false, updatable=false)
81  private int groupId;
82  /** Document content */
83  @Basic(optional = false)
84  @Lob
85  @Column(name = "content")
86  private String content;
87 
88  /** Owner of document (user) */
89  @OneToOne(optional = true)
90  @JoinColumn(name = "ownerId", referencedColumnName = "id")
91  private User owner;
92  /** User group to which this document belongs */
93  @OneToOne(optional = true)
94  @JoinColumn(name = "groupId", referencedColumnName = "id")
95  private UserGroup group;
96 
97  /**
98  * Constructor
99  */
100  public StoredDocument() {
101  }
102 
103  /**
104  * Constructor
105  *
106  * @param id document id
107  */
108  public StoredDocument(Integer id) {
109  this.id = id;
110  }
111 
112  /**
113  * Constructor
114  *
115  * @param name File name
116  * @param type File type of document
117  * @param owner Document owner
118  * @param group User group to which this document belongs
119  * @param content Document content
120  */
121  public StoredDocument(String name, String type, User owner, UserGroup group, String content) {
122  this.added = new Date();
123  this.name = name;
124  this.type = type;
125  this.owner = owner;
126  this.group = group;
127  this.content = content;
128  }
129 
130  /**
131  * Gets id of document
132  *
133  * @return Returns id of document
134  */
135  public Integer getId() {
136  return id;
137  }
138 
139  /**
140  * Sets id of document
141  *
142  * @param id Id of document
143  */
144  public void setId(Integer id) {
145  this.id = id;
146  }
147 
148  /**
149  * Gets URI of document
150  *
151  * @return Returns URI of document
152  */
153  public String getUri() {
154  return uri;
155  }
156 
157  /**
158  * Generate URI of document
159  * URI = base URI + document id
160  *
161  * @return Generated URI of document
162  */
163  public String getGeneratedUri() {
164  return AppBean.getBaseDocumentUri() + id;
165  }
166 
167  /**
168  * Sets URI of document
169  *
170  * @param uri URI of document
171  */
172  public void setUri(String uri) {
173  this.uri = uri;
174  }
175 
176  /**
177  * Gets date of document addition
178  *
179  * @return Returns date of document addition
180  */
181  public Date getAdded() {
182  return added;
183  }
184 
185  /**
186  * Sets date of document addition
187  *
188  * @param added Date of document addition
189  */
190  public void setAdded(Date added) {
191  this.added = added;
192  }
193 
194  /**
195  * Gets user group to which this document belongs
196  *
197  * @return Returns user group to which this document belongs
198  */
199  public UserGroup getGroup() {
200  return group;
201  }
202 
203  /**
204  * Sets user group to which this document belongs
205  *
206  * @param group User group to which this document belongs
207  */
208  public void setGroup(UserGroup group) {
209  this.group = group;
210  }
211 
212  /**
213  * Gets file name of document
214  *
215  * @return Returns file name of document
216  */
217  public String getName() {
218  return name;
219  }
220 
221  /**
222  * Sets file name of document
223  *
224  * @param name File name of document
225  */
226  public void setName(String name) {
227  this.name = name;
228  }
229 
230  /**
231  * Gets file type of document
232  *
233  * @return Returns file type of document
234  */
235  public String getType() {
236  return type;
237  }
238 
239  /**
240  * Sets file type of document
241  *
242  * @param type File type of document
243  */
244  public void setType(String type) {
245  this.type = type;
246  }
247 
248  /**
249  * Gets document owner
250  *
251  * @return Returns document owner
252  */
253  public User getOwner() {
254  return owner;
255  }
256 
257  /**
258  * Sets document owner
259  *
260  * @param owner Document owner
261  */
262  public void setOwner(User owner) {
263  this.owner = owner;
264  }
265 
266  /**
267  * Gets textual content of document
268  *
269  * @return Returns textual content of document
270  */
271  public String getContent() {
272  return content;
273  }
274 
275  /**
276  * Sets textual content of document
277  *
278  * @param content Textual content of document
279  */
280  public void setContent(String content) {
281  this.content = content;
282  }
283 
284  @Override
285  public int hashCode() {
286  int hash = 0;
287  hash += (id != null ? id.hashCode() : 0);
288  return hash;
289  }
290 
291  /**
292  * Compares this with other object and returns, whether objects are same type
293  * and have same id.
294  *
295  * @param object Object to compare with
296  * @return If object is same type and have same id, returns true, false otherwise
297  */
298  @Override
299  public boolean equals(Object object) {
300  if (!(object instanceof StoredDocument)) {
301  return false;
302  }
303  StoredDocument other = (StoredDocument) object;
304  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
305  return false;
306  }
307  return true;
308  }
309 
310  @Override
311  public String toString() {
312  return "cz.vutbr.fit.knot.annotations.entity.StoredDocument[id=" + id + "]";
313  }
314 
315 } // public class StoredDocument
StoredDocument(String name, String type, User owner, UserGroup group, String content)
Singleton for storing global variables.
Definition: AppBean.java:47
Class representing user group.
Definition: UserGroup.java:47
Class representing user.
Definition: User.java:51