4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
AnnotDocument.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: AnnotDocument.java
5  * Description: Class representing annotated copy of document
6  */
7 
8 /**
9  * @file AnnotDocument.java
10  *
11  * @brief Class representing annotated copy of 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.Lob;
26 import javax.persistence.NamedQueries;
27 import javax.persistence.NamedQuery;
28 import javax.persistence.Table;
29 import javax.persistence.Temporal;
30 import javax.persistence.TemporalType;
31 
32 /**
33  * Class representing annotated copy of document
34  *
35  * @brief Class representing annotated copy of document
36  * @author idytrych
37  */
38 @Entity
39 @Table(name = "annotDocument")
40 @NamedQueries({
41  @NamedQuery(name = "AnnotDocument.findAll", query = "SELECT d FROM AnnotDocument d"),
42  @NamedQuery(name = "AnnotDocument.findById", query = "SELECT d FROM AnnotDocument d WHERE d.id = :id"),
43  @NamedQuery(name = "AnnotDocument.findByUri", query = "SELECT d FROM AnnotDocument d WHERE d.uri = :uri"),
44  @NamedQuery(name = "AnnotDocument.findByAdded", query = "SELECT d FROM AnnotDocument d WHERE d.added = :added"),
45  @NamedQuery(name = "AnnotDocument.findByModified", query = "SELECT d FROM AnnotDocument d WHERE d.modified = :modified")})
46 public class AnnotDocument implements Serializable {
47  private static final long serialVersionUID = 1L;
48  /** ID of annotated copy of document */
49  @Id
50  @GeneratedValue(strategy = GenerationType.IDENTITY)
51  @Basic(optional = false)
52  @Column(name = "id")
53  private Integer id;
54  /** URI of original document */
55  @Basic(optional = false)
56  @Column(name = "uri")
57  private String uri;
58  /** Date of document addition (creation of annotated copy) */
59  @Basic(optional = false)
60  @Column(name = "added")
61  @Temporal(TemporalType.TIMESTAMP)
62  private Date added;
63  /** Date of document modification */
64  @Column(name = "modified")
65  @Temporal(TemporalType.TIMESTAMP)
66  private Date modified;
67  /** Document content */
68  @Basic(optional = false)
69  @Lob
70  @Column(name = "content")
71  private String content;
72 
73  /**
74  * Constructor
75  */
76  public AnnotDocument() {
77  }
78 
79  /**
80  * Constructor
81  *
82  * @param id id of object
83  */
84  public AnnotDocument(Integer id) {
85  this.id = id;
86  }
87 
88  /**
89  * Constructor
90  *
91  * @param uri URI of original document
92  * @param content Document content
93  */
94  public AnnotDocument(String uri, String content) {
95  this.uri = uri;
96  this.added = new Date();
97  this.modified = new Date();
98  this.content = content;
99  }
100 
101  /**
102  * Gets id of annotated copy of document
103  *
104  * @return Returns id of annotated copy of document
105  */
106  public Integer getId() {
107  return id;
108  }
109 
110  /**
111  * Sets id of annotated copy of document
112  *
113  * @param id Id of annotated copy of document
114  */
115  public void setId(Integer id) {
116  this.id = id;
117  }
118 
119  /**
120  * Gets URI of original document
121  *
122  * @return URI of original document
123  */
124  public String getUri() {
125  return uri;
126  }
127 
128  /**
129  * Sets URI of original document
130  *
131  * @param uri URI of original document
132  */
133  public void setUri(String uri) {
134  this.uri = uri;
135  }
136 
137  /**
138  * Gets URI of annotated copy of document
139  * URI = base uri + document id
140  *
141  * @return Returns URI of annotated copy of document
142  */
143  public String getUriForAnnot() {
144  return AppBean.getBaseDocumentUri() + id;
145  }
146 
147  /**
148  * Gets date of document addition (creation of annotated copy)
149  *
150  * @return Returns date of document addition (creation of annotated copy)
151  */
152  public Date getAdded() {
153  return added;
154  }
155 
156  /**
157  * Sets date of document addition (creation of annotated copy)
158  *
159  * @param added Date of document addition (creation of annotated copy)
160  */
161  public void setAdded(Date added) {
162  this.added = added;
163  }
164 
165  /**
166  * Gets date of last document modification
167  *
168  * @return Returns date of last document modification
169  */
170  public Date getModified() {
171  return modified;
172  }
173 
174  /**
175  * Sets date of last document modification
176  *
177  * @param modified Date of last document modification
178  */
179  public void setModified(Date modified) {
180  this.modified = modified;
181  }
182 
183  /**
184  * Gets textual content of document
185  *
186  * @return Returns textual content of document
187  */
188  public String getContent() {
189  return content;
190  }
191 
192  /**
193  * Sets textual content of document
194  *
195  * @param content Textual content of document
196  */
197  public void setContent(String content) {
198  this.content = content;
199  }
200 
201  @Override
202  public int hashCode() {
203  int hash = 0;
204  hash += (id != null ? id.hashCode() : 0);
205  return hash;
206  }
207 
208  /**
209  * Compares this with other object and returns, whether objects are same type
210  * and have same id.
211  *
212  * @param object Object to compare with
213  * @return If object is same type and have same id, returns true, false otherwise
214  */
215  @Override
216  public boolean equals(Object object) {
217  if (!(object instanceof AnnotDocument)) {
218  return false;
219  }
220  AnnotDocument other = (AnnotDocument) object;
221  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
222  return false;
223  }
224  return true;
225  }
226 
227  @Override
228  public String toString() {
229  return "cz.vutbr.fit.knot.annotations.entity.AnnotDocument[id=" + id + "]";
230  }
231 
232 } // class AnnotDocument
Class representing annotated copy of document.
Singleton for storing global variables.
Definition: AppBean.java:47