KickJava   Java API By Example, From Geeks To Geeks.

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


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

23 package com.geinuke.bizlogic;
24
25 import java.sql.SQLException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29
30 import com.geinuke.dao.UserDAO;
31
32 import com.geinuke.middle.ICommentBL;
33 import com.geinuke.middle.ITopicBL;
34 import com.geinuke.middle.IUserBL;
35 import com.geinuke.middle.MiddleFactory;
36 import com.geinuke.servlet.GeiServlet;
37 import com.geinuke.util.collection.CachedBL;
38 import com.geinuke.util.collection.SimpleCache;
39 import com.geinuke.vo.CommentVO;
40 import com.geinuke.vo.RoleVO;
41 import com.geinuke.vo.UserVO;
42 import com.geinuke.util.log.*;
43
44 public class UserBL extends CachedBL implements IUserBL {
45      
46     
47     
48     
49     public UserBL(){
50         
51         super();
52     }
53     
54
55     
56     public ArrayList JavaDoc getUsersByForumID(int fid) throws BLException {
57         ArrayList JavaDoc ll=null;
58         
59         
60         try{
61             UserDAO dao=new UserDAO();
62             List JavaDoc list=dao.getUsersByForumID(fid);
63             
64             ll=new ArrayList JavaDoc(list);
65         }catch(SQLException JavaDoc sqle){
66             throw new DBException(sqle.getMessage());
67         }catch(Throwable JavaDoc t){
68             throw new BLException(t.getMessage());
69         }
70         
71         return ll;
72     }
73     
74     public UserVO getDefUser()throws BLException{
75         BizLogger.intLog("USerBL.getDefUser(...), START");
76         UserVO user=null;
77         user=new UserVO();
78         user.setUName(UserVO.ANONYMOUS);
79         user=this.getUserByUName(user);
80         BizLogger.intLog("USerBL.getDefUser(...), style "+user.getDefStyle());
81         RoleVO role=null;
82         role=new RoleVO();
83         role.setRoleName(UserVO.ANONYMOUS);
84         role.setId(1);
85         role.setLevela(10);
86         user.setRole(role);
87         return user;
88     }
89     
90     public UserVO getUserToByPID(int pid)throws BLException{
91         UserVO user=null;
92         
93         try{
94             UserDAO dao=new UserDAO();
95             user=dao.getUserToByPID(pid);
96         }catch(SQLException JavaDoc sqle){
97             throw new DBException(sqle.getMessage());
98         }catch(Throwable JavaDoc t){
99             throw new BLException(t.getMessage());
100         }
101         
102         return user;
103     }
104     
105     public UserVO getUserFromByPID(int pid)throws BLException{
106         UserVO user=null;
107         
108         try{
109             UserDAO dao=new UserDAO();
110             user=dao.getUserFromByPID(pid);
111         }catch(SQLException JavaDoc sqle){
112             throw new DBException(sqle.getMessage());
113         }catch(Throwable JavaDoc t){
114             throw new BLException(t.getMessage());
115         }
116         
117         return user;
118     }
119     
120     
121     public UserVO getUUserByID(UserVO u)throws BLException{
122         UserVO user=null;
123         if(userCache.containsKey("UserBL.getUUserByID-"+u.getId())){
124             user=(UserVO)userCache.get("UserBL.getUUserByID-"+u.getId());
125             return user;
126         }
127         user=new UserVO();
128         try{
129             UserDAO dao=new UserDAO();
130             user=dao.getUserByID(u);
131         }catch(SQLException JavaDoc sqle){
132             throw new DBException(sqle.getMessage());
133         }catch(Throwable JavaDoc t){
134             throw new BLException(t.getMessage());
135         }
136         if(user!=null)
137             userCache.put("UserBL.getUUserByID-"+u.getId(),user,7200);
138         return user;
139     }
140     
141     public UserVO getUserByID(int id)throws BLException{
142         UserVO user=null;
143         user=new UserVO();
144         user.setId(id);
145         return getUUserByID(user);
146     }
147     
148     public UserVO getLastTopicAuthorByTId(int tid)throws BLException{
149         UserVO user=null;
150         int id=-1;
151         CommentVO co=null;
152         
153         ICommentBL coBL=(ICommentBL)MiddleFactory.getBL("ICommentBL");
154         
155         
156         co=coBL.getLastForumCommentByTId(tid);
157         if(co==null){
158             ITopicBL tBL=(ITopicBL)MiddleFactory.getBL("ITopicBL");
159             user=tBL.getForumTopicByTId(tid).getAuthor();
160             return user;
161         }else{
162             id=co.getUId();
163             user=new UserVO();
164             user.setId(id);
165             return getUUserByID(user);
166         }
167         
168     }
169     
170     public HashMap JavaDoc getLastTopicsAuthorByTIdArray(ArrayList JavaDoc tv)throws BLException{
171         HashMap JavaDoc map=new HashMap JavaDoc();
172         int j=-1;
173         for(int i=0;i<tv.size();i++){
174             j=((Integer JavaDoc)tv.get(i)).intValue();
175             map.put(""+j,this.getLastTopicAuthorByTId(j));
176         }
177         return map;
178     }
179     
180     
181     public void insUser(UserVO u)throws BLException{
182         userCache.clear();
183         try{
184             UserDAO dao=new UserDAO();
185             dao.insertUser(u);
186             
187         }catch(SQLException JavaDoc sqle){
188             throw new DBException(sqle.getMessage());
189         }catch(Throwable JavaDoc t){
190             throw new BLException(t.getMessage());
191         }
192         
193     }
194     
195     public void insRole(RoleVO u)throws BLException{
196         
197         try{
198             UserDAO dao=new UserDAO();
199             dao.insertRole(u);
200             
201         }catch(SQLException JavaDoc sqle){
202             throw new DBException(sqle.getMessage());
203         }catch(Throwable JavaDoc t){
204             throw new BLException(t.getMessage());
205         }
206         
207     }
208     
209     public void updateUser(UserVO u)throws BLException{
210         userCache.clear();
211         try{
212             UserDAO dao=new UserDAO();
213             dao.updateUser(u);
214             
215         }catch(SQLException JavaDoc sqle){
216             throw new DBException(sqle.getMessage());
217         }catch(Throwable JavaDoc t){
218             throw new BLException(t.getMessage());
219         }
220         
221     }
222     
223     public void updateAllDefStyle(String JavaDoc style)throws BLException{
224         userCache.clear();
225         try{
226             UserDAO dao=new UserDAO();
227             dao.updateAllDefStyle(style);
228             
229         }catch(SQLException JavaDoc sqle){
230             throw new DBException(sqle.getMessage());
231         }catch(Throwable JavaDoc t){
232             throw new BLException(t.getMessage());
233         }
234         
235     }
236     
237     public ArrayList JavaDoc getAllRoles() throws BLException{
238         ArrayList JavaDoc list=null;
239         try{
240             UserDAO dao=new UserDAO();
241             list=dao.getAllRoles();
242             
243         }catch(SQLException JavaDoc sqle){
244             throw new DBException(sqle.getMessage());
245         }catch(Throwable JavaDoc t){
246             throw new BLException(t.getMessage());
247         }
248         return list;
249     }
250     
251     public ArrayList JavaDoc getAllUsers() throws BLException{
252         ArrayList JavaDoc list=null;
253         BizLogger.intLog("UserBL.getAllUsers(), simple trace ...");
254         if(userCache.containsKey("UserBL.getAllUsers-")){
255             list=(ArrayList JavaDoc)userCache.get("UserBL.getAllUsers-");
256             return list;
257         }
258         try{
259             UserDAO dao=new UserDAO();
260             list=dao.getAllUsers();
261             
262         }catch(SQLException JavaDoc sqle){
263             throw new DBException(sqle.getMessage());
264         }catch(Throwable JavaDoc t){
265             throw new BLException(t.getMessage());
266         }
267         userCache.put("UserBL.getAllUsers-",list,7200);
268         return list;
269     }
270     
271     public void updateUserRole(UserVO u)throws BLException{
272         userCache.clear();
273         try{
274             UserDAO dao=new UserDAO();
275             dao.updateUserRole(u);
276             
277         }catch(SQLException JavaDoc sqle){
278             throw new DBException(sqle.getMessage());
279         }catch(Throwable JavaDoc t){
280             throw new BLException(t.getMessage());
281         }
282         
283     }
284     
285     public UserVO getUserByAuth(UserVO u)throws BLException{
286         UserVO user=null;
287         
288         user=new UserVO();
289         try{
290             UserDAO dao=new UserDAO();
291             user=dao.getUserByAuth(u);
292             
293         }catch(SQLException JavaDoc sqle){
294             throw new DBException(sqle.getMessage());
295         }catch(Throwable JavaDoc t){
296             throw new BLException(t.getMessage());
297         }
298         
299         return user;
300     }
301     
302     public UserVO getUserByUName(UserVO u)throws BLException{
303         BizLogger.intLog("USerBL.getUserByUName(...), START");
304         UserVO user=null;
305         if(userCache.containsKey("UserBL.getUserByUName-"+u.getUName())){
306             user=(UserVO)userCache.get("UserBL.getUserByUName-"+u.getUName());
307             return user;
308         }
309         if(u.getRole()==null){
310             RoleVO r=new RoleVO();
311             u.setRole(r);
312         }
313         user=new UserVO();
314         try{
315             UserDAO dao=new UserDAO();
316             user=dao.getUserByUName(u);
317         }catch(SQLException JavaDoc sqle){
318             throw new DBException(sqle.getMessage());
319         }catch(Throwable JavaDoc t){
320             throw new BLException(t.getMessage());
321         }
322         if(user!=null)
323             userCache.put("UserBL.getUserByUName-"+u.getUName(),user,7200);
324         return user;
325     }
326     
327     
328 }
329
Popular Tags