1 package hero.session; 2 24 import hero.interfaces.BnNodeLocal; 25 import hero.interfaces.BnNodeLocalHome; 26 import hero.interfaces.BnNodeUtil; 27 import hero.interfaces.BnProjectLocal; 28 import hero.interfaces.BnProjectLocalHome; 29 import hero.interfaces.BnProjectUtil; 30 import hero.interfaces.BnUserLightValue; 31 import hero.interfaces.BnUserLocal; 32 import hero.interfaces.BnUserLocalHome; 33 import hero.interfaces.BnUserPropertyLocal; 34 import hero.interfaces.BnUserValue; 35 import hero.interfaces.ProjectSessionLocal; 36 import hero.interfaces.UserServiceLocal; 37 import hero.interfaces.UserServiceLocalHome; 38 import hero.util.BonitaConfig; 39 import hero.util.HeroException; 40 import hero.util.ProjectNodes; 41 import hero.util.Projects; 42 import hero.util.UserProperties; 43 import hero.util.EventConstants; 44 45 import java.io.StringWriter ; 46 import java.util.ArrayList ; 47 import java.util.Arrays ; 48 import java.util.Collection ; 49 import java.util.Iterator ; 50 import java.util.Map ; 51 52 import javax.ejb.CreateException ; 53 import javax.ejb.EJBException ; 54 import javax.ejb.FinderException ; 55 import javax.ejb.SessionBean ; 56 import javax.ejb.SessionContext ; 57 58 59 import org.apache.log4j.Category; 60 import org.exolab.castor.xml.MarshalException; 61 import org.exolab.castor.xml.Marshaller; 62 import org.exolab.castor.xml.ValidationException; 63 64 87 88 public class UserSoapXMLBean implements SessionBean , EventConstants { 89 90 private static final Category trace = Category.getInstance(UserSessionBean.class); 95 96 100 private SessionContext mContext; 101 private BonitaConfig bonitaConfig; 102 103 107 115 public String getProjectList() throws HeroException { 116 trace.info("start by " + mContext.getCallerPrincipal().getName()); 117 Collection pjts = new ArrayList (); 118 Projects pb = new Projects(); 119 Collection pva; 120 try { 121 BnUserLocalHome userhome = 122 hero.interfaces.BnUserUtil.getLocalHome(); 123 BnUserLocal mUser = 124 userhome.findByName(mContext.getCallerPrincipal().getName()); 125 Collection projects = null; 126 projects = mUser.getBnProjects(); 127 BnUserValue uv = mUser.getBnUserValue(); 128 hero.interfaces.BnProjectLightValue[] pv = uv.getBnProjects(); 129 pva = new ArrayList (Arrays.asList(uv.getBnProjects())); 130 } catch (javax.naming.NamingException ne) { 131 throw new HeroException(ne.getMessage()); 132 } catch (javax.ejb.FinderException fe) { 133 throw new HeroException( 134 mContext.getCallerPrincipal().getName() + " does not exists"); 135 } 136 137 try { 138 pb.setProject(pva); 139 StringWriter sw = new StringWriter (); 140 Marshaller.marshal(pb, sw); 141 return (sw.toString()); 142 } catch (MarshalException ex1) { 143 throw new HeroException(ex1.getMessage()); 144 } catch (ValidationException ex2) { 145 throw new HeroException(ex2.getMessage()); 146 } 147 } 148 149 158 public String getToDoList(String projectName) throws HeroException { 159 if (this.getProjectConfigTrace(projectName)) 160 trace.info("parameter: projectName=" + projectName + "start by " + mContext.getCallerPrincipal().getName()); 161 ProjectNodes nb = new ProjectNodes(); 162 BnProjectLocalHome projhome; 163 BnProjectLocal project; 164 BnNodeLocalHome nodehome; 165 Collection ready; 166 try { 167 projhome = BnProjectUtil.getLocalHome(); 168 nodehome = BnNodeUtil.getLocalHome(); 169 } catch (javax.naming.NamingException ne) { 170 throw new HeroException(ne.getMessage()); 171 } 172 try { 173 project = projhome.findByName(projectName); 174 } catch (FinderException fe) { 175 throw new HeroException( 176 "BnProject " + projectName + " does not exists"); 177 } 178 try { 179 ready = 180 nodehome.findUserReady( 181 project.getId(), 182 mContext.getCallerPrincipal().getName()); 183 } catch (FinderException fe) { 184 ready = new ArrayList (); 185 } 186 ArrayList result = new ArrayList (); 187 for (Iterator i = ready.iterator(); i.hasNext();) { 188 BnNodeLocal nd = (BnNodeLocal) i.next(); 189 result.add(nd.getBnNodeLightValue()); 190 } 191 try { 192 nb.setNodes(result.toArray()); 193 StringWriter sw = new StringWriter (); 194 Marshaller.marshal(nb, sw); 195 return (sw.toString()); 196 } catch (MarshalException ex1) { 197 throw new HeroException(ex1.getMessage()); 198 } catch (ValidationException ex2) { 199 throw new HeroException(ex2.getMessage()); 200 } 201 } 202 203 213 public String getActivityList(String projectName) throws HeroException { 214 if (this.getProjectConfigTrace(projectName)) 215 trace.info("parameter: projectName=" + projectName + "start by " + mContext.getCallerPrincipal().getName()); 216 ProjectNodes nb = new ProjectNodes(); 217 BnProjectLocalHome projhome; 218 BnProjectLocal project; 219 BnNodeLocalHome nodehome; 220 Collection executing; 221 try { 222 projhome = BnProjectUtil.getLocalHome(); 223 nodehome = BnNodeUtil.getLocalHome(); 224 } catch (javax.naming.NamingException ne) { 225 throw new HeroException(ne.getMessage()); 226 } 227 try { 228 project = projhome.findByName(projectName); 229 } catch (FinderException fe) { 230 throw new HeroException( 231 "BnProject " + projectName + " does not exists"); 232 } 233 try { 234 executing = 235 nodehome.findUserExecuting( 236 project.getId(), 237 mContext.getCallerPrincipal().getName()); 238 } catch (FinderException fe) { 239 executing = new ArrayList (); 240 } 241 ArrayList result = new ArrayList (); 242 for (Iterator i = executing.iterator(); i.hasNext();) { 243 BnNodeLocal nd = (BnNodeLocal) i.next(); 244 result.add(nd.getBnNodeLightValue()); 245 } 246 try { 247 nb.setNodes(result.toArray()); 248 StringWriter sw = new StringWriter (); 249 Marshaller.marshal(nb, sw); 250 return (sw.toString()); 251 } catch (MarshalException ex1) { 252 throw new HeroException(ex1.getMessage()); 253 } catch (ValidationException ex2) { 254 throw new HeroException(ex2.getMessage()); 255 } 256 } 257 258 265 public BnUserLightValue getUserLightValue() throws HeroException{ 266 try{ 267 trace.info("start by " + mContext.getCallerPrincipal().getName()); 268 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 269 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 270 BnUserLightValue ulv= mUser.getBnUserLightValue(); 271 UserServiceLocalHome ushome = null; 272 try { 273 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 274 UserServiceLocal ul = ushome.create(); 275 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 276 ulv.setEmail((String )infos.get("email")); 277 ulv.setPassword((String )infos.get("password")); 278 ulv.setJabber((String )infos.get("jabber")); 279 return ulv; 280 } catch (Exception ce) { 281 trace.error(ce.getMessage()); 282 throw new HeroException(ce.getMessage()); 283 } 284 } catch (javax.naming.NamingException ne) { 285 trace.error(ne.getMessage()); 286 throw new HeroException(ne.getMessage()); 287 } catch (javax.ejb.FinderException fe) { 288 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 289 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 290 } 291 } 292 293 300 public String getUser() { 301 trace.info("start by " + mContext.getCallerPrincipal().getName()); 302 return mContext.getCallerPrincipal().getName(); 303 } 304 305 314 public String getUserMail(String userName) throws HeroException { 315 trace.info("parameter: userName = " + userName + " start by " + mContext.getCallerPrincipal().getName()); 316 UserServiceLocalHome ushome = null; 317 try { 318 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 319 UserServiceLocal ul = ushome.create(); 320 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 321 return ((String )infos.get("email")); 322 } catch (Exception ce) { 323 trace.error(ce.getMessage()); 324 throw new HeroException(ce.getMessage()); 325 } 326 } 327 328 329 336 public String getUserPassword() throws HeroException{ 337 UserServiceLocalHome ushome = null; 338 try { 339 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 340 UserServiceLocal ul = ushome.create(); 341 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 342 return ((String )infos.get("password")); 343 } catch (Exception ce) { 344 trace.error(ce.getMessage()); 345 throw new HeroException(ce.getMessage()); 346 } 347 } 348 349 356 public String getUserJabber() throws HeroException{ 357 UserServiceLocalHome ushome = null; 358 try { 359 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 360 UserServiceLocal ul = ushome.create(); 361 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 362 return ((String )infos.get("jabber")); 363 } catch (Exception ce) { 364 trace.error(ce.getMessage()); 365 throw new HeroException(ce.getMessage()); 366 } 367 } 368 369 377 public String getUserProperties() throws HeroException { 378 trace.info("start by " + mContext.getCallerPrincipal().getName()); 379 Collection prp = new ArrayList (); 380 BnUserPropertyLocal pl; 381 UserProperties ub = new UserProperties(); 382 try { 383 BnUserLocalHome userhome = 384 hero.interfaces.BnUserUtil.getLocalHome(); 385 BnUserLocal mUser = 386 userhome.findByName(mContext.getCallerPrincipal().getName()); 387 Collection pls = mUser.getBnProperties(); 388 389 for (Iterator i = pls.iterator(); i.hasNext();) { 390 pl = (BnUserPropertyLocal) i.next(); 391 prp.add(pl.getBnUserPropertyValue()); 392 } 393 394 try { 395 ub.setProperty(prp); 396 StringWriter sw = new StringWriter (); 397 Marshaller.marshal(ub, sw); 398 return (sw.toString()); 399 } catch (MarshalException ex1) { 400 throw new HeroException(ex1.getMessage()); 401 } catch (ValidationException ex2) { 402 throw new HeroException(ex2.getMessage()); 403 } 404 405 } catch (javax.naming.NamingException ne) { 406 throw new HeroException(ne.getMessage()); 407 } catch (javax.ejb.FinderException fe) { 408 throw new HeroException( 409 mContext.getCallerPrincipal().getName() + " does not exists"); 410 } 411 } 412 413 private boolean getProjectConfigTrace(String projectName) throws HeroException{ 414 return (bonitaConfig.getProcessTrace(projectName)); 415 } 416 417 418 425 public void ejbCreate() throws CreateException { 426 } 427 428 public void setSessionContext(final javax.ejb.SessionContext context) { 429 mContext = context; 430 try{ 431 this.bonitaConfig = new BonitaConfig(); 432 }catch(Exception e){throw new EJBException (e.getMessage());} 433 } 434 435 public void ejbRemove() { 436 } 437 438 public void ejbActivate() { 439 } 440 441 public void ejbPassivate() { 442 } 443 444 private boolean checkRights(ProjectSessionLocal ps) throws HeroException { 446 return ps.containsUser(mContext.getCallerPrincipal().getName()); 448 } 449 } 450 451 452 | Popular Tags |