1 19 20 package za.org.coefficient.modules.issueTracker; 21 22 import za.org.coefficient.authentication.CoefficientUser; 23 import za.org.coefficient.authentication.Role; 24 import za.org.coefficient.core.Project; 25 import za.org.coefficient.modules.issueTracker.DiscussionData; 26 27 import java.util.Date ; 28 import java.util.List ; 29 import java.util.Iterator ; 30 import java.util.ArrayList ; 31 32 36 public class SearchFilter implements java.io.Serializable { 37 38 private static final String SQL_1 = "select distinct issues from " 39 + IssueData.class.getName() + " as issues "; 40 private static final String SQL_2 = ", " + DiscussionData.class.getName() 41 + " as comments "; 42 private static final String SQL_3 = " where 1 = 1 and "; 43 private static final String SQL_4 = " issues.project.id = ? " ; 44 45 46 48 private CoefficientUser filterAuthor; 49 private CoefficientUser author; 50 private CoefficientUser assignedTo; 51 private Role authorRole; 52 private Role assignedToRole; 53 private Project project; 54 private String searchText; 55 private boolean summary; 56 private boolean comments; 57 private boolean description; 58 private boolean environment; 59 private List types = new ArrayList (); 60 private List statuses = new ArrayList (); 61 private List resolutions = new ArrayList (); 62 private List priorities = new ArrayList (); 63 private Role sharingLevel; 64 private Date createdAfter; 65 private Date createdBefore; 66 private Long createdInPrevious; 67 private Date updatedAfter; 68 private Date updatedBefore; 69 private Long updatedInPrevious; 70 71 private Long id; 72 private String filterDescription; 73 private String name; 74 private long version; 75 76 78 public SearchFilter() {} 79 80 82 public void setAuthor(CoefficientUser author) { 83 this.author = author; 84 } 85 86 93 public CoefficientUser getAuthor() { 94 return this.author; 95 } 96 97 public void setFilterAuthor(CoefficientUser filterAuthor) { 98 this.filterAuthor = filterAuthor; 99 } 100 101 108 public CoefficientUser getFilterAuthor() { 109 return this.filterAuthor; 110 } 111 112 public void setAssignedTo(CoefficientUser assignedTo) { 113 this.assignedTo = assignedTo; 114 } 115 116 123 public CoefficientUser getAssignedTo() { 124 return this.assignedTo; 125 } 126 127 132 public void setProject(Project project) { 133 this.project = project; 134 } 135 136 143 public Project getProject() { 144 return this.project; 145 } 146 147 152 public void setEnvironment(boolean environment) { 153 this.environment = environment; 154 } 155 156 163 public boolean getEnvironment() { 164 return this.environment; 165 } 166 167 172 public void setSummary(boolean summary) { 173 this.summary = summary; 174 } 175 176 183 public boolean getSummary() { 184 return this.summary; 185 } 186 187 192 public void setComments(boolean comments) { 193 this.comments = comments; 194 } 195 196 203 public boolean getComments() { 204 return this.comments; 205 } 206 207 212 public void setDescription(boolean description) { 213 this.description = description; 214 } 215 216 223 public boolean getDescription() { 224 return this.description; 225 } 226 227 232 public void setId(Long argId) { 233 this.id = argId; 234 } 235 236 243 public Long getId() { 244 return this.id; 245 } 246 247 252 public void setSearchText(String searchText) { 253 if (searchText != null && !searchText.trim().equals("")) { 254 this.searchText = searchText; 255 } 256 } 257 258 265 public String getSearchText() { 266 return this.searchText; 267 } 268 269 274 public void setName(String name) { 275 this.name = name; 276 } 277 278 285 public String getName() { 286 return this.name; 287 } 288 289 294 public void setVersion(long version) { 295 this.version = version; 296 } 297 298 306 public long getVersion() { 307 return this.version; 308 } 309 310 315 public void setTypes(List types) { 316 this.types = types; 317 } 318 319 334 public List getTypes() { 335 return this.types; 336 } 337 338 343 public void setStatuses(List statuses) { 344 this.statuses = statuses; 345 } 346 347 362 public List getStatuses() { 363 return this.statuses; 364 } 365 366 371 public void setPriorities(List priorities) { 372 this.priorities = priorities; 373 } 374 375 390 public List getPriorities() { 391 return this.priorities; 392 } 393 394 399 public void setResolutions(List resolutions) { 400 this.resolutions = resolutions; 401 } 402 403 418 public List getResolutions() { 419 return this.resolutions; 420 } 421 422 427 public void setSharingLevel(Role sharingLevel) { 428 this.sharingLevel = sharingLevel; 429 } 430 431 438 public Role getSharingLevel() { 439 return this.sharingLevel; 440 } 441 442 447 public void setAuthorRole(Role authorRole) { 448 this.authorRole = authorRole; 449 } 450 451 458 public Role getAuthorRole() { 459 return this.authorRole; 460 } 461 462 467 public void setAssignedToRole(Role assignedToRole) { 468 this.assignedToRole = assignedToRole; 469 } 470 471 478 public Role getAssignedToRole() { 479 return this.assignedToRole; 480 } 481 482 public void setFilterDescription(String filterDesc) { 483 this.filterDescription = filterDesc; 484 } 485 486 494 public String getFilterDescription() { 495 return this.filterDescription; 496 } 497 498 503 public void setCreatedAfter(Date argCreatedAfter) { 504 this.createdAfter = argCreatedAfter; 505 } 506 507 514 public Date getCreatedAfter() { 515 return this.createdAfter; 516 } 517 518 523 public void setCreatedBefore(Date argCreatedBefore) { 524 this.createdBefore = argCreatedBefore; 525 } 526 527 534 public Date getCreatedBefore() { 535 return this.createdBefore; 536 } 537 538 543 public void setCreatedInPrevious(Long argCreatedInPrevious) { 544 this.createdInPrevious = argCreatedInPrevious; 545 } 546 547 554 public Long getCreatedInPrevious() { 555 return this.createdInPrevious; 556 } 557 558 563 public void setUpdatedAfter(Date argUpdatedAfter) { 564 this.updatedAfter = argUpdatedAfter; 565 } 566 567 574 public Date getUpdatedAfter() { 575 return this.updatedAfter; 576 } 577 578 583 public void setUpdatedBefore(Date argUpdatedBefore) { 584 this.updatedBefore = argUpdatedBefore; 585 } 586 587 594 public Date getUpdatedBefore() { 595 return this.updatedBefore; 596 } 597 598 603 public void setUpdatedInPrevious(Long argUpdatedInPrevious) { 604 this.updatedInPrevious = argUpdatedInPrevious; 605 } 606 607 614 public Long getUpdatedInPrevious() { 615 return this.updatedInPrevious; 616 } 617 618 619 public String getQuery() { 620 StringBuffer selectFrom = new StringBuffer (); 621 selectFrom.append(SQL_1); 622 StringBuffer where = new StringBuffer (SQL_3); 623 624 if(project != null) { 625 where.append(SQL_4); 626 } 627 if(searchText != null && !searchText.trim().equals("")) { 628 StringBuffer searchTextQuery = new StringBuffer (""); 629 boolean isFirst = true; 630 if(summary || comments || description || environment) { 631 searchTextQuery.append(" and ("); 632 } 633 if(summary) { 634 if(isFirst) { 635 isFirst = false; 636 } 637 searchTextQuery.append(" lower(issues.summary) like ? "); 638 } 639 if(comments) { 640 selectFrom.append(SQL_2); 641 if(isFirst) { 642 isFirst = false; 643 } else { 644 searchTextQuery.append(" or "); 645 } 646 searchTextQuery.append(" (comments in elements (issues.discussion.children) and comments.parent.id = issues.discussion.id and lower(comments.comments) like ?) "); 647 } 648 if(description) { 649 if(isFirst) { 650 isFirst = false; 651 } else { 652 searchTextQuery.append(" or "); 653 } 654 searchTextQuery.append(" lower(issues.discussion.comments) like ? "); 655 } 656 if(environment) { 657 if(isFirst) { 658 isFirst = false; 659 } else { 660 searchTextQuery.append(" or "); 661 } 662 searchTextQuery.append(" lower(issues.environment) like ? "); 663 } 664 if(summary || comments || description || environment) { 665 searchTextQuery.append(" ) "); 666 } 667 where.append(searchTextQuery.toString()); 668 } 669 670 if (author != null) { 671 where.append(" and issues.author.id = ? "); 672 } 673 if (assignedTo != null) { 674 where.append(" and issues.assignedTo.id = ? "); 675 } 676 if (authorRole != null) { 677 where.append(" and issues.author.systemRole.id = ? "); 678 } 679 if (assignedToRole != null) { 680 where.append(" and issues.assignedTo.systemRole.id = ? "); 681 } 682 if (types.size() != 0) { 683 where.append(" and ( "); 684 int i = 0; 685 for (Iterator it = types.iterator(); it.hasNext(); ) { 686 String type = (String )it.next(); 687 if (type != null && !type.trim().equals("")) { 688 if (i != 0) { 689 where.append(" or "); 690 } 691 where.append(" issues.type = ? "); 692 i++; 693 } 694 } 695 where.append(" ) "); 696 } 697 698 if (statuses.size() != 0) { 699 where.append(" and ( "); 700 int i = 0; 701 for (Iterator it = statuses.iterator(); it.hasNext(); ) { 702 String status = (String )it.next(); 703 if (status != null && !status.trim().equals("")) { 704 if (i != 0) { 705 where.append(" or "); 706 } 707 where.append(" issues.status = ? "); 708 i++; 709 } 710 } 711 where.append(" ) "); 712 } 713 714 if (resolutions.size() != 0) { 715 where.append(" and ( "); 716 int i = 0; 717 for (Iterator it = resolutions.iterator(); it.hasNext();) { 718 String resolution = (String )it.next(); 719 if (resolution != null && !resolution.trim().equals("")) { 720 if (i != 0) { 721 where.append(" or "); 722 } 723 where.append(" issues.resolution = ? "); 724 i++; 725 } 726 } 727 where.append(" ) "); 728 } 729 730 if (priorities.size() != 0) { 731 where.append(" and ( "); 732 int i = 0; 733 for (Iterator it = priorities.iterator(); it.hasNext(); ) { 734 String priority = (String )it.next(); 735 if (priority != null && !priority.trim().equals("")) { 736 if (i != 0) { 737 where.append(" or "); 738 } 739 where.append(" issues.priority = ? "); 740 i++; 741 } 742 } 743 where.append(" ) "); 744 } 745 746 if (createdAfter != null) { 748 where.append(" and issues.createDate > ? "); 749 } 750 if (createdBefore != null) { 751 where.append(" and issues.createDate < ? "); 752 } 753 if (createdInPrevious != null) { 754 where.append(" and issues.createDate between ? and ? "); 755 } 756 757 if (updatedAfter != null) { 758 where.append(" and issues.updatedDate > ? "); 759 } 760 if (updatedBefore != null) { 761 where.append(" and issues.updatedDate < ? "); 762 } 763 if (updatedInPrevious != null) { 764 where.append(" and issues.updatedDate between ? and ? "); 765 } 766 767 768 where.append(" order by issues.priority, issues.id "); 769 770 selectFrom.append(where.toString()); 771 772 return selectFrom.toString(); 773 } 774 775 public Object [] getQueryObjects() { 776 ArrayList objs = new ArrayList (); 777 if (project != null) { 778 objs.add(project.getId()); 779 } 780 if (searchText != null && !searchText.trim().equals("")) { 781 if (summary) { 782 objs.add("%" + searchText.toLowerCase() + "%"); 783 } 784 if (comments) { 785 objs.add("%" + searchText.toLowerCase() + "%"); 786 } 787 if (description) { 788 objs.add("%" + searchText.toLowerCase() + "%"); 789 } 790 if (environment) { 791 objs.add("%" + searchText.toLowerCase() + "%"); 792 } 793 } 794 795 if (author != null) { 796 objs.add(author.getId()); 797 } 798 if (assignedTo != null) { 799 objs.add(assignedTo.getId()); 800 } 801 if (authorRole != null) { 802 objs.add(authorRole.getId()); 803 } 804 if (assignedToRole != null) { 805 objs.add(assignedToRole.getId()); 806 } 807 if (types.size() != 0) { 808 for (Iterator it = types.iterator(); it.hasNext(); ) { 809 String type = (String )it.next(); 810 if (type != null && !type.trim().equals("")) { 811 objs.add(type); 812 } 813 } 814 } 815 816 if (statuses.size() != 0) { 817 for (Iterator it = statuses.iterator(); it.hasNext(); ) { 818 String status = (String )it.next(); 819 if (status != null && !status.trim().equals("")) { 820 objs.add(status); 821 } 822 } 823 } 824 825 if (resolutions.size() != 0) { 826 for (Iterator it = resolutions.iterator(); it.hasNext(); ) { 827 String resolution = (String )it.next(); 828 if (resolution != null && !resolution.trim().equals("")) { 829 objs.add(resolution); 830 } 831 } 832 } 833 834 if (priorities.size() != 0) { 835 for (Iterator it = priorities.iterator(); it.hasNext(); ) { 836 String priority = (String )it.next(); 837 if (priority != null && !priority.trim().equals("")) { 838 objs.add(priority); 839 } 840 } 841 } 842 843 if (createdAfter != null) { 845 objs.add(createdAfter); 846 } 847 if (createdBefore != null) { 848 objs.add(createdBefore); 849 } 850 if (createdInPrevious != null) { 851 long currTime = System.currentTimeMillis(); 852 objs.add(new Date (currTime - createdInPrevious.longValue())); 853 objs.add(new Date (currTime)); 854 } 855 856 if (updatedAfter != null) { 857 objs.add(updatedAfter); 858 } 859 if (updatedBefore != null) { 860 objs.add(updatedBefore); 861 } 862 if (updatedInPrevious != null) { 863 long currTime = System.currentTimeMillis(); 864 objs.add(new Date (currTime - updatedInPrevious.longValue())); 865 objs.add(new Date (currTime)); 866 } 867 868 return objs.toArray(); 869 } 870 871 } 872 | Popular Tags |