KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > MITListItem


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2003 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import org.apache.commons.lang.ObjectUtils;
50 import org.apache.torque.om.Persistent;
51 import org.tigris.scarab.util.word.IssueSearch;
52 import org.tigris.scarab.util.word.IssueSearchFactory;
53 import org.tigris.scarab.util.word.MaxConcurrentSearchException;
54
55 /**
56  * A module and an issue type. Wildcards are possible, so that a single
57  * MITListItem could represent all the issue types in a module. A single
58  * issue type in all modules (that have it defined). Or all modules and
59  * issue types.
60  */

61 public class MITListItem
62     extends org.tigris.scarab.om.BaseMITListItem
63     implements Persistent
64 {
65     static final Integer JavaDoc MULTIPLE_KEY = new Integer JavaDoc(0);
66
67     /**
68      * The number of active issues of the this issue type within the module.
69      *
70      * @param user a <code>ScarabUser</code> value used to determine if
71      * a count should be given.
72      * @return an <code>int</code> the number of issues entered for the
73      * module unless the user does not have permission to
74      * search for issues in the given module, then a value of 0 will be
75      * returned. if resource limited, this method will return -1.
76      * @exception Exception if an error occurs
77      */

78     public int getIssueCount(ScarabUser user)
79         throws Exception JavaDoc
80     {
81         IssueSearch is = null;
82         int count = 0;
83         try
84         {
85             is = IssueSearchFactory.INSTANCE
86                 .getInstance(getModule(), getIssueType(), user);
87             count = is.getIssueCount();
88         }
89         catch (MaxConcurrentSearchException e)
90         {
91             count = -1;
92         }
93         finally
94         {
95             IssueSearchFactory.INSTANCE.notifyDone();
96         }
97         return count;
98     }
99
100     public boolean isSingleModuleIssueType()
101     {
102         boolean single = true;
103         if (MULTIPLE_KEY.equals(getModuleId())
104             || MULTIPLE_KEY.equals(getIssueTypeId()))
105         {
106             single = false;
107         }
108         return single;
109     }
110
111     public boolean isSingleModule()
112     {
113         return !MULTIPLE_KEY.equals(getModuleId());
114     }
115
116     public boolean isSingleIssueType()
117     {
118         return !MULTIPLE_KEY.equals(getIssueTypeId());
119     }
120
121     public boolean isUseCurrentModule()
122     {
123         return getModuleId() == null;
124     }
125
126     public String JavaDoc getQueryKey()
127     {
128         String JavaDoc key = super.getQueryKey();
129         if (key == null || key.length() == 0)
130         {
131             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
132             if (getModuleId() != null)
133             {
134                 sb.append(getModuleId());
135             }
136             sb.append(':');
137             if (getIssueTypeId() != null)
138             {
139                 sb.append(getIssueTypeId());
140             }
141             key = sb.toString();
142         }
143         return key;
144     }
145
146     public int hashCode()
147     {
148         int hashCode = 10;
149         if (getModuleId() != null)
150         {
151             hashCode += getModuleId().hashCode();
152         }
153         if (getIssueTypeId() != null)
154         {
155             hashCode += getIssueTypeId().hashCode();
156         }
157         return hashCode;
158     }
159
160     public boolean equals(Object JavaDoc obj)
161     {
162         boolean isEqual = false;
163         if (obj instanceof MITListItem)
164         {
165             MITListItem item = (MITListItem)obj;
166             isEqual = ObjectUtils.equals(this.getModuleId(), item.getModuleId());
167             isEqual &= ObjectUtils.equals(this.getIssueTypeId(),
168                                           item.getIssueTypeId());
169         }
170         return isEqual;
171     }
172
173     public String JavaDoc toString()
174     {
175         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(50);
176         sb.append('{').append(super.toString()).append('(');
177         if (getModuleId() != null)
178         {
179             sb.append(getModuleId());
180         }
181         sb.append(':');
182         if (getIssueTypeId() != null)
183         {
184             sb.append(getIssueTypeId());
185         }
186         sb.append(")}");
187
188         return sb.toString();
189     }
190 }
191
Popular Tags