1 package hero.session; 2 24 import hero.interfaces.BnNodeLocal; 25 import hero.interfaces.BnNodeLocalHome; 26 import hero.interfaces.BnNodeUtil; 27 import hero.interfaces.BnNodeValue; 28 import hero.interfaces.BnProjectLocal; 29 import hero.interfaces.BnProjectLightValue; 30 import hero.interfaces.BnProjectLocalHome; 31 import hero.interfaces.BnProjectUtil; 32 import hero.interfaces.BnProjectValue; 33 import hero.interfaces.BnUserLightValue; 34 import hero.interfaces.BnUserLocal; 35 import hero.interfaces.BnUserLocalHome; 36 import hero.interfaces.BnUserPropertyLocal; 37 import hero.interfaces.BnUserPropertyLocalHome; 38 import hero.interfaces.BnUserPropertyUtil; 39 import hero.interfaces.BnUserValue; 40 import hero.interfaces.EngineLocal; 41 import hero.interfaces.EngineLocalHome; 42 import hero.interfaces.InvalidValueException; 43 import hero.interfaces.ProjectSessionLocal; 44 import hero.interfaces.ProjectSessionLocalHome; 45 import hero.interfaces.ProjectSessionUtil; 46 import hero.interfaces.JMSServicesSessionUtil; 47 import hero.interfaces.JMSServicesSessionLocalHome; 48 import hero.interfaces.JMSServicesSessionLocal; 49 import hero.interfaces.UserServiceLocal; 50 import hero.interfaces.UserServiceLocalHome; 51 import hero.util.BonitaConfig; 52 import hero.historic.BonitaTransfer; 53 import hero.util.EngineException; 54 import hero.util.HeroException; 55 import hero.util.EventConstants; 56 import hero.interfaces.Constants; 57 58 import java.util.ArrayList ; 59 import java.util.Map ; 60 import java.util.Arrays ; 61 import java.util.Collection ; 62 import java.util.Iterator ; 63 import java.util.Hashtable ; 64 import java.util.Enumeration ; 65 66 import javax.ejb.CreateException ; 67 import javax.ejb.EJBException ; 68 import javax.ejb.FinderException ; 69 import javax.ejb.RemoveException ; 70 import javax.ejb.SessionBean ; 71 import javax.ejb.SessionContext ; 72 73 import org.apache.log4j.Logger; 74 75 133 134 public class UserSessionBean implements SessionBean , EventConstants { 135 136 private static final Logger trace = Logger.getLogger(UserSessionBean.class); 141 142 146 private SessionContext mContext; 147 private BonitaConfig bonitaConfig; 148 149 153 161 public Collection getProjectList() throws HeroException { 162 Collection pjts = new ArrayList (); 163 Collection pva; 164 try{ 165 this.synchronizeUser(); 166 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 167 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 168 trace.info("start by " + mContext.getCallerPrincipal().getName()); 169 BnUserValue uv = mUser.getBnUserValue(); 170 pva = new ArrayList (Arrays.asList(uv.getBnProjects())); 171 } catch (javax.naming.NamingException ne) { 172 trace.error(ne.getMessage()); 173 throw new HeroException(ne.getMessage()); 174 } catch (javax.ejb.FinderException fe) { 175 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 176 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 177 } 178 return pva; 179 } 180 188 public Collection getProjectListNames() throws HeroException { 189 trace.info("start by " + mContext.getCallerPrincipal().getName()); 190 Collection projectsNames; 192 try{ 193 this.synchronizeUser(); 194 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 195 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 196 BnUserValue uv = mUser.getBnUserValue(); 198 Collection pva = new ArrayList (Arrays.asList(uv.getBnProjects())); 199 projectsNames = new ArrayList (); 200 Iterator i = pva.iterator(); 201 while (i.hasNext()) 202 projectsNames.add(((hero.interfaces.BnProjectLightValue) i.next()).getName()); 203 } catch (javax.naming.NamingException ne) {ne.printStackTrace(); 204 trace.error(ne.getMessage()); 205 throw new HeroException(ne.getMessage()); 206 } catch (javax.ejb.FinderException fe) {fe.printStackTrace(); 207 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 208 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 209 } 210 return projectsNames; 211 } 212 213 222 public Collection getInstancesList() throws HeroException { 223 trace.info("start by " + mContext.getCallerPrincipal().getName()); 224 this.synchronizeUser(); 225 Collection instances = new ArrayList (); 226 Collection pva = this.getProjectList(); 227 Iterator ps = pva.iterator(); 228 229 while (ps.hasNext()) 230 { 231 BnProjectLightValue pro = (BnProjectLightValue)ps.next(); 232 if (pro.getType().equals(Constants.Pj.INSTANCE)) 233 instances.add(pro); 234 } 235 return instances; 236 } 237 238 247 public Collection getModelList() throws HeroException { 248 trace.info("start by " + mContext.getCallerPrincipal().getName()); 249 this.synchronizeUser(); 250 Collection models = new ArrayList (); 251 Collection pva = this.getProjectList(); 252 Iterator ps = pva.iterator(); 253 254 while (ps.hasNext()) 255 { 256 BnProjectLightValue pro = (BnProjectLightValue)ps.next(); 257 if (pro.getType().equals(Constants.Pj.MODEL)) 258 models.add(pro); 259 } 260 return models; 261 } 262 263 271 public Collection getModels() throws HeroException { 272 trace.info("start by " + mContext.getCallerPrincipal().getName()); 273 this.synchronizeUser(); 274 BnProjectLocalHome projhome; 275 BnProjectLocal project; 276 Collection models = new ArrayList (); 277 Collection pva = null; 278 try { 279 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 280 } catch (javax.naming.NamingException be) { 281 throw new HeroException(be.getMessage()); 282 } 283 try { 284 pva = projhome.findModels(Constants.Pj.MODEL); 285 } catch (FinderException fe) { 286 throw new HeroException("Error in findByModels: "+fe.getMessage()); 287 } 288 Iterator ps = pva.iterator(); 289 while (ps.hasNext()) 290 { 291 BnProjectLocal pro = (BnProjectLocal)ps.next(); 292 models.add(pro.getBnProjectLightValue()); 293 } 294 return models; 295 } 296 297 306 public Collection getCooperativeList() throws HeroException { 307 trace.info("start by " + mContext.getCallerPrincipal().getName()); 308 this.synchronizeUser(); 309 Collection coo = new ArrayList (); 310 Collection pva = this.getProjectList(); 311 Iterator ps = pva.iterator(); 312 313 while (ps.hasNext()) 314 { 315 BnProjectLightValue pro = (BnProjectLightValue)ps.next(); 316 if (pro.getType().equals(Constants.Pj.COOPERATIVE)) 317 coo.add(pro); 318 } 319 return coo; 320 } 321 322 331 public Collection getInstancesListNames() throws HeroException { 332 trace.info("start by " + mContext.getCallerPrincipal().getName()); 333 this.synchronizeUser(); 334 Collection instances = new ArrayList (); 335 Collection pva = this.getProjectList(); 336 Iterator ps = pva.iterator(); 337 while (ps.hasNext()) 338 { 339 BnProjectLightValue pro = (BnProjectLightValue)ps.next(); 340 if (pro.getName().matches(".*_instance.*")) 341 instances.add(pro.getName()); 342 } 343 return instances; 344 } 345 346 354 public void removeProject(String projectName) throws HeroException { 355 if (this.getProjectConfigTrace(projectName)) 356 trace.info("parameter: projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName()); 357 if (this.isAdmin(projectName)) 358 this.deleteProject(projectName); 359 else 360 throw new HeroException("Error in delete project: only admin users are allowed to removed it !!"); 361 } 362 363 372 public Collection getToDoList(String projectName) throws HeroException { 373 if (this.getProjectConfigTrace(projectName)) 374 trace.info("parameter: projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName()); 375 BnProjectLocalHome projhome; 376 BnProjectLocal project; 377 BnNodeLocalHome nodehome; 378 Collection ready; 379 this.synchronizeUser(); 380 try { 381 projhome = BnProjectUtil.getLocalHome(); 382 nodehome = BnNodeUtil.getLocalHome(); 383 } catch (javax.naming.NamingException ne) { 384 if (this.getProjectConfigTrace(projectName)) 385 trace.error(ne.getMessage()); 386 throw new HeroException(ne.getMessage()); 387 } 388 try { 389 project = projhome.findByName(projectName); 390 } catch (FinderException fe) { 391 if (this.getProjectConfigTrace(projectName)) 392 trace.error("BnProject " + projectName + " does not exists " + fe.getMessage()); 393 throw new HeroException("BnProject " + projectName + " does not exists"); 394 } 395 try { 396 ready = nodehome.findUserReady(project.getId(), mContext.getCallerPrincipal().getName()); 397 } catch (FinderException fe) { 398 if (this.getProjectConfigTrace(projectName)) 399 trace.error(fe.getMessage()); 400 ready = new ArrayList (); 401 } 402 ArrayList result = new ArrayList (); 403 for (Iterator i = ready.iterator(); i.hasNext();) { 404 BnNodeLocal nd = (BnNodeLocal) i.next(); 405 if (this.getProjectConfigTrace(projectName)) 406 trace.info("NODE NAME=" + nd.getName()); 407 result.add(nd.getName()); 408 } 409 return result; 410 } 411 412 422 public Collection getActivityList(String projectName) 423 throws HeroException { 424 BnProjectLocalHome projhome; 425 BnProjectLocal project; 426 BnNodeLocalHome nodehome; 427 Collection executing; 428 this.synchronizeUser(); 429 if (this.getProjectConfigTrace(projectName)) 430 trace.info("parameter: -begin projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName()); 431 try { 432 projhome = BnProjectUtil.getLocalHome(); 433 nodehome = BnNodeUtil.getLocalHome(); 434 } catch (javax.naming.NamingException ne) { 435 if (this.getProjectConfigTrace(projectName)) 436 trace.error(ne.getMessage()); 437 throw new HeroException(ne.getMessage()); 438 } 439 try { 440 project = projhome.findByName(projectName); 441 } catch (FinderException fe) { 442 if (this.getProjectConfigTrace(projectName)) 443 trace.error("BnProject " + projectName + " does not exists " + fe.getMessage()); 444 throw new HeroException("BnProject " + projectName + " does not exists"); 445 } 446 try { 447 executing = 448 nodehome.findUserExecuting(project.getId(), mContext.getCallerPrincipal().getName()); 449 } catch (FinderException fe) { 450 if (this.getProjectConfigTrace(projectName)) 451 trace.error(fe.getMessage()); 452 executing = new ArrayList (); 453 } 454 ArrayList result = new ArrayList (); 455 for (Iterator i = executing.iterator(); i.hasNext();) { 456 BnNodeLocal nd = (BnNodeLocal) i.next(); 457 result.add(nd.getName()); 458 } 459 return result; 460 } 461 462 470 public Collection getToDoListAllInstances() throws HeroException { 471 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 472 BnNodeLocalHome nodehome; 473 Collection ready; 474 this.synchronizeUser(); 475 try { 476 nodehome = BnNodeUtil.getLocalHome(); 477 } catch (javax.naming.NamingException ne) { 478 trace.error(ne.getMessage()); 479 throw new HeroException(ne.getMessage()); 480 } 481 try { 482 ready = nodehome.findUserReadyAllProjects(mContext.getCallerPrincipal().getName()); 483 } catch (FinderException fe) { 484 trace.error(fe.getMessage()); 485 ready = new ArrayList (); 486 } 487 ArrayList result = new ArrayList (); 488 for (Iterator i = ready.iterator(); i.hasNext();) { 489 BnNodeLocal nd = (BnNodeLocal) i.next(); 490 if (nd.getBnProject().getType().equals(Constants.Pj.INSTANCE) || nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE)) 491 result.add(nd.getBnNodeValue()); 492 } 493 return result; 494 } 495 496 504 public Collection getActivityListAllInstances() throws HeroException { 505 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 506 BnNodeLocalHome nodehome; 507 Collection executing; 508 this.synchronizeUser(); 509 try { 510 nodehome = BnNodeUtil.getLocalHome(); 511 } catch (javax.naming.NamingException ne) { 512 trace.error(ne.getMessage()); 513 throw new HeroException(ne.getMessage()); 514 } 515 try { 516 executing = nodehome.findUserExecutingAllProjects(mContext.getCallerPrincipal().getName()); 517 } catch (FinderException fe) { 518 trace.error(fe.getMessage()); 519 executing = new ArrayList (); 520 } 521 ArrayList result = new ArrayList (); 522 for (Iterator i = executing.iterator(); i.hasNext();) { 523 BnNodeLocal nd = (BnNodeLocal) i.next(); 524 if (nd.getBnProject().getType().equals(Constants.Pj.INSTANCE) || nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE)) 525 result.add(nd.getBnNodeValue()); 526 } 527 return result; 528 } 529 530 538 public Collection getTerminatedListAllInstances() throws HeroException { 539 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 540 BnNodeLocalHome nodehome; 541 Collection executing; 542 this.synchronizeUser(); 543 try { 544 nodehome = BnNodeUtil.getLocalHome(); 545 } catch (javax.naming.NamingException ne) { 546 trace.error(ne.getMessage()); 547 throw new HeroException(ne.getMessage()); 548 } 549 try { 550 executing = nodehome.findUserTerminatedAllProjects(mContext.getCallerPrincipal().getName()); 551 } catch (FinderException fe) { 552 trace.error(fe.getMessage()); 553 executing = new ArrayList (); 554 } 555 ArrayList result = new ArrayList (); 556 for (Iterator i = executing.iterator(); i.hasNext();) { 557 BnNodeLocal nd = (BnNodeLocal) i.next(); 558 if (nd.getBnProject().getType().equals(Constants.Pj.INSTANCE) || nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE)) 559 result.add(nd.getBnNodeValue()); 560 } 561 return result; 562 } 563 564 565 576 public Collection getToDoListByProperty(String key, String value) throws HeroException { 577 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 578 BnNodeLocalHome nodehome; 579 Collection ready; 580 this.synchronizeUser(); 581 try { 582 nodehome = BnNodeUtil.getLocalHome(); 583 } catch (javax.naming.NamingException ne) { 584 trace.error(ne.getMessage()); 585 throw new HeroException(ne.getMessage()); 586 } 587 try { 588 ready = nodehome.findUserReadyAllProjectsByProperty(mContext.getCallerPrincipal().getName(),key,value); 589 } catch (FinderException fe) { 590 trace.error(fe.getMessage()); 591 ready = new ArrayList (); 592 } 593 ArrayList result = new ArrayList (); 594 for (Iterator i = ready.iterator(); i.hasNext();) { 595 BnNodeLocal nd = (BnNodeLocal) i.next(); 596 if (nd.getBnProject().getName().matches(".*_instance.*")) 597 result.add(nd.getBnNodeValue()); 598 } 599 return result; 600 } 601 602 616 public Collection getToDoListByProperties(int operation, Hashtable properties) throws HeroException { 617 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 618 BnNodeLocalHome nodehome; 619 Collection ready = new ArrayList (); 620 this.synchronizeUser(); 621 try { 622 nodehome = BnNodeUtil.getLocalHome(); 623 } catch (javax.naming.NamingException ne) { 624 trace.error(ne.getMessage()); 625 throw new HeroException(ne.getMessage()); 626 } 627 try { 628 Enumeration keys = properties.keys(); 629 Collection vls = properties.values(); 630 Iterator values = vls.iterator(); 631 if (properties.size() >3) 632 { 633 throw new HeroException("This method uses EJBQL language to improve queries. These queries are based " + 634 "on static parameters numbers, so if you want use this method with more than three properties contact us !!"); 635 } 636 if (properties.size() == 1) 637 ready = nodehome.findUserReadyAllProjectsByProperty(mContext.getCallerPrincipal().getName(),(String )keys.nextElement(),(String )values.next()); 638 if (operation == Constants.AND) 639 { 640 if (properties.size() == 2) 641 ready = nodehome.findUserReadyAllProjectsByTwoPropertiesAND(mContext.getCallerPrincipal().getName(),(String )keys.nextElement(),(String )values.next(),(String )keys.nextElement(),(String )values.next()); 642 else if (properties.size() == 3) 643 ready = nodehome.findUserReadyAllProjectsByThreePropertiesAND(mContext.getCallerPrincipal().getName(),(String )keys.nextElement(),(String )values.next(),(String )keys.nextElement(),(String )values.next(),(String )keys.nextElement(),(String )values.next()); 644 } 645 else if (operation == Constants.OR) 646 { 647 if (properties.size() == 2) 648 ready = nodehome.findUserReadyAllProjectsByTwoPropertiesOR(mContext.getCallerPrincipal().getName(),(String )keys.nextElement(),(String )values.next(),(String )keys.nextElement(),(String )values.next()); 649 else if (properties.size() == 3) 650 ready = nodehome.findUserReadyAllProjectsByThreePropertiesOR(mContext.getCallerPrincipal().getName(),(String )keys.nextElement(),(String )values.next(),(String )keys.nextElement(),(String )values.next(),(String )keys.nextElement(),(String )values.next()); 651 } 652 } catch (FinderException fe) { 653 trace.error(fe.getMessage()); 654 ready = new ArrayList (); 655 } 656 ArrayList result = new ArrayList (); 657 for (Iterator i = ready.iterator(); i.hasNext();) { 658 BnNodeLocal nd = (BnNodeLocal) i.next(); 659 if (nd.getBnProject().getName().matches(".*_instance.*")) 660 result.add(nd.getBnNodeValue()); 661 } 662 return result; 663 } 664 665 676 public Collection getToDoListByActivityProperty(String key, String value) throws HeroException { 677 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 678 BnNodeLocalHome nodehome; 679 Collection ready; 680 this.synchronizeUser(); 681 try { 682 nodehome = BnNodeUtil.getLocalHome(); 683 } catch (javax.naming.NamingException ne) { 684 trace.error(ne.getMessage()); 685 throw new HeroException(ne.getMessage()); 686 } 687 try { 688 ready = nodehome.findUserReadyAllActivitiesByProperty(mContext.getCallerPrincipal().getName(),key,value); 689 } catch (FinderException fe) { 690 trace.error(fe.getMessage()); 691 ready = new ArrayList (); 692 } 693 ArrayList result = new ArrayList (); 694 for (Iterator i = ready.iterator(); i.hasNext();) { 695 BnNodeLocal nd = (BnNodeLocal) i.next(); 696 if (nd.getBnProject().getName().matches(".*_instance.*")) 697 result.add(nd.getBnNodeValue()); 698 } 699 return result; 700 } 701 702 713 public Collection getActivityListByProperty(String key, String value) throws HeroException { 714 trace.info(" start by " + mContext.getCallerPrincipal().getName()); 715 BnNodeLocalHome nodehome; 716 Collection executing; 717 this.synchronizeUser(); 718 try { 719 nodehome = BnNodeUtil.getLocalHome(); 720 } catch (javax.naming.NamingException ne) { 721 trace.error(ne.getMessage()); 722 throw new HeroException(ne.getMessage()); 723 } 724 try { 725 executing = nodehome.findUserExecutingAllProjectsByProperty(mContext.getCallerPrincipal().getName(),key,value); 726 } catch (FinderException fe) { 727 trace.error(fe.getMessage()); 728 executing = new ArrayList (); 729 } 730 ArrayList result = new ArrayList (); 731 for (Iterator i = executing.iterator(); i.hasNext();) { 732 BnNodeLocal nd = (BnNodeLocal) i.next(); 733 if (nd.getBnProject().getName().matches(".*_instance.*")) 734 result.add(nd.getBnNodeValue()); 735 } 736 return result; 737 } 738 748 public Collection getProjectInstancesNames(String projectName) 749 throws HeroException { 750 if (this.getProjectConfigTrace(projectName)) 751 trace.info("parameter: projectName = "+ projectName+ " start by "+ mContext.getCallerPrincipal().getName()); 752 ArrayList result = new ArrayList (); 753 BnProjectLocalHome projhome; 754 this.synchronizeUser(); 755 try { 756 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 757 758 Collection instances =projhome.findUserInstancesByProject(projectName+"_instance%",this.getUser()); 759 for (Iterator i = instances.iterator(); i.hasNext();) { 760 BnProjectLocal pl = (BnProjectLocal) i.next(); 761 if (!pl.getName().equals(projectName)) 762 result.add(pl.getName()); 763 } 764 return (result); 765 } catch (javax.naming.NamingException ne) { 766 if (this.getProjectConfigTrace(projectName)) 767 trace.error(ne.getMessage()); 768 throw new HeroException(ne.getMessage()); 769 } catch (javax.ejb.FinderException fe) { 770 if (this.getProjectConfigTrace(projectName)) 771 trace.error(fe.getMessage()); 772 throw new HeroException(fe.getMessage()); 773 } 774 } 775 784 public Collection getProjectInstances(String projectName) throws HeroException { 785 if (this.getProjectConfigTrace(projectName)) 786 trace.info("parameter: projectName = "+projectName + " start by " + mContext.getCallerPrincipal().getName()); 787 ArrayList result = new ArrayList (); 788 BnProjectLocalHome projhome; 789 this.synchronizeUser(); 790 try { 791 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 792 Collection instances = projhome.findUserInstancesByProject(projectName+"_instance%",this.getUser()); 793 for (Iterator i = instances.iterator(); i.hasNext();) { 794 BnProjectLocal pl = (BnProjectLocal) i.next(); 795 if (!pl.getName().equals(projectName)) 796 result.add(pl.getBnProjectValue()); 797 } 798 return (result); 799 } catch (javax.naming.NamingException ne) { 800 if (this.getProjectConfigTrace(projectName)) 801 trace.error(ne.getMessage()); 802 throw new HeroException(ne.getMessage()); 803 } catch (javax.ejb.FinderException fe) { 804 if (this.getProjectConfigTrace(projectName)) 805 trace.error(fe.getMessage()); 806 throw new HeroException(fe.getMessage()); 807 } 808 } 809 810 819 820 public Collection getInstancesByProperty(String key, String value) 821 throws HeroException { 822 trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName()); 823 ArrayList result = new ArrayList (); 824 BnProjectLocalHome projhome; 825 this.synchronizeUser(); 826 try { 827 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 828 Collection instances = projhome.findProjectsByProperty(key, value); 829 for (Iterator i = instances.iterator(); i.hasNext();) { 830 BnProjectLocal pl = (BnProjectLocal) i.next(); 831 if (pl.getName().matches(".*_instance.*")) 832 result.add(pl.getBnProjectValue()); 833 } 834 return (result); 835 } catch (javax.naming.NamingException ne) { 836 trace.error(ne.getMessage()); 837 throw new HeroException(ne.getMessage()); 838 } catch (javax.ejb.FinderException fe) { 839 trace.error(fe.getMessage()); 840 throw new HeroException(fe.getMessage()); 841 } 842 } 843 844 853 854 public Collection getInstancesByPropertyNames(String key, String value) 855 throws HeroException { 856 trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName()); 857 ArrayList result = new ArrayList (); 858 BnProjectLocalHome projhome; 859 this.synchronizeUser(); 860 try { 861 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 862 Collection instances = projhome.findProjectsByProperty(key, value); 863 for (Iterator i = instances.iterator(); i.hasNext();) { 864 BnProjectLocal pl = (BnProjectLocal) i.next(); 865 if (pl.getName().matches(".*_instance.*")) 866 result.add(pl.getName()); 867 868 } 869 return (result); 870 } catch (javax.naming.NamingException ne) { 871 trace.error(ne.getMessage()); 872 throw new HeroException(ne.getMessage()); 873 } catch (javax.ejb.FinderException fe) { 874 trace.error(fe.getMessage()); 875 throw new HeroException(fe.getMessage()); 876 } 877 } 878 879 888 889 public Collection getProjectsByProperty(String key, String value) 890 throws HeroException { 891 trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName()); 892 ArrayList result = new ArrayList (); 893 BnProjectLocalHome projhome; 894 this.synchronizeUser(); 895 try { 896 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 897 Collection instances = projhome.findProjectsByProperty(key, value); 898 for (Iterator i = instances.iterator(); i.hasNext();) { 899 BnProjectLocal pl = (BnProjectLocal) i.next(); 900 if (!pl.getName().matches(".*_instance.*")) 901 result.add(pl.getBnProjectValue()); 902 } 903 return (result); 904 } catch (javax.naming.NamingException ne) { 905 trace.error(ne.getMessage()); 906 throw new HeroException(ne.getMessage()); 907 } catch (javax.ejb.FinderException fe) { 908 trace.error(fe.getMessage()); 909 throw new HeroException(fe.getMessage()); 910 } 911 } 912 913 922 923 public Collection getProjectsByPropertyNames(String key, String value) 924 throws HeroException { 925 trace.info("parameters: key = " + key +" value = " + value + " start by " + mContext.getCallerPrincipal().getName()); 926 ArrayList result = new ArrayList (); 927 BnProjectLocalHome projhome; 928 this.synchronizeUser(); 929 try { 930 projhome = hero.interfaces.BnProjectUtil.getLocalHome(); 931 Collection instances = projhome.findProjectsByProperty(key, value); 932 for (Iterator i = instances.iterator(); i.hasNext();) { 933 BnProjectLocal pl = (BnProjectLocal) i.next(); 934 if (!pl.getName().matches(".*_instance.*")) 935 result.add(pl.getName()); 936 937 } 938 return (result); 939 } catch (javax.naming.NamingException ne) { 940 trace.error(ne.getMessage()); 941 throw new HeroException(ne.getMessage()); 942 } catch (javax.ejb.FinderException fe) { 943 trace.error(fe.getMessage()); 944 throw new HeroException(fe.getMessage()); 945 } 946 } 947 948 956 957 public void startActivity(String projectName, String nodeName) 958 throws HeroException { 959 if (this.getProjectConfigTrace(projectName)) 960 trace.info("parameters: projectName="+ projectName+ " nodeName="+ nodeName + " start by " + mContext.getCallerPrincipal().getName()); 961 EngineLocalHome enghome; 962 this.synchronizeUser(); 963 try { 964 enghome = hero.interfaces.EngineUtil.getLocalHome(); 965 EngineLocal engine = enghome.create(); 966 engine.startActivity(projectName, nodeName); 967 engine.remove(); 968 } catch (javax.naming.NamingException ne) { 969 if (this.getProjectConfigTrace(projectName)) 970 trace.error(ne.getMessage()); 971 throw new HeroException(ne.getMessage()); 972 } catch (RemoveException r) { 973 if (this.getProjectConfigTrace(projectName)) 974 trace.error("Cannot remove Engine bean for "+ projectName+ " " + r.getMessage()); 975 throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage()); 976 } catch (CreateException c) { 977 if (this.getProjectConfigTrace(projectName)) 978 trace.error("Cannot create Engine bean for "+ projectName+ " " + c.getMessage()); 979 throw new HeroException("Cannot create Engine bean for "+ projectName+ " "+ c.getMessage()); 980 } 981 } 982 983 990 public void terminateActivity(String projectName, String nodeName) 991 throws HeroException { 992 if (this.getProjectConfigTrace(projectName)) 993 trace.info("parameters: projectName="+ projectName+ " nodeName="+ nodeName + " start by " + mContext.getCallerPrincipal().getName()); 994 EngineLocalHome enghome; 995 this.synchronizeUser(); 996 try { 997 enghome = hero.interfaces.EngineUtil.getLocalHome(); 998 EngineLocal engine = enghome.create(); 999 engine.terminateActivity(projectName, nodeName); 1000 engine.remove(); 1001 } catch (RemoveException r) { 1002 if (this.getProjectConfigTrace(projectName)) 1003 trace.error("Cannot remove Engine bean for "+ projectName+ " " + r.getMessage()); 1004 throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage()); 1005 } catch (javax.naming.NamingException ne) { 1006 if (this.getProjectConfigTrace(projectName)) 1007 trace.error(ne.getMessage()); 1008 throw new HeroException(ne.getMessage()); 1009 } catch (CreateException c) { 1010 if (this.getProjectConfigTrace(projectName)) 1011 trace.error("Cannot create Engine bean for " + projectName + " " + c.getMessage()); 1012 throw new HeroException("Cannot create Engine bean for " + projectName); 1013 } 1014 } 1015 1016 1023 public void cancelActivity(String projectName, String nodeName) 1024 throws HeroException { 1025 if (this.getProjectConfigTrace(projectName)) 1026 trace.info("parameters: projectName="+ projectName+ " nodeName="+ nodeName + " start by " + mContext.getCallerPrincipal().getName()); 1027 EngineLocalHome enghome; 1028 this.synchronizeUser(); 1029 try { 1030 enghome = hero.interfaces.EngineUtil.getLocalHome(); 1031 EngineLocal engine = enghome.create(); 1032 engine.cancelActivity(projectName, nodeName); 1033 engine.remove(); 1034 } catch (RemoveException r) { 1035 if (this.getProjectConfigTrace(projectName)) 1036 trace.error("Cannot remove Engine bean for "+ projectName + " " + r.getMessage()); 1037 throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage()); 1038 } catch (javax.naming.NamingException ne) { 1039 if (this.getProjectConfigTrace(projectName)) 1040 trace.error(ne.getMessage()); 1041 throw new HeroException(ne.getMessage()); 1042 } catch (CreateException c) { 1043 if (this.getProjectConfigTrace(projectName)) 1044 trace.error("Cannot create Engine bean for " + projectName + " " + c.getMessage()); 1045 throw new EJBException ("Cannot create Engine bean for " + projectName); 1046 } 1047 } 1048 1055 public void terminate(String projectName) throws HeroException { 1056 if (this.getProjectConfigTrace(projectName)) 1057 trace.info("parameter; projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName()); 1058 EngineLocalHome enghome; 1059 this.synchronizeUser(); 1060 try { 1061 enghome = hero.interfaces.EngineUtil.getLocalHome(); 1062 EngineLocal engine = enghome.create(); 1063 engine.terminate(projectName); 1064 engine.remove(); 1065 if (this.getProjectConfigHistoric(projectName).equals(Constants.TRANSFER)) 1066 BonitaTransfer.TransferFile(projectName); 1067 deleteProject(projectName); 1068 } catch (RemoveException r) { 1069 if (this.getProjectConfigTrace(projectName)) 1070 trace.error("Cannot remove Engine bean for "+ projectName+ " " + r.getMessage()); 1071 throw new HeroException("Cannot remove Engine bean for "+ projectName+ " "+ r.getMessage()); 1072 } catch (javax.naming.NamingException ne) { 1073 if (this.getProjectConfigTrace(projectName)) 1074 trace.error(ne.getMessage()); 1075 throw new HeroException(ne.getMessage()); 1076 } catch (CreateException c) { 1077 if (this.getProjectConfigTrace(projectName)) 1078 trace.error("Cannot create Engine bean for " + projectName + " " + c.getMessage()); 1079 throw new EJBException ("Cannot create Engine bean for " + projectName); 1080 } catch (EngineException e) { 1081 if (this.getProjectConfigTrace(projectName)) 1082 trace.error("Cannot terminate project " + e.getMessage()); 1083 throw new HeroException("Cannot terminate project " + e.getMessage()); 1084 } 1085 } 1086 1087 1095 public BnNodeValue getNode(String projectName, String nodeName) 1096 throws HeroException { 1097 if (this.getProjectConfigTrace(projectName)) 1098 trace.info("parameters: projectName=" + projectName + " nodeName=" + nodeName + "start by " + mContext.getCallerPrincipal().getName()); 1099 this.synchronizeUser(); 1100 try { 1101 ProjectSessionLocalHome projectseshome =ProjectSessionUtil.getLocalHome(); 1102 ProjectSessionLocal project = projectseshome.create(); 1103 project.initProject(projectName); 1104 return project.getNodeValue(nodeName); 1105 } catch (CreateException f) { 1106 if (this.getProjectConfigTrace(projectName)) 1107 trace.error("Project does not exists " + projectName + " " + f.getMessage()); 1108 throw new HeroException("Project does not exists " + projectName); 1109 } catch (javax.naming.NamingException r) { 1110 if (this.getProjectConfigTrace(projectName)) 1111 trace.error("Cannot access to project " + r.getMessage()); 1112 throw new HeroException("Cannot access to project " + r.getMessage()); 1113 } 1114 } 1115 1116 1123 public String getUser() { 1124 trace.info("start by " + mContext.getCallerPrincipal().getName()); 1125 return mContext.getCallerPrincipal().getName(); 1126 } 1127 1128 1135 public BnUserLightValue getUserLightValue() throws HeroException{ 1136 try{ 1137 trace.info("start by " + mContext.getCallerPrincipal().getName()); 1138 this.synchronizeUser(); 1139 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 1140 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 1141 BnUserLightValue ulv= mUser.getBnUserLightValue(); 1142 UserServiceLocalHome ushome = null; 1143 try { 1144 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 1145 UserServiceLocal ul = ushome.create(); 1146 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 1147 ulv.setEmail((String )infos.get("email")); 1148 ulv.setPassword((String )infos.get("password")); 1149 ulv.setJabber((String )infos.get("jabber")); 1150 return ulv; 1151 } catch (Exception ce) { 1152 trace.error(ce.getMessage()); 1153 throw new HeroException(ce.getMessage()); 1154 } 1155 } catch (javax.naming.NamingException ne) { 1156 trace.error(ne.getMessage()); 1157 throw new HeroException(ne.getMessage()); 1158 } catch (javax.ejb.FinderException fe) { 1159 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 1160 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 1161 } 1162 } 1163 1164 1174 public void setUserMail(String userName, String mail) throws HeroException { 1175 trace.info("parameters:: userName = " + userName+" mail = "+mail + " start by " + mContext.getCallerPrincipal().getName()); 1176 this.synchronizeUser(); 1177 try { 1178 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 1179 BnUserLocal user = userhome.findByName(userName); 1180 user.setEmail(mail); 1181 } catch (javax.naming.NamingException ne) { 1182 trace.error(ne.getMessage()); 1183 throw new HeroException(ne.getMessage()); 1184 } catch (FinderException fe) { 1185 trace.error(fe.getMessage()); 1186 throw new HeroException(fe.getMessage()); 1187 } 1188 } 1189 1190 1199 public String getUserMail(String userName) throws HeroException { 1200 trace.info("parameter: userName = " + userName + " start by " + mContext.getCallerPrincipal().getName()); 1201 UserServiceLocalHome ushome = null; 1202 this.synchronizeUser(); 1203 try { 1204 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 1205 UserServiceLocal ul = ushome.create(); 1206 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 1207 return ((String )infos.get("email")); 1208 } catch (Exception ce) { 1209 trace.error(ce.getMessage()); 1210 throw new HeroException(ce.getMessage()); 1211 } 1212 } 1213 1214 1215 1222 public String getUserPassword() throws HeroException{ 1223 UserServiceLocalHome ushome = null; 1224 this.synchronizeUser(); 1225 try { 1226 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 1227 UserServiceLocal ul = ushome.create(); 1228 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 1229 return ((String )infos.get("password")); 1230 } catch (Exception ce) { 1231 trace.error(ce.getMessage()); 1232 throw new HeroException(ce.getMessage()); 1233 } 1234 } 1235 1236 1243 public String getUserJabber() throws HeroException{ 1244 UserServiceLocalHome ushome = null; 1245 this.synchronizeUser(); 1246 try { 1247 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 1248 UserServiceLocal ul = ushome.create(); 1249 Map infos = ul.getUserInfos(mContext.getCallerPrincipal().getName()); 1250 return ((String )infos.get("jabber")); 1251 } catch (Exception ce) { 1252 trace.error(ce.getMessage()); 1253 throw new HeroException(ce.getMessage()); 1254 } 1255 } 1256 1257 1265 public Collection getUserProperties() throws HeroException { 1266 Collection prp = new ArrayList (); 1267 BnUserPropertyLocal pl; 1268 this.synchronizeUser(); 1269 try{ 1270 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 1271 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 1272 Collection pls = mUser.getBnProperties(); 1273 1274 for (Iterator i = pls.iterator(); i.hasNext();) { 1275 pl = (BnUserPropertyLocal) i.next(); 1276 prp.add(pl.getBnUserPropertyValue()); 1277 } 1278 return (prp); 1279 } catch (javax.naming.NamingException ne) { 1280 trace.error(ne.getMessage()); 1281 throw new HeroException(ne.getMessage()); 1282 } catch (javax.ejb.FinderException fe) { 1283 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 1284 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 1285 } 1286 } 1287 1288 1297 1298 public void setUserProperty(String key, String value) 1299 throws HeroException { 1300 BnUserPropertyLocalHome pHome; 1301 BnUserPropertyLocal propertyLocal = null; 1302 trace.info("parameters: key=" + key + " value=" + value + " start by " + mContext.getCallerPrincipal().getName()); 1303 this.synchronizeUser(); 1304 1305 try { 1306 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 1307 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 1308 try { 1309 pHome = BnUserPropertyUtil.getLocalHome(); 1310 } catch (javax.naming.NamingException ne) { 1311 trace.error(ne.getMessage()); 1312 throw new HeroException(ne.getMessage()); 1313 } 1314 Collection c = null; 1315 try { 1316 c = pHome.findByTheKey(mUser.getId(), key); 1317 } catch (FinderException fe) { 1318 trace.error(fe.getMessage()); 1319 throw new HeroException(fe.getMessage()); 1320 } 1321 1322 if (!c.isEmpty()) { 1323 1324 propertyLocal = (BnUserPropertyLocal) (c.toArray())[0]; 1325 propertyLocal.setTheValue(value); 1326 1327 } else { 1328 try { 1329 propertyLocal = pHome.create(key, value); 1330 propertyLocal.setBnUser(mUser); 1331 1332 } catch (InvalidValueException ie) { 1333 trace.error(ie.getMessage()); 1334 throw new HeroException(ie.getMessage()); 1335 } catch (javax.ejb.CreateException ce) { 1336 trace.error(ce.getMessage()); 1337 throw new HeroException(ce.getMessage()); 1338 } 1339 1340 } 1341 } catch (javax.naming.NamingException ne) { 1342 trace.error(ne.getMessage()); 1343 throw new HeroException(ne.getMessage()); 1344 } catch (javax.ejb.FinderException fe) { 1345 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 1346 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 1347 } 1348 } 1349 1350 1358 public void deleteUserProperty(String key) throws HeroException { 1359 trace.info("parameter key=" + key + " start by " + mContext.getCallerPrincipal().getName()); 1360 1361 BnUserPropertyLocalHome pHome; 1362 BnUserPropertyLocal propertyLocal = null; 1363 this.synchronizeUser(); 1364 try { 1365 BnUserLocalHome userhome = hero.interfaces.BnUserUtil.getLocalHome(); 1366 BnUserLocal mUser = userhome.findByName(mContext.getCallerPrincipal().getName()); 1367 try { 1368 pHome = BnUserPropertyUtil.getLocalHome(); 1369 } catch (javax.naming.NamingException ne) { 1370 trace.error(ne.getMessage()); 1371 throw new HeroException(ne.getMessage()); 1372 } 1373 Collection c = null; 1374 try { 1375 c = pHome.findByTheKey(mUser.getId(), key); 1376 } catch (FinderException fe) { 1377 trace.error(fe.getMessage()); 1378 throw new HeroException(fe.getMessage()); 1379 } 1380 1381 if (!c.isEmpty()) { 1382 try { 1383 propertyLocal = (BnUserPropertyLocal) (c.toArray())[0]; 1384 propertyLocal.remove(); 1385 } catch (RemoveException rm) { 1386 trace.error(rm.getMessage()); 1387 throw new HeroException(rm.getMessage()); 1388 } 1389 } else { 1390 throw new HeroException("Property not found :" + key); 1391 } 1392 1393 } catch (javax.naming.NamingException ne) { 1394 trace.error(ne.getMessage()); 1395 throw new HeroException(ne.getMessage()); 1396 } catch (javax.ejb.FinderException fe) { 1397 trace.error(mContext.getCallerPrincipal().getName() + " does not exists " + fe.getMessage()); 1398 throw new HeroException(mContext.getCallerPrincipal().getName() + " does not exists"); 1399 } 1400 } 1401 1402 private void deleteInstances(Collection instances) throws HeroException{ 1403 Iterator inst = instances.iterator(); 1404 JMSServicesSessionLocal jms; 1405 this.synchronizeUser(); 1406 try{ 1407 JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome(); 1408 jms=home.create(); 1409 }catch(Exception e){ 1410 trace.error(e.getMessage()); 1411 throw new EngineException(e.getMessage()); 1412 } 1413 try{ 1414 while (inst.hasNext()) 1415 { 1416 BnProjectLocal ins = (BnProjectLocal)inst.next(); 1417 if (ins.getName().matches(".*_instance.*")) 1418 { 1419 ins.remove(); 1420 jms.sendProjectEvent(DELETEPROJECT, ins.getName()); 1421 } 1422 } 1423 } catch (RemoveException re) { 1424 trace.error("Error in delete instance " + re.getMessage()); 1425 throw new HeroException("Error in delete project"); 1426 } 1427 } 1428 1429 private void deleteSubProcesses(String projectName) throws HeroException{ 1430 BnProjectLocalHome pHome; 1431 JMSServicesSessionLocal jms; 1432 this.synchronizeUser(); 1433 try{ 1434 JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome(); 1435 jms=home.create(); 1436 }catch(Exception e){ 1437 if (this.getProjectConfigTrace(projectName)) 1438 trace.error(e.getMessage()); 1439 throw new EngineException(e.getMessage()); 1440 } 1441 try { 1442 pHome = hero.interfaces.BnProjectUtil.getLocalHome(); 1443 } catch (javax.naming.NamingException be) { 1444 if (this.getProjectConfigTrace(projectName)) 1445 trace.error(be.getMessage()); 1446 throw new HeroException(be.getMessage()); 1447 } 1448 try { 1449 BnProjectLocal pl = pHome.findByName(projectName); 1450 String userName = mContext.getCallerPrincipal().getName(); 1451 Collection nodes = pl.getBnNodes(); 1452 Iterator nds = nodes.iterator(); 1453 while (nds.hasNext()) { 1455 BnNodeLocal nd = (BnNodeLocal)nds.next(); 1456 if (nd.getType()==Constants.Nd.SUB_PROCESS_NODE) 1457 this.deleteSubProcesses(nd.getName()); 1458 } 1459 pl.remove(); 1460 jms.sendProjectEvent(DELETEPROJECT, projectName); 1461 } catch (Exception re) { 1462 trace.error("Error in delete subProcess " + re.getMessage()); 1463 throw new HeroException("Error in delete subProcess"); 1464 } 1465 } 1466 1467 private boolean getProjectConfigTrace(String projectName) throws HeroException{ 1468 return (bonitaConfig.getProcessTrace(projectName)); 1469 } 1470 1471 private String getProjectConfigHistoric(String projectName) throws HeroException{ 1472 return (bonitaConfig.getPocessHistoric(projectName)); 1473 } 1474 1475 1483 public void ejbCreate() throws CreateException { 1484 } 1485 1486 private void synchronizeUser() throws HeroException{ 1487 UserServiceLocalHome ushome = null; 1488 try { 1489 ushome = hero.interfaces.UserServiceUtil.getLocalHome(); 1490 UserServiceLocal ul = ushome.create(); 1491 ul.findUserLocal(mContext.getCallerPrincipal().getName()); 1492 } catch (Exception ce) {ce.printStackTrace(); 1493 trace.error("Error in findUserLocal " + ce.getMessage()); 1494 throw new HeroException("Error in findUserLocal: "+ce.getMessage()); 1495 } 1496 } 1497 1498 private boolean isAdmin(String projectName) 1499 throws HeroException { 1500 if (this.getProjectConfigTrace(projectName)) 1501 trace.info("parameters: projectName=" + projectName + "start by " + mContext.getCallerPrincipal().getName()); 1502 this.synchronizeUser(); 1503 try { 1504 ProjectSessionLocalHome projectseshome =ProjectSessionUtil.getLocalHome(); 1505 ProjectSessionLocal project = projectseshome.create(); 1506 project.initProject(projectName); 1507 return(project.isAdminOfProject(projectName)); 1508 1509 } catch (CreateException f) { 1510 if (this.getProjectConfigTrace(projectName)) 1511 trace.error("Project does not exists " + projectName + " " + f.getMessage()); 1512 throw new HeroException("Project does not exists " + projectName); 1513 } catch (javax.naming.NamingException r) { 1514 if (this.getProjectConfigTrace(projectName)) 1515 trace.error("Cannot access to project " + r.getMessage()); 1516 throw new HeroException("Cannot access to project " + r.getMessage()); 1517 } 1518 } 1519 1520 private void deleteProject(String projectName) throws HeroException { 1521 if (this.getProjectConfigTrace(projectName)) 1522 trace.info("parameter: projectName=" + projectName + " start by " + mContext.getCallerPrincipal().getName()); 1523 BnProjectLocalHome pHome; 1524 JMSServicesSessionLocal jms; 1525 this.synchronizeUser(); 1526 try{ 1527 JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome(); 1528 jms=home.create(); 1529 }catch(Exception e){ 1530 if (this.getProjectConfigTrace(projectName)) 1531 trace.error(e.getMessage()); 1532 throw new EngineException(e.getMessage()); 1533 } 1534 try { 1535 pHome = hero.interfaces.BnProjectUtil.getLocalHome(); 1536 } catch (javax.naming.NamingException be) { 1537 if (this.getProjectConfigTrace(projectName)) 1538 trace.error(be.getMessage()); 1539 throw new HeroException(be.getMessage()); 1540 } 1541 try { 1542 BnProjectLocal pl = pHome.findByName(projectName); 1543 String userName = mContext.getCallerPrincipal().getName(); 1544 if (this.isAdmin(projectName)) 1545 { 1546 if (pl.getParent().equals(pl.getName())) 1547 { 1548 Collection ins = new ArrayList (); 1549 if (pl.getModel().getName().equals(pl.getName())) { 1551 ins = this.getProjectInstances(pl.getName()); 1552 Iterator instances = ins.iterator(); 1553 while (instances.hasNext()) 1554 { 1555 BnProjectValue pr = (BnProjectValue)instances.next(); 1556 if (!pr.getName().equals(pl.getName()) && pr.getState() != Constants.Pj.TERMINATED) 1557 throw new HeroException("Error in delete project: This Workflow model has running instances !!"); 1558 } 1559 } 1560 1561 Collection nodes = pl.getBnNodes(); 1562 Iterator nds = nodes.iterator(); 1563 while (nds.hasNext()) { 1565 BnNodeLocal nd = (BnNodeLocal)nds.next(); 1566 if (nd.getType()==Constants.Nd.SUB_PROCESS_NODE) 1567 this.deleteSubProcesses(nd.getName()); 1568 } 1569 1570 if (!ins.isEmpty()) 1571 this.deleteInstances(ins); 1572 pl.remove(); 1573 jms.sendProjectEvent(DELETEPROJECT, projectName); 1574 } 1575 else 1576 throw new HeroException("Error in delete project: You have to delete subProcess activity of this project !!"); 1577 } 1578 else 1579 throw new HeroException("Error in delete project: only admin users are allowed to removed it !!"); 1580 } catch (javax.ejb.FinderException fe) { 1581 if (this.getProjectConfigTrace(projectName)) 1582 trace.error("User does not exist " + fe.getMessage()); 1583 throw new HeroException("User does not exist"); 1584 } catch (RemoveException re) { 1585 if (this.getProjectConfigTrace(projectName)) 1586 trace.error("Error in delete project " + re.getMessage()); 1587 throw new HeroException("Error in delete project"); 1588 } 1589 } 1590 1591 1594 1595 public void setSessionContext(final javax.ejb.SessionContext context) { 1596 mContext = context; 1597 try{ 1598 this.bonitaConfig = new BonitaConfig(); 1599 }catch(Exception e){throw new EJBException (e.getMessage());} 1600 } 1601 1602 1605 public void ejbRemove() { 1606 } 1607 1608 1611 public void ejbActivate() { 1612 } 1613 1614 1617 public void ejbPassivate() { 1618 } 1619 1620} 1621 | Popular Tags |