KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > geinuke > bizlogic > ForumBL


1
2
3  /*
4  -- GeiNuke --
5 Copyright (c) 2005 by Roberto Sidoti [geinuke@users.sourceforge.net]
6  http://www.hostingjava.it/-geinuke/
7
8 This file is part of GeiNuke.
9
10     GeiNuke is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     GeiNuke is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with GeiNuke; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */

24 package com.geinuke.bizlogic;
25
26 import java.sql.SQLException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29
30 import com.geinuke.dao.ForumDAO;
31 import com.geinuke.middle.ICategoryBL;
32 import com.geinuke.middle.ICommentBL;
33 import com.geinuke.middle.IForumBL;
34 import com.geinuke.middle.ITopicBL;
35 import com.geinuke.middle.IUserBL;
36 import com.geinuke.middle.MiddleFactory;
37 import com.geinuke.util.CountArrayList;
38 import com.geinuke.util.collection.ForumTopicComparator;
39 import com.geinuke.util.collection.MagicCollections;
40 import com.geinuke.vo.CategoryVO;
41 import com.geinuke.vo.CommentVO;
42 import com.geinuke.vo.ForumVO;
43 import com.geinuke.vo.TopicVO;
44 import com.geinuke.vo.UserVO;
45
46
47 public class ForumBL implements IForumBL {
48     protected static IForumBL instance=null;
49     
50     public ForumBL(){
51         
52     }
53     
54
55     
56     protected void fillForum(ForumVO f)throws BLException{
57         IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL");
58         ITopicBL tbl=(ITopicBL)MiddleFactory.getBL("ITopicBL");
59         ICategoryBL cbl=(ICategoryBL)MiddleFactory.getBL("ICategoryBL");
60         ICommentBL cobl=(ICommentBL)MiddleFactory.getBL("ICommentBL");
61         
62         CommentVO co=null;
63         ArrayList JavaDoc mods=null;
64         mods=ubl.getUsersByForumID(f.getFId());
65         f.setModerators(mods);
66         f.setTopics(tbl.getTopicsByFId(f.getFId()));
67         //I use this work around for Hessian incompatibility
68
//with ArrayList extensions
69
f.setCommentCount(f.getTopics().getCount());
70         f.setCategories(cbl.getCategoriesByFId(f.getFId()));
71         co=cobl.getLastForumCommentByFId(f.getFId());
72         boolean visited=true;
73         TopicVO t=null;
74         for(int i=0;i<f.getTopics().size() && visited;i++){
75             t=(TopicVO)f.getTopics().get(i);
76             tbl.setLastModTime(t);
77             if(t.hasNewContent())
78                 visited=false;
79                 //GeiServlet.intLog("ForumBL.fillForum(...), topic "+t.getName()+" "+visited);
80

81         }
82         f.setVisited(visited);
83         TopicVO tt=null;
84         tt=tbl.getLastTopicByFId(f.getFId());
85         if(co!=null){
86             //f.setLastEntry(co.getDateTime().getTimeInMillis());
87
if(tt!=null && tt.getCreationTime()>co.getDateTime().getTimeInMillis()){
88                 f.setLastEntry(tt.getCreationTime());
89                 f.setLastUser(tt.getAuthor());
90                 
91             }else{
92                 f.setLastUser(ubl.getUserByID(co.getUId()));
93                 f.setLastEntry(co.getDateTime().getTimeInMillis());
94             }
95                 
96             //f.setLastUser(ubl.getUserByID(co.getUId()));
97

98             
99         }else{
100             //getLAsttopic???
101
//tt=tbl.getLastTopicByFId(f.getFId());
102

103             if(tt!=null){
104                 f.setLastEntry(tt.getCreationTime());
105                 f.setLastUser(tt.getAuthor());
106             }else{
107                 f.setLastUser((UserVO)f.getModerators().get(0));
108                 //mmm si puo dfare di piu
109
}
110         }
111     }
112     
113     public ArrayList JavaDoc getVisibleForums() throws BLException {
114         ArrayList JavaDoc ll=null;
115         try{
116             ForumDAO dao=new ForumDAO();
117             List JavaDoc list=dao.getVisibleForums();
118             
119             ll=new ArrayList JavaDoc(list);
120         }catch(SQLException JavaDoc sqle){
121             throw new DBException(sqle.getMessage());
122         }catch(Throwable JavaDoc t){
123             throw new BLException(t.getMessage());
124         }
125         /*
126         UserBL ubl=UserBL.singleton();
127         TopicBL tbl=TopicBL.singleton();
128         CategoryBL cbl=CategoryBL.singleton();
129         CommentBL cobl=CommentBL.singleton();
130         
131         CommentVO co=null;
132         ArrayList mods=null;
133         */

134         ForumVO f=null;
135         
136         for(int i=0;i<ll.size();i++){
137             f=(ForumVO)ll.get(i);
138             this.fillForum(f);
139             /*
140             mods=ubl.getUsersByForumID(f.getFId());
141             f.setModerators(mods);
142             f.setTopics(tbl.getTopicsByFId(f.getFId()));
143             f.setCategories(cbl.getCategoriesByFId(f.getFId()));
144             co=cobl.getLastForumCommentByXId(f.getFId());
145             if(co!=null){
146                 f.setLastEntry(co.getDateTime().getTimeInMillis());
147                 f.setLastUser(ubl.getUserByID(co.getUId()));
148             }else{
149                 //getLAsttopic???
150             }
151             */

152         }
153         
154         return ll;
155     }
156     
157     public ArrayList JavaDoc getEmptyVisibleForums() throws BLException {
158         ArrayList JavaDoc ll=null;
159         try{
160             ForumDAO dao=new ForumDAO();
161             List JavaDoc list=dao.getVisibleForums();
162             
163             ll=new ArrayList JavaDoc(list);
164         }catch(SQLException JavaDoc sqle){
165             throw new DBException(sqle.getMessage());
166         }catch(Throwable JavaDoc t){
167             throw new BLException(t.getMessage());
168         }
169             
170         return ll;
171     }
172     
173     public void insForum(ForumVO f)throws BLException{
174         
175         try{
176             ForumDAO dao=new ForumDAO();
177             dao.insForum(f);
178             dao.insForumModerator(f.getFId(),1);
179             dao.insCategoryForum(f.getFId(), ((CategoryVO)f.getCategories().get(0)).getCatId() );
180             
181         }catch(SQLException JavaDoc sqle){
182             throw new DBException(sqle.getMessage());
183         }catch(Throwable JavaDoc t){
184             throw new BLException(t.getMessage());
185         }
186         
187     }
188     
189     public void updateForum(ForumVO f)throws BLException{
190         
191         try{
192             ForumDAO dao=new ForumDAO();
193             dao.updateForum(f);
194             
195             
196         }catch(SQLException JavaDoc sqle){
197             throw new DBException(sqle.getMessage());
198         }catch(Throwable JavaDoc t){
199             throw new BLException(t.getMessage());
200         }
201         
202     }
203     
204     
205     public ForumVO getForumByFId(int fid) throws BLException {
206         ForumVO res=null;
207         try{
208             ForumDAO dao=new ForumDAO();
209             res=dao.getForumByFId(fid);
210             
211             
212         }catch(SQLException JavaDoc sqle){
213             throw new DBException(sqle.getMessage());
214         }catch(Throwable JavaDoc t){
215             throw new BLException(t.getMessage());
216         }
217                     
218         if(res!=null){
219             this.fillForum(res);
220             int tot=res.getTopics().size();
221             TopicVO t=null;
222             CountArrayList list=new CountArrayList();
223             list.setCount(res.getTopics().getCount());
224             for(int i=0;i<tot;i++){
225                 t=(TopicVO)res.getTopics().get(i);
226                 ITopicBL tbl=(ITopicBL)MiddleFactory.getBL("ITopicBL");
227                 t=tbl.fillTopic(t);
228                 list.add(t);
229             }
230             
231             int c=list.getCount();
232             
233             list= new CountArrayList( MagicCollections.semplifyAndSort(list,new ForumTopicComparator()) ) ;
234             list.setCount(c);
235             
236             res.setTopics(list);
237         }
238         return res;
239     }
240     
241     public void delForumByFId(int fid) throws BLException {
242         
243         try{
244             
245             ITopicBL tbl=(ITopicBL)MiddleFactory.getBL("ITopicBL");
246             tbl.delForumTopicsByFid(fid);
247             ForumDAO dao=new ForumDAO();
248             dao.delForumByFId(fid);
249             
250             
251         }catch(SQLException JavaDoc sqle){
252             throw new DBException(sqle.getMessage());
253         }catch(Throwable JavaDoc t){
254             throw new BLException(t.getMessage());
255         }
256                     
257         
258     }
259     
260     public ForumVO getForumByTId(int fid) throws BLException {
261         ForumVO res=null;
262         try{
263             ForumDAO dao=new ForumDAO();
264             res=dao.getForumByTId(fid);
265             
266             
267         }catch(SQLException JavaDoc sqle){
268             throw new DBException(sqle.getMessage());
269         }catch(Throwable JavaDoc t){
270             throw new BLException(t.getMessage());
271         }
272                     
273         if(res!=null){
274             this.fillForum(res);
275             /*
276             int tot=res.getTopics().size();
277             TopicVO t=null;
278             CountArrayList list=new CountArrayList();
279             list.setCount(res.getTopics().getCount());
280             for(int i=0;i<tot;i++){
281                 t=(TopicVO)res.getTopics().get(i);
282                 t=TopicBL.singleton().fillTopic(t);
283                 list.add(t);
284             }
285             res.setTopics(list);
286             */

287         }
288         return res;
289     }
290
291 }
292
Popular Tags