KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 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 java.util.List JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import org.apache.torque.TorqueException;
52 import org.apache.torque.util.Criteria;
53 import org.apache.fulcrum.localization.Localization;
54
55 import org.tigris.scarab.util.Log;
56 import org.tigris.scarab.util.ScarabConstants;
57 import org.tigris.scarab.om.ScarabUser;
58
59 /**
60  * This class manages MITList objects.
61  */

62 public class MITListManager
63     extends BaseMITListManager
64 {
65     /**
66      * Creates a new <code>MITListManager</code> instance.
67      *
68      * @exception TorqueException if an error occurs
69      */

70     public MITListManager()
71         throws TorqueException
72     {
73         super();
74     }
75
76     public static MITList getSingleItemList(Module module, IssueType issueType,
77                                             ScarabUser user)
78         throws TorqueException
79     {
80         MITList list = getInstance();
81         if (user != null)
82         {
83             list.setScarabUser(user);
84         }
85         MITListItem item = MITListItemManager.getInstance();
86         item.setModule(module);
87         item.setIssueType(issueType);
88         list.addMITListItem(item);
89         return list;
90     }
91
92     public static MITList getSingleModuleAllIssueTypesList(Module module,
93                                                            ScarabUser user)
94         throws TorqueException
95     {
96         MITList list = MITListManager.getInstance();
97         list.setModifiable(false);
98         list.setScarabUser(user);
99         list.setName(Localization.format(ScarabConstants.DEFAULT_BUNDLE_NAME,
100                                          user.getLocale(),
101                                          "AllIssueTypesCurrentModule",
102                                          module.getRealName()));
103         
104         MITListItem item = MITListItemManager.getInstance();
105         item.setModule(module);
106         item.setIssueTypeId(MITListItem.MULTIPLE_KEY);
107         list.addMITListItem(item);
108         return list;
109     }
110
111     public static MITList getAllModulesAllIssueTypesList(ScarabUser user)
112         throws TorqueException
113     {
114         MITList list = MITListManager.getInstance();
115         list.setModifiable(false);
116         list.setScarabUser(user);
117         list.setName(Localization.getString(ScarabConstants.DEFAULT_BUNDLE_NAME,
118                                       user.getLocale(),
119                                       "AllModulesAndIssueTypes"));
120
121         MITListItem item = MITListItemManager.getInstance();
122         item.setModuleId(MITListItem.MULTIPLE_KEY);
123         list.addMITListItem(item);
124         item.setIssueTypeId(MITListItem.MULTIPLE_KEY);
125         return list;
126     }
127
128     public static MITList getAllModulesSingleIssueTypeList(IssueType issueType,
129                                                            ScarabUser user)
130         throws TorqueException
131     {
132         MITList list = MITListManager.getInstance();
133         list.setModifiable(false);
134         list.setScarabUser(user);
135         list.setName(Localization.format(ScarabConstants.DEFAULT_BUNDLE_NAME,
136                                          user.getLocale(),
137                                          "CurrentIssueTypeAllModules",
138                                          issueType.getName()));
139
140         MITListItem item = MITListItemManager.getInstance();
141         item.setModuleId(MITListItem.MULTIPLE_KEY);
142         item.setIssueType(issueType);
143         list.addMITListItem(item);
144         return list;
145     }
146
147     /**
148      * An issue has an associated Module and IssueType, this method takes
149      * a list of issues and creates an MITList from these associations.
150      *
151      * @param issues a <code>List</code> value
152      * @param user a <code>ScarabUser</code> value
153      * @return a <code>MITList</code> value
154      * @exception TorqueException if an error occurs
155      */

156     public static MITList getInstanceFromIssueList(List JavaDoc issues,
157                                                    ScarabUser user)
158         throws TorqueException
159     {
160         if (issues == null)
161         {
162             throw new IllegalArgumentException JavaDoc("Null issue list is not allowed."); //EXCEPTION
163
}
164         if (user == null)
165         {
166             throw new IllegalArgumentException JavaDoc("Null user is not allowed."); //EXCEPTION
167
}
168         
169         MITList list = getInstance();
170         list.setScarabUser(user);
171         List JavaDoc dupeCheck = list.getMITListItems();
172         Iterator JavaDoc i = issues.iterator();
173         if (i.hasNext())
174         {
175             Issue issue = (Issue)i.next();
176             MITListItem item = MITListItemManager.getInstance();
177             item.setModule(issue.getModule());
178             item.setIssueType(issue.getIssueType());
179             if (!dupeCheck.contains(item))
180             {
181                 list.addMITListItem(item);
182             }
183         }
184         
185         return list;
186     }
187
188     public static MITList getInstanceByName(String JavaDoc name, ScarabUser user)
189         throws TorqueException
190     {
191         MITList result = null;
192         Criteria crit = new Criteria();
193         crit.add(MITListPeer.NAME, name);
194         crit.add(MITListPeer.ACTIVE, true);
195         crit.add(MITListPeer.USER_ID, user.getUserId());
196         List JavaDoc mitLists = MITListPeer.doSelect(crit);
197         if (mitLists != null && !mitLists.isEmpty())
198         {
199             result = (MITList)mitLists.get(0);
200             // it is not good if more than one active list has the
201
// same name (per user). We could throw an exception here
202
// but its possible the system can still function under
203
// this circumstance, so just log it for now.
204
Log.get().error("Multiple active lists exist with list name="
205                             + name + " for user=" + user.getUserName() +
206                             "("+user.getUserId()+")");
207         }
208         return result;
209     }
210 }
211
212
213
214
215
216
Popular Tags