1 package hero.session; 2 23 24 import hero.interfaces.BnEdgeLocal; 25 import hero.interfaces.BnNodeLocal; 26 import hero.interfaces.BnProjectLocal; 27 import hero.interfaces.BnProjectLocalHome; 28 import hero.interfaces.BnRoleLocal; 29 import hero.interfaces.BnUserLocal; 30 import hero.interfaces.BnUserLocalHome; 31 import hero.util.BonitaConfig; 32 import hero.util.EventConstants; 33 import hero.util.HeroException; 34 35 import hero.interfaces.JMSServicesSessionUtil; 36 import hero.interfaces.JMSServicesSessionLocalHome; 37 import hero.interfaces.JMSServicesSessionLocal; 38 39 import java.rmi.RemoteException ; 40 import java.util.ArrayList ; 41 import java.util.Collection ; 42 import java.util.Date ; 43 44 import java.util.Iterator ; 45 46 import javax.ejb.CreateException ; 47 import javax.ejb.FinderException ; 48 import javax.ejb.SessionBean ; 49 import javax.ejb.SessionContext ; 50 import javax.ejb.EJBException ; 51 import javax.naming.Context ; 52 53 import java.util.Vector ; 54 55 import org.apache.log4j.Category; 56 57 80 81 public class ProjectSoapBasicBean implements SessionBean , EventConstants { 82 83 private static final Category trace = Category.getInstance(ProjectSessionBean.class); 88 89 93 private SessionContext mContext; 94 private BnProjectLocalHome pHome; 95 private BnProjectLocal mProject; 96 private JMSServicesSessionLocal jms; 97 private Collection subProjects = new ArrayList (); 98 private ArrayList visited = new ArrayList (); 99 private BonitaConfig bonitaConfig; 100 101 102 106 114 public String getName() throws HeroException { 115 if (this.getProjectConfigTrace()) 116 trace.info(" process name = " + this.getName() +" started by " + mContext.getCallerPrincipal().getName()); 117 return mProject.getName(); 118 } 119 120 128 public String getCreator() throws HeroException { 129 if (this.getProjectConfigTrace()) 130 trace.info(" process name = " + this.getName() +" started by " + mContext.getCallerPrincipal().getName()); 131 return mProject.getCreator(); 132 } 133 134 143 public String getNodeExecutor(String name) throws HeroException { 144 145 if (this.getProjectConfigTrace()) 146 trace.info("parameter: name=" + name + "process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName()); 147 BnNodeLocal nd=mProject.getBnNode(name); 148 return nd.getExecutor(); 149 } 150 151 160 public int getNodeState(String name) throws HeroException { 161 if (this.getProjectConfigTrace()) 162 trace.info("parameter: name=" + name + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 163 BnNodeLocal nd = mProject.getBnNode(name); 164 int s = nd.getState(); 165 return (s); 166 } 167 168 176 public Object [] getUsers() throws HeroException { 177 if (this.getProjectConfigTrace()) 178 trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName()); 179 Collection users = mProject.getBnUsers(); 180 ArrayList result=new ArrayList (); 181 for (Iterator i=users.iterator();i.hasNext();) { 182 result.add(((BnUserLocal)i.next()).getName()); 183 } 184 return result.toArray(); 185 } 186 187 195 public Object [] getAllUsers() throws HeroException { 196 if (this.getProjectConfigTrace()) 197 trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName()); 198 BnUserLocalHome uHome; 199 Collection users; 200 try { 201 uHome = (BnUserLocalHome)hero.interfaces.BnUserUtil.getLocalHome(); 202 } catch (javax.naming.NamingException be) { 203 throw new HeroException(be.getMessage()); 204 } 205 try { 206 users=uHome.findAll(); 207 } catch (FinderException f) { 208 throw new HeroException("FinderException in findByAll users"); 209 } 210 ArrayList result=new ArrayList (); 211 for (Iterator i=users.iterator();i.hasNext();) { 212 result.add(((BnUserLocal)i.next()).getName()); 213 } 214 return result.toArray(); 215 } 216 217 225 public Object [] getRolesNames() throws HeroException { 226 if (this.getProjectConfigTrace()) 227 trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName()); 228 Collection roles = mProject.getBnRoles(); 229 ArrayList result=new ArrayList (); 230 for (Iterator i=roles.iterator();i.hasNext();) { 231 result.add(((BnRoleLocal)i.next()).getName()); 232 } 233 return result.toArray(); 234 } 235 236 244 public Object [] getNodesNames() throws HeroException { 245 if (this.getProjectConfigTrace()) 246 trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName()); 247 248 Vector names = new Vector (); 249 Collection nodes = mProject.getBnNodes(); 250 Iterator i = nodes.iterator(); 251 while (i.hasNext()) 252 { 253 BnNodeLocal n = (BnNodeLocal)i.next(); 254 names.add(n.getName()); 255 } 256 return((Collection )names).toArray(); 257 } 258 259 267 public Object [] getNodes() throws HeroException { 268 if (this.getProjectConfigTrace()) 269 trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName()); 270 Vector nodesDetails = new Vector (); 271 Collection nodes = mProject.getBnNodes(); 272 273 Iterator i = nodes.iterator(); 274 while (i.hasNext()) 275 { 276 BnNodeLocal n = (BnNodeLocal)i.next(); 277 String [] details = new String [5]; 278 details[0]=n.getName(); 279 details[1]=hero.interfaces.Constants.Nd.nodeStateName[n.getState()]; 280 details[2]=((BnRoleLocal)n.getBnRole()).getName(); 281 285 if (n.getDeadlines().size() != 0) { 286 Collection co = n.getDeadlines(); 287 Iterator it = co.iterator(); 288 Date date = null; 289 while (it.hasNext()){ 290 date = (Date )it.next(); 291 } 292 details[3]=date.toString(); 293 } 294 else 295 details[3]="null"; 296 details[4]=(new Boolean (n.getAnticipable())).toString(); 297 nodesDetails.add(details); 298 } 299 return((Collection )nodesDetails).toArray(); 300 } 301 302 310 311 public Object [] getNodeDetails(String node) throws HeroException { 312 if (this.getProjectConfigTrace()) 313 trace.info("parameter: node=" + node + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 314 BnNodeLocal nd=mProject.getBnNode(node); 315 Vector detail = new Vector (); 316 317 detail.add(nd.getName()); 318 detail.add(mProject.getName()); 319 detail.add(nd.getCreator()); 320 detail.add(hero.interfaces.Constants.Nd.nodeStateName[nd.getState()]); 321 detail.add(((BnRoleLocal)nd.getBnRole()).getName()); 322 if (nd.getExecutor()!=null) 323 detail.add(nd.getExecutor()); 324 else 325 detail.add("null"); 326 330 if (nd.getDeadlines().size() != 0) { 331 Collection co = nd.getDeadlines(); 332 Iterator it = co.iterator(); 333 Date date = null; 334 while (it.hasNext()){ 335 date = (Date )it.next(); 336 } 337 detail.add(date.toString()); 338 } 339 340 else detail.add("null"); 341 342 detail.add(new Boolean ((nd.getAnticipable())).toString()); 343 344 if (nd.getDescription()!=null) 345 detail.add(nd.getDescription()); 346 else detail.add("null"); 347 348 return(detail.toArray()); 349 } 350 351 361 public Object [] getUserRolesInProjectNames(String userName) throws HeroException { 362 if (this.getProjectConfigTrace()) 363 trace.info("parameter: userName=" + userName + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 364 BnUserLocalHome uHome; 365 BnUserLocal user; 366 ArrayList result=new ArrayList (); 367 try { 368 uHome = (BnUserLocalHome)hero.interfaces.BnUserUtil.getLocalHome(); 369 } catch (javax.naming.NamingException be) { 370 throw new HeroException(be.getMessage()); 371 } 372 try { 373 user=uHome.findByName(userName); 374 } catch (FinderException f) { 375 throw new HeroException("FinderException"); 376 } 377 Collection userRoles = user.getBnRoles(); 378 Collection projectRoles=mProject.getBnRoles(); 379 for(Iterator i=userRoles.iterator();i.hasNext();){ 380 BnRoleLocal ur=(BnRoleLocal)i.next(); 381 for(Iterator j=projectRoles.iterator();j.hasNext();){ 382 BnRoleLocal up=(BnRoleLocal)j.next(); 383 if(ur.getId()==up.getId()) 384 result.add(ur.getName()); 385 } 386 } 387 return result.toArray(); 388 } 389 390 400 public Object [] getNodeInEdges(String name) throws HeroException { 401 if (this.getProjectConfigTrace()) 402 trace.info("parameter: name=" + name + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 403 Vector in=new Vector (); 404 BnNodeLocal nd=mProject.getBnNode(name); 405 406 Collection edgesIn=nd.getInBnEdges(); 407 Iterator i = edgesIn.iterator(); 408 while (i.hasNext()){ 409 BnEdgeLocal e = (BnEdgeLocal)i.next(); 410 String [] details = new String [4]; 411 details[0]=e.getName(); 412 details[1]=hero.interfaces.Constants.Ed.edgeStateName[e.getState()]; 413 BnNodeLocal nIn = (BnNodeLocal)e.getInBnNode(); 414 details[2]=nIn.getName(); 415 BnNodeLocal nOut = (BnNodeLocal)e.getOutBnNode(); 416 details[3]=nOut.getName(); 417 in.add(details); 418 } 419 420 return(in.toArray()); 421 } 422 423 431 public Object [] getEdges() throws HeroException { 432 if (this.getProjectConfigTrace()) 433 trace.info("process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 434 Vector edgesDetails = new Vector (); 435 Collection edges = mProject.getBnEdges(); 436 Iterator i = edges.iterator(); 437 while (i.hasNext()) 438 { 439 BnEdgeLocal e = (BnEdgeLocal)i.next(); 440 String [] details = new String [4]; 441 details[0]=e.getName(); 442 details[1]=hero.interfaces.Constants.Ed.edgeStateName[e.getState()]; 443 BnNodeLocal nIn = (BnNodeLocal)e.getInBnNode(); 444 details[2]=nIn.getName(); 445 BnNodeLocal nOut = (BnNodeLocal)e.getOutBnNode(); 446 details[3]=nOut.getName(); 447 edgesDetails.add(details); 448 } 449 return(edgesDetails.toArray()); 450 } 451 452 462 public Object [] getNodeOutEdges(String name) throws HeroException { 463 if (this.getProjectConfigTrace()) 464 trace.info("parameter: name=" + name+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 465 466 Vector out=new Vector (); 467 BnNodeLocal nd=mProject.getBnNode(name); 468 469 Collection edgesOut=nd.getOutBnEdges(); 470 Iterator i = edgesOut.iterator(); 471 while (i.hasNext()){ 472 BnEdgeLocal e = (BnEdgeLocal)i.next(); 473 String [] details = new String [4]; 474 details[0]=e.getName(); 475 details[1]=hero.interfaces.Constants.Ed.edgeStateName[e.getState()]; 476 BnNodeLocal nIn = (BnNodeLocal)e.getInBnNode(); 477 details[2]=nIn.getName(); 478 BnNodeLocal nOut = (BnNodeLocal)e.getOutBnNode(); 479 details[3]=nOut.getName(); 480 out.add(details); 481 } 482 483 return(out.toArray()); 484 } 485 486 495 public int getNodeType(String name) throws HeroException { 496 if (this.getProjectConfigTrace()) 497 trace.info("parameter: name=" + name+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName()); 498 BnNodeLocal nd = mProject.getBnNode(name); 499 return (nd.getType()); 500 } 501 502 506 515 public void initProject(String projectName) throws HeroException { 516 Context lContext; 517 if (this.getProjectConfigTrace()) 518 trace.info("parameter: projectName=" + projectName+" started by " + mContext.getCallerPrincipal().getName()); 519 try { 520 pHome = hero.interfaces.BnProjectUtil.getLocalHome(); 521 this.mProject = pHome.findByName(projectName); 522 } catch (javax.naming.NamingException ne) { 523 throw new HeroException(ne.getMessage()); 524 } catch (javax.ejb.FinderException fe) { 525 throw new HeroException(fe.getMessage()); 526 } 527 } 528 529 private boolean getProjectConfigTrace() throws HeroException{ 530 if (this.getName()!=null) 531 return (bonitaConfig.getProcessTrace(this.getName())); 532 else 533 return true; 534 } 535 536 537 545 public void ejbCreate() throws CreateException { 546 } 547 548 551 public void ejbPostCreate(String oldProject, String newProject) 552 throws CreateException , RemoteException { 553 } 554 555 558 public void setSessionContext(final javax.ejb.SessionContext context) { 559 mContext = context; 560 try{ 561 JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome(); 562 this.jms=home.create(); 563 this.bonitaConfig = new BonitaConfig(); 564 }catch(Exception e){throw new EJBException (e.getMessage());} 565 } 566 567 570 571 public void ejbRemove() { 572 } 573 574 577 578 public void ejbActivate() { 579 } 580 581 584 585 public void ejbPassivate() { 586 } 587 } 588 | Popular Tags |