KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > issueTracker > DiscussionData


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.modules.issueTracker;
21
22 import za.org.coefficient.authentication.CoefficientUser;
23 import za.org.coefficient.authentication.Role;
24 import za.org.coefficient.core.Project;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import net.sf.hibernate.Validatable;
32 import net.sf.hibernate.ValidationFailure;
33
34 /**
35  * @hibernate.class
36  * table="COEFFICIENT_DISCUSSION_DATA"
37  */

38 public class DiscussionData implements Validatable, java.io.Serializable JavaDoc {
39     //~ Instance fields ========================================================
40

41     private CoefficientUser user;
42     private Date JavaDoc postDate;
43     private DiscussionData parent;
44     private List JavaDoc children = new ArrayList JavaDoc();
45     private Long JavaDoc id;
46     private Project project;
47     private Role maxReadRole;
48     private Role maxWriteRole;
49     private String JavaDoc comments;
50     private String JavaDoc subject;
51     private String JavaDoc type;
52     private int replies;
53
54     //~ Methods ================================================================
55

56     public DiscussionData () {
57         postDate = new Date JavaDoc(System.currentTimeMillis());
58     }
59
60     public void setAllMaxReadRoles(Role maxReadRole) {
61         this.maxReadRole = maxReadRole;
62
63         // Make sure the children have the correct roles
64
for (Iterator JavaDoc it = children.iterator(); it.hasNext();) {
65             DiscussionData child = (DiscussionData) it.next();
66             child.setMaxReadRole(maxReadRole);
67         }
68     }
69
70     public void setAllMaxWriteRoles(Role maxWriteRole) {
71         this.maxWriteRole = maxWriteRole;
72
73         // Make sure the children have the correct roles
74
for (Iterator JavaDoc it = children.iterator(); it.hasNext();) {
75             DiscussionData child = (DiscussionData) it.next();
76             child.setMaxWriteRole(maxWriteRole);
77         }
78     }
79
80     public void setChildren(List JavaDoc argList) {
81         this.children = argList;
82     }
83
84     /**
85      *
86      * @hibernate.list
87      * cascade="all"
88      * order-by="SUBJECT"
89      * table="COEFFICIENT_DISCUSSION_DATA_CHILDREN"
90      * @hibernate.collection-key
91      * column="CHILDREN"
92      * @hibernate.collection-index
93      * column="IDX"
94      * @hibernate.collection-one-to-many
95      * class="za.org.coefficient.modules.issueTracker.DiscussionData"
96      * column="CHILDREN"
97      */

98     public List JavaDoc getChildren() {
99         return this.children;
100     }
101
102     public int getChildrenCount() {
103         int count = children.size();
104         for (Iterator JavaDoc it = children.iterator(); it.hasNext();) {
105             DiscussionData child = (DiscussionData) it.next();
106             count += child.getChildrenCount();
107         }
108
109         return count;
110     }
111
112     public void setComments(String JavaDoc argComments) {
113         this.comments = argComments;
114     }
115
116     /**
117      * Gets the value of name
118      *
119      * @return the value of name
120      * @hibernate.property
121      * column="COMMENTS"
122      * length="3999"
123      */

124     public String JavaDoc getComments() {
125         return this.comments;
126     }
127
128     public void setId(Long JavaDoc argId) {
129         this.id = argId;
130     }
131
132     /**
133      * Gets the value of id
134      *
135      * @return the value of id
136      * @hibernate.id
137      * generator-class="native"
138      *
139      */

140     public Long JavaDoc getId() {
141         return this.id;
142     }
143
144     public void setMaxReadRole(Role maxReadRole) {
145         this.maxReadRole = maxReadRole;
146     }
147
148     /**
149      * @hibernate.many-to-one
150      * cascade="none"
151      * column="MAX_READ_ROLE"
152      */

153     public Role getMaxReadRole() {
154         return maxReadRole;
155     }
156
157     public void setMaxWriteRole(Role maxWriteRole) {
158         this.maxWriteRole = maxWriteRole;
159     }
160
161     /**
162      * @hibernate.many-to-one
163      * cascade="none"
164      * column="MAX_WRITE_ROLE"
165      */

166     public Role getMaxWriteRole() {
167         return maxWriteRole;
168     }
169
170     public void setParent(DiscussionData data) {
171         this.parent = data;
172     }
173
174     /**
175      *
176      *@hibernate.many-to-one
177      * cascade="none"
178      * column="PARENT_ID"
179      */

180     public DiscussionData getParent() {
181         return this.parent;
182     }
183
184     public void setPostDate(Date JavaDoc argPostDate) {
185         this.postDate = argPostDate;
186     }
187
188     /**
189      * Gets the value of description
190      *
191      * @return the value of description
192      * @hibernate.property
193      * column="POST_DATE"
194      */

195     public Date JavaDoc getPostDate() {
196         return this.postDate;
197     }
198
199     public void setProject(Project argProject) {
200         this.project = argProject;
201     }
202
203     /**
204      *
205      *@hibernate.many-to-one
206      * cascade="none"
207      * column="PROJECT_ID"
208      */

209     public Project getProject() {
210         return this.project;
211     }
212
213     public void setReplies(int argReplies) {
214         this.replies = argReplies;
215     }
216
217     /**
218      * Gets the value of description
219      *
220      * @return the value of description
221      * @hibernate.property
222      * column="REPLIES"
223      */

224     public int getReplies() {
225         return this.replies;
226     }
227
228     public void setSubject(String JavaDoc argSubject) {
229         this.subject = argSubject;
230     }
231
232     /**
233      * Gets the value of description
234      *
235      * @return the value of description
236      * @hibernate.property
237      * column="SUBJECT"
238      * length="1024"
239      */

240     public String JavaDoc getSubject() {
241         return this.subject;
242     }
243
244     /**
245      * Sets the different type of discussions:(forum or discussion)
246      *
247      * @param active Value to assign to this.type
248      */

249     public void setType(String JavaDoc type) {
250         this.type = type;
251     }
252
253     /**
254      * Gets the value of type: forum or discussion
255      *
256      * @return the value of type: forum or discussion
257      * @hibernate.property
258      * column="TYPE"
259      * not-null="true"
260      */

261     public String JavaDoc getType() {
262         return this.type;
263     }
264
265     public void setUser(CoefficientUser argUser) {
266         this.user = argUser;
267     }
268
269     /**
270      *
271      * @hibernate.many-to-one
272      * cascade="none"
273      * column="USER_ID"
274      */

275     public CoefficientUser getUser() {
276         return this.user;
277     }
278
279     public void addChild(DiscussionData child) {
280         this.children.add(child);
281     }
282
283     public boolean equals(Object JavaDoc other) {
284         DiscussionData o = (DiscussionData) other;
285
286         return (o != null) && (this != null)
287         && (((o.id == null) && (this.id == null)) || o.id.equals(this.id));
288     }
289
290     public void removeChild(DiscussionData child) {
291         int idx = this.children.indexOf(child);
292         if (idx != -1) {
293             this.children.remove(idx);
294         }
295     }
296
297     public void validate() throws ValidationFailure {
298         if (subject.length() > 1024) {
299             throw new ValidationFailure("Subject can not be greater than 1024 characters");
300         }
301     }
302 }
303
Popular Tags