1 package org.tigris.scarab.tools; 2 3 48 49 import java.text.DateFormat ; 50 import java.util.ArrayList ; 51 import java.util.Arrays ; 52 import java.util.Calendar ; 53 import java.util.Collections ; 54 import java.util.Comparator ; 55 import java.util.HashMap ; 56 import java.util.Hashtable ; 57 import java.util.Iterator ; 58 import java.util.List ; 59 import java.util.Locale ; 60 import java.util.Map ; 61 import java.util.TimeZone ; 62 63 import org.apache.commons.collections.map.LinkedMap; 64 import org.apache.commons.lang.StringUtils; 65 import org.apache.fulcrum.intake.Intake; 66 import org.apache.fulcrum.intake.model.Field; 67 import org.apache.fulcrum.intake.model.Group; 68 import org.apache.fulcrum.localization.Localization; 69 import org.apache.fulcrum.parser.ParameterParser; 70 import org.apache.fulcrum.parser.StringValueParser; 71 import org.apache.fulcrum.pool.Recyclable; 72 import org.apache.torque.TorqueException; 73 import org.apache.torque.om.ComboKey; 74 import org.apache.torque.om.NumberKey; 75 import org.apache.torque.om.SimpleKey; 76 import org.apache.torque.util.Criteria; 77 import org.apache.turbine.RunData; 78 import org.apache.turbine.TemplateContext; 79 import org.apache.turbine.Turbine; 80 import org.apache.turbine.services.pull.ApplicationTool; 81 import org.apache.turbine.tool.IntakeTool; 82 import org.tigris.scarab.attribute.DateAttribute; 83 import org.tigris.scarab.om.Activity; 84 import org.tigris.scarab.om.ActivitySet; 85 import org.tigris.scarab.om.Attachment; 86 import org.tigris.scarab.om.AttachmentManager; 87 import org.tigris.scarab.om.Attribute; 88 import org.tigris.scarab.om.AttributeGroup; 89 import org.tigris.scarab.om.AttributeGroupManager; 90 import org.tigris.scarab.om.AttributeManager; 91 import org.tigris.scarab.om.AttributeOption; 92 import org.tigris.scarab.om.AttributeOptionManager; 93 import org.tigris.scarab.om.AttributeOptionPeer; 94 import org.tigris.scarab.om.AttributePeer; 95 import org.tigris.scarab.om.AttributeValue; 96 import org.tigris.scarab.om.Depend; 97 import org.tigris.scarab.om.DependManager; 98 import org.tigris.scarab.om.FrequencyPeer; 99 import org.tigris.scarab.om.Issue; 100 import org.tigris.scarab.om.IssueManager; 101 import org.tigris.scarab.om.IssueTemplateInfo; 102 import org.tigris.scarab.om.IssueTemplateInfoManager; 103 import org.tigris.scarab.om.IssueTemplateInfoPeer; 104 import org.tigris.scarab.om.IssueType; 105 import org.tigris.scarab.om.IssueTypeManager; 106 import org.tigris.scarab.om.MITList; 107 import org.tigris.scarab.om.MITListManager; 108 import org.tigris.scarab.om.Module; 109 import org.tigris.scarab.om.ModuleManager; 110 import org.tigris.scarab.om.ParentChildAttributeOption; 111 import org.tigris.scarab.om.Query; 112 import org.tigris.scarab.om.QueryManager; 113 import org.tigris.scarab.om.QueryPeer; 114 import org.tigris.scarab.om.RModuleAttribute; 115 import org.tigris.scarab.om.RModuleAttributeManager; 116 import org.tigris.scarab.om.RModuleIssueType; 117 import org.tigris.scarab.om.RModuleIssueTypePeer; 118 import org.tigris.scarab.om.ROptionOption; 119 import org.tigris.scarab.om.ReportManager; 120 import org.tigris.scarab.om.ScarabUser; 121 import org.tigris.scarab.om.ScarabUserImplPeer; 122 import org.tigris.scarab.om.ScarabUserManager; 123 import org.tigris.scarab.om.ScopePeer; 124 import org.tigris.scarab.om.Transition; 125 import org.tigris.scarab.om.TransitionPeer; 126 import org.tigris.scarab.reports.ReportBridge; 127 import org.tigris.scarab.services.cache.ScarabCache; 128 import org.tigris.scarab.tools.localization.L10NKeySet; 129 import org.tigris.scarab.tools.localization.L10NMessage; 130 import org.tigris.scarab.tools.localization.Localizable; 131 import org.tigris.scarab.util.AnonymousUserUtil; 132 import org.tigris.scarab.util.IteratorWithSize; 133 import org.tigris.scarab.util.Log; 134 import org.tigris.scarab.util.ScarabConstants; 135 import org.tigris.scarab.util.ScarabException; 136 import org.tigris.scarab.util.ScarabLink; 137 import org.tigris.scarab.util.ScarabPaginatedList; 138 import org.tigris.scarab.util.SimpleSkipFiltering; 139 import org.tigris.scarab.util.SnippetRenderer; 140 import org.tigris.scarab.util.SubsetIteratorWithSize; 141 import org.tigris.scarab.util.WindowIterator; 142 import org.tigris.scarab.util.word.ComplexQueryException; 143 import org.tigris.scarab.util.word.IssueSearch; 144 import org.tigris.scarab.util.word.IssueSearchFactory; 145 import org.tigris.scarab.util.word.MaxConcurrentSearchException; 146 import org.tigris.scarab.util.word.QueryResult; 147 import org.tigris.scarab.util.word.SearchIndex; 148 149 152 public class ScarabRequestTool 153 implements ApplicationTool,Recyclable 154 { 155 private static final String TIME_ZONE = 156 Turbine.getConfiguration().getString("scarab.timezone", ""); 157 158 161 private boolean disposed; 162 163 164 private RunData data; 165 166 169 private ScarabUser user = null; 170 171 174 private Issue issue = null; 175 176 179 private Object alert = null; 180 181 184 private Attribute attribute = null; 185 186 189 private Attachment attachment = null; 190 191 194 private Depend depend = null; 195 196 199 private Query query = null; 200 201 204 private IssueTemplateInfo templateInfo = null; 205 206 209 private IssueType issueType = null; 210 211 214 private AttributeGroup group = null; 215 216 219 private Issue reportingIssue = null; 220 221 224 private Module module = null; 225 226 229 private AttributeOption attributeOption = null; 230 231 234 private ROptionOption roo = null; 235 236 239 private ParentChildAttributeOption pcao = null; 240 241 244 private IssueSearch issueSearch = null; 245 246 249 private List issueList; 250 251 254 int initialIssueListColumnsSize = 0; 255 256 260 List issueListColumns = null; 261 262 265 private ReportBridge reportGenerator = null; 266 267 private int nbrPages = 0; 268 private int prevPage = 0; 269 private int nextPage = 0; 270 private String cachedNextIssueId; 271 private String cachedPrevIssueId; 272 273 274 private Object confirmMessage; 275 private Object infoMessage; 276 private Object alertMessage; 277 278 279 private final TimeZone timezone; 280 281 Map attributeTypes = new HashMap (); 282 283 286 public ScarabRequestTool() 287 { 288 recycle(); 289 timezone = TIME_ZONE == null ? null : TimeZone.getTimeZone(TIME_ZONE); 290 } 291 292 295 public void init(Object data) 296 { 297 this.data = (RunData)data; 298 299 } 300 301 304 public void refresh() 305 { 306 user = null; 307 issue = null; 308 attribute = null; 309 attachment = null; 310 depend = null; 311 query = null; 312 templateInfo = null; 313 issueType = null; 314 group = null; 315 reportingIssue = null; 316 module = null; 317 attributeOption = null; 318 roo = null; 319 pcao = null; 320 attributeTypes = new HashMap (); 321 if (issueSearch != null) 322 { 323 Log.get().debug("IssueSearch object is disposed of properly."); 325 issueSearch.close(); 326 IssueSearchFactory.INSTANCE.notifyDone(); 327 issueSearch = null; 328 } 329 issueList = null; 330 issueListColumns = null; 331 initialIssueListColumnsSize = 0; 332 reportGenerator = null; 333 nbrPages = 0; 334 prevPage = 0; 335 nextPage = 0; 336 confirmMessage = null; 337 infoMessage = null; 338 alertMessage = null; 339 cachedPrevIssueId = null; 340 cachedNextIssueId = null; 341 } 342 343 348 public void setAlert(Object message) 349 { 350 this.alert = message; 351 } 352 353 358 public Object getAlert() 359 { 360 return alert; 361 } 362 363 366 public void setAttachment(Attachment attachment) 367 { 368 this.attachment = attachment; 369 } 370 371 374 public void setAttribute (Attribute attribute) 375 { 376 this.attribute = attribute; 377 } 378 379 382 public void setDepend (Depend depend) 383 { 384 this.depend = depend; 385 } 386 387 390 public void setQuery (Query query) 391 { 392 this.query = query; 393 } 394 395 398 private IntakeTool getIntakeTool() 399 { 400 return (IntakeTool)org.apache.turbine.modules.Module.getTemplateContext(data) 401 .get(ScarabConstants.INTAKE_TOOL); 402 } 403 404 409 public ROptionOption getROptionOption() 410 { 411 if (roo == null) 412 { 413 roo = ROptionOption.getInstance(); 414 } 415 return roo; 416 } 417 418 421 public void setROptionOption(ROptionOption roo) 422 { 423 this.roo = roo; 424 } 425 426 427 430 public void setIssueTemplateInfo (IssueTemplateInfo templateInfo) 431 { 432 this.templateInfo = templateInfo; 433 } 434 435 438 public void setIssueType (IssueType issuetype) 439 { 440 this.issueType = issuetype; 441 } 442 443 444 449 public ParentChildAttributeOption getParentChildAttributeOption() 450 { 451 if (pcao == null) 452 { 453 pcao = ParentChildAttributeOption.getInstance(); 454 } 455 return pcao; 456 } 457 458 461 public void setParentChildAttributeOption(ParentChildAttributeOption roo) 462 { 463 this.pcao = roo; 464 } 465 466 469 public void setAttributeOption (AttributeOption option) 470 { 471 this.attributeOption = option; 472 } 473 474 477 public AttributeOption getAttributeOption() 478 throws Exception 479 { 480 if (attributeOption == null) 481 { 482 String optId = getIntakeTool() 483 .get("AttributeOption", IntakeTool.DEFAULT_KEY) 484 .get("OptionId").toString(); 485 if (optId == null || optId.length() == 0) 486 { 487 attributeOption = AttributeOption.getInstance(); 488 } 489 else 490 { 491 attributeOption = AttributeOptionManager 492 .getInstance(new Integer (optId)); 493 } 494 } 495 return attributeOption; 496 } 497 498 502 public void setUser(ScarabUser user) 503 { 504 this.user = user; 505 } 506 507 518 public ScarabUser getUser() 519 { 520 return this.user; 521 } 522 523 529 public ScarabUser getUser(Object id) 530 throws Exception 531 { 532 if (id == null) 533 { 534 return null; 535 } 536 ScarabUser su = null; 537 try 538 { 539 Integer pk = null; 540 if (id instanceof Integer ) 541 { 542 pk = (Integer ) id; 543 } 544 else 545 { 546 pk = new Integer (id.toString()); 547 } 548 su = ScarabUserManager.getInstance(pk); 549 } 550 catch (Exception e) 551 { 552 Log.get().debug("User with user id "+ id +" could not be found,", e); 555 } 556 return su; 557 } 558 559 562 public ScarabUser getUserByUserName(String username) 563 throws Exception 564 { 565 ScarabUser su = null; 566 try 567 { 568 su = ScarabUserManager 569 .getInstance(username, getCurrentModule().getScarabInstanceId()); 570 } 571 catch (Exception e) 572 { 573 Log.get().debug("User, "+username+" could not be found,", e); 576 } 577 return su; 578 } 579 580 584 public Attribute getAttribute() 585 throws Exception 586 { 587 try 588 { 589 if (attribute == null) 590 { 591 String attId = getIntakeTool() 592 .get("Attribute", IntakeTool.DEFAULT_KEY) 593 .get("Id").toString(); 594 if (attId == null || attId.length() == 0) 595 { 596 attId = data.getParameters().getString("attId"); 597 if (attId == null || attId.length() == 0) 598 { 599 attribute = AttributeManager.getInstance(); 600 } 601 else 602 { 603 attribute = AttributeManager.getInstance(new Integer (attId)); 604 } 605 } 606 else 607 { 608 attribute = AttributeManager.getInstance(new Integer (attId)); 609 } 610 } 611 } 612 catch (Exception e) 613 { 614 e.printStackTrace(); 615 } 616 return attribute; 617 } 618 619 622 public Attribute getAttribute(Integer pk) 623 throws Exception 624 { 625 Attribute attr = null; 626 try 627 { 628 attr = AttributeManager.getInstance(pk); 629 } 630 catch (Exception e) 631 { 632 e.printStackTrace(); 633 } 634 this.attribute = attr; 635 return attr; 636 } 637 638 641 public AttributeOption getAttributeOption(Integer pk) 642 throws Exception 643 { 644 try 645 { 646 attributeOption = AttributeOptionManager.getInstance(pk); 647 } 648 catch(Exception e) 649 { 650 e.printStackTrace(); 651 } 652 return attributeOption; 653 } 654 655 public AttributeOption getAttributeOption(String key) 656 throws Exception 657 { 658 return getAttributeOption(new Integer (key)); 659 } 660 661 666 public List getRModuleUserAttributes() 667 { 668 ScarabUser user = (ScarabUser)data.getUser(); 669 670 if(issueListColumns == null){ 671 ScarabLocalizationTool l10n = getLocalizationTool(); 672 ScarabToolManager toolManager = new ScarabToolManager(l10n); 673 issueListColumns= toolManager.getRModuleUserAttributes(user, module, issueType); 674 if (issueListColumns != null) 675 initialIssueListColumnsSize = issueListColumns.size(); 676 } 677 678 if (initialIssueListColumnsSize > issueListColumns.size()) 680 { 681 TemplateContext context = 682 (TemplateContext) data.getTemp(Turbine.CONTEXT); 683 context.put("columnLimitExceeded", Boolean.TRUE); 684 } 685 return issueListColumns; 686 } 687 688 689 public List getValidIssueListAttributes() 690 { 691 ScarabUser user = (ScarabUser)data.getUser(); 692 List result = null; 693 try 694 { 695 MITList currentList = user.getCurrentMITList(); 696 if (currentList != null) 697 { 698 result = currentList.getCommonAttributes(false); 699 } 700 } 701 catch (Exception e) 702 { 703 Log.get().error("Could not get list attributes", e); 704 } 705 if (result == null) 706 { 707 result = Collections.EMPTY_LIST; 708 } 709 return result; 710 } 711 712 715 public Query getQuery() 716 throws Exception 717 { 718 try 719 { 720 if (query == null) 721 { 722 String queryId = data.getParameters() 723 .getString("queryId"); 724 if (queryId == null || queryId.length() == 0) 725 { 726 query = Query.getInstance(); 727 } 728 else 729 { 730 query = QueryManager 731 .getInstance(new NumberKey(queryId), false); 732 } 733 } 734 } 735 catch (Exception e) 736 { 737 e.printStackTrace(); 738 } 739 return query; 740 } 741 742 745 public IssueTemplateInfo getIssueTemplateInfo() 746 throws Exception 747 { 748 try 749 { 750 if (templateInfo == null) 751 { 752 String templateId = data.getParameters() 753 .getString("templateId"); 754 755 if (templateId == null || templateId.length() == 0) 756 { 757 templateInfo = IssueTemplateInfo.getInstance(); 758 } 759 else 760 { 761 templateInfo = IssueTemplateInfoManager 762 .getInstance(new NumberKey(templateId), false); 763 } 764 } 765 } 766 catch (Exception e) 767 { 768 e.printStackTrace(); 769 } 770 return templateInfo; 771 } 772 773 776 public Issue getIssueTemplate() 777 throws Exception 778 { 779 Issue template = null; 780 String templateId = data.getParameters() 781 .getString("templateId"); 782 try 783 { 784 if (templateId == null || templateId.length() == 0) 785 { 786 template = getCurrentModule().getNewIssue(getIssueType( 787 getCurrentIssueType().getTemplateId().toString())); 788 } 789 else 790 { 791 template = IssueManager 792 .getInstance(new NumberKey(templateId), false); 793 } 794 } 795 catch (Exception e) 796 { 797 e.printStackTrace(); 798 } 799 return template; 800 } 801 802 805 public Issue getIssueTemplate(String templateId) 806 throws Exception 807 { 808 Issue template = null; 809 try 810 { 811 if (templateId == null || templateId.length() == 0) 812 { 813 setAlertMessage(L10NKeySet.NoTemplateId); 814 } 815 else 816 { 817 template = IssueManager 818 .getInstance(new NumberKey(templateId), false); 819 } 820 } 821 catch (Exception e) 822 { 823 e.printStackTrace(); 824 } 825 return template; 826 } 827 828 831 public Depend getDepend() 832 throws Exception 833 { 834 try 835 { 836 if (depend == null) 837 { 838 String dependId = getIntakeTool() 839 .get("Depend", IntakeTool.DEFAULT_KEY).get("Id").toString(); 840 if (dependId == null || dependId.length() == 0) 841 { 842 depend = DependManager.getInstance(); 843 } 844 else 845 { 846 depend = DependManager 847 .getInstance(new NumberKey(dependId), false); 848 } 849 } 850 } 851 catch (Exception e) 852 { 853 e.printStackTrace(); 854 } 855 return depend; 856 } 857 858 861 public String getActivityReason(ActivitySet activitySet, Activity activity) 862 throws Exception 863 { 864 ScarabLocalizationTool l10n = getLocalizationTool(); 865 ScarabToolManager toolManager = new ScarabToolManager(l10n); 866 return toolManager.getActivityReason(activitySet,activity); 867 868 } 869 870 871 874 public Attachment getAttachment() 875 throws Exception 876 { 877 try 878 { 879 if (attachment == null) 880 { 881 Group att = getIntakeTool() 882 .get("Attachment", IntakeTool.DEFAULT_KEY, false); 883 if (att != null) 884 { 885 String attId = att.get("Id").toString(); 886 if (attId == null || attId.length() == 0) 887 { 888 attachment = new Attachment(); 889 } 890 else 891 { 892 attachment = AttachmentManager 893 .getInstance(new NumberKey(attId), false); 894 } 895 } 896 else 897 { 898 attachment = new Attachment(); 899 } 900 } 901 } 902 catch(Exception e) 903 { 904 e.printStackTrace(); throw e; } 906 return attachment; 907 } 908 909 912 public AttributeGroup getAttributeGroup() 913 throws Exception 914 { 915 AttributeGroup group = null; 916 try 917 { 918 String attGroupId = getIntakeTool() 919 .get("AttributeGroup", IntakeTool.DEFAULT_KEY) 920 .get("AttributeGroupId").toString(); 921 if (attGroupId == null || attGroupId.length() == 0) 922 { 923 group = new AttributeGroup(); 924 } 925 else 926 { 927 group = AttributeGroupManager 928 .getInstance(new NumberKey(attGroupId), false); 929 } 930 } 931 catch(Exception e) 932 { 933 e.printStackTrace(); 934 } 935 return group; 936 937 } 938 941 public AttributeGroup getAttributeGroup(String key) 942 { 943 AttributeGroup group = null; 944 try 945 { 946 group = AttributeGroupManager 947 .getInstance(new NumberKey(key), false); 948 } 949 catch (Exception e) 950 { 951 e.printStackTrace(); 952 } 953 return group; 954 } 955 956 963 public IssueType getIssueType(String key) 964 { 965 IssueType issueType = null; 966 try 967 { 968 issueType = IssueTypeManager 969 .getInstance(new NumberKey(key), false); 970 } 971 catch (Exception e) 972 { 973 } 975 return issueType; 976 } 977 978 981 public IssueType getIssueType() 982 throws Exception 983 { 984 if (issueType == null) 985 { 986 String key = data.getParameters() 987 .getString("issuetypeid"); 988 if (key == null) 989 { 990 issueType = new IssueType(); 992 } 993 else 994 { 995 try 996 { 997 issueType = IssueTypeManager 998 .getInstance(new NumberKey(key), false); 999 } 1000 catch (Exception e) 1001 { 1002 issueType = new IssueType(); 1003 } 1004 } 1005 } 1006 return issueType; 1007 } 1008 1009 1010 1013 public AttributeValue getNewAttributeValue(Attribute attribute, Issue issue) 1014 throws Exception 1015 { 1016 1017 return AttributeValue.getNewInstance(attribute.getAttributeId(),issue); 1018 } 1019 1020 1025 public RModuleAttribute getRModuleAttribute() 1026 throws Exception 1027 { 1028 RModuleAttribute rma = null; 1029try 1030{ 1031 ComboKey rModAttId = (ComboKey)getIntakeTool() 1032 .get("RModuleAttribute", IntakeTool.DEFAULT_KEY) 1033 .get("Id").getValue(); 1034 if (rModAttId == null) 1035 { 1036 Integer attId = (Integer )getIntakeTool() 1037 .get("Attribute", IntakeTool.DEFAULT_KEY) 1038 .get("Id").getValue(); 1039 Module currentModule = getCurrentModule(); 1040 if (attId != null && currentModule != null) 1041 { 1042 SimpleKey[] nka = { 1043 SimpleKey.keyFor(attId), 1044 SimpleKey.keyFor(currentModule.getModuleId()) 1045 }; 1046 rma = RModuleAttributeManager 1047 .getInstance(new ComboKey(nka), false); 1048 } 1049 else 1050 { 1051 rma = new RModuleAttribute(); 1052 } 1053 } 1054 else 1055 { 1056 rma = RModuleAttributeManager.getInstance(rModAttId, false); 1057 } 1058} 1059catch(Exception e) 1060{ 1061e.printStackTrace(); 1062} 1063 return rma; 1064 } 1065 1066 1069 public void setAttributeGroup(AttributeGroup group) 1070 { 1071 this.group = group; 1072 } 1073 1074 1077 public void setModule(Module module) 1078 { 1079 this.module = module; 1080 } 1081 1082 1087 public Module getModule() 1088 throws Exception 1089 { 1090try 1091{ 1092 String modId = getIntakeTool() 1093 .get("Module", IntakeTool.DEFAULT_KEY).get("Id").toString(); 1094 if (modId == null || modId.length() == 0) 1095 { 1096 module = ModuleManager.getInstance(); 1097 } 1098 else 1099 { 1100 module = ModuleManager.getInstance(new Integer (modId)); 1101 } 1102} 1103catch(Exception e) 1104{ 1105e.printStackTrace(); 1106} 1107 return module; 1108 } 1109 1110 1117 public Module getModule(String key) 1118 { 1119 Module me = null; 1120 if (key != null && key.length() > 0) 1121 { 1122 try 1123 { 1124 me = ModuleManager.getInstance(new Integer (key)); 1125 } 1126 catch (Exception e) 1127 { 1128 Log.get().info("[ScarabRequestTool] Unable to retrieve Module: " + 1129 key, e); 1130 } 1131 } 1132 return me; 1133 } 1134 1135 1140 public Module getCurrentModule() 1141 { 1142 ScarabUser user = (ScarabUser)data.getUser(); 1143 Module currentModule = null; 1144 if (user != null) 1145 { 1146 currentModule = user.getCurrentModule(); 1147 } 1148 1149 return currentModule; 1150 } 1151 1152 1156 public IssueType getCurrentIssueType() throws Exception 1157 { 1158 ScarabUser user = (ScarabUser)data.getUser(); 1159 IssueType curit = user.getCurrentIssueType(); 1160 if (curit == null) 1161 { 1162 curit = IssueTypeManager.getInstance(data.getParameters(). 1163 getInteger(ScarabConstants.CURRENT_ISSUE_TYPE)); 1164 } 1165 return curit; 1166 } 1167 1168 public void setCurrentIssueType(IssueType type) 1169 { 1170 ScarabUser user = (ScarabUser)data.getUser(); 1171 if (user != null) 1172 { 1173 user.setCurrentIssueType(type); 1174 } 1175 } 1176 1177 1182 public String getNextEntryTemplate(IssueType issueType) 1183 { 1184 RModuleIssueType rmit = null; 1185 String nextTemplate = null; 1186 try 1187 { 1188 Module module = getCurrentModule(); 1189 if (module == null) 1190 { 1191 nextTemplate = ((ScarabUser)data.getUser()).getHomePage(); 1192 setAlertMessage(L10NKeySet.ModuleIssueTypeRequiredToEnterIssue); 1193 } 1194 else 1195 { 1196 rmit = module.getRModuleIssueType(issueType); 1197 if (rmit == null) 1198 { 1199 nextTemplate = ((ScarabUser)data.getUser()).getHomePage(); 1200 setAlertMessage(L10NKeySet.ModuleIssueTypeRequiredToEnterIssue); 1201 } 1202 else if (rmit.getDedupe() && !module 1203 .getDedupeGroupsWithAttributes(issueType).isEmpty()) 1204 { 1205 nextTemplate = "entry,Wizard1.vm"; 1206 } 1207 else 1208 { 1209 nextTemplate = "entry,Wizard3.vm"; 1210 } 1211 } 1212 } 1213 catch (Exception e) 1214 { 1215 nextTemplate = "Index.vm"; 1217 setAlertMessage(L10NKeySet.CannotDetermineIssueEntryTemplate); 1218 Log.get().error("CannotDetermineIssueEntryTemplate", e); 1219 } 1220 return nextTemplate; 1221 } 1222 1223 1226 public String getCurrentTemplate() 1227 { 1228 return data.getTarget().replace('/',','); 1229 } 1230 1231 1236 public Issue getReportingIssue() 1237 throws Exception 1238 { 1239 if (reportingIssue == null) 1240 { 1241 String key = data.getParameters() 1242 .getString(ScarabConstants.REPORTING_ISSUE); 1243 1244 if (key == null) 1245 { 1246 getNewReportingIssue(); 1247 } 1248 else 1249 { 1250 reportingIssue = ((ScarabUser)data.getUser()) 1251 .getReportingIssue(key); 1252 1253 if (reportingIssue == null) 1256 { 1257 getNewReportingIssue(); 1258 } 1259 } 1260 } 1261 return reportingIssue; 1262 } 1263 1264 private void getNewReportingIssue() 1265 throws Exception 1266 { 1267 reportingIssue = getCurrentModule().getNewIssue(getCurrentIssueType()); 1268 String key = ((ScarabUser)data.getUser()) 1269 .setReportingIssue(reportingIssue); 1270 data.getParameters().add(ScarabConstants.REPORTING_ISSUE, key); 1271 } 1272 1273 public void setReportingIssue(Issue issue) 1274 { 1275 reportingIssue = issue; 1276 } 1277 1278 1281 public void setCurrentModule(Module me) 1282 { 1283 ScarabUser user = (ScarabUser)data.getUser(); 1284 if (user != null) 1285 { 1286 user.setCurrentModule(me); 1287 } 1288 } 1289 1290 1293 public void setIssue(Issue issue) 1294 { 1295 this.issue = issue; 1296 } 1297 1298 1304 public Issue getIssue() 1305 throws Exception 1306 { 1307 if (issue == null) 1308 { 1309 String issueId = null; 1310 Group issueGroup = getIntakeTool() 1311 .get("Issue", IntakeTool.DEFAULT_KEY, false); 1312 if (issueGroup != null) 1313 { 1314 issueId = issueGroup.get("Id").toString(); 1315 } 1316 else 1317 { 1318 issueId = data.getParameters().getString("id"); 1319 } 1320 if (issueId != null && issueId.length() > 0) 1321 { 1322 issue = getIssue(issueId); 1323 } 1324 } 1325 return issue; 1326 } 1327 1328 1332 public Issue getIssue(String id) 1333 { 1334 Issue issue = null; 1335 if (id == null || id.length() == 0) 1336 { 1337 setInfoMessage(L10NKeySet.EnterId); 1338 } 1339 else 1340 { 1341 try 1342 { 1343 issue = IssueManager 1344 .getIssueById(id, getCurrentModule().getCode()); 1345 if (issue == null) 1346 { 1347 setAlertMessage(L10NKeySet.InvalidId); 1348 } 1349 else if (issue.getDeleted()) 1350 { 1351 setAlertMessage(L10NKeySet.ViewIssueIssueMoved); 1352 issue = null; 1353 } 1354 } 1355 catch (Exception e) 1356 { 1357 setAlertMessage(L10NKeySet.InvalidId); 1358 } 1359 } 1360 return issue; 1361 } 1362 1363 1369 public Issue getIssueByPk(String key) 1370 { 1371 Issue issue = null; 1372 try 1373 { 1374 issue = IssueManager.getInstance(new Long (key)); 1375 } 1376 catch (Exception e) 1377 { 1378 setAlertMessage(L10NKeySet.InvalidIssueId); 1379 } 1380 return issue; 1381 } 1382 1383 1388 public List getIssues() 1389 throws Exception 1390 { 1391 List issues = null; 1392 1393 Group issueGroup = getIntakeTool() 1394 .get("Issue", IntakeTool.DEFAULT_KEY, false); 1395 if (issueGroup != null) 1396 { 1397 Long [] issueIds = (Long []) issueGroup.get("Ids").getValue(); 1398 if (issueIds != null) 1399 { 1400 issues = getIssues(Arrays.asList(issueIds)); 1401 } 1402 } 1403 else 1404 { 1405 String [] paramIssueIds = data.getParameters().getStrings("issue_ids"); 1406 if (paramIssueIds != null) 1407 { 1408 issues = getIssues(Arrays.asList(paramIssueIds)); 1409 } 1410 } 1411 if (issues == null) 1412 { 1413 issues = Collections.EMPTY_LIST; 1414 } 1415 return issues; 1416 } 1417 1418 1427 public List getIssues(List issueIds) 1428 throws Exception 1429 { 1430 List issues = null; 1431 StringBuffer invalidIds = null; 1432 if (issueIds == null || issueIds.isEmpty()) 1433 { 1434 issues = Collections.EMPTY_LIST; 1435 } 1436 else 1437 { 1438 if (issueIds.get(0) instanceof String ) 1439 { 1440 issues = new ArrayList (issueIds.size()); 1441 Iterator i = issueIds.iterator(); 1442 while (i.hasNext()) 1443 { 1444 String id = (String )i.next(); 1445 Issue issue = getIssue(id); 1446 if (issue == null) 1447 { 1448 if (invalidIds == null) 1449 { 1450 invalidIds = new StringBuffer (id); 1451 } 1452 else 1453 { 1454 invalidIds.append(' ').append(id); 1455 } 1456 } 1457 else 1458 { 1459 issues.add(issue); 1460 } 1461 } 1462 if (invalidIds != null) 1463 { 1464 setAlertMessage(getLocalizationTool() 1465 .format("SomeIssueIdsNotValid", invalidIds.toString())); 1466 } 1467 } 1468 else if (issueIds.get(0) instanceof Long ) 1469 { 1470 issues = new ArrayList (issueIds.size()); 1471 Iterator i = issueIds.iterator(); 1472 while (i.hasNext()) 1473 { 1474 Issue issue = IssueManager.getInstance((Long )i.next()); 1475 if (issue == null) 1476 { 1477 setAlertMessage(L10NKeySet.SomeIssuePKsNotValid); 1478 } 1479 else 1480 { 1481 issues.add(issue); 1482 } 1483 } 1484 } 1485 else 1486 { 1487 throw new IllegalArgumentException ( 1488 "issue ids must be Strings or Longs, not " + 1489 issueIds.get(0).getClass().getName()); } 1491 } 1492 return issues; 1493 } 1494 1495 1496 1499 public List getScopes() 1500 throws Exception 1501 { 1502 return ScopePeer.getAllScopes(); 1503 } 1504 1505 1508 public List getFrequencies() 1509 throws Exception 1510 { 1511 return FrequencyPeer.getFrequencies(); 1512 } 1513 1514 1517 public String getExecuteLink(String link, Query query) 1518 { 1519 link = link 1521 + "?action=Search&eventSubmit_doSearch=Search" 1522 + "&pagenum=1" + query.getValue(); 1523 1524 Long listId = query.getListId(); 1525 if (listId != null) 1526 { 1527 link += '&' + ScarabConstants.CURRENT_MITLIST_ID + '=' + listId; 1528 } 1529 else 1530 { 1531 link += '&' + ScarabConstants.REMOVE_CURRENT_MITLIST_QKEY + "=true"; 1532 } 1533 return link; 1534 } 1535 1536 1539 public String getEditLink(String link, Query query) 1540 { 1541 link = link + "?queryId=" + query.getQueryId() 1543 + "&refine=true" 1544 + "&action=Search&eventSubmit_doPreparequery=foo" 1545 + query.getValue(); 1546 1547 Long listId = query.getListId(); 1548 if (listId != null) 1549 { 1550 link += '&' + ScarabConstants.CURRENT_MITLIST_ID + '=' + listId; 1551 } 1552 else 1553 { 1554 link += '&' + ScarabConstants.REMOVE_CURRENT_MITLIST_QKEY + "=true"; 1555 } 1556 return link; 1557 } 1558 1559 public Intake getConditionalIntake(String parameter) 1560 throws Exception 1561 { 1562 Intake intake = null; 1563 String param = data.getParameters().getString(parameter); 1564 if (param == null) 1565 { 1566 intake = getIntakeTool(); 1567 } 1568 else 1569 { 1570 intake = new Intake(); 1571 StringValueParser parser = new StringValueParser(); 1572 parser.parse(param, '&', '=', true); 1573 intake.init(parser); 1574 } 1575 1576 return intake; 1577 } 1578 1579 1584 public IssueSearch getNewSearch() 1585 throws Exception , MaxConcurrentSearchException 1586 { 1587 if (issueSearch == null) 1588 { 1589 ScarabUser user = (ScarabUser)data.getUser(); 1590 MITList mitList = user.getCurrentMITList(); 1591 if (mitList == null) 1592 { 1593 setAlertMessage(L10NKeySet.NoIssueTypeList); 1594 Log.get().warn("Attempted to create a new IssueSearch and " + 1595 " issue types had not been selected."); 1596 } 1597 else 1598 { 1599 issueSearch = 1600 IssueSearchFactory.INSTANCE.getInstance(mitList, user); 1601 issueSearch.setLocale(getLocalizationTool().getPrimaryLocale()); 1602 } 1603 } 1604 return issueSearch; 1605 } 1606 1607 1612 public IssueSearch getPopulatedSearch(String query) 1613 throws Exception 1614 { 1615 IssueSearch search = getNewSearch(); 1616 if (null == search) 1617 return null; 1618 1619 ScarabLocalizationTool l10n = getLocalizationTool(); 1620 search.setIssueListAttributeColumns(getRModuleUserAttributes()); 1621 search.setLocalizationTool(getLocalizationTool()); 1622 search.setQuery(query); 1623 1624 Intake intake = null; 1625 1626 if (query == null) 1627 { 1628 setInfoMessage(L10NKeySet.EnterQuery); 1629 return null; 1630 } 1631 else 1632 { 1633 intake = parseQuery(query); 1634 1635 if (!intake.isAllValid()) 1636 { 1637 return null; 1638 } 1639 } 1640 1641 StringValueParser parser = new StringValueParser(); 1643 parser.parse(query, '&', '=', true); 1644 String [] userList = parser.getStrings("user_list"); 1645 if (userList != null && userList.length > 0) 1646 { 1647 for (int i = 0; i < userList.length; i++) 1648 { 1649 String userId = userList[i]; 1650 String [] attrIds = parser.getStrings("user_attr_" + userId); 1651 if (attrIds != null) 1652 { 1653 for (int j = 0; j < attrIds.length; j++) 1654 { 1655 search.addUserCriteria(userId, attrIds[j]); 1656 } 1657 } 1658 } 1659 } 1660 1661 boolean searchSuccess = true; 1663 Group searchGroup = intake.get("SearchIssue", 1664 search.getQueryKey()); 1665 1666 Field minDate = searchGroup.get("MinDate"); 1667 if (minDate != null && minDate.toString().length() > 0) 1668 { 1669 searchSuccess = checkDate(search, minDate.toString()); 1670 } 1671 1672 Field maxDate = searchGroup.get("MaxDate"); 1673 if (maxDate != null && maxDate.toString().length() > 0) 1674 { 1675 searchSuccess = checkDate(search, maxDate.toString()); 1676 } 1677 1678 Field stateChangeFromDate = searchGroup.get("StateChangeFromDate"); 1679 if (stateChangeFromDate != null 1680 && stateChangeFromDate.toString().length() > 0) 1681 { 1682 searchSuccess = checkDate(search, stateChangeFromDate.toString()); 1683 } 1684 1685 Field stateChangeToDate = searchGroup.get("StateChangeToDate"); 1686 if (stateChangeToDate != null 1687 && stateChangeToDate.toString().length() > 0) 1688 { 1689 searchSuccess = checkDate(search, stateChangeToDate.toString()); 1690 } 1691 1692 if (!searchSuccess) 1693 { 1694 setAlertMessage(l10n.format("DateFormatPrompt", 1695 L10NKeySet.ShortDateDisplay)); 1696 return null; 1697 } 1698 1699 try 1700 { 1701 searchGroup.setProperties(search); 1702 } 1703 catch (Exception e) 1704 { 1705 setAlertMessage(l10n.getMessage(e)); 1706 return null; 1707 } 1708 1709 Integer oldOptionId = search.getStateChangeFromOptionId(); 1710 if (oldOptionId != null && oldOptionId.intValue() != 0 1711 && oldOptionId.equals(search.getStateChangeToOptionId())) 1712 { 1713 setAlertMessage(L10NKeySet.StateChangeOldEqualNew); 1714 return null; 1715 } 1716 1717 LinkedMap avMap = search.getCommonAttributeValuesMap(); 1719 Iterator i = avMap.mapIterator(); 1720 while (i.hasNext()) 1721 { 1722 AttributeValue aval = (AttributeValue)avMap.get(i.next()); 1723 Group group = intake.get("AttributeValue", aval.getQueryKey()); 1724 if (group != null) 1725 { 1726 group.setProperties(aval); 1727 } 1728 } 1729 1730 String sortColumn = data.getParameters().getString("sortColumn"); 1734 if (sortColumn != null && sortColumn.length() > 0 1735 && StringUtils.isNumeric(sortColumn)) 1736 { 1737 search.setSortAttributeId(new Integer (sortColumn)); 1738 } 1739 1740 String sortPolarity = data.getParameters().getString("sortPolarity"); 1741 if (sortPolarity != null && sortPolarity.length() > 0) 1742 { 1743 search.setSortPolarity(sortPolarity); 1744 } 1745 1746 return search; 1747 } 1748 1749 1754 public IssueSearch getPopulatedSearch() 1755 throws Exception 1756 { 1757 String currentQueryString = ((ScarabUser)data.getUser()).getMostRecentQuery(); 1758 return getPopulatedSearch(currentQueryString); 1759 } 1760 1761 1764 public Intake parseQuery(String query) 1765 throws Exception 1766 { 1767 Intake intake = new Intake(); 1768 StringValueParser parser = new StringValueParser(); 1769 parser.parse(query, '&', '=', true); 1770 1771 intake.init(parser); 1772 return intake; 1773 } 1774 1775 1778 public IteratorWithSize getCurrentSearchResults() 1779 { 1780 return getCurrentSearchResults(false); 1781 } 1782 1783 1786 public IteratorWithSize getCurrentSearchResults(boolean mergePartialQueryResults) 1787 { 1788 IteratorWithSize matchingIssueIds = null; 1789 try 1790 { 1791 matchingIssueIds = getUnprotectedCurrentSearchResults(mergePartialQueryResults); 1792 } 1793 catch (MaxConcurrentSearchException e) 1794 { 1795 setAlertMessage(L10NKeySet.ResourceLimitationsPreventedSearch); 1796 } 1797 catch (ComplexQueryException e) 1798 { 1799 matchingIssueIds = IteratorWithSize.EMPTY; 1800 setAlertMessage(new SimpleSkipFiltering(getLocalizationTool() 1801 .format("SearchAbortedDueToComplexity", 1802 new SnippetRenderer(data, "ComplexQueryHelpLink.vm")))); 1803 } 1804 catch (Exception e) 1805 { 1806 matchingIssueIds = IteratorWithSize.EMPTY; 1807 L10NMessage l10nMessage = new L10NMessage(L10NKeySet.ErrorProcessingQuery,e); 1808 setAlertMessage(l10nMessage); 1809 Log.get().info("Error processing a query", e); 1810 } 1811 1812 return matchingIssueIds; 1813 } 1814 1815 1819 private IteratorWithSize getUnprotectedCurrentSearchResults(boolean mergePartialQueryResults) 1820 throws Exception 1821 { 1822 String queryString = ((ScarabUser)data.getUser()).getMostRecentQuery(); 1830 IteratorWithSize results = null; 1831 Object obj = 1832 ScarabCache.get(queryString, "getUnprotectedCurrentSearchResults"); 1833 if (obj == null) 1834 { 1835 results = getUncachedCurrentSearchResults(mergePartialQueryResults); 1836 ScarabCache.put(results, queryString, 1837 "getUnprotectedCurrentSearchResults"); 1838 } 1839 else 1840 { 1841 results = (IteratorWithSize)obj; 1842 } 1843 return results; 1844 } 1845 1846 1849 private IteratorWithSize getUncachedCurrentSearchResults(boolean mergePartialQueryResults) 1850 throws Exception 1851 { 1852 ScarabLocalizationTool l10n = getLocalizationTool(); 1853 ScarabUser user = (ScarabUser)data.getUser(); 1854 String currentQueryString = user.getMostRecentQuery(); 1855 IssueSearch search = getPopulatedSearch(currentQueryString); 1856 IteratorWithSize queryResults = null; 1857 1858 try 1860 { 1861 if (search == null) 1862 { 1863 queryResults = IteratorWithSize.EMPTY; 1866 } 1867 else 1868 { 1869 queryResults = search.getQueryResults(mergePartialQueryResults); 1870 if (!queryResults.hasNext()) 1871 { 1872 setInfoMessage(L10NKeySet.NoMatchingIssues); 1873 } 1874 } 1875 } 1876 catch (ScarabException e) 1877 { 1878 String queryError = e.getMessage(); 1879 if (queryError.startsWith(SearchIndex.PARSE_ERROR)) 1880 { 1881 Log.get().info(queryError); 1882 setAlertMessage(new SimpleSkipFiltering( 1883 l10n.format("QueryParserError", 1884 new SnippetRenderer(data, "TextQueryHelp.vm")))); 1885 } 1886 else 1887 { 1888 throw e; } 1890 } 1891 return queryResults; 1892 } 1893 1894 1898 public int getCurrentSearchResultsSize() 1899 { 1900 String [] prevNextList = data.getParameters().getStrings("issueList"); 1901 int result = 0; 1902 if (prevNextList == null) 1903 { 1904 result = getCurrentSearchResults().size(); 1905 } 1906 else 1907 { 1908 result = Integer.parseInt(prevNextList[1]); 1909 } 1910 return result; 1911 } 1912 1913 1916 public int getIssuePosInList() 1917 throws Exception , ScarabException 1918 { 1919 int issuePos = -1; 1920 String id = getIssue().getUniqueId(); 1921 String [] prevNextList = data.getParameters().getStrings("issueList"); 1922 if (prevNextList != null) 1923 { 1924 int listOffset = Math.max(0, Integer.parseInt(prevNextList[0])); 1925 for (int i=2; i<prevNextList.length; i++) 1926 { 1927 if (prevNextList[i].equals(id)) 1928 { 1929 issuePos = listOffset + i - 1; 1930 break; 1931 } 1932 } 1933 } 1934 1935 return (issuePos <= 0) ? 1 : issuePos; 1936 } 1937 1938 1941 public String getNextIssue() 1942 throws Exception , ScarabException 1943 { 1944 String nextIssueId = null; 1945 String [] prevNextList = data.getParameters().getStrings("issueList"); 1946 if (prevNextList != null) 1947 { 1948 String id = getIssue().getUniqueId(); 1949 for (int i=2; i<prevNextList.length-1; i++) 1950 { 1951 if (prevNextList[i].equals(id)) 1952 { 1953 nextIssueId = prevNextList[i+1]; 1954 break; 1955 } 1956 } 1957 } 1958 1959 if (nextIssueId == null) 1960 { 1961 if (cachedNextIssueId == null) 1962 { 1963 int issuePos = getIssuePosInList(); 1964 if (issuePos <= getCurrentSearchResultsSize()) 1965 { 1966 resetIssueIdList(issuePos); 1967 nextIssueId = cachedNextIssueId; 1968 } 1969 } 1970 else 1971 { 1972 nextIssueId = cachedNextIssueId; 1973 } 1974 } 1975 return nextIssueId; 1976 } 1977 1978 1981 public String getPrevIssue() 1982 throws Exception , ScarabException 1983 { 1984 String prevIssueId = null; 1985 String [] prevNextList = data.getParameters().getStrings("issueList"); 1986 if (prevNextList != null) 1987 { 1988 String id = getIssue().getUniqueId(); 1989 for (int i=3; i<prevNextList.length; i++) 1990 { 1991 if (prevNextList[i].equals(id)) 1992 { 1993 prevIssueId = prevNextList[i-1]; 1994 break; 1995 } 1996 } 1997 } 1998 1999 if (prevIssueId == null) 2000 { 2001 if (cachedPrevIssueId == null) 2002 { 2003 int issuePos = getIssuePosInList(); 2004 if (issuePos > 1) 2005 { 2006 resetIssueIdList(issuePos); 2007 prevIssueId = cachedPrevIssueId; 2008 } 2009 } 2010 else 2011 { 2012 prevIssueId = cachedPrevIssueId; 2013 } 2014 } 2015 return prevIssueId; 2016 } 2017 2018 private void resetIssueIdList(int issuePos) 2019 { 2020 IteratorWithSize idList = getCurrentSearchResults(); 2021 ParameterParser pp = data.getParameters(); 2022 pp.remove("issueList"); 2023 int min = issuePos - 5; 2024 int max = issuePos + 10; 2025 pp.add("issueList", min); 2026 pp.add("issueList", idList.size()); 2027 2028 int count; 2029 for (count = 0; idList.hasNext() && count < min; count++) 2030 { 2031 idList.next(); 2032 } 2033 for (; idList.hasNext() && count < issuePos - 2; count++) 2034 { 2035 pp.add("issueList", 2036 ((QueryResult) idList.next()).getUniqueId()); 2037 } 2038 if (idList.hasNext()) 2039 { 2040 cachedPrevIssueId = ((QueryResult)idList.next()) 2041 .getUniqueId(); 2042 pp.add("issueList", cachedPrevIssueId); 2043 } 2044 if (idList.hasNext()) 2045 { 2046 pp.add("issueList", 2047 ((QueryResult) idList.next()).getUniqueId()); 2048 } 2049 if (idList.hasNext()) 2050 { 2051 cachedNextIssueId = ((QueryResult)idList.next()) 2052 .getUniqueId(); 2053 pp.add("issueList", cachedNextIssueId); 2054 } 2055 for (count += 3; idList.hasNext() && count < max; count++) 2056 { 2057 pp.add("issueList", 2058 ((QueryResult) idList.next()).getUniqueId()); 2059 } 2060 } 2061 2062 2065 private boolean checkDate(IssueSearch search, String date) 2066 throws Exception 2067 { 2068 boolean success = true; 2069 try 2070 { 2071 search.parseDate(date, false); 2072 } 2073 catch (Exception e) 2074 { 2075 success = false; 2076 } 2077 return success; 2078 } 2079 2080 2081 2084 public String convertPath(String path) 2085 throws Exception 2086 { 2087 return path.replace('/',','); 2088 } 2089 2090 2094 public List getAllIssueTemplates(IssueType issueType) 2095 throws Exception 2096 { 2097 ParameterParser params = data.getParameters(); 2098 String sortColumn = params.getString("sortColumn", "name"); 2099 String sortPolarity = params.getString("sortPolarity", "asc"); 2100 return IssueTemplateInfoPeer.getTemplates(getCurrentModule(), 2101 issueType, (ScarabUser)data.getUser(), 2102 sortColumn, sortPolarity, IssueTemplateInfoPeer.TYPE_ALL); 2103 } 2104 2105 2108 public List getPrivateTemplates(IssueType issueType) 2109 throws Exception 2110 { 2111 return IssueTemplateInfoPeer.getTemplates(getCurrentModule(), 2112 issueType, (ScarabUser)data.getUser(), 2113 "name", "asc", IssueTemplateInfoPeer.TYPE_PRIVATE); 2114 } 2115 2116 2119 public List getGlobalTemplates(IssueType issueType) 2120 throws Exception 2121 { 2122 return IssueTemplateInfoPeer.getTemplates(getCurrentModule(), 2123 issueType, (ScarabUser)data.getUser(), 2124 "name", "asc", IssueTemplateInfoPeer.TYPE_GLOBAL); 2125 } 2126 2127 2131 public List getAllQueries() 2132 throws Exception 2133 { 2134 String sortColumn = data.getParameters().getString("sortColumn"); 2135 String sortPolarity = data.getParameters().getString("sortPolarity"); 2136 if (sortColumn == null) 2137 { 2138 sortColumn = "avail"; 2139 } 2140 if (sortPolarity == null) 2141 { 2142 sortPolarity = "desc"; 2143 } 2144 return QueryPeer.getQueries(getCurrentModule(), 2145 null, (ScarabUser)data.getUser(), 2146 sortColumn, sortPolarity, IssueTemplateInfoPeer.TYPE_ALL); 2147 } 2148 2149 2152 public List getPrivateQueries() 2153 throws Exception 2154 { 2155 return QueryPeer.getQueries(getCurrentModule(), 2156 null, (ScarabUser)data.getUser(), 2157 "name", "asc", QueryPeer.TYPE_PRIVATE); 2158 } 2159 2160 2163 public List getUserQueries() 2164 throws Exception 2165 { 2166 return QueryPeer.getQueries(getCurrentModule(), 2167 null, (ScarabUser)data.getUser(), 2168 "name", "asc", QueryPeer.TYPE_ALL_USER); 2169 } 2170 2171 2174 public List getGlobalQueries() 2175 throws Exception 2176 { 2177 return QueryPeer.getQueries(getCurrentModule(), 2178 null, (ScarabUser)data.getUser(), 2179 "name", "asc", QueryPeer.TYPE_GLOBAL); 2180 } 2181 2182 2185 public List getUserAllQueries() 2186 throws Exception 2187 { 2188 return QueryPeer.getQueries(getCurrentModule(), 2189 null, (ScarabUser)data.getUser(), 2190 "name", "asc", QueryPeer.TYPE_ALL_USER); 2191 } 2192 2193 2196 public ReportBridge getReport() 2197 throws Exception 2198 { 2199 if (reportGenerator == null) 2200 { 2201 String key = data.getParameters() 2202 .getString(ScarabConstants.CURRENT_REPORT); 2203 ParameterParser parameters = data.getParameters(); 2204 String id = parameters.getString("report_id"); 2205 if (id == null || id.length() == 0) 2206 { 2207 ScarabUser user = (ScarabUser)data.getUser(); 2208 MITList mitlist = user.getCurrentMITList(); 2209 if (key == null) 2210 { 2211 reportGenerator = getNewReport(mitlist); 2212 } 2213 else 2214 { 2215 reportGenerator = user.getCurrentReport(key); 2216 2217 if (reportGenerator == null && 2220 mitlist != null && !mitlist.isEmpty()) 2221 { 2222 reportGenerator = getNewReport(mitlist); 2223 } 2224 } 2225 } 2226 else 2227 { 2228 reportGenerator = new ReportBridge( 2229 ReportManager.getInstance(new NumberKey(id), false)); 2230 key = ((ScarabUser)data.getUser()) 2231 .setCurrentReport(reportGenerator); 2232 data.getParameters() 2233 .remove(ScarabConstants.CURRENT_REPORT); 2234 data.getParameters() 2235 .add(ScarabConstants.CURRENT_REPORT, key); 2236 } 2237 } 2238 2239 return reportGenerator; 2240 } 2241 2242 private ReportBridge getNewReport(MITList mitList) 2243 throws Exception 2244 { 2245 if (mitList == null) 2246 { 2247 throw new IllegalArgumentException ( 2248 "Cannot create a new report without any issue types."); } 2250 2251 ScarabUser user = (ScarabUser)data.getUser(); 2252 org.tigris.scarab.om.Report om = new org.tigris.scarab.om.Report(); 2253 ReportBridge report = new ReportBridge(om); 2254 report.setGeneratedBy(user); 2255 report.setMITList(mitList); 2256 2257 String key = ((ScarabUser)data.getUser()).setCurrentReport(report); 2258 data.getParameters().add(ScarabConstants.CURRENT_REPORT, key); 2259 2260 return report; 2261 } 2262 2263 public void setReport(ReportBridge report) 2264 { 2265 this.reportGenerator = report; 2266 } 2267 2268 2272 public ScarabPaginatedList getUserSearchResults(MITList mitList, 2273 int pageNum, 2274 int resultsPerPage, 2275 String sortColumn, 2276 String sortPolarity, 2277 boolean includeCommitters) 2278 throws Exception 2279 { 2280 return userFilteredSearchResults(mitList, pageNum, resultsPerPage, 2281 sortColumn, sortPolarity, "", "", 2282 includeCommitters); 2283 } 2284 2285 2289 public ScarabPaginatedList getUserFilteredSearchResults(MITList mitList, 2290 int pageNum, int resultsPerPage, String sortColumn, 2291 String sortPolarity, boolean includeCommitters) 2292 throws Exception 2293 { 2294 String searchString = data.getParameters() 2295 .getString("searchString"); 2296 String searchField = data.getParameters() 2297 .getString("searchField"); 2298 2299 if (searchField == null) 2300 { 2301 setInfoMessage(L10NKeySet.SearchFieldPrompt); 2302 return null ; 2303 } 2304 2305 return userFilteredSearchResults(mitList, pageNum, resultsPerPage, 2306 sortColumn, sortPolarity, 2307 searchString, searchField, includeCommitters); 2308 2309 } 2310 2311 private ScarabPaginatedList userFilteredSearchResults(MITList mitList, 2312 int pageNum, 2313 int resultsPerPage, 2314 String sortColumn, 2315 String sortPolarity, 2316 String searchString, 2317 String searchField, 2318 boolean includeCommitters) 2319 throws Exception 2320 { 2321 ScarabPaginatedList list = null; 2322 String name = null; 2323 String userName = null; 2324 2325 if ("FullName".equalsIgnoreCase(searchField)) 2326 { 2327 name = searchString; 2328 } 2329 else if ("UserName".equalsIgnoreCase(searchField)) 2330 { 2331 userName = searchString; 2332 } 2333 2334 try 2335 { 2336 list = getCurrentModule().getUsers(name, userName, mitList, 2337 pageNum, resultsPerPage, 2338 sortColumn, sortPolarity, 2339 includeCommitters); 2340 } 2341 catch (Exception e) 2342 { 2343 Log.get().error("Problem getting user list", e); 2344 list = new ScarabPaginatedList(); 2345 } 2346 2347 this.nbrPages = list.getNumberOfPages(); 2351 this.nextPage = list.getNextPageNumber(); 2352 this.prevPage = list.getPrevPageNumber(); 2353 2354 return list; 2355 } 2356 2357 2358 2361 public List getAttributeSearchResults() throws Exception 2362 { 2363 String searchString = data.getParameters() 2364 .getString("searchString"); 2365 String searchField = data.getParameters() 2366 .getString("searchField"); 2367 if (searchField == null) 2368 { 2369 setInfoMessage(L10NKeySet.SearchFieldPrompt); 2370 return null ; 2371 } 2372 2373 String name = null; 2374 String description = null; 2375 if (searchField.equals("Name") || searchField.equals("Any")) 2376 { 2377 name = searchString; 2378 } 2379 if (searchField.equals("Description") || searchField.equals("Any")) 2380 { 2381 description = searchString; 2382 } 2383 2384 return sortAttributes(AttributePeer 2385 .getFilteredAttributes(name, description, searchField)); 2386 } 2387 2388 2391 public List sortUsers(List userList) throws Exception 2392 { 2393 final String sortColumn = data.getParameters().getString("sortColumn"); 2394 final String sortPolarity = data.getParameters().getString("sortPolarity"); 2395 final int polarity = ("desc".equals(sortPolarity)) ? -1 : 1; 2396 Comparator c = new Comparator () 2397 { 2398 public int compare(Object o1, Object o2) 2399 { 2400 int i = 0; 2401 if ("username".equals(sortColumn)) 2402 { 2403 i = polarity * ((ScarabUser)o1).getUserName() 2404 .compareTo(((ScarabUser)o2).getUserName()); 2405 } 2406 else 2407 { 2408 i = polarity * ((ScarabUser)o1).getName() 2409 .compareTo(((ScarabUser)o2).getName()); 2410 } 2411 return i; 2412 } 2413 }; 2414 Collections.sort(userList, c); 2415 return userList; 2416 } 2417 2418 2419 2422 public List sortAttributes(List attList) throws Exception 2423 { 2424 final String sortColumn = data.getParameters().getString("sortColumn"); 2425 final String sortPolarity = data.getParameters().getString("sortPolarity"); 2426 final int polarity = ("desc".equals(sortPolarity)) ? -1 : 1; 2427 Comparator c = new Comparator () 2428 { 2429 public int compare(Object o1, Object o2) 2430 { 2431 int i = 0; 2432 if (sortColumn != null && sortColumn.equals("name")) 2433 { 2434 i = polarity * ((Attribute)o1).getName() 2435 .compareTo(((Attribute)o2).getName()); 2436 } 2437 else 2438 { 2439 i = polarity * ((Attribute)o1).getDescription() 2440 .compareTo(((Attribute)o2).getDescription()); 2441 } 2442 return i; 2443 } 2444 }; 2445 Collections.sort(attList, c); 2446 return attList; 2447 } 2448 2449 2454 public List getPaginatedList(List fullList, int pgNbr, int nbrItmsPerPage) 2455 { 2456 List pageResults = null; 2457 try 2458 { 2459 if (nbrItmsPerPage < 0) 2460 { 2461 pageResults = fullList; 2462 } 2463 else 2464 { 2465 this.nbrPages = (int)Math.ceil((float)fullList.size() 2466 / nbrItmsPerPage); 2467 this.nextPage = pgNbr + 1; 2468 this.prevPage = pgNbr - 1; 2469 pageResults = fullList.subList ((pgNbr - 1) * nbrItmsPerPage, 2470 Math.min(pgNbr * nbrItmsPerPage, fullList.size())); 2471 } 2472 } 2473 catch(Exception e) 2474 { 2475 Log.get().error("", e); 2476 } 2477 return pageResults; 2478 } 2479 2480 2485 public IteratorWithSize getPaginatedIterator(IteratorWithSize fullList, 2486 int pgNbr, 2487 int nbrItmsPerPage) 2488 { 2489 IteratorWithSize pageResults; 2490 try 2491 { 2492 if (nbrItmsPerPage < 0) 2493 { 2494 pageResults = fullList; 2495 } 2496 else 2497 { 2498 this.nbrPages = (int)Math.ceil((float)fullList.size() 2499 / nbrItmsPerPage); 2500 this.nextPage = pgNbr + 1; 2501 this.prevPage = pgNbr - 1; 2502 pageResults = new SubsetIteratorWithSize( 2503 fullList, (pgNbr - 1) * nbrItmsPerPage, nbrItmsPerPage); 2504 } 2505 } 2506 catch(Exception e) 2507 { 2508 Log.get().error("", e); 2509 pageResults = IteratorWithSize.EMPTY; 2510 } 2511 return pageResults; 2512 } 2513 2514 2515 2516 2520 public void setIssueList(List v) 2521 { 2522 this.issueList = v; 2523 } 2524 2525 2534 public int getAdjustedPageNum() 2535 { 2536 ParameterParser parameters = data.getParameters(); 2537 int resultsPerPage = parameters.getInt("resultsPerPage", 0); 2538 int oldResultsPerPage = parameters.getInt("oldResultsPerPage", 0); 2539 int pageNum = parameters.getInt("pageNum", 1); 2540 2545 if (oldResultsPerPage != 0 && oldResultsPerPage != resultsPerPage) 2547 { 2548 pageNum = 1; 2549 } 2550 return pageNum; 2551 } 2552 2553 2554 2558 public int getNbrPages() 2559 { 2560 return nbrPages; 2561 } 2562 2563 2567 public int getNextPage() 2568 { 2569 if (nextPage <= nbrPages) 2570 { 2571 return nextPage; 2572 } 2573 else 2574 { 2575 return 0; 2576 } 2577 } 2578 2579 2583 public int getPrevPage() 2584 { 2585 return prevPage; 2586 } 2587 2588 2592 public DateFormat getDateFormat() 2593 { 2594 Locale locale = Localization.getLocale(data.getRequest()); 2595 DateFormat df = DateFormat 2596 .getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG, locale); 2597 if (timezone != null) 2598 { 2599 df.setTimeZone(timezone); 2600 } 2601 return df; 2602 2603 } 2609 2610 2614 public Calendar getCalendar() 2615 { 2616 Locale locale = Localization.getLocale(data.getRequest()); 2617 Calendar cal = Calendar 2618 .getInstance(locale); 2619 if (timezone != null) 2620 { 2621 cal.setTimeZone(timezone); 2622 } 2623 return cal; 2624 } 2625 2626 2636 public boolean hasPermission(String permission) 2637 { 2638 boolean hasPermission = false; 2639 try 2640 { 2641 Module module = getCurrentModule(); 2642 hasPermission = hasPermission(permission, module); 2643 } 2644 catch (Exception e) 2645 { 2646 hasPermission = false; 2647 Log.get().error("Permission check failed on:" + permission, e); 2648 } 2649 return hasPermission; 2650 } 2651 2652 2662 public boolean hasPermission(String permission, Module module) 2663 { 2664 boolean hasPermission = false; 2665 try 2666 { 2667 hasPermission = ((ScarabUser)data.getUser()) 2668 .hasPermission(permission, module); 2669 } 2670 catch (Exception e) 2671 { 2672 hasPermission = false; 2673 Log.get().error("Permission check failed on:" + permission, e); 2674 } 2675 return hasPermission; 2676 } 2677 2678 2682 public void resetAssociatedUsers() throws Exception 2683 { 2684 HashMap assoUsers = new HashMap (); 2685 List issueList = getIssues(); 2686 if (issueList != null) 2687 { 2688 for (int i=0; i<issueList.size(); i++) 2689 { 2690 Issue issue = (Issue)issueList.get(i); 2691 assoUsers.put(issue.getIssueId(), issue.getAssociatedUsers()); 2692 } 2693 ((ScarabUser)data.getUser()).setAssociatedUsersMap(assoUsers); 2694 } 2695 } 2696 public void resetSelectedUsers() throws Exception 2697 { 2698 ScarabUser user = (ScarabUser)data.getUser(); 2699 user.setSelectedUsersMap(null); 2700 } 2701 2702 public List getAssignIssuesList() 2703 throws Exception 2704 { 2705 List issues = null; 2706 Map userMap = ((ScarabUser)data.getUser()).getAssociatedUsersMap(); 2707 if (userMap != null && userMap.size() > 0) 2708 { 2709 issues = new ArrayList (); 2710 Iterator iter = userMap.keySet().iterator(); 2711 while (iter.hasNext()) 2712 { 2713 issues.add(IssueManager.getInstance((Long )iter.next())); 2714 } 2715 } 2716 return issues; 2717 } 2718 2719 2730 public List getGlobalUserSearch() 2731 { 2732 List users = (List ) data.getUser().getTemp("userList"); 2733 if (users == null) 2734 { 2735 users = new ArrayList (); 2736 } 2737 return users; 2738 } 2739 2740 public ScarabPaginatedList getPaginatedGlobalUsersList(int pageNum, int resultsPerPage, 2741 String searchField, String searchCriteria, String sortColumn, String sortPolarity) 2742 throws Exception 2743 { 2744 ScarabPaginatedList paginated; 2745 Criteria crit = new Criteria(); 2746 Criteria critCount = new Criteria(); 2747 crit.setOffset((pageNum-1)*resultsPerPage); 2748 crit.setLimit(resultsPerPage); 2749 crit.add(ScarabUserImplPeer.USER_ID, (Object )(ScarabUserImplPeer.USER_ID+" IS NOT NULL"), Criteria.CUSTOM); 2750 2751 if (searchField.equals("LOGIN_NAME")) 2752 searchField = ScarabUserImplPeer.LOGIN_NAME; 2753 else if (searchField.equals("LAST_NAME")) 2754 searchField = ScarabUserImplPeer.LAST_NAME; 2755 else if (searchField.equals("FIRST_NAME")) 2756 searchField = ScarabUserImplPeer.FIRST_NAME; 2757 else if (searchField.equals("EMAIL")) 2758 searchField = ScarabUserImplPeer.EMAIL; 2759 crit.add(searchField, (Object )("%" + searchCriteria + "%"), Criteria.LIKE); 2760 critCount.add(searchField, (Object )("%" + searchCriteria + "%"), Criteria.LIKE); 2761 2762 String col = ScarabUserImplPeer.FIRST_NAME; 2763 if (sortColumn.equals("LOGIN_NAME")) 2764 col = ScarabUserImplPeer.LOGIN_NAME; 2765 else if (sortColumn.equals("LAST_NAME")) 2766 col = ScarabUserImplPeer.LAST_NAME; 2767 else if (sortColumn.equals("FIRST_NAME")) 2768 col = ScarabUserImplPeer.FIRST_NAME; 2769 else if (sortColumn.equals("EMAIL")) 2770 col = ScarabUserImplPeer.EMAIL; 2771 if (sortPolarity.equalsIgnoreCase("asc")) 2772 { 2773 crit.addAscendingOrderByColumn(col); 2774 } 2775 else 2776 { 2777 crit.addDescendingOrderByColumn(col); 2778 } 2779 2780 2781 critCount.add(ScarabUserImplPeer.USER_ID, (Object )(ScarabUserImplPeer.USER_ID+" IS NOT NULL"), Criteria.CUSTOM); 2782 List result = ScarabUserImplPeer.doSelect(crit); 2783 critCount.addSelectColumn("COUNT(*)"); 2784 int totalResultSize = ScarabUserImplPeer.getUsersCount(critCount); 2785 if (totalResultSize > 0 && resultsPerPage > 0) 2786 { 2787 2788 paginated = new ScarabPaginatedList(result, totalResultSize, 2789 pageNum, 2790 resultsPerPage); 2791 } 2792 else 2793 { 2794 paginated = new ScarabPaginatedList(); 2795 } 2796 2797 return paginated; 2798 } 2799 2800 2808 public void setGlobalUserSearch(List users) 2809 { 2810 data.getUser().setTemp("userList", users); 2811 } 2812 2813 2824 public String getGlobalUserSearchParam(String name) 2825 { 2826 Hashtable params = (Hashtable ) data.getUser().getTemp("userListParams"); 2827 2828 if (params == null) 2829 { 2830 return ""; 2831 } 2832 2833 return (String ) params.get(name); 2834 } 2835 2836 2846 public void setGlobalUserSearchParam(String name, String value) 2847 { 2848 Hashtable params = (Hashtable ) data.getUser().getTemp("userListParams"); 2849 if (params == null) 2850 { 2851 params = new Hashtable (); 2852 } 2853 2854 if ((name != null) && (value != null)) 2855 { 2856 params.put(name, value); 2857 } 2858 data.getUser().setTemp("userListParams", params); 2859 } 2860 2861 public boolean hasItemsToApprove() 2862 { 2863 try 2864 { 2865 SecurityAdminTool sat = (SecurityAdminTool)org.apache.turbine.modules.Module.getTemplateContext(data) 2866 .get(ScarabConstants.SECURITY_ADMIN_TOOL); 2867 if (getCurrentModule().getUnapprovedQueries().isEmpty() && 2868 getCurrentModule().getUnapprovedTemplates().isEmpty() && 2869 sat.getPendingGroupUserRoles(getCurrentModule()).isEmpty()) 2870 { 2871 return false; 2872 } 2873 } 2874 catch (Exception e) 2875 { 2876 Log.get().debug("Error: ", e); 2877 } 2878 return true; 2879 } 2880 2881 public MITList getMITList(List issues) 2882 throws Exception 2883 { 2884 return MITListManager 2885 .getInstanceFromIssueList(issues, (ScarabUser)data.getUser()); 2886 } 2887 2888 2896 public List getUserAttributes(List issues, boolean activeOnly) 2897 throws Exception 2898 { 2899 List attributes = null; 2900 if (issues == null || issues.isEmpty()) 2901 { 2902 attributes = Collections.EMPTY_LIST; 2903 Log.get().warn("ScarabRequestTool.getUserAttributes issue list was" 2904 + (issues == null ? " null" : " empty")) ; 2905 } 2906 else 2907 { 2908 attributes = getMITList(issues).getCommonUserAttributes(activeOnly); 2909 } 2910 2911 return attributes; 2912 } 2913 2914 2915 private long startTime; 2918 private long lapTime; 2919 2920 2924 public void startTimer() 2925 { 2926 startTime = System.currentTimeMillis(); 2927 lapTime = startTime; 2928 } 2929 2930 2947 public String reportTimer(String mesg) 2948 { 2949 long endTime = System.currentTimeMillis(); 2950 String s = mesg + ". Time for " + data.getTarget() + ": Lap/Split= " 2951 + (endTime-lapTime) + "ms; Cumulative= " + 2952 (endTime-startTime) + "ms"; 2953 lapTime = endTime; 2954 return s; 2955 } 2956 2957 2960 private ScarabLocalizationTool getLocalizationTool() 2961 { 2962 return (ScarabLocalizationTool)org.apache.turbine.modules.Module 2963 .getTemplateContext(data).get(ScarabConstants.LOCALIZATION_TOOL); 2964 } 2965 2966 2969 private ScarabGlobalTool getGlobalTool() 2970 { 2971 return (ScarabGlobalTool)org.apache.turbine.modules.Module 2972 .getTemplateContext(data).get(ScarabConstants.SCARAB_GLOBAL_TOOL); 2973 } 2974 2975 2979 public Object getConfirmMessage() 2980 { 2981 return confirmMessage; 2982 } 2983 2984 2989 public void setConfirmMessage(Object v) 2990 { 2991 this.confirmMessage = v; 2992 } 2993 2994 2998 public void setConfirmMessage(Localizable localizable) 2999 { 3000 ScarabLocalizationTool l10n = getLocalizationTool(); 3001 this.confirmMessage = new SimpleSkipFiltering(localizable.getMessage(l10n)); 3002 } 3003 3004 3008 public Object getInfoMessage() 3009 { 3010 return infoMessage; 3011 } 3012 3013 3018 public void setInfoMessage(Object v) 3019 { 3020 this.infoMessage = v; 3021 } 3022 3023 3027 public void setInfoMessage(Localizable localizable) 3028 { 3029 ScarabLocalizationTool l10n = getLocalizationTool(); 3030 this.infoMessage = new SimpleSkipFiltering(localizable.getMessage(l10n)); 3031 } 3032 3033 3037 public Object getAlertMessage() 3038 { 3039 return alertMessage; 3040 } 3041 3042 3047 public void setAlertMessage(Object v) 3048 { 3049 this.alertMessage = v; 3050 } 3051 3052 3056 public void setAlertMessage(Localizable localizable) 3057 { 3058 ScarabLocalizationTool l10n = getLocalizationTool(); 3059 this.alertMessage = new SimpleSkipFiltering(localizable.getMessage(l10n)); 3060 } 3061 3062 public IssueListIterator getIssueListIterator(IteratorWithSize iterator, 3063 int listOffset, int size) 3064 { 3065 return new IssueListIterator(iterator, listOffset, size); 3066 } 3067 3068 public class IssueListIterator implements Iterator 3069 { 3070 private static final String ISSUE_LIST = "issueList"; 3071 private static final int PREV_SIZE = 1; 3072 private static final int NEXT_SIZE = 2; 3073 3074 private WindowIterator i; 3075 private int size; 3076 private int listOffset; 3077 private int count = -1; 3078 3079 private IssueListIterator(IteratorWithSize iterator, 3080 int listOffset, int size) 3081 { 3082 this.listOffset = Math.max(listOffset, 0); 3083 this.size = size; 3084 this.i = new WindowIterator(iterator, PREV_SIZE, NEXT_SIZE); 3085 } 3086 3087 public Object next() 3088 { 3089 count++; 3090 return i.next(); 3091 } 3092 3093 public boolean hasNext() 3094 { 3095 return i.hasNext(); 3096 } 3097 3098 public void remove() 3099 { 3100 i.remove(); 3101 } 3102 3103 public void initializeLink(ScarabLink link) 3104 { 3105 link.setPage("ViewIssue.vm") 3106 .addPathInfo("id", 3107 ((QueryResult)i.get(0)).getUniqueId()); 3108 int offset = listOffset + count; 3109 for (int m = -1 * PREV_SIZE; m < 0; m++) 3110 { 3111 if (i.hasValue(m)) 3112 { 3113 offset--; 3114 } 3115 } 3116 link.addPathInfo(ISSUE_LIST, offset); 3117 link.addPathInfo(ISSUE_LIST, size); 3118 for (int m = -1 * PREV_SIZE; m <= NEXT_SIZE; m++) 3119 { 3120 if (i.hasValue(m)) 3121 { 3122 link.addPathInfo(ISSUE_LIST, 3123 ((QueryResult)i.get(m)).getUniqueId()); 3124 } 3125 } 3126 } 3127 } 3128 3129 3130 3131 3134 public Object getLastEnteredIssueTypeOrTemplate() 3135 throws Exception 3136 { 3137 Object result = null; 3138 IssueType issueType = getCurrentIssueType(); 3139 ScarabUser user = (ScarabUser)data.getUser(); 3140 String templateId = data.getParameters().getString("templateId"); 3141 if (templateId != null && templateId.trim().length() > 0) 3142 { 3143 Issue template = getIssueTemplate(templateId); 3144 issueType = template.getIssueType().getIssueTypeForTemplateType(); 3145 user.setLastEnteredTemplate(template); 3146 result = template; 3147 } 3148 3149 if (result == null && issueType != null) 3150 { 3151 result = issueType; 3152 user.setLastEnteredIssueType(issueType); 3153 } 3154 3155 if (result == null) 3156 { 3157 result = user.lastEnteredIssueTypeOrTemplate(); 3158 if (result != null) 3159 { 3160 if (result instanceof Issue) 3161 { 3162 issueType = ((Issue)result).getIssueType() 3163 .getIssueTypeForTemplateType(); 3164 } 3165 else if (result instanceof IssueType) 3166 { 3167 issueType = (IssueType)result; 3168 } 3169 else 3170 { 3171 Log.get().warn("An object of unexpected class was saved as" 3172 + " the last entered issuetype or template: " + 3173 result.getClass().getName()); 3174 result = null; 3175 } 3176 3177 } 3178 } 3179 3180 if (issueType != null) 3182 { 3183 RModuleIssueType rmit = 3184 getCurrentModule().getRModuleIssueType(issueType); 3185 if (rmit == null || !rmit.getActive()) 3186 { 3187 result = null; 3188 } 3189 } 3190 3191 return result; 3192 } 3193 3194 public List getSortedAttributeOptions() 3195 { 3196 return AttributeOptionPeer.getSortedAttributeOptions(); 3197 } 3198 3199 3206 public List getSortedAttributeOptionsForRMIT(RModuleIssueType rmit) throws Exception 3207 { 3208 List attributes = rmit.getIssueType().getActiveAttributes(rmit.getModule()); 3209 List result = new ArrayList (); 3210 for (Iterator it = attributes.iterator(); it.hasNext(); ) 3211 { 3212 Attribute attr = (Attribute)it.next(); 3213 if (attr.getAttributeType().getAttributeClass().getName().equals("select-one")) 3214 result.addAll(attr.getAttributeOptions()); 3215 } 3216 return result; 3217 } 3218 3222 public boolean isAnonymousLoginAllowed() 3223 { 3224 return AnonymousUserUtil.anonymousAccessAllowed(); 3225 } 3226 3227 public Transition getTransition(Integer pk) 3228 { 3229 Transition tran = null; 3230 try 3231 { 3232 tran = TransitionPeer.retrieveByPK(pk); 3233 } 3234 catch (Exception e) 3235 { 3236 } 3238 return tran; 3239 } 3240 3241 3245 public void recycle() 3246 { 3247 disposed = false; 3248 } 3249 3254 public void dispose() 3255 { 3256 disposed = true; 3257 data = null; 3258 refresh(); 3259 } 3260 3265 public boolean isDisposed() 3266 { 3267 return disposed; 3268 } 3269 3270 3275 public String formatDate(String value) 3276 { 3277 return DateAttribute.dateFormat(value, getLocalizationTool().get(L10NKeySet.ShortDatePattern)); 3278 } 3279 3280 3285 public void setAttributeType(int key, String type) 3286 { 3287 attributeTypes.put(Integer.toString(key), type); 3288 } 3289 3290 3295 public String getAttributeType(int key) 3296 { 3297 return (String )attributeTypes.get(Integer.toString(key)); 3298 } 3299 3300 public RModuleIssueType getRModuleIssueType(Integer moduleId, Integer issueTypeId) throws Exception 3301 { 3302 return RModuleIssueTypePeer.retrieveByPK(moduleId, issueTypeId); 3303 } 3304 3305} 3306 3307 3308 | Popular Tags |