| 1 package hero.session; 2 23 24 import hero.entity.EdgeState; 25 import hero.entity.NodeState; 26 import hero.interfaces.BnAgentEdgeLocal; 27 import hero.interfaces.BnAgentEdgeLocalHome; 28 import hero.interfaces.BnAgentEdgeValue; 29 import hero.interfaces.BnAgentLocal; 30 import hero.interfaces.BnAgentLocalHome; 31 import hero.interfaces.BnAgentValue; 32 import hero.interfaces.BnEdgeLocal; 33 import hero.interfaces.BnEdgeLocalHome; 34 import hero.interfaces.BnEdgeUtil; 35 import hero.interfaces.BnEdgeValue; 36 import hero.interfaces.BnNodeHookLocal; 37 import hero.interfaces.BnNodeHookLocalHome; 38 import hero.interfaces.BnNodeHookUtil; 39 import hero.interfaces.BnNodeInterHookLocal; 40 import hero.interfaces.BnNodeInterHookValue; 41 import hero.interfaces.BnNodeInterHookLocalHome; 42 import hero.interfaces.BnNodeInterHookUtil; 43 import hero.interfaces.BnNodeLightValue; 44 import hero.interfaces.BnNodeLocal; 45 import hero.interfaces.BnNodeLocalHome; 46 import hero.interfaces.BnNodePropertyLocal; 47 import hero.interfaces.BnNodePropertyValue; 48 import hero.interfaces.BnNodePropertyLocalHome; 49 import hero.interfaces.BnNodePropertyUtil; 50 import hero.interfaces.BnNodeUtil; 51 import hero.interfaces.BnNodeValue; 52 import hero.interfaces.BnIterationLocal; 53 import hero.interfaces.BnIterationLocalHome; 54 import hero.interfaces.BnIterationUtil; 55 import hero.interfaces.BnIterationLightValue; 56 import hero.interfaces.BnProjectHookLocal; 57 import hero.interfaces.BnProjectHookLocalHome; 58 import hero.interfaces.BnProjectHookUtil; 59 import hero.interfaces.BnProjectInterHookLocal; 60 import hero.interfaces.BnProjectInterHookLocalHome; 61 import hero.interfaces.BnProjectInterHookUtil; 62 import hero.interfaces.BnProjectLocal; 63 import hero.interfaces.BnProjectLocalHome; 64 import hero.interfaces.BnProjectPropertyLocal; 65 import hero.interfaces.BnProjectPropertyLocalHome; 66 import hero.interfaces.BnProjectPropertyUtil; 67 import hero.interfaces.BnProjectPropertyValue; 68 import hero.interfaces.BnProjectValue; 69 import hero.interfaces.BnProjectConfigLocalHome; 70 import hero.interfaces.BnRoleLocal; 71 import hero.interfaces.BnRoleLocalHome; 72 import hero.interfaces.BnRoleUtil; 73 import hero.interfaces.BnRoleValue; 74 import hero.interfaces.BnUserLightValue; 75 import hero.interfaces.BnUserLocal; 76 import hero.interfaces.BnUserLocalHome; 77 import hero.interfaces.BnUserUtil; 78 import hero.interfaces.EngineLocal; 79 import hero.interfaces.EngineLocalHome; 80 import hero.interfaces.InvalidValueException; 81 import hero.interfaces.Constants; 82 import hero.interfaces.ProjectSessionLocal; 83 84 import hero.interfaces.UserServiceLocal; 85 import hero.interfaces.UserServiceLocalHome; 86 87 import hero.util.BonitaConfig; 88 import hero.util.BonitaDeadline; 89 import hero.util.BonitaProjectLocator; 90 import hero.util.BonitaServiceException; 91 import hero.util.DeleteEdgeException; 92 import hero.util.EventConstants; 93 import hero.util.HeroException; 94 import hero.util.AdminException; 95 import hero.util.HiddenException; 96 import hero.util.AccessException; 97 import hero.util.NodeExecutingException; 98 import hero.util.StrutsEdgeValue; 99 import hero.util.StrutsNodeValue; 100 import hero.util.values.BonitaEdgeValue; 101 import hero.util.values.BonitaIterationValue; 102 import hero.util.values.BonitaNodeValue; 103 import hero.util.values.BonitaProjectValue; 104 import hero.util.values.BonitaPropertyValue; 105 import hero.util.values.BonitaRoleValue; 106 import hero.util.values.BonitaUserValue; 107 import hero.interfaces.JMSServicesSessionUtil; 108 import hero.interfaces.JMSServicesSessionLocalHome; 109 import hero.interfaces.JMSServicesSessionLocal; 110 111 import hero.interfaces.BnRoleMapperLocal; 112 import hero.interfaces.BnRoleMapperLocalHome; 113 import hero.interfaces.BnRoleMapperUtil; 114 115 import hero.interfaces.BnNodePerformerAssignLocal; 116 import hero.interfaces.BnNodePerformerAssignLocalHome; 117 import hero.interfaces.BnNodePerformerAssignUtil; 118 import hero.interfaces.BnNodePerformerAssignValue; 119 120 import java.rmi.RemoteException ; 121 import java.util.ArrayList ; 122 123 import java.util.Collection ; 124 import java.util.Date ; 125 import java.util.Iterator ; 126 import java.util.Map ; 127 128 import javax.ejb.CreateException ; 129 import javax.ejb.FinderException ; 130 import javax.ejb.RemoveException ; 131 import javax.ejb.SessionBean ; 132 import javax.ejb.SessionContext ; 133 import javax.ejb.EJBException ; 134 import javax.naming.Context ; 135 136 import org.apache.log4j.Logger; 137 import org.apache.log4j.Level; 138 139 219 220 public class ProjectSessionBean implements SessionBean , EventConstants{ 221 222 private static final Logger trace = Logger.getLogger(ProjectSessionBean.class); 227 private static final Logger thelog = Logger.getLogger("log"); 228 229 233 private SessionContext mContext; 234 235 private BnProjectLocalHome pHome; 236 private BnProjectLocal mProject=null; 237 private Collection subProjects = new ArrayList (); 238 private JMSServicesSessionLocal jms = null; 239 private ArrayList visited = new ArrayList (); 240 private String caller=null; 241 private BonitaConfig bonitaConfig; 242 243 247 251 261 public void addUser(String userName) throws HeroException { 262 if (this.getProjectConfigTrace()) 263 trace.info(" Parameter: name=" + userName + " process name = "+this.getName()+ " started by " + this.getCaller()); 264 UserServiceLocalHome ushome; 265 UserServiceLocal ul; 266 if (!isAdminOfProject(this.getCaller())) 267 { 268 if (this.getProjectConfigTrace()) 269 trace.error("Only the Admin of the project is allowed to do this operation... "); 270 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 271 } 272 BnUserLocalHome uHome; 273 BnRoleLocalHome rHome; 274 BnRoleLocal mRole; 275 BnUserLocal mUser; 276 try { 277 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 278 uHome = hero.interfaces.BnUserUtil.getLocalHome(); 279 rHome = hero.interfaces.BnRoleUtil.getLocalHome(); 280 } catch (javax.naming.NamingException be) { 281 if (this.getProjectConfigTrace()) 282 trace.error(be.getMessage()); 283 throw new HeroException(be.getMessage()); 284 } 285 try { 286 ul = ushome.create(); 287 mUser = ul.findUser(userName); 288 } catch (Exception fe) { 289 if (this.getProjectConfigTrace()) 290 trace.error("User does not exist " + fe.getMessage()); 291 throw new HeroException("User does not exist"); 292 } 293 Collection cUsers = mProject.getBnUsers(); 294 if (!cUsers.contains(mUser)) 295 { 296 cUsers.add(mUser); 297 if (!userName.equals(Constants.ADMIN)) 298 this.addRole(userName, "BnUser BnRole"); 299 this.setUserRole(userName, userName); 300 jms.sendProjectEvent(ADDUSERPROJECT,this.getName(),userName); 301 } 302 } 303 304 323 324 public void addNode(String name, int nodeType) throws HeroException { 325 if (this.getProjectConfigTrace()) 326 trace.info("parameter: name= " + name + " nodeType= " + name + " process name = "+this.getName()+ " started by " + this.getCaller()); 327 BnNodeLocalHome nHome; 328 BnNodeLocal mNode; 329 if (!isAdminOfProject(this.getCaller())) 330 { 331 if (this.getProjectConfigTrace()) 332 trace.error("Only the Admin of the project is allowed to do this operation... "); 333 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 334 } 335 336 try { 337 nHome = hero.interfaces.BnNodeUtil.getLocalHome(); 338 } catch (javax.naming.NamingException be) { 339 if (this.getProjectConfigTrace()) 340 trace.error(be.getMessage()); 341 throw new HeroException(be.getMessage()); 342 } 343 344 try { 345 BnNodeLocal nf = nHome.findByName(name, mProject.getId()); 346 throw new HeroException("Node "+ name+ " already exist in project "+ mProject.getName()); 347 } catch (javax.ejb.FinderException nn) { 348 if (this.getProjectConfigTrace()) 349 if (this.getProjectConfigTrace()) 350 trace.error(nn.getMessage()); 351 try { 352 if (name.equals("")) 353 throw new HeroException("Node name can not be empty..."); 354 BnNodeLocal nd = nHome.create(name, nodeType); 355 if (mProject.getType().equals(Constants.Pj.MODEL)) 357 nd.setState(Constants.Nd.INITIAL); 358 BnNodeValue ndata = nd.getBnNodeValue(); 359 ndata.setCreationDate(new java.util.Date ()); 360 nd.setBnNodeValue(ndata); 361 362 Collection cNodes = mProject.getBnNodes(); 363 cNodes.add(nd); 364 366 String creator = this.getCaller(); 367 nd.setCreator(creator); 368 nd.setExecutor(creator); BnRoleLocalHome rHome = BnRoleUtil.getLocalHome(); 370 BnRoleLocal role = rHome.findByName(hero.interfaces.Constants.INITIALROLE,mProject.getId()); 371 nd.setBnRole(role); 372 373 if (nodeType == Constants.Nd.SUB_PROCESS_NODE) 374 { 375 try { 376 BnProjectLocal pl = pHome.findByName(name); 377 pl.setParent(mProject.getName()); 378 } catch (javax.ejb.FinderException pe) { 379 if (this.getProjectConfigTrace()) 380 trace.error("Project "+ name+ " does not exist " + pe.getMessage()); 381 throw new HeroException("Project "+ name+ " does not exist");} 382 } 383 384 jms.sendNodeEvent(ADDNODE,this.getName(),name,nodeType,ndata.getState(),this.getCaller()); 386 } catch (InvalidValueException ie) { 387 if (this.getProjectConfigTrace()) 388 trace.error(ie.getMessage()); 389 throw new HeroException(ie.getMessage()); 390 } catch (CreateException ce) { 391 if (this.getProjectConfigTrace()) 392 trace.error(ce.getMessage()); 393 throw new HeroException(ce.getMessage()); 394 } catch (FinderException fe) {fe.printStackTrace(); 395 if (this.getProjectConfigTrace()) 396 trace.error(fe.getMessage()); 397 throw new HeroException(fe.getMessage()); 398 } catch (javax.naming.NamingException ne) { 399 if (this.getProjectConfigTrace()) 400 trace.error(ne.getMessage()); 401 throw new HeroException(ne.getMessage()); 402 } 403 } 404 } 405 406 419 420 public void addNodeSubProcess(String name, String projectName) throws HeroException { 421 if (this.getProjectConfigTrace()) 422 trace.info("parameters : name=" + name + "project=" + projectName + " process name = " + this.getName()+ " started by " + this.getCaller()); 423 if (!isAdminOfProject(this.getCaller())) 424 { 425 if (this.getProjectConfigTrace()) 426 trace.error("Only the Admin of the project is allowed to do this operation... "); 427 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 428 } 429 try{ 430 String aP = mProject.getName(); 431 this.initProject(projectName,name); 432 Collection nodes = mProject.getBnNodes(); 433 Iterator nds = nodes.iterator(); 434 while (nds.hasNext()) { 436 BnNodeLocal subNode = (BnNodeLocal)nds.next(); 437 if (subNode.getState()==Constants.Nd.READY) 438 this.setNodeState(subNode,Constants.Nd.INITIAL); 439 } 440 if (mProject.getType().equals(Constants.Pj.MODEL)) 441 this.initModel(aP); 442 else 443 this.initProject(aP); 444 this.addNode(name,Constants.Nd.SUB_PROCESS_NODE); 445 subProjects.clear(); 446 }catch (Exception ans){ 447 if (this.getProjectConfigTrace()) 448 trace.error("Error in addNodeSubProcess " + ans.getMessage()); 449 throw new HeroException("Error in addNodeSubProcess"); 450 } 451 } 452 453 463 public void addAgent(String name) throws HeroException { 464 if (this.getProjectConfigTrace()) 465 trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller()); 466 BnAgentLocalHome nHome; 467 BnAgentLocal mAgent; 468 if (!isAdminOfProject(this.getCaller())) 469 { 470 if (this.getProjectConfigTrace()) 471 trace.error("Only the Admin of the project is allowed to do this operation... "); 472 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 473 } 474 try { 475 nHome = hero.interfaces.BnAgentUtil.getLocalHome(); 476 } catch (javax.naming.NamingException be) { 477 if (this.getProjectConfigTrace()) 478 trace.error(be.getMessage()); 479 throw new HeroException(be.getMessage()); 480 } 481 482 try { 483 BnAgentLocal nf = nHome.findByName(name, mProject.getId()); 484 throw new HeroException("BnAgent "+ name+ " already exist in project "+ mProject.getName()); 485 } catch (javax.ejb.FinderException nn) { 486 if (this.getProjectConfigTrace()) 487 trace.error(nn.getMessage()); 488 489 try { 490 BnAgentLocal ag = nHome.create(name); 491 BnAgentValue adata = ag.getBnAgentValue(); 492 adata.setCreationDate(new java.util.Date ()); 493 ag.setBnAgentValue(adata); 494 Collection cAgents = mProject.getBnAgents(); 495 cAgents.add(ag); 496 String creator = this.getCaller(); 497 BnUserLocalHome uHome = hero.interfaces.BnUserUtil.getLocalHome(); 498 BnUserLocal user = uHome.findByName(creator); 499 ag.setCreator(user); 500 501 } catch (InvalidValueException ie) { 504 if (this.getProjectConfigTrace()) 505 trace.error(ie.getMessage()); 506 throw new HeroException(ie.getMessage()); 507 } catch (CreateException ce) { 508 if (this.getProjectConfigTrace()) 509 trace.error(ce.getMessage()); 510 throw new HeroException(ce.getMessage()); 511 } catch (FinderException fe) { 512 if (this.getProjectConfigTrace()) 513 trace.error(fe.getMessage()); 514 throw new HeroException(fe.getMessage()); 515 } catch (javax.naming.NamingException ne) { 516 if (this.getProjectConfigTrace()) 517 trace.error(ne.getMessage()); 518 throw new HeroException(ne.getMessage()); 519 } 520 } 521 } 522 523 534 public void addEdge(String name, String in, String out) 535 throws HeroException { 536 if (this.getProjectConfigTrace()) 537 trace.error("parameters: name=" + name + " in=" + in + " out=" + out + " process name = " + this.getName()+ " started by " + this.getCaller()); 538 throw new HeroException("no more implemented"); 539 } 540 541 554 public String addEdge(String in, String out) throws HeroException { 555 if (this.getProjectConfigTrace()) 556 trace.info("parameters: in=" + in + " out:" + out + " process name = " + this.getName()+ " started by " + this.getCaller()); 557 BnEdgeLocalHome eHome; 558 BnNodeLocalHome nHome; 559 BnNodeLocal mInNode; 560 BnNodeLocal mOutNode; 561 BnEdgeLocal mEdge; 562 if (!isAdminOfProject(this.getCaller())) 563 { 564 if (this.getProjectConfigTrace()) 565 trace.error("Only the Admin of the project is allowed to do this operation... "); 566 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 567 } 568 try { 569 nHome = hero.interfaces.BnNodeUtil.getLocalHome(); 570 } catch (javax.naming.NamingException be) { 571 if (this.getProjectConfigTrace()) 572 trace.error(be.getMessage()); 573 throw new HeroException(be.getMessage()); 574 } 575 try { 576 mInNode = nHome.findByName(in, mProject.getId()); 577 } catch (FinderException fe) { 578 if (this.getProjectConfigTrace()) 579 trace.error("In Node does not exist " + fe.getMessage()); 580 throw new HeroException("In Node does not exist"); 581 } 582 try { 583 mOutNode = nHome.findByName(out, mProject.getId()); 584 } catch (FinderException fe) { 585 if (this.getProjectConfigTrace()) 586 trace.error("Out Node does not exist " + fe.getMessage()); 587 throw new HeroException("Out Node does not exist"); 588 } 589 try { 590 eHome = hero.interfaces.BnEdgeUtil.getLocalHome(); 591 } catch (javax.naming.NamingException be) { 592 if (this.getProjectConfigTrace()) 593 trace.error(be.getMessage()); 594 throw new HeroException(be.getMessage()); 595 } 596 visited.clear(); 597 if (!checkStructuralConstraints(in, out)) 598 throw new hero.util.EdgeCycleException("This edge add a cycle"); 599 600 if (checkDynamics(out)) { if (checkDuplicateEdge(in, out)) { 602 try { 603 mEdge = eHome.create(); 604 mEdge.setBnProject(mProject); 605 mEdge.setInBnNode(mInNode); 606 mEdge.setOutBnNode(mOutNode); 607 608 jms.sendEdgeEvent(ADDEDGE,this.getName(),mEdge.getName(),mInNode.getName(),mOutNode.getName(),this.getCaller()); 609 610 } catch (InvalidValueException ie) { 611 if (this.getProjectConfigTrace()) 612 trace.error(ie.getMessage()); 613 throw new HeroException(ie.getMessage()); 614 } catch (CreateException ce) { 615 if (this.getProjectConfigTrace()) 616 trace.error(ce.getMessage()); 617 throw new HeroException(ce.getMessage()); 618 } 619 } else { 620 throw new hero.util.DuplicatedEdgeException("Cannot add edge. BnEdge between nodes already exist"); 621 } 622 } else { 623 throw new hero.util.NodeStartedException("Cannot add edge. " + out + " is already started"); 624 } 625 628 629 int edgeState = hero.interfaces.Constants.edgeTransition[Constants.CONDITION_TRUE][mInNode.getState()]; 631 this.setEdgeState(mEdge, edgeState); 632 634 635 int newOperation = mOutNode.getActivation().state(mOutNode); 636 int newState = mOutNode.getTransition().computeState(mOutNode, newOperation); 637 if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) { 638 throw new HeroException("AddEdge generated a bad Node transition"); 639 } 640 this.setNodeState(mOutNode, newState); 641 return mEdge.getName(); 643 } 644 645 657 public String addAgentEdge(String in, String out) throws HeroException { 658 if (this.getProjectConfigTrace()) 659 trace.info("parameters: in=" + in + " out:" + out + " process name = " + this.getName()+ " started by " + this.getCaller()); 660 BnAgentEdgeLocalHome eHome; 661 BnNodeLocalHome nHome; 662 BnAgentLocalHome aHome; 663 BnAgentLocal mInAgent; 664 BnNodeLocal mOutNode; 665 BnAgentEdgeLocal mEdge; 666 if (!isAdminOfProject(this.getCaller())) 667 { 668 if (this.getProjectConfigTrace()) 669 trace.error("Only the Admin of the project is allowed to do this operation... "); 670 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 671 } 672 try { 673 aHome = hero.interfaces.BnAgentUtil.getLocalHome(); 674 } catch (javax.naming.NamingException be) { 675 if (this.getProjectConfigTrace()) 676 trace.error(be.getMessage()); 677 throw new HeroException(be.getMessage()); 678 } 679 try { 680 mInAgent = aHome.findByName(in, mProject.getId()); 681 } catch (FinderException fe) { 682 if (this.getProjectConfigTrace()) 683 trace.error("In Agent does not exist " + fe.getMessage()); 684 throw new HeroException("In Agent does not exist"); 685 } 686 try { 687 nHome = hero.interfaces.BnNodeUtil.getLocalHome(); 688 } catch (javax.naming.NamingException be) { 689 if (this.getProjectConfigTrace()) 690 trace.error(be.getMessage()); 691 throw new HeroException(be.getMessage()); 692 } 693 try { 694 mOutNode = nHome.findByName(out, mProject.getId()); 695 } catch (FinderException fe) { 696 if (this.getProjectConfigTrace()) 697 trace.error("Out Node does not exist " + fe.getMessage()); 698 throw new HeroException("Out Node does not exist"); 699 } 700 try { 701 eHome = hero.interfaces.BnAgentEdgeUtil.getLocalHome(); 702 } catch (javax.naming.NamingException be) { 703 if (this.getProjectConfigTrace()) 704 trace.error(be.getMessage()); 705 throw new HeroException(be.getMessage()); 706 } 707 if (checkDynamics(out)) { if (checkDuplicateAgentEdge(in, out)) { 709 try { 710 mEdge = eHome.create(); 711 mEdge.setBnProject(mProject); 712 mEdge.setInBnAgent(mInAgent); 713 mEdge.setOutBnNode(mOutNode); 714 715 717 } catch (InvalidValueException ie) { 718 if (this.getProjectConfigTrace()) 719 trace.error(ie.getMessage()); 720 throw new HeroException(ie.getMessage()); 721 } catch (CreateException ce) { 722 if (this.getProjectConfigTrace()) 723 trace.error(ce.getMessage()); 724 throw new HeroException(ce.getMessage()); 725 } 726 } else { 727 throw new hero.util.DuplicatedEdgeException("Cannot add agentEdge. AgentEdge between nodes already exist"); 728 } 729 } else { 730 throw new hero.util.NodeStartedException( 731 "Cannot add agentEdge. " + out + " is already started"); 732 } 733 734 this.setAgentEdgeState(mEdge, hero.interfaces.Constants.Ed.INITIAL); 736 737 int newOperation = mOutNode.getActivation().state(mOutNode); 738 int newState = mOutNode.getTransition().computeState(mOutNode, newOperation); 739 if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) { 740 throw new HeroException("AddEdge generated a bad Node transition"); 741 } 742 this.setNodeState(mOutNode, newState); 743 return mEdge.getName(); 745 } 746 747 759 public void addRole(String roleName, String description) 760 throws HeroException { 761 BnRoleLocalHome roleh; 762 if (this.getProjectConfigTrace()) 763 trace.info("parameters: roleName=" + roleName + " description=" + description + " process name = " + this.getName()+ " started by " + this.getCaller()); 764 if (!isAdminOfProject(this.getCaller())) 765 { 766 if (this.getProjectConfigTrace()) 767 trace.error("Only the Admin of the project is allowed to do this operation... "); 768 throw new AdminException("Only the Admin of the project is allowed to do this operation... "); 769 } 770 try { 771 roleh = BnRoleUtil.getLocalHome(); 772 } catch (javax.naming.NamingException ne) { 773 if (this.getProjectConfigTrace()) 774 trace.error(ne.getMessage()); <
|