KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > pipeline > FreshenUserValve


1 package org.tigris.scarab.pipeline;
2
3 /* ================================================================
4  * Copyright (c) 2001 Collab.Net. 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.io.IOException JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.Map JavaDoc;
52
53 import org.apache.fulcrum.parser.ParameterParser;
54 import org.apache.torque.TorqueException;
55 import org.apache.torque.om.NumberKey;
56 import org.apache.turbine.RunData;
57 import org.apache.turbine.TurbineException;
58 import org.apache.turbine.ValveContext;
59 import org.apache.turbine.pipeline.AbstractValve;
60 import org.tigris.scarab.om.IssueManager;
61 import org.tigris.scarab.om.IssueType;
62 import org.tigris.scarab.om.IssueTypeManager;
63 import org.tigris.scarab.om.MITList;
64 import org.tigris.scarab.om.MITListManager;
65 import org.tigris.scarab.om.Module;
66 import org.tigris.scarab.om.ModuleManager;
67 import org.tigris.scarab.om.ScarabUser;
68 import org.tigris.scarab.util.Log;
69 import org.tigris.scarab.util.ScarabConstants;
70
71 /**
72  * This valve clears any stale data out of the user due to aborted wizards.
73  *
74  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
75  * @version $Id: FreshenUserValve.java 9360 2005-01-04 01:31:06Z dabbous $
76  */

