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.turbine.RunData; 55 import org.apache.turbine.TemplateContext; 56 import org.apache.turbine.tool.IntakeTool; 57 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 58 import org.tigris.scarab.om.IssueType; 59 import org.tigris.scarab.om.Module; 60 import org.tigris.scarab.om.RModuleIssueType; 61 import org.tigris.scarab.om.ScarabUser; 62 import org.tigris.scarab.services.cache.ScarabCache; 63 import org.tigris.scarab.tools.ScarabLocalizationTool; 64 import org.tigris.scarab.tools.ScarabRequestTool; 65 import org.tigris.scarab.util.Log; 66 67 76 public class ManageArtifactTypes extends RequireLoginFirstAction 77 { 78 81 public synchronized void doSave (RunData data, TemplateContext context) 82 throws Exception 83 { 84 IntakeTool intake = getIntakeTool(context); 85 ScarabRequestTool scarabR = getScarabRequestTool(context); 86 ScarabLocalizationTool l10n = getLocalizationTool(context); 87 88 Module module = scarabR.getCurrentModule(); 89 List rmits = module.getRModuleIssueTypes(); 90 int navCount = 0; 91 Group rmitGroup = null; 92 93 if (areThereDupeSequences(rmits, intake, "RModuleIssueType", "Order", 0)) 94 { 95 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound", 96 l10n.get("IssueTypes").toLowerCase())); 97 return; 98 } 99 100 if (intake.isAllValid()) 101 { 102 for (int i=0;i < rmits.size(); i++) 103 { 104 RModuleIssueType rmit = (RModuleIssueType)rmits.get(i); 105 rmitGroup = intake.get("RModuleIssueType", 106 rmit.getQueryKey(), false); 107 Field display = rmitGroup.get("Display"); 108 109 if (display.toString().equals("true")) 110 { 111 navCount++; 112 } 113 if (navCount > 5) 114 { 115 scarabR.setAlertMessage(l10n.get("NavIssueTypeLimit")); 116 return; 117 } 118 } 119 for (int i=0;i < rmits.size(); i++) 120 { 121 RModuleIssueType rmit = (RModuleIssueType)rmits.get(i); 122 rmitGroup = intake.get("RModuleIssueType", 123 rmit.getQueryKey(), false); 124 rmitGroup.setProperties(rmit); 125 rmit.save(); 126 127 String pageNum = data.getParameters().getString("pageNum","1"); 129 data.getParameters().add("pageNum", pageNum); 130 } 131 ScarabCache.clear(); 132 } 133 } 134 135 136 139 public void doSelectissuetype(RunData data, TemplateContext context) 140 throws Exception 141 { 142 ScarabRequestTool scarabR = getScarabRequestTool(context); 143 ScarabLocalizationTool l10n = getLocalizationTool(context); 144 IssueType issueType = scarabR.getIssueType(); 145 Module module = scarabR.getCurrentModule(); 146 147 if (issueType.getIssueTypeId() == null) 148 { 149 scarabR.setAlertMessage(l10n.get("SelectIssueType")); 150 } 151 else if (module.getRModuleIssueType(issueType) != null) 152 { 153 scarabR.setAlertMessage(l10n.get("IssueTypeAlreadyAssociated")); 154 } 155 else 156 { 157 module.addIssueType(issueType); 158 ScarabCache.clear(); 159 scarabR.setConfirmMessage(l10n.get("IssueTypeAddedToModule")); 160 setTarget(data, "admin,ManageArtifactTypes.vm"); 161 } 162 } 163 164 165 168 public void doCreateartifacttype(RunData data, TemplateContext context) 169 throws Exception 170 { 171 data.getParameters().remove("issueTypeId"); 172 setTarget(data, getOtherTemplate(data)); 173 } 174 175 178 public void doDeletemoduleissuetype (RunData data, 179 TemplateContext context) 180 throws Exception 181 { 182 ScarabRequestTool scarabR = getScarabRequestTool(context); 183 ScarabLocalizationTool l10n = getLocalizationTool(context); 184 ScarabUser user = (ScarabUser)data.getUser(); 185 ParameterParser params = data.getParameters(); 186 Module module = scarabR.getCurrentModule(); 187 Object [] keys = params.getKeys(); 188 String key; 189 String issueTypeId; 190 List rmits = module.getRModuleIssueTypes(); 191 192 boolean foundOne = false; 193 boolean success = false; 194 for (int i =0; i<keys.length; i++) 195 { 196 key = keys[i].toString(); 197 if (key.startsWith("delete_")) 198 { 199 if (rmits.size() < 1) 200 { 201 scarabR.setAlertMessage(l10n.get("CannotZeroIssueType")); 202 break; 203 } 204 else 205 { 206 issueTypeId = key.substring(7); 207 IssueType issueType = scarabR.getIssueType(issueTypeId); 208 RModuleIssueType rmit = module.getRModuleIssueType(issueType); 209 Group rmitGroup = getIntakeTool(context).get("RModuleIssueType", 210 rmit.getQueryKey(), false); 211 Field field = rmitGroup.get("DisplayName"); 212 if (issueType != null) 213 { 214 foundOne = true; 215 if (issueType.getLocked()) 216 { 217 field.setMessage("LockedIssueType"); 219 } 220 else if (issueType.hasIssues(module)) 221 { 222 scarabR.setAlertMessage(l10n.get("CannotDeleteIssueTypesWithIssues")); 223 field.setMessage("IssueTypeHasIssues"); 224 } 225 else 226 { 227 try 228 { 229 rmit.delete(user); 231 success = true; 232 module.getNavIssueTypes().remove(issueType); 234 } 235 catch (Exception e) 236 { 237 scarabR.setAlertMessage( 238 l10n.get("CannotDeleteIssueType")); 239 Log.get().warn( 240 "Could not delete issue type", e); 241 } 242 } 243 244 } 245 } 246 } 247 248 } 249 if (success) 250 { 251 String msg = l10n.get("SelectedIssueTypesRemovedFromModule"); 252 scarabR.setConfirmMessage(msg); 253 } 254 if (!foundOne) 255 { 256 String msg = l10n.get("SelectIssueTypeToDeleteFromModule"); 257 scarabR.setAlertMessage(msg); 258 } 259 } 260 } 261 | Popular Tags |