1 2 23 package com.geinuke.bizlogic; 24 25 import java.sql.SQLException ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 import com.geinuke.common.UserI; 30 import com.geinuke.dao.ModuleDAO; 31 import com.geinuke.middle.IModuleBL; 32 import com.geinuke.middle.IUserBL; 33 import com.geinuke.middle.MiddleFactory; 34 import com.geinuke.util.NukeResource; 35 import com.geinuke.vo.ModuleDBVO; 36 import com.geinuke.vo.RoleVO; 37 38 39 public class ModuleBL implements IModuleBL { 40 41 protected static IModuleBL instance=null; 42 43 public ModuleBL(){ 44 45 } 46 47 48 49 public ModuleDBVO getDefModule()throws BLException { 50 ModuleDBVO mod=null; 51 try{ 52 ModuleDAO dao=new ModuleDAO(); 53 mod=dao.getDefModule(); 54 }catch(SQLException sqle){ 55 throw new DBException(sqle.getMessage()); 56 }catch(Throwable t){ 57 throw new BLException(t.getMessage()); 58 } 59 return mod; 60 } 61 62 private ModuleDBVO getStaticModule(){ 63 ModuleDBVO mod=null; 64 mod=new ModuleDBVO(); 65 mod.setActive(true); 66 String cont="<table width=100% bgcolor=\"#FFFFFF\"><tr><td> "+ 67 "<br/>Questa e+ una prova" + 68 "</td></tr></table>"; 69 mod.setContent(cont); 70 mod.setDbStored(true); 71 mod.setHomePosition(-10); 72 mod.setId(356); 73 mod.setInMenu(false); 74 mod.setName("Prova"); 75 mod.setPos(0); 76 mod.setRoleLevel(10); 77 mod.setSkin(0); 78 mod.setTitle("La prova"); 79 mod.setWeight(1); 80 return mod; 81 } 82 83 public ModuleDBVO getModule(String modd)throws BLException { 84 ModuleDBVO mod=null; 87 try{ 88 ModuleDAO dao=new ModuleDAO(); 89 mod=dao.getModuleByName(modd); 90 }catch(SQLException sqle){ 91 sqle.printStackTrace(System.out); 92 throw new DBException(sqle.getMessage()); 93 }catch(Throwable t){ 94 throw new BLException(t.getMessage()); 95 } 96 return mod; 97 } 98 99 public ModuleDBVO getModuleByID(int id)throws BLException { 100 ModuleDBVO mod=null; 101 try{ 102 ModuleDAO dao=new ModuleDAO(); 103 mod=dao.getModuleById(id); 104 }catch(SQLException sqle){ 105 sqle.printStackTrace(System.out); 106 throw new DBException(sqle.getMessage()); 107 }catch(Throwable t){ 108 throw new BLException(t.getMessage()); 109 } 110 return mod; 111 } 112 113 public void updateSingleModule(int id,String action)throws BLException { 114 ModuleDBVO mod=null; 115 ArrayList roles=null; 116 IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL"); 117 roles=ubl.getAllRoles(); 118 RoleVO role=null; 119 mod=this.getModuleByID(id); 120 if(action.equalsIgnoreCase("skin")){ 121 int skin=mod.getSkin(); 122 mod.setSkin( (skin+1)%4 ); 123 }else if(action.equalsIgnoreCase("width")){ 124 int width=mod.getWidth(); 125 mod.setWidth( (width+1)%3 ); 126 }else if(action.equalsIgnoreCase("inmenu")){ 127 mod.setInMenu(! mod.isInMenu() ); 128 }else if(action.equalsIgnoreCase("active")){ 129 mod.setActive(! mod.isActive() ); 130 }else if(action.equalsIgnoreCase("inHome")){ 131 int hp=mod.getHomePosition(); 132 hp=hp+1; 133 if(hp==4) 134 hp=-1; 135 mod.setHomePosition(hp ); 136 }else if(action.equalsIgnoreCase("rolel")){ 137 int level=mod.getRoleLevel(); 138 int pos=NukeResource.getRolePositionByRoleLevel(level,roles); 139 if(pos>=0){ 140 pos=(pos+1)%roles.size(); 141 role=(RoleVO)roles.get(pos); 142 mod.setRoleLevel(role.getLevela()); 143 } 144 } 145 this.updateDBModule(mod); 146 } 147 148 149 150 155 public ArrayList getAllModulesInMainBlock(UserI user) throws BLException { 156 ArrayList ll=null; 157 try{ 158 ModuleDAO dao=new ModuleDAO(); 159 List list=dao.getAllModuleInMainBlock(user); 160 161 ll=new ArrayList (list); 162 }catch(SQLException sqle){ 163 sqle.printStackTrace(System.out); 164 throw new DBException(sqle.getMessage()); 165 }catch(Throwable t){ 166 throw new BLException(t.getMessage()); 167 } 168 169 return ll; 170 } 171 172 public ArrayList getModulesInHomePage(UserI user) throws BLException { 173 ArrayList ll=null; 174 try{ 175 ModuleDAO dao=new ModuleDAO(); 176 List list=dao.getModulesInHomePage(user); 177 178 ll=new ArrayList (list); 179 }catch(SQLException sqle){ 180 sqle.printStackTrace(System.out); 181 throw new DBException(sqle.getMessage()); 182 }catch(Throwable t){ 183 throw new BLException(t.getMessage()); 184 } 185 186 return ll; 187 } 188 189 public void updateDBModule(ModuleDBVO mod)throws BLException{ 190 try{ 191 ModuleDAO dao=new ModuleDAO(); 192 dao.updateDBModule(mod); 193 }catch(SQLException sqle){ 194 throw new DBException(sqle.getMessage()); 195 }catch(Throwable t){ 196 throw new BLException(t.getMessage()); 197 } 198 } 199 200 public void insertDBStoredModule(ModuleDBVO mod)throws BLException{ 201 try{ 202 ModuleDAO dao=new ModuleDAO(); 203 dao.insertDBStoredModule(mod); 204 }catch(SQLException sqle){ 205 throw new DBException(sqle.getMessage()); 206 }catch(Throwable t){ 207 throw new BLException(t.getMessage()); 208 } 209 } 210 211 public ArrayList getAllDBModules() throws BLException { 212 ArrayList ll=null; 213 try{ 214 ModuleDAO dao=new ModuleDAO(); 215 List list=dao.getAllDBModules(); 216 217 ll=new ArrayList (list); 218 }catch(SQLException sqle){ 219 throw new DBException(sqle.getMessage()); 220 }catch(Throwable t){ 221 throw new BLException(t.getMessage()); 222 } 223 224 return ll; 225 } 226 227 public ArrayList getAllDBStoredModules() throws BLException { 228 ArrayList ll=null; 229 try{ 230 ModuleDAO dao=new ModuleDAO(); 231 List list=dao.getAllDBStoredModules(); 232 233 ll=new ArrayList (list); 234 }catch(SQLException sqle){ 235 throw new DBException(sqle.getMessage()); 236 }catch(Throwable t){ 237 throw new BLException(t.getMessage()); 238 } 239 240 return ll; 241 } 242 243 244 245 246 public void delDBModule(int id) throws BLException { 247 248 try{ 249 ModuleDAO dao=new ModuleDAO(); 250 dao.delDBModule(id); 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 261 262 } 263 | Popular Tags |