KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > issueTracker > SearchFilter


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

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 JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 /**
33  * @hibernate.class
34  * table="COEFFICIENT_SEARCH_FILTER"
35  */

36 public class SearchFilter implements java.io.Serializable JavaDoc {
37
38     private static final String JavaDoc SQL_1 = "select distinct issues from "
39         + IssueData.class.getName() + " as issues ";
40     private static final String JavaDoc SQL_2 = ", " + DiscussionData.class.getName()
41         + " as comments ";
42     private static final String JavaDoc SQL_3 = " where 1 = 1 and ";
43     private static final String JavaDoc SQL_4 = " issues.project.id = ? " ;
44
45
46     //~ Instance fields ========================================================
47

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 JavaDoc searchText;
55     private boolean summary;
56     private boolean comments;
57     private boolean description;
58     private boolean environment;
59     private List JavaDoc types = new ArrayList JavaDoc();
60     private List JavaDoc statuses = new ArrayList JavaDoc();
61     private List JavaDoc resolutions = new ArrayList JavaDoc();
62     private List JavaDoc priorities = new ArrayList JavaDoc();
63     private Role sharingLevel;
64     private Date JavaDoc createdAfter;
65     private Date JavaDoc createdBefore;
66     private Long JavaDoc createdInPrevious;
67     private Date JavaDoc updatedAfter;
68     private Date JavaDoc updatedBefore;
69     private Long JavaDoc updatedInPrevious;
70
71     private Long JavaDoc id;
72     private String JavaDoc filterDescription;
73     private String JavaDoc name;
74     private long version;
75
76     //~ Constructors ===========================================================
77

78     public SearchFilter() {}
79
80     //~ Methods ================================================================
81

82     public void setAuthor(CoefficientUser author) {
83         this.author = author;
84     }
85
86     /**
87      * Gets the value of name
88      *
89      * @return the value of name
90      * @hibernate.many-to-one
91      * column="AUTHOR"
92      */

93     public CoefficientUser getAuthor() {
94         return this.author;
95     }
96
97     public void setFilterAuthor(CoefficientUser filterAuthor) {
98         this.filterAuthor = filterAuthor;
99     }
100
101     /**
102      * Gets the value of name
103      *
104      * @return the value of name
105      * @hibernate.many-to-one
106      * column="FILTER_AUTHOR"
107      */

108     public CoefficientUser getFilterAuthor() {
109         return this.filterAuthor;
110     }
111
112     public void setAssignedTo(CoefficientUser assignedTo) {
113         this.assignedTo = assignedTo;
114     }
115
116     /**
117      * Gets the value of name
118      *
119      * @return the value of name
120      * @hibernate.many-to-one
121      * column="ASSIGNED_TO"
122      */

123     public CoefficientUser getAssignedTo() {
124         return this.assignedTo;
125     }
126
127     /**
128      * Sets the value of project
129      *
130      * @param argId Value to assign to this.project
131      */

132     public void setProject(Project project) {
133         this.project = project;
134     }
135
136     /**
137      * Gets the value of project
138      *
139      * @return the value of project
140      * @hibernate.many-to-one
141      * column="PROJECT_ID"
142      */

143     public Project getProject() {
144         return this.project;
145     }
146
147     /**
148      * Sets the value of environment
149      *
150      * @param argEnvironment Value to assign to this.environment
151      */

152     public void setEnvironment(boolean environment) {
153         this.environment = environment;
154     }
155
156     /**
157      * Gets the value of environment
158      *
159      * @return the value of environment
160      * @hibernate.property
161      * column="ENVIRONMENT"
162      */

163     public boolean getEnvironment() {
164         return this.environment;
165     }
166
167     /**
168      * Sets the value of summary
169      *
170      * @param argSummary Value to assign to this.summary
171      */

172     public void setSummary(boolean summary) {
173         this.summary = summary;
174     }
175
176     /**
177      * Gets the value of summary
178      *
179      * @return the value of summary
180      * @hibernate.property
181      * column="SUMMARY"
182      */

183     public boolean getSummary() {
184         return this.summary;
185     }
186
187     /**
188      * Sets the value of comments
189      *
190      * @param argComments Value to assign to this.comments
191      */

192     public void setComments(boolean comments) {
193         this.comments = comments;
194     }
195
196     /**
197      * Gets the value of comments
198      *
199      * @return the value of comments
200      * @hibernate.property
201      * column="COMMENTS"
202      */

203     public boolean getComments() {
204         return this.comments;
205     }
206
207     /**
208      * Sets the value of description
209      *
210      * @param argDescription Value to assign to this.description
211      */

212     public void setDescription(boolean description) {
213         this.description = description;
214     }
215
216     /**
217      * Gets the value of description
218      *
219      * @return the value of description
220      * @hibernate.property
221      * column="DESCRIPTION"
222      */

223     public boolean getDescription() {
224         return this.description;
225     }
226
227     /**
228      * Sets the value of id
229      *
230      * @param argId Value to assign to this.id
231      */

232     public void setId(Long JavaDoc argId) {
233         this.id = argId;
234     }
235
236     /**
237      * Gets the value of id
238      *
239      * @return the value of id
240      * @hibernate.id
241      * generator-class="native"
242      */

243     public Long JavaDoc getId() {
244         return this.id;
245     }
246
247     /**
248      * Sets the value of searchText
249      *
250      * @param argSearchText Value to assign to this.searchText
251      */

252     public void setSearchText(String JavaDoc searchText) {
253         if (searchText != null && !searchText.trim().equals("")) {
254             this.searchText = searchText;
255         }
256     }
257
258     /**
259      * Gets the value of searchText
260      *
261      * @return the value of searchText
262      * @hibernate.property
263      * column="SEARCH_TEXT"
264      */

265     public String JavaDoc getSearchText() {
266         return this.searchText;
267     }
268
269     /**
270      * Sets the value of name
271      *
272      * @param argName Value to assign to this.name
273      */

274     public void setName(String JavaDoc name) {
275         this.name = name;
276     }
277
278     /**
279      * Gets the value of name
280      *
281      * @return the value of name
282      * @hibernate.property
283      * column="NAME"
284      */

285     public String JavaDoc getName() {
286         return this.name;
287     }
288
289     /**
290      * Sets the value of version
291      *
292      * @param version Value to assign to this.version
293      */

294     public void setVersion(long version) {
295         this.version = version;
296     }
297
298     /**
299      * Gets the value of version
300      *
301      * @return the value of version
302      * @hibernate.version
303      * type="long"
304      * column="VERSION"
305      */

306     public long getVersion() {
307         return this.version;
308     }
309
310     /**
311      * Sets the value of types
312      *
313      * @param types Value to assign to this.types
314      */

315     public void setTypes(List JavaDoc types) {
316         this.types = types;
317     }
318
319     /**
320      * Gets the value of types
321      *
322      * @return the value of types
323      * @hibernate.list
324      * cascade="all"
325      * table="COEFFICIENT_SEARCH_FILTER_TYPES"
326      * @hibernate.collection-key
327      * column="SEARCH_FILTER_ID"
328      * @hibernate.collection-index
329      * column="IDX"
330      * @hibernate.collection-element
331      * column="TYPES"
332      * type="string"
333      */

334     public List JavaDoc getTypes() {
335         return this.types;
336     }
337
338     /**
339      * Sets the value of statuses
340      *
341      * @param statuses Value to assign to this.statuses
342      */

343     public void setStatuses(List JavaDoc statuses) {
344         this.statuses = statuses;
345     }
346
347     /**
348      * Gets the value of statuses
349      *
350      * @return the value of statuses
351      * @hibernate.list
352      * cascade="all"
353      * table="COEFFICIENT_SEARCH_FILTER_STATUSES"
354      * @hibernate.collection-key
355      * column="SEARCH_FILTER_ID"
356      * @hibernate.collection-index
357      * column="IDX"
358      * @hibernate.collection-element
359      * column="STATUSES"
360      * type="string"
361      */

362     public List JavaDoc getStatuses() {
363         return this.statuses;
364     }
365
366     /**
367      * Sets the value of priorities
368      *
369      * @param priorities Value to assign to this.priorities
370      */

371     public void setPriorities(List JavaDoc priorities) {
372         this.priorities = priorities;
373     }
374
375     /**
376      * Gets the value of priorities
377      *
378      * @return the value of priorities
379      * @hibernate.list
380      * cascade="all"
381      * table="COEFFICIENT_SEARCH_FILTER_PRIORITIES"
382      * @hibernate.collection-key
383      * column="SEARCH_FILTER_ID"
384      * @hibernate.collection-index
385      * column="IDX"
386      * @hibernate.collection-element
387      * column="PRIORITIES"
388      * type="string"
389      */

390     public List JavaDoc getPriorities() {
391         return this.priorities;
392     }
393
394     /**
395      * Sets the value of resolutions
396      *
397      * @param resolutions Value to assign to this.resolutions
398      */

399     public void setResolutions(List JavaDoc resolutions) {
400         this.resolutions = resolutions;
401     }
402
403     /**
404      * Gets the value of resolutions
405      *
406      * @return the value of resolutions
407      * @hibernate.list
408      * cascade="all"
409      * table="COEFFICIENT_SEARCH_FILTER_RESOLUTIONS"
410      * @hibernate.collection-key
411      * column="SEARCH_FILTER_ID"
412      * @hibernate.collection-index
413      * column="IDX"
414      * @hibernate.collection-element
415      * column="RESOLUTIONS"
416      * type="string"
417      */

418     public List JavaDoc getResolutions() {
419         return this.resolutions;
420     }
421
422     /**
423      * Sets the value of sharingLevel
424      *
425      * @param argSharingLevel Value to assign to this.sharingLevel
426      */

427     public void setSharingLevel(Role sharingLevel) {
428         this.sharingLevel = sharingLevel;
429     }
430
431     /**
432      * Gets the value of sharingLevel
433      *
434      * @return the value of sharingLevel
435      * @hibernate.many-to-one
436      * colum="SHARING_LEVEL"
437      */

438     public Role getSharingLevel() {
439         return this.sharingLevel;
440     }
441
442     /**
443      * Sets the value of authorRole
444      *
445      * @param argAuthorRole Value to assign to this.authorRole
446      */

447     public void setAuthorRole(Role authorRole) {
448         this.authorRole = authorRole;
449     }
450
451     /**
452      * Gets the value of authorRole
453      *
454      * @return the value of authorRole
455      * @hibernate.many-to-one
456      * colum="AUTHOR_ROLE"
457      */

458     public Role getAuthorRole() {
459         return this.authorRole;
460     }
461
462     /**
463      * Sets the value of assignedToRole
464      *
465      * @param argAssignedToRole Value to assign to this.assignedToRole
466      */

467     public void setAssignedToRole(Role assignedToRole) {
468         this.assignedToRole = assignedToRole;
469     }
470
471     /**
472      * Gets the value of assignedToRole
473      *
474      * @return the value of assignedToRole
475      * @hibernate.many-to-one
476      * colum="ASSIGNED_TO_ROLE"
477      */

478     public Role getAssignedToRole() {
479         return this.assignedToRole;
480     }
481
482     public void setFilterDescription(String JavaDoc filterDesc) {
483         this.filterDescription = filterDesc;
484     }
485
486     /**
487      * Gets the value of name
488      *
489      * @return the value of name
490      * @hibernate.property
491      * length="3999"
492      * colum="DESCRIPTION"
493      */

494     public String JavaDoc getFilterDescription() {
495         return this.filterDescription;
496     }
497
498     /**
499      * Sets the value of createdAfter
500      *
501      * @param argId Value to assign to this.createdAfter
502      */

503     public void setCreatedAfter(Date JavaDoc argCreatedAfter) {
504         this.createdAfter = argCreatedAfter;
505     }
506
507     /**
508      * Gets the value of createdAfter
509      *
510      * @return the value of createdAfter
511      * @hibernate.property
512      * column="CREATED_AFTER"
513      */

514     public Date JavaDoc getCreatedAfter() {
515         return this.createdAfter;
516     }
517
518     /**
519      * Sets the value of createdBefore
520      *
521      * @param argId Value to assign to this.createdBefore
522      */

523     public void setCreatedBefore(Date JavaDoc argCreatedBefore) {
524         this.createdBefore = argCreatedBefore;
525     }
526
527     /**
528      * Gets the value of createdBefore
529      *
530      * @return the value of createdBefore
531      * @hibernate.property
532      * column="CREATED_BEFORE"
533      */

534     public Date JavaDoc getCreatedBefore() {
535         return this.createdBefore;
536     }
537
538     /**
539      * Sets the value of createdInPrevious
540      *
541      * @param argId Value to assign to this.createdInPrevious
542      */

543     public void setCreatedInPrevious(Long JavaDoc argCreatedInPrevious) {
544         this.createdInPrevious = argCreatedInPrevious;
545     }
546
547     /**
548      * Gets the value of createdInPrevious
549      *
550      * @return the value of createdInPrevious
551      * @hibernate.property
552      * column="CREATED_IN_PREVIOUS"
553      */

554     public Long JavaDoc getCreatedInPrevious() {
555         return this.createdInPrevious;
556     }
557
558     /**
559      * Sets the value of createdAfter
560      *
561      * @param argId Value to assign to this.createdAfter
562      */

563     public void setUpdatedAfter(Date JavaDoc argUpdatedAfter) {
564         this.updatedAfter = argUpdatedAfter;
565     }
566
567     /**
568      * Gets the value of updatedAfter
569      *
570      * @return the value of updatedAfter
571      * @hibernate.property
572      * column="UPDATED_AFTER"
573      */

574     public Date JavaDoc getUpdatedAfter() {
575         return this.updatedAfter;
576     }
577
578     /**
579      * Sets the value of updatedBefore
580      *
581      * @param argId Value to assign to this.updatedBefore
582      */

583     public void setUpdatedBefore(Date JavaDoc argUpdatedBefore) {
584         this.updatedBefore = argUpdatedBefore;
585     }
586
587     /**
588      * Gets the value of updatedBefore
589      *
590      * @return the value of updatedBefore
591      * @hibernate.property
592      * column="UPDATED_BEFORE"
593      */

594     public Date JavaDoc getUpdatedBefore() {
595         return this.updatedBefore;
596     }
597
598     /**
599      * Sets the value of updatedInPrevious
600      *
601      * @param argId Value to assign to this.updatedInPrevious
602      */

603     public void setUpdatedInPrevious(Long JavaDoc argUpdatedInPrevious) {
604         this.updatedInPrevious = argUpdatedInPrevious;
605     }
606
607     /**
608      * Gets the value of updatedInPrevious
609      *
610      * @return the value of updatedInPrevious
611      * @hibernate.property
612      * column="UPDATED_IN_PREVIOUS"
613      */

614     public Long JavaDoc getUpdatedInPrevious() {
615         return this.updatedInPrevious;
616     }
617
618
619     public String JavaDoc getQuery() {
620         StringBuffer JavaDoc selectFrom = new StringBuffer JavaDoc();
621         selectFrom.append(SQL_1);
622         StringBuffer JavaDoc where = new StringBuffer JavaDoc(SQL_3);
623
624         if(project != null) {
625             where.append(SQL_4);
626         }
627         if(searchText != null && !searchText.trim().equals("")) {
628             StringBuffer JavaDoc searchTextQuery = new StringBuffer JavaDoc("");
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 JavaDoc it = types.iterator(); it.hasNext(); ) {
686                 String JavaDoc type = (String JavaDoc)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 JavaDoc it = statuses.iterator(); it.hasNext(); ) {
702                 String JavaDoc status = (String JavaDoc)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 JavaDoc it = resolutions.iterator(); it.hasNext();) {
718                 String JavaDoc resolution = (String JavaDoc)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 JavaDoc it = priorities.iterator(); it.hasNext(); ) {
734                 String JavaDoc priority = (String JavaDoc)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         // Process the date and time fields
747
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 JavaDoc [] getQueryObjects() {
776         ArrayList JavaDoc objs = new ArrayList JavaDoc();
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 JavaDoc it = types.iterator(); it.hasNext(); ) {
809                 String JavaDoc type = (String JavaDoc)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 JavaDoc it = statuses.iterator(); it.hasNext(); ) {
818                 String JavaDoc status = (String JavaDoc)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 JavaDoc it = resolutions.iterator(); it.hasNext(); ) {
827                 String JavaDoc resolution = (String JavaDoc)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 JavaDoc it = priorities.iterator(); it.hasNext(); ) {
836                 String JavaDoc priority = (String JavaDoc)it.next();
837                 if (priority != null && !priority.trim().equals("")) {
838                     objs.add(priority);
839                 }
840             }
841         }
842
843         // Process the date and time fields
844
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 JavaDoc(currTime - createdInPrevious.longValue()));
853             objs.add(new Date JavaDoc(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 JavaDoc(currTime - updatedInPrevious.longValue()));
865             objs.add(new Date JavaDoc(currTime));
866         }
867
868         return objs.toArray();
869     }
870
871 }
872
Popular Tags