1 package org.tigris.scarab.actions; 2 3 48 49 import java.util.List ; 50 import java.util.ArrayList ; 51 52 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 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 85 public class DefineXModuleList extends RequireLoginFirstAction 86 { 87 public void doGotoquerywithinternallist(RunData data, 88 TemplateContext context) 89 throws Exception 90 { 91 ScarabRequestTool scarabR = getScarabRequestTool(context); 92 ScarabLocalizationTool l10n = getLocalizationTool(context); 93 String 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 (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 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 131 { 132 addSelectedRMITs(data, context); 134 ScarabUser user = (ScarabUser)data.getUser(); 135 MITList currentList = user.getCurrentMITList(); 136 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 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 190 { 191 ScarabRequestTool scarabR = getScarabRequestTool(context); 192 String 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 } 202 } 203 204 public void doRemoveitemsfromlist(RunData data, TemplateContext context) 205 throws Exception 206 { 207 ScarabRequestTool scarabR = getScarabRequestTool(context); 208 ScarabLocalizationTool l10n = getLocalizationTool(context); 209 ScarabUser user = (ScarabUser)data.getUser(); 210 String [] 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 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 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 254 { 255 ((ScarabUser)data.getUser()).setCurrentMITList(null); 256 } 257 258 public void doSavelist(RunData data, TemplateContext context) 259 throws Exception 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 MITList oldList = MITListManager 274 .getInstanceByName(list.getName(), user); 275 if (oldList != null) 276 { 277 if (!list.equals(oldList)) 280 { 281 oldList.setActive(false); 282 oldList.save(); 283 } 284 } 285 list.save(); 287 288 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 300 { 301 ScarabRequestTool scarabR = getScarabRequestTool(context); 302 ScarabLocalizationTool l10n = getLocalizationTool(context); 303 String [] rmitIds = data.getParameters().getStrings("rmitid"); 304 String 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 334 { 335 ScarabRequestTool scarabR = getScarabRequestTool(context); 336 ScarabLocalizationTool l10n = getLocalizationTool(context); 337 338 String 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 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 [] rmitIds = data.getParameters().getStrings("rmitid"); 360 if (rmitIds != null && rmitIds.length != 0) 361 { 362 List rmits = new ArrayList (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 e) 380 { 381 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 MITList mitlist = user.getCurrentMITList(); 400 if (mitlist != null) 401 { 402 mitlist.setScarabUser(user); 403 } 404 } 405 406 private void setAndGetCurrentList(String 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 (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 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 434 { 435 String flag = data.getParameters() 436 .getString("eventSubmit_doToggleothermodules"); 437 ((ScarabUser)data.getUser()).setShowOtherModulesInIssueTypeList( 438 "show".equals(flag)); 439 } 440 } 441 | Popular Tags |