4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
Source.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: Source.java
5  * Description: Class representing source of subscription.
6  */
7 
8 /**
9  * @file Source.java
10  *
11  * @brief Class representing source of subscription.
12  */
13 package cz.vutbr.fit.knot.annotations.entity;
14 
16 import java.io.Serializable;
17 import javax.persistence.Basic;
18 import javax.persistence.Column;
19 import javax.persistence.Entity;
20 import javax.persistence.GeneratedValue;
21 import javax.persistence.GenerationType;
22 import javax.persistence.Id;
23 import javax.persistence.JoinColumn;
24 import javax.persistence.ManyToOne;
25 import javax.persistence.NamedQueries;
26 import javax.persistence.NamedQuery;
27 import javax.persistence.Table;
28 import javax.validation.constraints.NotNull;
29 import javax.validation.constraints.Size;
30 
31 /**
32  * Class representing source of subscription.
33  *
34  * @brief Class representing source of subscription
35  * @author Martin Petr (xpetrm05)
36  */
37 @Entity
38 @Table(name = "source")
39 @NamedQueries({
40  @NamedQuery(name = "Source.findAll", query = "SELECT s FROM Source s"),
41  @NamedQuery(name = "Source.findById", query = "SELECT s FROM Source s WHERE s.id = :id"),
42  @NamedQuery(name = "Source.findByAnnotType", query = "SELECT s FROM Source s WHERE s.annotType = :annotType"),
43  @NamedQuery(name = "Source.findByUser", query = "SELECT s FROM Source s WHERE s.userUri = :userUri"),
44  @NamedQuery(name = "Source.findBySource", query = "SELECT s FROM Source s WHERE s.source = :source"),
45  @NamedQuery(name = "Source.findByPolarity", query = "SELECT s FROM Source s WHERE s.polarity = :polarity"),
46  @NamedQuery(name = "Source.findByPackageId", query = "SELECT s FROM Source s WHERE s.packageId = :packageId")})
47 public class Source implements Serializable {
48  private static final long serialVersionUID = 1L;
49  /** Id of source of subscription */
50  @Id
51  @GeneratedValue(strategy = GenerationType.IDENTITY)
52  @Basic(optional = false)
53  @Column(name = "id")
54  private Integer id;
55 
56  /** Uri of annotation type as source */
57  @Size(max = 255)
58  @Column(name = "annotType")
59  private String annotType;
60 
61  /** Uri of user as source */
62  @Size(max = 255)
63  @Column(name = "userUri")
64  private String userUri;
65 
66  /** Uri of other sources */
67  @Size(max = 255)
68  @Column(name = "source")
69  private String source;
70 
71  /** Indicates wether is positive or negative subscription */
72  @Basic(optional = false)
73  @NotNull
74  @Column(name = "polarity")
75  private boolean polarity;
76 
77  /** Id of subscription that this source belongs */
78  @Basic(optional = false)
79  @Column(name = "packageId", nullable = false, insertable = false, updatable = false)
80  private Integer packageId;
81 
82  /** Subscription that this source belongs */
83  @ManyToOne(optional = false)
84  @JoinColumn(name = "packageId", referencedColumnName = "id")
85  private Subscription refSubscription;
86 
87  /**
88  * Constructor
89  */
90  public Source() {
91  }
92 
93  /**
94  * Constructor
95  *
96  * @param id identificator of source of subscription
97  */
98  public Source(Integer id) {
99  this.id = id;
100  }
101 
102  /**
103  * Constructor
104  *
105  * @param id identificator of source of subscription
106  * @param polarity set if subscription is positive or negative
107  */
108  public Source(Integer id, boolean polarity) {
109  this.id = id;
110  this.polarity = polarity;
111  }
112 
113  /**
114  * Gets id of source of subscription.
115  *
116  * @return id of source of subscription
117  */
118  public Integer getId() {
119  return id;
120  }
121 
122  /**
123  * Sets id of source of subscription.
124  *
125  * @param id id of source of subscription
126  */
127  public void setId(Integer id) {
128  this.id = id;
129  }
130 
131  /**
132  * Gets uri of annotation type as source.
133  *
134  * @return uri of annotation type as source
135  */
136  public String getAnnotType() {
137  return annotType;
138  }
139 
140  /**
141  * Sets uri of annotation type as source.
142  *
143  * @param annotType uri of annotation type as source
144  */
145  public void setAnnotType(String annotType) {
146  this.annotType = annotType;
147  }
148 
149  /**
150  * Gets uri of user as source.
151  *
152  * @return uri of user as source
153  */
154  public String getUser() {
155  return userUri;
156  }
157 
158  /**
159  * Sets uri of user as source.
160  *
161  * @param user uri of user as source
162  */
163  public void setUser(String user) {
164  this.userUri = user;
165  }
166 
167  /**
168  * Gets uri of other sources.
169  *
170  * @return uri of other sources
171  */
172  public String getSource() {
173  return source;
174  }
175 
176  /**
177  * Sets uri of other sources.
178  *
179  * @param source uri of other sources
180  */
181  public void setSource(String source) {
182  this.source = source;
183  }
184 
185  /**
186  * Gets variable that indicates wether is positive or negative subscription.
187  *
188  * @return variable that indicates wether is positive or negative subscription
189  */
190  public boolean getPolarity() {
191  return polarity;
192  }
193 
194  /**
195  * Sets variable that indicates wether is positive or negative subscription.
196  *
197  * @param polarity indicates wether is positive or negative subscription
198  */
199  public void setPolarity(boolean polarity) {
200  this.polarity = polarity;
201  }
202 
203  /**
204  * Gets id of subscription that this source belongs.
205  *
206  * @return id of subscription that this source belongs
207  */
208  public Integer getPackageId() {
209  return packageId;
210  }
211 
212  /**
213  * Sets id of subscription that this source belongs.
214  *
215  * @param packageId id of subscription that this source belongs
216  */
217  public void setPackageId(Integer packageId) {
218  this.packageId = packageId;
219  }
220 
221  /**
222  * Gets subscription that this source belongs.
223  *
224  * @return subscription that this source belongs
225  */
227  return refSubscription;
228  }
229 
230  /**
231  * Sets subscription that this source belongs.
232  *
233  * @param refSubscription subscription that this source belongs
234  */
235  public void setRefSubscription(Subscription refSubscription) {
236  this.refSubscription = refSubscription;
237  }
238 
239  @Override
240  public int hashCode() {
241  int hash = 0;
242  hash += (id != null ? id.hashCode() : 0);
243  return hash;
244  }
245 
246  /**
247  * Compares this with other object and returns, whether objects are same type
248  * and have same id.
249  *
250  * @param object Object to compare with
251  * @return If object is same type and have same id, returns true, false otherwise
252  */
253  @Override
254  public boolean equals(Object object) {
255  if (!(object instanceof Source)) {
256  return false;
257  }
258  Source other = (Source) object;
259  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
260  return false;
261  }
262  return true;
263  }
264 
265  @Override
266  public String toString() {
267  return "cz.vutbr.fit.knot.annotations.entity.Source[ id=" + id + " ]";
268  }
269 
270  /**
271  * Returns serialized informations about source of subscription in XML for protocol
272  * version 2.
273  *
274  * @return Returns serialized informations about source of subscription in XML
275  */
276  public String toXMLStringV2(){
277  StringBuilder result = new StringBuilder("<source ");
278 
279  result.append("subscribe=\"");
280  result.append(polarity);
281  result.append("\" ");
282 
283  if(annotType != null && !annotType.isEmpty()){
284  result.append("typeUri=\"");
285  result.append(annotType);
286  result.append("\" ");
287  }
288 
289  if(userUri != null && !userUri.isEmpty()){
290  result.append("authorUri=\"");
291  result.append(userUri);
292  result.append("\" ");
293  }
294 
295  if(source != null && !source.isEmpty()){
296  result.append("groupUri=\"");
297  result.append(source);
298  result.append("\" ");
299  }
300  result.append("/>");
301 
302  return result.toString();
303  }
304 
305  /**
306  * Gets this source as SubscribedSource
307  *
308  * @return Returns this source as SubscribedSource
309  */
311  SubscribedSource subscribed = new SubscribedSource(annotType,userUri,source);
312  return subscribed;
313  }
314 } // public class Source
Source(Integer id, boolean polarity)
Definition: Source.java:108
void setRefSubscription(Subscription refSubscription)
Definition: Source.java:235
void setPackageId(Integer packageId)
Definition: Source.java:217
Class representing source of subscription.
Definition: Source.java:47