1 2 3 24 package com.geinuke.bizlogic; 25 26 import java.sql.SQLException ; 27 import java.util.ArrayList ; 28 import java.util.List ; 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 mods=null; 64 mods=ubl.getUsersByForumID(f.getFId()); 65 f.setModerators(mods); 66 f.setTopics(tbl.getTopicsByFId(f.getFId())); 67 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 81 } 82 f.setVisited(visited); 83 TopicVO tt=null; 84 tt=tbl.getLastTopicByFId(f.getFId()); 85 if(co!=null){ 86 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 98 99 }else{ 100 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 } 110 } 111 } 112 113 public ArrayList getVisibleForums() throws BLException { 114 ArrayList ll=null; 115 try{ 116 ForumDAO dao=new ForumDAO(); 117 List list=dao.getVisibleForums(); 118 119 ll=new ArrayList (list); 120 }catch(SQLException sqle){ 121 throw new DBException(sqle.getMessage()); 122 }catch(Throwable t){ 123 throw new BLException(t.getMessage()); 124 } 125 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 152 } 153 154 return ll; 155 } 156 157 public ArrayList getEmptyVisibleForums() throws BLException { 158 ArrayList ll=null; 159 try{ 160 ForumDAO dao=new ForumDAO(); 161 List list=dao.getVisibleForums(); 162 163 ll=new ArrayList (list); 164 }catch(SQLException sqle){ 165 throw new DBException(sqle.getMessage()); 166 }catch(Throwable 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 sqle){ 182 throw new DBException(sqle.getMessage()); 183 }catch(Throwable 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 sqle){ 197 throw new DBException(sqle.getMessage()); 198 }catch(Throwable 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 sqle){ 213 throw new DBException(sqle.getMessage()); 214 }catch(Throwable 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 sqle){ 252 throw new DBException(sqle.getMessage()); 253 }catch(Throwable 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 sqle){ 268 throw new DBException(sqle.getMessage()); 269 }catch(Throwable t){ 270 throw new BLException(t.getMessage()); 271 } 272 273 if(res!=null){ 274 this.fillForum(res); 275 287 } 288 return res; 289 } 290 291 } 292 | Popular Tags |