1 2 3 24 package com.geinuke.bizlogic; 25 26 import java.sql.SQLException ; 27 import java.util.ArrayList ; 28 29 import com.geinuke.common.UserI; 30 import com.geinuke.dao.BlockDAO; 31 import com.geinuke.middle.IBlockBL; 32 import com.geinuke.middle.IBlogBL; 33 import com.geinuke.middle.IUserBL; 34 import com.geinuke.middle.MiddleFactory; 35 import com.geinuke.util.NukeResource; 36 import com.geinuke.vo.BlockDBVO; 37 import com.geinuke.vo.RoleVO; 38 39 40 41 public class BlockBL implements IBlockBL{ 42 43 44 45 public BlockBL(){ 46 47 } 48 49 private void addMockBlock(ArrayList l){ 50 BlockDBVO b=new BlockDBVO(); 51 b.setActive(true); 52 b.setDbStored(true); 53 b.setId(876); 54 b.setIdRole(1); 55 b.setContent("<b>prova</b>"); 56 b.setTitle("La Prova"); 57 b.setName("Prova la"); 58 b.setPos(1); 59 b.setRoleLevel(10); 60 b.setSkin(0); 61 b.setWeight(1); 62 l.add(b); 63 64 } 65 66 public ArrayList getBlocksForUser(UserI user) throws BLException{ 67 ArrayList list=null; 68 try{ 69 BlockDAO dao=new BlockDAO(); 70 list=dao.getBlocksForUser(user); 71 }catch(SQLException sqle){ 73 sqle.printStackTrace(System.out); 74 throw new DBException(sqle.getMessage()); 75 }catch(Throwable t){ 76 throw new BLException(t.getMessage()); 77 } 78 return list; 79 } 80 81 public BlockDBVO getBlock(int id) throws BLException{ 82 BlockDBVO mod=null; 83 try{ 84 BlockDAO dao=new BlockDAO(); 85 mod=dao.getBlockById(id); 86 }catch(SQLException sqle){ 87 throw new DBException(sqle.getMessage()); 88 }catch(Throwable t){ 89 throw new BLException(t.getMessage()); 90 } 91 return mod; 92 } 93 94 public BlockDBVO getBlockByName(String name) throws BLException{ 95 BlockDBVO mod=null; 96 try{ 97 BlockDAO dao=new BlockDAO(); 98 mod=dao.getBlockByName(name); 99 }catch(SQLException sqle){ 100 throw new DBException(sqle.getMessage()); 101 }catch(Throwable t){ 102 throw new BLException(t.getMessage()); 103 } 104 return mod; 105 } 106 107 108 109 public void insertDBStoredBlock(BlockDBVO blo)throws BLException{ 110 try{ 111 BlockDAO dao=new BlockDAO(); 112 dao.insertDBStoredBlock(blo); 113 }catch(SQLException sqle){ 114 throw new DBException(sqle.getMessage()); 115 }catch(Throwable t){ 116 throw new BLException(t.getMessage()); 117 } 118 } 119 120 public void updateDBBlock(BlockDBVO blo)throws BLException{ 121 try{ 122 BlockDAO dao=new BlockDAO(); 123 dao.updateDBBlock(blo); 124 }catch(SQLException sqle){ 125 throw new DBException(sqle.getMessage()); 126 }catch(Throwable t){ 127 throw new BLException(t.getMessage()); 128 } 129 } 130 131 public void updateSingleBlock(int id,String action)throws BLException { 132 BlockDBVO blo=null; 133 ArrayList roles=null; 134 RoleVO role=null; 135 136 blo=this.getBlock(id); 137 IUserBL ubl=(IUserBL)MiddleFactory.getBL("IUserBL"); 138 roles=ubl.getAllRoles(); 139 140 if(action.equalsIgnoreCase("active")){ 141 blo.setActive(! blo.isActive() ); 142 }else if(action.equalsIgnoreCase("pos")){ 143 int pos=blo.getPos(); 144 pos=(pos+1)%2; 145 blo.setPos(pos); 146 }else if(action.equalsIgnoreCase("Aweight")){ 147 int weight=blo.getWeight(); 148 weight=(weight+1)%50; 149 blo.setWeight(weight); 150 } else if(action.equalsIgnoreCase("Mweight")){ 151 int weight=blo.getWeight(); 152 weight--; 153 if(weight<0) 154 weight=0; 155 blo.setWeight(weight); 156 }else if(action.equalsIgnoreCase("skin")){ 157 int skin=blo.getSkin(); 158 skin++; 159 if(skin>3) 160 skin=0; 161 blo.setSkin(skin); 162 } else if(action.equalsIgnoreCase("rolel")){ 163 int level=blo.getRoleLevel(); 164 int pos=NukeResource.getRolePositionByRoleLevel(level,roles); 165 166 if(pos>=0){ 167 pos=(pos+1)%roles.size(); 168 role=(RoleVO)roles.get(pos); 169 blo.setRoleLevel(role.getLevela()); 170 } 171 } 172 this.updateDBBlock(blo); 173 } 174 175 176 177 178 public ArrayList getAllStoredBlocks() throws BLException{ 179 ArrayList list=null; 180 try{ 181 BlockDAO dao=new BlockDAO(); 182 list=dao.getAllStoredBlocks(); 183 184 }catch(SQLException sqle){ 185 throw new DBException(sqle.getMessage()); 186 }catch(Throwable t){ 187 throw new BLException(t.getMessage()); 188 } 189 return list; 190 } 191 192 public ArrayList getAllBlocks() throws BLException{ 193 ArrayList list=null; 194 try{ 195 BlockDAO dao=new BlockDAO(); 196 list=dao.getAllBlocks(); 197 198 }catch(SQLException sqle){ 199 throw new DBException(sqle.getMessage()); 200 }catch(Throwable t){ 201 throw new BLException(t.getMessage()); 202 } 203 return list; 204 } 205 206 207 public void delDBBlock(int id) throws BLException { 208 try{ 209 BlockDAO dao=new BlockDAO(); 210 dao.delDBBlock(id); 211 212 }catch(SQLException sqle){ 213 throw new DBException(sqle.getMessage()); 214 }catch(Throwable t){ 215 throw new BLException(t.getMessage()); 216 } 217 } 218 219 } 220 | Popular Tags |