KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > actions > DefineXModuleList


1 package org.tigris.scarab.actions;
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 java.util.List JavaDoc;
50 import java.util.ArrayList JavaDoc;
51
52 // Turbine Stuff
53
import org.apache.turbine.TemplateContext;
54 import org.apache.turbine.RunData;
55
56 import org.apache.turbine.tool.IntakeTool;
57 import org.apache.fulcrum.intake.model.Group;
58 import org.apache.torque.TorqueException;
59
60 // Scarab Stuff
61
import org.tigris.scarab.actions.base.RequireLoginFirstAction;
62 import org.tigris.scarab.om.ScarabUser;
63 import org.tigris.scarab.om.Module;
64 import org.tigris.scarab.om.MITList;
65 import org.tigris.scarab.om.MITListManager;
66 import org.tigris.scarab.om.IssueType;
67 import org.tigris.scarab.om.RModuleIssueType;
68 import org.tigris.scarab.om.RModuleIssueTypeManager;
69 import org.tigris.scarab.om.IssueTypeManager;
70 import org.tigris.scarab.om.Scope;
71 import org.tigris.scarab.reports.ReportBridge;
72 import org.tigris.scarab.reports.IncompatibleMITListException;
73 import org.tigris.scarab.util.Log;
74 import org.tigris.scarab.util.ScarabConstants;
75 import org.tigris.scarab.tools.ScarabRequestTool;
76 import org.tigris.scarab.tools.ScarabLocalizationTool;
77 import org.tigris.scarab.tools.localization.L10NKeySet;
78
79 /**
80  * This class is responsible for building a list of Module/IssueTypes.
81  *
82  * @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
83  * @version $Id: DefineXModuleList.java 9290 2004-12-03 15:57:52Z dep4b $
84  */

