1 package org.tigris.scarab.pipeline; 2 3 48 49 import java.io.IOException ; 50 import java.util.HashMap ; 51 import java.util.Map ; 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 77 public class FreshenUserValve 78 extends AbstractValve 79 { 80 protected static final Map XMIT_SCREENS = new HashMap (); 81 82 83 public void initialize() throws Exception { 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 XMIT_SCREENS.put("IssueListExport.vm", null); 102 103 } 104 105 108 public void invoke(RunData data, ValveContext context) 109 throws IOException , TurbineException 110 { 111 ScarabUser user = (ScarabUser)data.getUser(); 112 113 try 114 { 115 if(user.isPasswordExpired()) 117 { 118 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 e) 130 { 131 Log.get().error("", e); 132 } 135 136 ParameterParser parameters = data.getParameters(); 138 String key = parameters.getString(ScarabConstants.THREAD_QUERY_KEY); 139 if (key != null) 140 { 141 user.setThreadKey(new Integer (key)); 142 } 143 else 144 { 145 user.setThreadKey(null); 146 } 147 148 String reportKey = parameters.getString(ScarabConstants.REMOVE_CURRENT_REPORT); 150 if (reportKey != null && reportKey.length() > 0) 151 { 152 user.setCurrentReport(reportKey, null); 153 } 154 155 String removeMitKey = 157 parameters.getString(ScarabConstants.REMOVE_CURRENT_MITLIST_QKEY); 158 String 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 String mitid = parameters.getString(ScarabConstants.CURRENT_MITLIST_ID); 170 if (mitid != null) 171 { 172 MITList mitList = null; 173 try 174 { 175 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); } 184 } 185 186 context.invokeNext(data); 188 } 189 190 private void adjustCurrentModule(ScarabUser user, RunData data) 191 throws TurbineException, Exception 192 { 193 Module module = null; 194 ParameterParser parameters = data.getParameters(); 195 String key = parameters.getString(ScarabConstants.CURRENT_MODULE); 196 if (key != null) 197 { 198 try 199 { 200 module = ModuleManager.getInstance(new Integer (key)); 201 } 202 catch (Exception e) 203 { 204 throw new TurbineException(e); } 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 e) 216 { 217 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 238 private void adjustCurrentIssueType(ScarabUser user, RunData data) 239 throws TurbineException 240 { 241 IssueType issueType = null; 242 ParameterParser parameters = data.getParameters(); 243 String key = parameters.getString(ScarabConstants.CURRENT_ISSUE_TYPE); 244 if (key != null && key.length() > 0) 245 { 246 try 247 { 248 issueType = IssueTypeManager.getInstance(new Integer (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 noIssueType) 256 { 257 } 258 catch (Exception e) 259 { 260 throw new TurbineException(e); } 262 } 263 else 264 { 265 String templateId = data.getParameters().getString("templateId"); 266 if (templateId != null && templateId.length() > 0) 267 { 268 try 269 { 270 IssueType templateType = IssueManager.getInstance( 271 new Long (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 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 |