1 package org.tigris.scarab.actions.admin; 2 3 48 49 import java.util.List ; 50 51 import org.apache.fulcrum.intake.model.Field; 52 import org.apache.fulcrum.intake.model.Group; 53 import org.apache.fulcrum.parser.ParameterParser; 54 import org.apache.torque.om.NumberKey; 55 import org.apache.turbine.RunData; 56 import org.apache.turbine.TemplateContext; 57 import org.apache.turbine.tool.IntakeTool; 58 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 59 import org.tigris.scarab.om.Attribute; 60 import org.tigris.scarab.om.AttributeGroup; 61 import org.tigris.scarab.om.AttributeGroupManager; 62 import org.tigris.scarab.om.AttributeManager; 63 import org.tigris.scarab.om.IssueType; 64 import org.tigris.scarab.om.IssueTypePeer; 65 import org.tigris.scarab.om.RIssueTypeAttribute; 66 import org.tigris.scarab.services.cache.ScarabCache; 67 import org.tigris.scarab.tools.ScarabLocalizationTool; 68 import org.tigris.scarab.tools.ScarabRequestTool; 69 import org.tigris.scarab.util.Log; 70 71 77 public class GlobalArtifactTypeCreate extends RequireLoginFirstAction 78 { 79 80 83 public boolean doSaveinfo(RunData data, TemplateContext context) 84 throws Exception 85 { 86 boolean success = true; 87 IntakeTool intake = getIntakeTool(context); 88 ScarabRequestTool scarabR = getScarabRequestTool(context); 89 ScarabLocalizationTool l10n = getLocalizationTool(context); 90 IssueType issueType = getScarabRequestTool(context).getIssueType(); 91 if (issueType.isSystemDefined()) 92 { 93 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 94 return false; 95 } 96 Group group = intake.get("IssueType", issueType.getQueryKey()); 97 Field field = group.get("Name"); 98 String name = field.toString(); 99 Integer id = issueType.getIssueTypeId(); 100 101 if (intake.isAllValid()) 102 { 103 if (id == null) 104 { 105 if (IssueTypePeer.isUnique(name, null)) 108 { 109 group.setProperties(issueType); 110 issueType.setParentId(IssueTypePeer.getRootKey()); 111 issueType.save(); 112 113 issueType.createDefaultGroups(); 115 116 IssueType template = new IssueType(); 118 template.setName(issueType.getName() + " Template"); 119 template.setParentId(issueType.getIssueTypeId()); 120 template.save(); 121 } 122 else 123 { 124 scarabR.setAlertMessage(l10n.get("IssueTypeNameExists")); 125 } 126 } 127 else 128 { 129 if (IssueTypePeer.isUnique(name, id)) 131 { 132 Field deleted = group.get("Deleted"); 134 if (deleted != null && deleted.toString().equals("true") 135 && issueType.hasIssues()) 136 { 137 scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE)); 138 deleted.setMessage("IssueTypeHasIssues"); 139 success = false; 140 } 141 else 142 { 143 group.setProperties(issueType); 144 issueType.save(); 145 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 146 } 147 } 148 else 149 { 150 success = false; 151 scarabR.setAlertMessage(l10n.get("IssueTypeNameExists")); 152 } 153 } 154 } 155 else 156 { 157 scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE)); 158 success = false; 159 } 160 return success; 161 } 162 163 164 167 public boolean doSavegroups (RunData data, TemplateContext context) 168 throws Exception 169 { 170 boolean success = true; 171 IntakeTool intake = getIntakeTool(context); 172 ScarabRequestTool scarabR = getScarabRequestTool(context); 173 ScarabLocalizationTool l10n = getLocalizationTool(context); 174 IssueType issueType = scarabR.getIssueType(); 175 if (issueType.isSystemDefined()) 176 { 177 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 178 return false; 179 } 180 List attGroups = issueType.getAttributeGroups(null, false); 181 int nbrAttGroups = attGroups.size(); 182 int dupeOrder = 2; 183 184 if (issueType.getAttributeGroups(null, true).size() > 1) 187 { 188 dupeOrder = data.getParameters().getInt("dupe_order"); 189 190 if (dupeOrder == 1) 192 { 193 scarabR.setAlertMessage(l10n.get("CannotPositionDuplicateCheckFirst")); 194 return false; 195 } 196 197 if (areThereDupeSequences(attGroups, intake, "AttributeGroup", 199 "Order", dupeOrder)) 200 { 201 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound", 202 l10n.get("AttributeGroups").toLowerCase())); 203 return false; 204 } 205 } 206 207 if (intake.isAllValid()) 208 { 209 boolean areThereDedupeAttrs = false; 210 for (int i = nbrAttGroups - 1; i >= 0; i--) 212 { 213 AttributeGroup attGroup = (AttributeGroup)attGroups.get(i); 214 Group agGroup = intake.get("AttributeGroup", 215 attGroup.getQueryKey(), false); 216 agGroup.setProperties(attGroup); 217 218 areThereDedupeAttrs = attGroup.getOrder() < dupeOrder; 224 attGroup.setDedupe(areThereDedupeAttrs); 225 attGroup.save(); 226 } 227 if (areThereDedupeAttrs) 228 { 229 Group itGroup = intake.get("IssueType", 230 issueType.getQueryKey(), false); 231 Field dedupe = itGroup.get("Dedupe"); 232 dedupe.setProperty(issueType); 233 } 234 issueType.save(); 235 ScarabCache.clear(); 236 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 237 } 238 else 239 { 240 scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE)); 241 success = false; 242 } 243 return success; 244 } 245 246 249 public void doCreatenewuserattribute(RunData data, 250 TemplateContext context) 251 throws Exception 252 { 253 IntakeTool intake = getIntakeTool(context); 254 ScarabRequestTool scarabR = getScarabRequestTool(context); 255 ScarabLocalizationTool l10n = getLocalizationTool(context); 256 IssueType issueType = scarabR.getIssueType(); 257 if (issueType.isSystemDefined()) 258 { 259 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 260 return; 261 } 262 Group attGroup = intake.get("Attribute", IntakeTool.DEFAULT_KEY); 263 intake.remove(attGroup); 264 scarabR.setAttribute(null); 265 setTarget(data, getOtherTemplate(data)); 266 } 267 268 271 public AttributeGroup doCreatenewgroup (RunData data, 272 TemplateContext context) 273 throws Exception 274 { 275 ScarabRequestTool scarabR = getScarabRequestTool(context); 276 ScarabLocalizationTool l10n = getLocalizationTool(context); 277 IssueType issueType = scarabR.getIssueType(); 278 if (issueType.isSystemDefined()) 279 { 280 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 281 return null; 282 } 283 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 284 return issueType.createNewGroup(); 285 } 286 287 290 public void doDeletegroup (RunData data, TemplateContext context) 291 throws Exception 292 { 293 ParameterParser params = data.getParameters(); 294 Object [] keys = params.getKeys(); 295 String key; 296 String groupId; 297 ScarabRequestTool scarabR = getScarabRequestTool(context); 298 ScarabLocalizationTool l10n = getLocalizationTool(context); 299 IssueType issueType = scarabR.getIssueType(); 300 if (issueType.isSystemDefined()) 301 { 302 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 303 return; 304 } 305 List attributeGroups = issueType.getAttributeGroups(null, false); 306 307 boolean atLeastOne = false; 308 for (int i =0; i<keys.length; i++) 309 { 310 key = keys[i].toString(); 311 if (key.startsWith("group_action")) 312 { 313 atLeastOne = true; 314 groupId = key.substring(13); 315 AttributeGroup ag = AttributeGroupManager 316 .getInstance(new NumberKey(groupId), false); 317 if (Log.get().isDebugEnabled()) 318 { 319 Log.get().info("Deleting attribute group: " + groupId); 320 } 321 ag.delete(); 322 ScarabCache.clear(); 323 } 324 } 325 if (atLeastOne) 326 { 327 scarabR.setConfirmMessage(l10n.get("SelectedGroupDeleted")); 328 if (attributeGroups.size() -1 < 2) 331 { 332 issueType.setDedupe(false); 335 issueType.save(); 336 } 337 } 338 else 339 { 340 scarabR.setAlertMessage(l10n.get("NoGroupSelected")); 341 } 342 } 343 344 347 public void doSelectuserattribute(RunData data, TemplateContext context) 348 throws Exception 349 { 350 ScarabRequestTool scarabR = getScarabRequestTool(context); 351 ScarabLocalizationTool l10n = getLocalizationTool(context); 352 IssueType issueType = scarabR.getIssueType(); 353 if (issueType.isSystemDefined()) 354 { 355 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 356 return; 357 } 358 String [] attributeIds = data.getParameters() 359 .getStrings("attribute_ids"); 360 361 if (attributeIds == null || attributeIds.length <= 0) 362 { 363 scarabR.setAlertMessage(l10n.get("SelectAttribute")); 364 return; 365 } 366 else 367 { 368 for (int i=0; i < attributeIds.length; i++) 369 { 370 Attribute attribute = 371 scarabR.getAttribute(new Integer (attributeIds[i])); 372 if (attribute != null) 373 { 374 issueType.addRIssueTypeAttribute(attribute); 376 } 377 doCancel(data, context); 378 ScarabCache.clear(); 379 } 380 } 381 } 382 383 386 public void doDeleteuserattribute(RunData data, TemplateContext context) 387 throws Exception 388 { 389 ScarabRequestTool scarabR = getScarabRequestTool(context); 390 ScarabLocalizationTool l10n = getLocalizationTool(context); 391 ParameterParser params = data.getParameters(); 392 IssueType issueType = scarabR.getIssueType(); 393 if (issueType.isSystemDefined()) 394 { 395 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 396 return; 397 } 398 Object [] keys = params.getKeys(); 399 String key; 400 String attributeId; 401 boolean atLeastOne = false; 402 403 for (int i =0; i<keys.length; i++) 404 { 405 key = keys[i].toString(); 406 if (key.startsWith("att_delete_")) 407 { 408 atLeastOne = true; 409 attributeId = key.substring(11); 410 Attribute attribute = AttributeManager 411 .getInstance(new NumberKey(attributeId), false); 412 413 RIssueTypeAttribute ria = issueType 415 .getRIssueTypeAttribute(attribute); 416 try 417 { 418 ria.delete(); 419 } 420 catch (Exception e) 421 { 422 scarabR.setAlertMessage(l10n.get(NO_PERMISSION_MESSAGE)); 423 } 424 425 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 426 ScarabCache.clear(); 427 } 428 } 429 if (!atLeastOne) 430 { 431 scarabR.setAlertMessage(l10n.get("NoAttributesSelected")); 432 } 433 } 434 435 438 public boolean doSaveuserattributes (RunData data, TemplateContext context) 439 throws Exception 440 { 441 IntakeTool intake = getIntakeTool(context); 442 ScarabRequestTool scarabR = getScarabRequestTool(context); 443 IssueType issueType = scarabR.getIssueType(); 444 ScarabLocalizationTool l10n = getLocalizationTool(context); 445 if (issueType.isSystemDefined()) 446 { 447 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 448 return false; 449 } 450 if (intake.isAllValid()) 451 { 452 List rias = issueType.getRIssueTypeAttributes(false,"user"); 453 if (areThereDupeSequences(rias, intake, "RIssueTypeAttribute", 454 "Order", 0)) 455 { 456 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound", 457 l10n.get("UserAttributes").toLowerCase())); 458 return false; 459 } 460 for (int i=0; i < rias.size(); i++) 461 { 462 RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i); 464 Group riaGroup = intake.get("RIssueTypeAttribute", 465 ria.getQueryKey(), false); 466 riaGroup.setProperties(ria); 467 ria.save(); 468 } 469 getScarabRequestTool(context) 470 .setConfirmMessage(l10n.get(DEFAULT_MSG)); 471 } 472 return true; 473 } 474 475 478 public void doDone(RunData data, TemplateContext context) 479 throws Exception 480 { 481 boolean success = doSaveinfo(data, context) && 482 doSavegroups(data, context) && 483 doSaveuserattributes(data, context); 484 if (success) 485 { 486 doCancel(data, context); 487 } 488 else 490 { 491 getScarabRequestTool(context).setConfirmMessage(null); 492 } 493 } 494 495 499 500 public void doGotoothertemplate(RunData data, 501 TemplateContext context) 502 throws Exception 503 { 504 ScarabRequestTool scarabR = getScarabRequestTool(context); 505 IssueType issueType = scarabR.getIssueType(); 506 ScarabLocalizationTool l10n = getLocalizationTool(context); 507 if (issueType.isSystemDefined()) 508 { 509 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 510 return; 511 } 512 super.doGotoothertemplate(data,context); 513 } 514 } 515 | Popular Tags |