77 public class FreshenUserValve
78     extends AbstractValve
79 {
80     protected static final Map JavaDoc XMIT_SCREENS = new HashMap JavaDoc();
81
82     
83     public void initialize() throws Exception JavaDoc {
84         XMIT_SCREENS.put("IssueTypeList.vm", null);
85         XMIT_SCREENS.put("AdvancedQuery.vm", null);
86         XMIT_SCREENS.put("Search.vm", null);
87         XMIT_SCREENS.put("IssueList.vm", null);
88         XMIT_SCREENS.put("ViewIssue.vm", null);
89         XMIT_SCREENS.put("QueryList.vm", null);
90         XMIT_SCREENS.put("SaveQuery.vm", null);
91         XMIT_SCREENS.put("EditQuery.vm", null);
92         XMIT_SCREENS.put("UserList.vm", null);
93         XMIT_SCREENS.put("ConfigureIssueList.vm", null);
94         XMIT_SCREENS.put("EditXModuleList.vm", null);
95         XMIT_SCREENS.put("reports,Info.vm", null);
96         XMIT_SCREENS.put("reports,ConfineDataset.vm", null);
97         XMIT_SCREENS.put("reports,XModuleList.vm", null);
98         XMIT_SCREENS.put("reports,AxisConfiguration.vm", null);
99         XMIT_SCREENS.put("reports,Report_1.vm", null);
100         // this is not a real .vm file, but a pointer to a java screen class
101
XMIT_SCREENS.put("IssueListExport.vm", null);
102         
103     }
104
105     /**
106      * @see org.apache.turbine.Valve#invoke(RunData, ValveContext)
107      */

108     public void invoke(RunData data, ValveContext context)
109         throws IOException JavaDoc, TurbineException
110     {
111         ScarabUser user = (ScarabUser)data.getUser();
112         
113         try
114         {
115             // Check, whether password is expired
116
if(user.isPasswordExpired())
117             {
118                 // Under no conditions an expired password will be
119
// accepted. The request is always forwarded to the
120
// password change mask until the password has been reset. [HD]
121
data.setTarget("ChangePassword.vm");
122                 data.save();
123                 context.invokeNext(data);
124                 return;
125             }
126             adjustCurrentModule(user, data);
127             adjustCurrentIssueType(user, data);
128         }
129         catch(Exception JavaDoc e)
130         {
131             Log.get().error("", e);
132             // Ignore on purpose because if things
133
// are screwed up, we don't need to know about it.
134
}
135
136         // set the thread key
137
ParameterParser parameters = data.getParameters();
138         String JavaDoc key = parameters.getString(ScarabConstants.THREAD_QUERY_KEY);
139         if (key != null)
140         {
141             user.setThreadKey(new Integer JavaDoc(key));
142         }
143         else
144         {
145             user.setThreadKey(null);
146         }
147         
148         // remove any report that was aborted
149
String JavaDoc reportKey = parameters.getString(ScarabConstants.REMOVE_CURRENT_REPORT);
150         if (reportKey != null && reportKey.length() > 0)
151         {
152             user.setCurrentReport(reportKey, null);
153         }
154
155         // remove the current module/issuetype list, if needed
156
String JavaDoc removeMitKey =
157             parameters.getString(ScarabConstants.REMOVE_CURRENT_MITLIST_QKEY);
158         String JavaDoc target = data.getTarget();
159         boolean xmitScreen =XMIT_SCREENS.containsKey(target);
160         if (removeMitKey != null
161             || !xmitScreen)
162         {
163             Log.get().debug("xmit list set to null");
164             user.setCurrentMITList(null);
165         }
166
167         // override the current module/issuetype list if one is given
168
// in the url.
169
String JavaDoc mitid = parameters.getString(ScarabConstants.CURRENT_MITLIST_ID);
170         if (mitid != null)
171         {
172             MITList mitList = null;
173             try
174             {
175                 // FIXME: no getInstance(Integer)
176
mitList = MITListManager.getInstance(new NumberKey(mitid));
177                 user.setCurrentMITList(mitList);
178                 mitList.setScarabUser(user);
179             }
180             catch (TorqueException e)
181             {
182                 throw new TurbineException(e); //EXCEPTION
183
}
184         }
185
186         // Pass control to the next Valve in the Pipeline
187
context.invokeNext(data);
188     }
189
190     private void adjustCurrentModule(ScarabUser user, RunData data)
191         throws TurbineException, Exception JavaDoc
192     {
193         Module module = null;
194         ParameterParser parameters = data.getParameters();
195         String JavaDoc key = parameters.getString(ScarabConstants.CURRENT_MODULE);
196         if (key != null)
197         {
198             try
199             {
200                 module = ModuleManager.getInstance(new Integer JavaDoc(key));
201             }
202             catch (Exception JavaDoc e)
203             {
204                 throw new TurbineException(e); //EXCEPTION
205
}
206         }
207         else if (parameters.getString("id") != null)
208         {
209             try
210             {
211                 module = IssueManager.getIssueById(parameters.getString("id")).getModule();
212                 parameters.setString(ScarabConstants.CURRENT_MODULE,
213                              module.getQueryKey());
214             }
215             catch (Exception JavaDoc e)
216             {
217                 // ignore
218
Log.get().debug("'id' parameter was available, "
219                     + parameters.getString("id") +
220                     ", but did not contain enough info to create issue.");
221             }
222         }
223         if(module!=null)
224         {
225             user.setCurrentModule(module);
226         }
227     }
228
229     /**
230      * Sets the current issue type if its value changed in the RunData instance.
231      * If the RunData instance does not contain an issueType, this method
232      * returns without doing anything.
233      *
234      * @param user
235      * @param data
236      * @throws TurbineException
237      */

238     private void adjustCurrentIssueType(ScarabUser user, RunData data)
239         throws TurbineException
240     {
241         IssueType issueType = null;
242         ParameterParser parameters = data.getParameters();
243         String JavaDoc key = parameters.getString(ScarabConstants.CURRENT_ISSUE_TYPE);
244         if (key != null && key.length() > 0)
245         {
246             try
247             {
248                 issueType = IssueTypeManager.getInstance(new Integer JavaDoc(key));
249                 if (Log.get().isDebugEnabled())
250                 {
251                     Log.get().debug("setting issue type: " +
252                          issueType.getName() + " based on curit");
253                 }
254             }
255             catch (NumberFormatException JavaDoc noIssueType)
256             {
257             }
258             catch (Exception JavaDoc e)
259             {
260                 throw new TurbineException(e); //EXCEPTION
261
}
262         }
263         else
264         {
265             String JavaDoc templateId = data.getParameters().getString("templateId");
266             if (templateId != null && templateId.length() > 0)
267             {
268                 try
269                 {
270                     IssueType templateType = IssueManager.getInstance(
271                         new Long JavaDoc(templateId)).getIssueType();
272                     issueType = templateType.getIssueTypeForTemplateType();
273                     parameters.setString(ScarabConstants.CURRENT_ISSUE_TYPE,
274                                          issueType.getQueryKey());
275                     if (Log.get().isDebugEnabled())
276                     {
277                         Log.get().debug("setting issue type: " +
278                             issueType.getName() + " based on template");
279                     }
280                 }
281                 catch (Exception JavaDoc e)
282                 {
283                     Log.get().warn("'templateId' parameter was available, "
284                         + parameters.getString("templateId") +
285                         ", but invalid.", e);
286                 }
287             }
288         }
289         
290         if(issueType != null)
291         {
292             user.setCurrentIssueType(issueType);
293         }
294
295     }
296         
297 }
298
Popular Tags