4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
SubscribedItem.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: SubscribedItem.java
5  * Description: Class representing item of subscripted or unsubscripted sources list
6  */
7 
8 /**
9  * @file SubscribedItem.java
10  *
11  * @brief Class representing item of subscripted or unsubscripted sources list
12  */
13 
14 package cz.vutbr.fit.knot.annotations.modules.StoryscopeInterface;
15 
18 import java.io.Serializable;
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.NamedQueries;
27 import javax.persistence.NamedQuery;
28 import javax.persistence.OneToOne;
29 import javax.persistence.Table;
30 
31 
32 /**
33  * This class represent item of subscripted or unsubscripted sources list and is
34  * used for StoryscopeInterfaceModule needs.
35  *
36  * @brief Class representing item of subscripted or unsubscripted sources list.
37  * @author Martin Petr (xpetrm05)
38  */
39 @Entity
40 @Table(name = "subscribedItem")
41 @NamedQueries({
42  @NamedQuery(name = "SubscribedItem.findAll", query = "SELECT s FROM SubscribedItem s"),
43  @NamedQuery(name = "SubscribedItem.findById", query = "SELECT s FROM SubscribedItem s WHERE s.id = :id"),
44  @NamedQuery(name = "SubscribedItem.findSubscriptions", query = "SELECT s FROM SubscribedItem s WHERE s.storyScope = :storyScope"),
45  @NamedQuery(name = "SubscribedItem.findSubscribed", query = "SELECT s FROM SubscribedItem s WHERE s.polarity = 0 AND s.storyScope = :storyScope"),
46  @NamedQuery(name = "SubscribedItem.findUnsubscribed", query = "SELECT s FROM SubscribedItem s WHERE s.polarity = 1 AND s.storyScope = :storyScope")})
47 public class SubscribedItem implements Serializable {
48  /** ID of subscribed item */
49  @Id
50  @GeneratedValue(strategy = GenerationType.IDENTITY)
51  @Basic(optional = false)
52  @Column(name = "id")
53  private Integer id;
54 
55  /** ID of story space that item belongs */
56  @Basic(optional = false)
57  @Column(name = "storyScope")
58  private Integer storyScope;
59 
60  /** Type of annotation that story space wants (or don't wants) recive */
61  @OneToOne(optional = true)
62  @JoinColumn(name = "annotType", referencedColumnName = "id")
63  private AnnotType annotationType;
64 
65  /** User which story space wants subscribe or unsubscribe */
66  @OneToOne(optional = true)
67  @JoinColumn(name = "user", referencedColumnName = "id")
68  private User user;
69 
70  /** Source which story space wants subscribe or unsubscribe */
71  @Basic(optional = true)
72  @Column(name = "source")
73  private String source;
74 
75  /** Type of subscription (0 = unsubscribed, 1 = subscribed) */
76  @Basic(optional = false)
77  @Column(name = "polarity")
78  private int polarity;
79 
80  /** Indicator of subscribed type */
81  public static final int SUBSCRIBED = 0;
82  /** Indicator of unsubscribed type */
83  public static final int UNSUBSCRIBED = 1;
84 
85 
86  /**
87  * Gets id of subscription
88  *
89  * @return Returns id of user
90  */
91  public Integer getId() {
92  return id;
93  }
94 
95  /**
96  * Sets id of subscription
97  *
98  * @param id id of subscription
99  */
100  public void setId(Integer id) {
101  this.id = id;
102  }
103 
104  /**
105  * Gets id of Story Space that sunscription belongs
106  *
107  * @return Returns id of story space
108  */
109  public Integer getStoryScopeId() {
110  return storyScope;
111  }
112 
113  /**
114  * Sets id of Story Space that sunscription belongs
115  *
116  * @param id id of Story Space that sunscription belongs
117  */
118  public void setStoryScopeId(Integer id) {
119  this.storyScope = id;
120  }
121 
122  /**
123  * Gets annotation type that is subscribed (or unsubscribed)
124  *
125  * @return Returns instance of class AnnotType with type of annotation or null if isn't fill
126  */
128  return annotationType;
129  }
130 
131  /**
132  * Sets annotation type that is subscribed (or unsubscribed)
133  *
134  * @param type annotation type that is subscribed (or unsubscribed)
135  */
136  public void setAnnotationType(AnnotType type) {
137  this.annotationType = type;
138  }
139 
140  /**
141  * Gets user which is subscribed (or unsubscribed)
142  *
143  * @return Returns instance of class User with user or null if user isn't fill
144  */
145  public User getUser() {
146  return user;
147  }
148 
149  /**
150  * Sets user which is subscribed (or unsubscribed)
151  *
152  * @param user user which is subscribed (or unsubscribed)
153  */
154  public void setUser(User user) {
155  this.user = user;
156  }
157 
158  /**
159  * Gets source that is subscribed (or unsubscribed)
160  *
161  * @return Returns instance of class String with URL of source or null if isn't fill
162  */
163  public String getSource(){
164  return source;
165  }
166 
167  /**
168  * Sets source that is subscribed (or unsubscribed)
169  *
170  * @param source source that is subscribed (or unsubscribed)
171  */
172  public void setSource(String source){
173  this.source = source;
174  }
175 
176  /**
177  * Gets type of subscription
178  *
179  * @return Returns 0 if is unsubscribed or 1 if is subscribed
180  */
181  public int getType(){
182  return polarity;
183  }
184 
185  /**
186  * Sets type of subscription
187  *
188  * @param type type of subscription
189  */
190  public void setType(int type){
191  this.polarity = type;
192  }
193 
194  @Override
195  public int hashCode() {
196  int hash = 0;
197  hash += (id != null ? id.hashCode() : 0);
198  return hash;
199  }
200 
201  /**
202  * Compares this with other object and returns, whether objects are same type
203  * and have same id.
204  *
205  * @param object Object to compare with
206  * @return If object is same type and have same id, returns true, false otherwise
207  */
208  @Override
209  public boolean equals(Object object) {
210  if (!(object instanceof SubscribedItem)) {
211  return false;
212  }
213  SubscribedItem tested = (SubscribedItem) object;
214  if ((this.id == null && tested.id != null) || (this.id != null && !this.id.equals(tested.id))) {
215  return false;
216  }
217  return true;
218  }
219 
220  @Override
221  public String toString() {
222  return "cz.vutbr.fit.knot.annotations.modules.StoryscopeInterface.SubscribedItem[id=" + id + "]";
223  }
224 
225 } // class SubscribedItem
Class representing type of annotation.
Definition: AnnotType.java:58
Class representing item of subscripted or unsubscripted sources list.
Class representing user.
Definition: User.java:51