4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
Settings.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: Settings.java
5  * Description: Class representing parameter of user settings
6  */
7 
8 /**
9  * @file Settings.java
10  *
11  * @brief Class representing parameter of user settings
12  */
13 
14 package cz.vutbr.fit.knot.annotations.entity;
15 
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.Lob;
25 import javax.persistence.NamedQueries;
26 import javax.persistence.NamedQuery;
27 import javax.persistence.OneToOne;
28 import javax.persistence.Table;
29 
30 /**
31  * Class representing parameter of user settings
32  *
33  * @brief Class representing parameter of user settings
34  * @author Martin Petr (xpetrm05)
35  */
36 @Entity
37 @Table(name = "settings")
38 @NamedQueries({
39  @NamedQuery(name = "Settings.findAll", query = "SELECT s FROM Settings s"),
40  @NamedQuery(name = "Settings.findById", query = "SELECT s FROM Settings s WHERE s.id = :id"),
41  @NamedQuery(name = "Settings.findByUser", query = "SELECT s FROM Settings s WHERE s.userId = :userId"),
42  @NamedQuery(name = "Settings.findByName", query = "SELECT s FROM Settings s WHERE s.name = :name"),
43  @NamedQuery(name = "Settings.findByUserAndName", query = "SELECT s FROM Settings s WHERE s.userId = :userId AND s.name = :name"),
44  @NamedQuery(name = "Settings.findByValue", query = "SELECT s FROM Settings s WHERE s.value = :value")})
45 public class Settings implements Serializable {
46  private static final long serialVersionUID = 1L;
47  /** Id of parameter of user settings */
48  @Id
49  @GeneratedValue(strategy = GenerationType.IDENTITY)
50  @Basic(optional = false)
51  @Column(name = "id")
52  private Integer id;
53  /** Id of user to which this parameter belongs to */
54  @Basic(optional = false)
55  @Column(name = "userId", nullable=false, insertable=false, updatable=false)
56  private int userId;
57  /** Name of parameter of user settings */
58  @Basic(optional = false)
59  @Lob
60  @Column(name = "name")
61  private String name;
62  /** Value of parameter of user settings */
63  @Basic(optional = false)
64  @Lob
65  @Column(name = "paramValue")
66  private String value;
67 
68  /** Description of parameter of user settings */
69  @Basic(optional = true)
70  @Lob
71  @Column(name = "description")
72  private String description;
73 
74  /** User to which this parameter belongs to */
75  @OneToOne(optional = true)
76  @JoinColumn(name = "userId", referencedColumnName = "id")
77  private User user;
78 
79  /**
80  * Constructor
81  */
82  public Settings() {
83  }
84 
85  /**
86  * Constructor
87  *
88  * @param id id of parameter of user settings
89  */
90  public Settings(Integer id) {
91  this.id = id;
92  }
93 
94  /**
95  * Constructor
96  *
97  * @param user User to which this parameter belongs to
98  * @param name Name of parameter
99  * @param value Value of parameter
100  */
101  public Settings(User user, String name, String value) {
102  this.user = user;
103  this.userId = user.getId();
104  this.name = name;
105  this.value = value;
106  this.description = "";
107  }
108 
109  /**
110  * Constructor
111  *
112  * @param user User to which this parameter belongs to
113  * @param name Name of parameter
114  * @param value Value of parameter
115  * @param description Description of parameter
116  */
117  public Settings(User user, String name, String value, String description) {
118  this.user = user;
119  this.userId = user.getId();
120  this.name = name;
121  this.value = value;
122  this.description = description;
123  }
124 
125  /**
126  * Gets id of parameter of user settings
127  *
128  * @return id of parameter of user settings
129  */
130  public Integer getId() {
131  return id;
132  }
133 
134  /**
135  * Sets id of parameter of user settings
136  *
137  * @param id id of parameter of user settings
138  */
139  public void setId(Integer id) {
140  this.id = id;
141  }
142 
143  /**
144  * Gets id of user to which this parameter belongs to
145  *
146  * @return id of user to which this parameter belongs to
147  */
148  public int getUserId() {
149  return userId;
150  }
151 
152  /**
153  * Sets id of user to which this parameter belongs to
154  *
155  * @param userId Id of user to which this parameter belongs to
156  */
157  public void setUserId(int userId) {
158  this.userId = userId;
159  }
160 
161  /**
162  * Gets the user to which this parameter belongs to
163  *
164  * @return Returns user to which this parameter belongs to
165  */
166  public User getUser() {
167  return user;
168  }
169 
170  /**
171  * Sets the user to which this parameter belongs to
172  *
173  * @param user User to which this parameter belongs to
174  */
175  public void setUser(User user) {
176  this.user = user;
177  }
178 
179  /**
180  * Gets name of parameter
181  *
182  * @return Returns name of parameter
183  */
184  public String getName() {
185  return name;
186  }
187 
188  /**
189  * Sets name of parameter
190  *
191  * @param name Name of parameter
192  */
193  public void setName(String name) {
194  this.name = name;
195  }
196 
197  /**
198  * Gets value of parameter
199  *
200  * @return Returns value of parameter
201  */
202  public String getValue() {
203  return value;
204  }
205 
206  /**
207  * Sets value of parameter
208  *
209  * @param value Value of parameter
210  */
211  public void setValue(String value) {
212  this.value = value;
213  }
214 
215  /**
216  * Gets description of parameter
217  *
218  * @return Returns description of parameter
219  */
220  public String getDescription() {
221  return description;
222  }
223 
224  /**
225  * Sets description of parameter
226  *
227  * @param description Description of parameter
228  */
229  public void setDescription(String description) {
230  this.description = description;
231  }
232 
233  /**
234  * Method returns true wether value is string with annotation style
235  *
236  * @return true if value is annotation style
237  */
238  public boolean isStyleSetting(){
239  String[] result = name.split(":");
240  if(result.length == 2) return true;
241  else return false;
242  }
243 
244  @Override
245  public int hashCode() {
246  int hash = 0;
247  hash += (id != null ? id.hashCode() : 0);
248  return hash;
249  }
250 
251  /**
252  * Compares this with other object and returns, whether objects are same type
253  * and have same id.
254  *
255  * @param object Object to compare with
256  * @return If object is same type and have same id, returns true, false otherwise
257  */
258  @Override
259  public boolean equals(Object object) {
260  if (!(object instanceof Settings)) {
261  return false;
262  }
263  Settings other = (Settings) object;
264  if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
265  return false;
266  }
267  return true;
268  }
269 
270  @Override
271  public String toString() {
272  return "cz.vutbr.fit.knot.annotations.entity.Settings[id=" + id + "]";
273  }
274 
275  /**
276  * Returns serialized informations about parameter of user settings in XML
277  *
278  * @return Returns serialized informations about parameter of user settings in XML
279  */
280  public String toXMLString() {
281  String desc = "";
282  if (description != null && !description.isEmpty()) {
283  desc = " description=\"" + description + "\"";
284  }
285  return "<param name=\"" + name + "\" value=\"" + value + "\"" + desc + "/>";
286  }
287 
288 } // class Settings
Class representing parameter of user settings.
Definition: Settings.java:45
Settings(User user, String name, String value)
Definition: Settings.java:101
Class representing user.
Definition: User.java:51
Settings(User user, String name, String value, String description)
Definition: Settings.java:117