85 public class DefineXModuleList extends RequireLoginFirstAction
86 {
87     public void doGotoquerywithinternallist(RunData data,
88                                             TemplateContext context)
89         throws Exception JavaDoc
90     {
91         ScarabRequestTool scarabR = getScarabRequestTool(context);
92         ScarabLocalizationTool l10n = getLocalizationTool(context);
93         String JavaDoc listId = data.getParameters().getString("pd_list_id");
94         if (listId == null || listId.length()==0)
95         {
96             scarabR.setAlertMessage(L10NKeySet.NoPredefinedXModuleListSelected);
97         }
98         else
99         {
100             MITList list = null;
101             ScarabUser user = (ScarabUser)data.getUser();
102             if ("allmits".equals(listId))
103             {
104                 list = MITListManager.getAllModulesAllIssueTypesList(user);
105             }
106             else
107             {
108                 IssueType issueType = IssueTypeManager
109                     .getInstance(new Integer JavaDoc(listId.substring(13)));
110                 if (issueType.getDeleted())
111                 {
112
113                     scarabR.setAlertMessage(L10NKeySet.GlobalIssueTypesDeleted);
114                 }
115                 else
116                 {
117                     list = MITListManager.getAllModulesSingleIssueTypeList(
118                         issueType, user);
119                 }
120             }
121             user.setCurrentMITList(list);
122             // reset selected users map
123
scarabR.resetSelectedUsers();
124             setTarget(data, data.getParameters()
125                       .getString(ScarabConstants.NEXT_TEMPLATE));
126         }
127     }
128
129     public void doFinished(RunData data, TemplateContext context)
130         throws Exception JavaDoc
131     {
132         // add any last minute additions
133
addSelectedRMITs(data, context);
134         ScarabUser user = (ScarabUser)data.getUser();
135         MITList currentList = user.getCurrentMITList();
136         // reset selected users map
137
getScarabRequestTool(context).resetSelectedUsers();
138
139         if (currentList != null && !currentList.isEmpty())
140         {
141             setTarget(data, user.getQueryTarget());
142         }
143         else
144         {
145             ScarabRequestTool scarabR = getScarabRequestTool(context);
146             ScarabLocalizationTool l10n = getLocalizationTool(context);
147             scarabR.setAlertMessage(L10NKeySet.ListWithAtLeastOneMITRequired);
148         }
149     }
150
151     public void doFinishedreportlist(RunData data, TemplateContext context)
152         throws Exception JavaDoc
153     {
154         doFinished(data, context);
155         ScarabLocalizationTool l10n = getLocalizationTool(context);
156         ScarabUser user = (ScarabUser)data.getUser();
157         ScarabRequestTool scarabR = getScarabRequestTool(context);
158         ReportBridge report = scarabR.getReport();
159         if (!report.isEditable(user))
160         {
161             scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
162             setTarget(data, "reports,ReportList.vm");
163             return;
164         }
165
166         MITList mitList = user.getCurrentMITList();
167         try
168         {
169             report.setMITList(mitList);
170             scarabR.setConfirmMessage(DEFAULT_MSG);
171
172             if (!mitList.isSingleModule() &&
173                 Scope.MODULE__PK.equals(report.getScopeId()))
174             {
175                 report.setScopeId(Scope.PERSONAL__PK);
176                 scarabR.setInfoMessage(L10NKeySet.ScopeChangedToPersonal);
177             }
178             setTarget(data, "reports,Info.vm");
179         }
180         catch (IncompatibleMITListException e)
181         {
182             scarabR.setAlertMessage(L10NKeySet.IncompatibleMITListReport);
183             setTarget(data, "reports,XModuleList.vm");
184         }
185     }
186
187
188     public void doRemoveSavedlist(RunData data, TemplateContext context)
189         throws Exception JavaDoc
190     {
191         ScarabRequestTool scarabR = getScarabRequestTool(context);
192         String JavaDoc listId = data.getParameters().getString("list_id");
193         if (listId == null || listId.length()==0)
194         {
195             ScarabLocalizationTool l10n = getLocalizationTool(context);
196             scarabR.setAlertMessage(L10NKeySet.NoSavedXModuleQuerySelected);
197         }
198         else
199         {
200             // TODO: implement
201
}
202     }
203
204     public void doRemoveitemsfromlist(RunData data, TemplateContext context)
205         throws Exception JavaDoc
206     {
207         ScarabRequestTool scarabR = getScarabRequestTool(context);
208         ScarabLocalizationTool l10n = getLocalizationTool(context);
209         ScarabUser user = (ScarabUser)data.getUser();
210         String JavaDoc[] mitids = data.getParameters().getStrings("mitlistitem");
211         if (mitids == null || mitids.length == 0)
212         {
213             scarabR.setAlertMessage(L10NKeySet.NoItemsSelectedForRemoval);
214         }
215         else
216         {
217             user.removeItemsFromCurrentMITList(mitids);
218             scarabR.setConfirmMessage(
219                 l10n.format("NumberItemsRemoved", String.valueOf(mitids.length)));
220         }
221     }
222
223     public void doGotosavelist(RunData data, TemplateContext context)
224         throws Exception JavaDoc
225     {
226         ScarabRequestTool scarabR = getScarabRequestTool(context);
227         ScarabLocalizationTool l10n = getLocalizationTool(context);
228         ScarabUser user = (ScarabUser)data.getUser();
229         MITList list = user.getCurrentMITList();
230         if (list == null)
231         {
232             scarabR.setAlertMessage(L10NKeySet.ApplicationErrorListWasNull);
233             Log.get().error("Current list was null in DefineXModuleList.doGotosavelist.");
234         }
235         else if (list.isAnonymous())
236         {
237             list.save();
238             scarabR.setConfirmMessage(DEFAULT_MSG);
239             String JavaDoc queryId = data.getParameters().getString("queryId");
240             if (queryId != null && queryId.length() > 0)
241             {
242                 setTarget(data, "EditQuery.vm");
243             }
244         }
245         else
246         {
247             list.setName(null);
248             setTarget(data, "EditXModuleList.vm");
249         }
250     }
251
252     public void doStartover(RunData data, TemplateContext context)
253         throws Exception JavaDoc
254     {
255         ((ScarabUser)data.getUser()).setCurrentMITList(null);
256     }
257
258     public void doSavelist(RunData data, TemplateContext context)
259         throws Exception JavaDoc
260     {
261         IntakeTool intake = getIntakeTool(context);
262         ScarabRequestTool scarabR = getScarabRequestTool(context);
263         ScarabLocalizationTool l10n = getLocalizationTool(context);
264        
265         if (intake.isAllValid())
266         {
267             ScarabUser user = (ScarabUser)data.getUser();
268             MITList list = user.getCurrentMITList();
269             Group group =
270                 intake.get("MITList", list.getQueryKey(), false);
271             group.setProperties(list);
272             // check if the name already exists and inactivate the old list
273
MITList oldList = MITListManager
274                 .getInstanceByName(list.getName(), user);
275             if (oldList != null)
276             {
277                 // oldList should not be the same as the new, but checking
278
// will not hurt
279
if (!list.equals(oldList))
280                 {
281                     oldList.setActive(false);
282                     oldList.save();
283                 }
284             }
285             // save the new list
286
list.save();
287
288             // Setting the current list to null
289
// So that on IssueTypeList screen can select a saved list
290
user.setCurrentMITList(null);
291  
292             scarabR.setConfirmMessage(DEFAULT_MSG);
293             setTarget(data, data.getParameters()
294                       .getString(ScarabConstants.LAST_TEMPLATE));
295         }
296     }
297
298     public void doAddselectedrmits(RunData data, TemplateContext context)
299         throws Exception JavaDoc
300     {
301         ScarabRequestTool scarabR = getScarabRequestTool(context);
302         ScarabLocalizationTool l10n = getLocalizationTool(context);
303         String JavaDoc[] rmitIds = data.getParameters().getStrings("rmitid");
304         String JavaDoc listId = data.getParameters().getString("list_id");
305         if ( (listId == null || listId.length() == 0)
306              && (rmitIds == null || rmitIds.length == 0)
307              && !data.getParameters().getBoolean("allit"))
308         {
309             scarabR.setAlertMessage(L10NKeySet.MustSelectAtLeastOneIssueType);
310             return;
311         }
312         else
313         {
314             addSelectedRMITs(data, context);
315         }
316     }
317
318     private void addToUsersList(ScarabUser user, MITList list)
319         throws TorqueException
320     {
321         MITList currentList = user.getCurrentMITList();
322         if (currentList == null)
323         {
324             user.setCurrentMITList(list);
325         }
326         else
327         {
328             currentList.addAll(list);
329         }
330     }
331
332     private void addSelectedRMITs(RunData data, TemplateContext context)
333         throws Exception JavaDoc
334     {
335         ScarabRequestTool scarabR = getScarabRequestTool(context);
336         ScarabLocalizationTool l10n = getLocalizationTool(context);
337
338         String JavaDoc listId = data.getParameters().getString("list_id");
339         if (listId != null && listId.length() != 0)
340         {
341             setAndGetCurrentList(listId, data, context);
342         }
343
344         ScarabUser user = (ScarabUser)data.getUser();
345         if (data.getParameters().getBoolean("allit"))
346         {
347             Module module = user.getCurrentModule();
348             List JavaDoc issueTypes = module.getIssueTypes(false);
349             if (issueTypes == null || issueTypes.isEmpty())
350             {
351                 scarabR.setAlertMessage(L10NKeySet.IssueTypeUnavailable);
352                 return;
353             }
354             MITList list = MITListManager.getSingleModuleAllIssueTypesList(
355                 module, user);
356             addToUsersList(user, list.copy());
357         }
358
359         String JavaDoc[] rmitIds = data.getParameters().getStrings("rmitid");
360         if (rmitIds != null && rmitIds.length != 0)
361         {
362             List JavaDoc rmits = new ArrayList JavaDoc(rmitIds.length);
363             boolean isIssueTypeAvailable = true;
364             for (int i=0; i<rmitIds.length && isIssueTypeAvailable; i++)
365             {
366                 try
367                 {
368                     RModuleIssueType rmit = RModuleIssueTypeManager
369                         .getInstance(rmitIds[i]);
370                     if (rmit == null || rmit.getIssueType().getDeleted())
371                     {
372                         isIssueTypeAvailable = false;
373                     }
374                     else
375                     {
376                         rmits.add(rmit);
377                     }
378                 }
379                 catch (Exception JavaDoc e)
380                 {
381                     // would probably be a hack of the form
382
scarabR.setAlertMessage(L10NKeySet.IssueTypeUnavailable);
383                     Log.get().debug("", e);
384                     return;
385                 }
386             }
387             if (isIssueTypeAvailable)
388             {
389                 user.addRMITsToCurrentMITList(rmits);
390             }
391             else
392             {
393                 scarabR.setAlertMessage(L10NKeySet.IssueTypeUnavailable);
394             }
395         }
396         
397         // Another oddity due to ScarabUserImpl not extending
398
// AbstractScarabUser
399
MITList mitlist = user.getCurrentMITList();
400         if (mitlist != null)
401         {
402             mitlist.setScarabUser(user);
403         }
404     }
405
406     private void setAndGetCurrentList(String JavaDoc listId, RunData data,
407                                       TemplateContext context)
408         
409     {
410         ScarabRequestTool scarabR = getScarabRequestTool(context);
411         ScarabLocalizationTool l10n = getLocalizationTool(context);
412         try
413         {
414             MITList list = MITListManager.getInstance(new Long JavaDoc(listId));
415             if (list == null)
416             {
417                 scarabR.setAlertMessage(L10NKeySet.InvalidId);
418                 Log.get().warn("An invalid id was entered: "+listId);
419             }
420             else
421             {
422                 addToUsersList((ScarabUser)data.getUser(), list.copy());
423             }
424         }
425         catch (Exception JavaDoc e)
426         {
427             scarabR.setAlertMessage(L10NKeySet.InvalidId);
428             Log.get().warn("An invalid id was entered: "+listId);
429         }
430     }
431
432     public void doToggleothermodules(RunData data, TemplateContext context)
433         throws Exception JavaDoc
434     {
435         String JavaDoc flag = data.getParameters()
436             .getString("eventSubmit_doToggleothermodules");
437         ((ScarabUser)data.getUser()).setShowOtherModulesInIssueTypeList(
438             "show".equals(flag));
439     }
440 }
441
Popular Tags