1 package org.tigris.scarab.actions.admin; 2 3 48 49 import java.util.Iterator ; 50 import java.util.List ; 51 52 import org.apache.fulcrum.intake.model.Field; 53 import org.apache.fulcrum.intake.model.Group; 54 import org.apache.fulcrum.parser.ParameterParser; 55 import org.apache.torque.om.NumberKey; 56 import org.apache.turbine.RunData; 57 import org.apache.turbine.TemplateContext; 58 import org.apache.turbine.tool.IntakeTool; 59 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 60 import org.tigris.scarab.om.Attribute; 61 import org.tigris.scarab.om.AttributeGroup; 62 import org.tigris.scarab.om.AttributeGroupManager; 63 import org.tigris.scarab.om.AttributeManager; 64 import org.tigris.scarab.om.IssueType; 65 import org.tigris.scarab.om.Module; 66 import org.tigris.scarab.om.RModuleAttribute; 67 import org.tigris.scarab.om.RModuleIssueType; 68 import org.tigris.scarab.services.cache.ScarabCache; 69 import org.tigris.scarab.tools.ScarabLocalizationTool; 70 import org.tigris.scarab.tools.ScarabRequestTool; 71 import org.tigris.scarab.tools.localization.L10NKeySet; 72 import org.tigris.scarab.workflow.WorkflowFactory; 73 74 80 public class ArtifactTypeEdit extends RequireLoginFirstAction 81 { 82 85 public boolean doSaveinfo (RunData data, TemplateContext context) 86 throws Exception 87 { 88 boolean success = true; 89 ScarabRequestTool scarabR = getScarabRequestTool(context); 90 ScarabLocalizationTool l10n = getLocalizationTool(context); 91 IssueType issueType = scarabR.getIssueType(); 92 if (issueType.isSystemDefined()) 93 { 94 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 95 return false; 96 } 97 if (issueType.getLocked()) 98 { 99 scarabR.setAlertMessage(L10NKeySet.LockedIssueType); 100 return false; 101 } 102 IntakeTool intake = getIntakeTool(context); 103 Module module = scarabR.getCurrentModule(); 104 RModuleIssueType rmit = module.getRModuleIssueType(issueType); 105 if (rmit == null) 106 { 107 scarabR.setAlertMessage(L10NKeySet.IssueTypeRemovedFromModule); 108 doCancel(data, context); 109 return false; 110 } 111 Group rmitGroup = intake.get("RModuleIssueType", 113 rmit.getQueryKey(), false); 114 if (intake.isAllValid()) 115 { 116 boolean nameTaken = false; 117 List issueTypes = module.getRModuleIssueTypes(); 118 if (issueTypes != null) 119 { 120 Field displayName = rmitGroup.get("DisplayName"); 121 if (displayName.toString().trim().length() == 0) 122 { 123 displayName.setMessage("intake_IssueTypeNameNotAllowedEmpty"); 124 scarabR.setAlertMessage(ERROR_MESSAGE); 125 return false; 126 } 127 for (int i=0;i<issueTypes.size();i++) 128 { 129 RModuleIssueType tmpRmit = ((RModuleIssueType)issueTypes.get(i)); 130 if (tmpRmit.getDisplayName().equals(displayName.toString()) 131 && !tmpRmit.getIssueTypeId().equals(issueType.getIssueTypeId())) 132 { 133 nameTaken = true; 134 break; 135 } 136 } 137 } 138 139 if (nameTaken) 140 { 141 scarabR.setAlertMessage(ERROR_MESSAGE); 142 rmitGroup.get("DisplayName").setMessage("IssueTypeNameExists"); 143 return false; 144 } 145 else 146 { 147 rmitGroup.setProperties(rmit); 148 rmit.save(); 149 scarabR.setConfirmMessage(DEFAULT_MSG); 150 } 151 } 152 else 153 { 154 scarabR.setAlertMessage(ERROR_MESSAGE); 155 return false; 156 } 157 return success; 158 } 159 160 163 public boolean doSavegroups (RunData data, TemplateContext context) 164 throws Exception 165 { 166 IntakeTool intake = getIntakeTool(context); 167 ScarabRequestTool scarabR = getScarabRequestTool(context); 168 ScarabLocalizationTool l10n = getLocalizationTool(context); 169 170 IssueType issueType = scarabR.getIssueType(); 171 if (issueType.isSystemDefined()) 172 { 173 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 174 return false; 175 } 176 if (issueType.getLocked()) 177 { 178 scarabR.setAlertMessage(L10NKeySet.LockedIssueType); 179 return false; 180 } 181 182 Module module = scarabR.getCurrentModule(); 183 RModuleIssueType rmit = module.getRModuleIssueType(issueType); 184 if (rmit == null) 185 { 186 scarabR.setAlertMessage(L10NKeySet.IssueTypeRemovedFromModule); 187 doCancel(data, context); 188 return false; 189 } 190 List attGroups = issueType.getAttributeGroups(module, false); 191 192 int dupeOrder = 2; 193 boolean areThereDedupeAttrs = false; 194 195 if (issueType.getAttributeGroups(module, true).size() > 1) 198 { 199 dupeOrder = data.getParameters().getInt("dupe_order"); 200 201 if (dupeOrder == 1) 203 { 204 scarabR.setAlertMessage(L10NKeySet.CannotPositionDuplicateCheckFirst); 205 return false; 206 } 207 if (areThereDupeSequences(attGroups, intake, "AttributeGroup", 209 "Order", dupeOrder)) 210 { 211 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound", 212 l10n.get("AttributeGroups").toLowerCase())); 213 return false; 214 } 215 } 216 217 for (int i=attGroups.size()-1; i>=0; i--) 219 { 220 AttributeGroup attGroup = (AttributeGroup)attGroups.get(i); 221 Group agGroup = intake.get("AttributeGroup", 222 attGroup.getQueryKey(), false); 223 agGroup.setProperties(attGroup); 224 225 if (attGroup.getOrder() < dupeOrder) 228 { 229 areThereDedupeAttrs = true; 230 attGroup.setDedupe(true); 231 List dedupeGroups = module. 232 getDedupeGroupsWithAttributes(issueType); 233 if (!dedupeGroups.contains(attGroup)) 234 { 235 dedupeGroups.add(attGroup); 236 } 237 } 238 else 239 { 240 attGroup.setDedupe(false); 241 } 242 attGroup.save(); 243 } 244 245 if (!areThereDedupeAttrs 247 || issueType.getAttributeGroups(module, true).size() < 2) 248 { 249 rmit.setDedupe(false); 250 } 251 else 252 { 253 Group rmitGroup = intake.get("RModuleIssueType", 254 rmit.getQueryKey(), false); 255 Field dedupe = rmitGroup.get("Dedupe"); 256 dedupe.setProperty(rmit); 257 } 258 rmit.save(); 259 ScarabCache.clear(); 260 scarabR.setConfirmMessage(DEFAULT_MSG); 261 262 return true; 263 } 264 265 268 public boolean doSaveuserattributes (RunData data, TemplateContext context) 269 throws Exception 270 { 271 IntakeTool intake = getIntakeTool(context); 272 ScarabRequestTool scarabR = getScarabRequestTool(context); 273 ScarabLocalizationTool l10n = getLocalizationTool(context); 274 IssueType issueType = scarabR.getIssueType(); 275 boolean success = true; 276 277 if (issueType.isSystemDefined()) 278 { 279 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 280 success = false; 281 } 282 else if (issueType.getLocked()) 283 { 284 scarabR.setAlertMessage(L10NKeySet.LockedIssueType); 285 success = false; 286 } 287 else 288 { 289 Module module = scarabR.getCurrentModule(); 290 List rmas = module.getRModuleAttributes(issueType, false, "user"); 291 if (areThereDupeSequences(rmas, intake, "RModuleAttribute", 292 "Order", 0)) 293 { 294 scarabR.setAlertMessage( 295 l10n.format("DuplicateSequenceNumbersFound", 296 l10n.get("UserAttributes").toLowerCase())); 297 success = false; 298 } 299 else 300 { 301 for (Iterator itr = rmas.iterator(); itr.hasNext(); ) 302 { 303 RModuleAttribute rma = (RModuleAttribute)itr.next(); 305 Group rmaGroup = intake.get("RModuleAttribute", 306 rma.getQueryKey(), false); 307 boolean newActive = Boolean.valueOf(rmaGroup.get("Active"). 309 toString()).booleanValue(); 310 boolean oldActive = rma.getActive(); 311 if (!newActive && oldActive) 312 { 313 WorkflowFactory.getInstance(). 314 deleteWorkflowsForAttribute( 315 rma.getAttribute(), module, issueType); 316 } 317 rmaGroup.setProperties(rma); 318 rma.save(); 319 } 320 scarabR.setConfirmMessage(DEFAULT_MSG); 321 } 322 323 } 324 return success; 325 } 326 327 330 public AttributeGroup doCreatenewgroup (RunData data, 331 TemplateContext context) 332 throws Exception 333 { 334 ScarabRequestTool scarabR = getScarabRequestTool(context); 335 ScarabLocalizationTool l10n = getLocalizationTool(context); 336 Module module = scarabR.getCurrentModule(); 337 IssueType issueType = scarabR.getIssueType(); 338 if (issueType.isSystemDefined()) 339 { 340 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 341 return null; 342 } 343 scarabR.setConfirmMessage(DEFAULT_MSG); 344 return issueType.createNewGroup(module); 345 } 346 347 350 public void doDeletegroup (RunData data, TemplateContext context) 351 throws Exception 352 { 353 ScarabRequestTool scarabR = getScarabRequestTool(context); 354 ScarabLocalizationTool l10n = getLocalizationTool(context); 355 IssueType issueType = scarabR.getIssueType(); 356 boolean noAGSelected = true; 357 if (issueType.isSystemDefined()) 358 { 359 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 360 return; 361 } 362 if (issueType.getLocked()) 363 { 364 scarabR.setAlertMessage(L10NKeySet.LockedIssueType); 365 return; 366 } 367 368 ParameterParser params = data.getParameters(); 369 Object [] keys = params.getKeys(); 370 String key; 371 String groupId; 372 Module module = scarabR.getCurrentModule(); 373 List attributeGroups = issueType.getAttributeGroups(module, false); 374 375 for (int i =0; i<keys.length; i++) 376 { 377 key = keys[i].toString(); 378 if (key.startsWith("group_action")) 379 { 380 try 381 { 382 groupId = key.substring(13); 383 AttributeGroup ag = AttributeGroupManager 384 .getInstance(new NumberKey(groupId), false); 385 ag.delete(); 386 noAGSelected = false; 387 scarabR.setConfirmMessage(DEFAULT_MSG); 388 ScarabCache.clear(); 389 getIntakeTool(context).removeAll(); 390 } 391 catch (Exception e) 392 { 393 scarabR.setAlertMessage(NO_PERMISSION_MESSAGE); 394 } 395 if (attributeGroups.size() -1 < 2) 396 { 397 RModuleIssueType rmit = module.getRModuleIssueType(issueType); 400 rmit.setDedupe(false); 401 rmit.save(); 402 } 403 } 404 } 405 if (noAGSelected) 406 { 407 scarabR.setAlertMessage(L10NKeySet.NoAttributeGroupSelected); 408 } 409 } 410 411 412 415 public void doDeleteuserattribute(RunData data, TemplateContext context) 416 throws Exception 417 { 418 ScarabRequestTool scarabR = getScarabRequestTool(context); 419 ScarabLocalizationTool l10n = getLocalizationTool(context); 420 IssueType issueType = scarabR.getIssueType(); 421 boolean hasAttributes = false; 422 if (issueType.isSystemDefined()) 423 { 424 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 425 return; 426 } 427 if (issueType.getLocked()) 428 { 429 scarabR.setAlertMessage(L10NKeySet.LockedIssueType); 430 return; 431 } 432 Module module = scarabR.getCurrentModule(); 433 ParameterParser params = data.getParameters(); 434 Object [] keys = params.getKeys(); 435 String key; 436 String attributeId; 437 438 for (int i =0; i<keys.length; i++) 439 { 440 key = keys[i].toString(); 441 if (key.startsWith("att_delete_")) 442 { 443 hasAttributes = true; 444 attributeId = key.substring(11); 445 Attribute attribute = AttributeManager 446 .getInstance(new NumberKey(attributeId), false); 447 448 RModuleAttribute rma = module 450 .getRModuleAttribute(attribute, issueType); 451 rma.delete(); 452 453 RModuleAttribute rma2 = module 455 .getRModuleAttribute(attribute, 456 scarabR.getIssueType(issueType.getTemplateId().toString())); 457 rma2.delete(); 458 scarabR.setConfirmMessage(DEFAULT_MSG); 459 ScarabCache.clear(); 460 } 461 } 462 if(!hasAttributes) 463 { 464 scarabR.setAlertMessage(L10NKeySet.NoUserAttributeSelected); 465 } 466 } 467 468 469 public void doCreatenewuserattribute(RunData data, 470 TemplateContext context) 471 throws Exception 472 { 473 IntakeTool intake = getIntakeTool(context); 474 ScarabRequestTool scarabR = getScarabRequestTool(context); 475 IssueType issueType = scarabR.getIssueType(); 476 if (issueType.isSystemDefined()) 477 { 478 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 479 return; 480 } 481 Group attGroup = intake.get("Attribute", IntakeTool.DEFAULT_KEY); 482 intake.remove(attGroup); 483 scarabR.setAttribute(null); 484 setTarget(data, getOtherTemplate(data)); 485 } 486 487 490 public void doSelectuserattribute(RunData data, TemplateContext context) 491 throws Exception 492 { 493 ScarabRequestTool scarabR = getScarabRequestTool(context); 494 ScarabLocalizationTool l10n = getLocalizationTool(context); 495 IssueType issueType = scarabR.getIssueType(); 496 if (issueType.isSystemDefined()) 497 { 498 scarabR.setAlertMessage(L10NKeySet.SystemSpecifiedIssueType); 499 return; 500 } 501 if (issueType.getLocked()) 502 { 503 scarabR.setAlertMessage(L10NKeySet.LockedIssueType); 504 return; 505 } 506 507 Module module = scarabR.getCurrentModule(); 508 String [] attributeIds = data.getParameters() 509 .getStrings("attribute_ids"); 510 511 if (attributeIds == null || attributeIds.length <= 0) 512 { 513 scarabR.setAlertMessage(L10NKeySet.SelectAttribute); 514 return; 515 } 516 else 517 { 518 for (int i=0; i < attributeIds.length; i++) 519 { 520 Attribute attribute = 521 scarabR.getAttribute(new Integer (attributeIds[i])); 522 if (attribute != null) 523 { 524 module.addRModuleAttribute(issueType,attribute); 526 } 527 doCancel(data, context); 528 } 529 } 530 } 531 532 535 public void doDone(RunData data, TemplateContext context) 536 throws Exception 537 { 538 boolean success = doSaveinfo(data, context) && 539 doSavegroups(data, context) && 540 doSaveuserattributes(data, context); 541 if (success) 542 { 543 doCancel(data, context); 544 } 545 else 547 { 548 getScarabRequestTool(context).setConfirmMessage(null); 549 } 550 } 551 552 } 553 | Popular Tags |