1 package org.tigris.scarab.actions.admin; 2 3 48 49 import java.util.List ; 50 51 import org.apache.turbine.RunData; 52 import org.apache.turbine.TemplateContext; 53 import org.apache.turbine.tool.IntakeTool; 54 import org.apache.fulcrum.intake.model.Group; 55 import org.apache.fulcrum.intake.model.Field; 56 57 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 58 import org.tigris.scarab.tools.ScarabRequestTool; 59 import org.tigris.scarab.tools.ScarabLocalizationTool; 60 import org.tigris.scarab.om.IssueType; 61 import org.tigris.scarab.om.IssueTypeManager; 62 import org.tigris.scarab.om.IssueTypePeer; 63 import org.tigris.scarab.services.cache.ScarabCache; 64 65 72 public class GlobalArtifactTypes extends RequireLoginFirstAction 73 { 74 78 public void doSave(RunData data, TemplateContext context) 79 throws Exception 80 { 81 IntakeTool intake = getIntakeTool(context); 82 ScarabLocalizationTool l10n = getLocalizationTool(context); 83 List issueTypes = IssueTypePeer.getAllIssueTypes(false); 84 boolean dupe = false; 85 boolean saved = false; 86 if (intake.isAllValid()) 87 { 88 ScarabRequestTool scarabR = getScarabRequestTool(context); 89 for (int i=0; i<issueTypes.size(); i++) 90 { 91 IssueType issueType = (IssueType)issueTypes.get(i); 92 Group group = intake.get("IssueType", issueType.getQueryKey()); 93 Field field = group.get("Name"); 95 String name = field.toString(); 96 if (IssueTypePeer.isUnique(name, issueType.getIssueTypeId())) 97 { 98 group.setProperties(issueType); 99 issueType.save(); 100 ScarabCache.clear(); 101 saved = true; 102 } 103 else 104 { 105 dupe = true; 106 field.setMessage("Duplicate"); 107 } 108 } 109 if (dupe) 110 { 111 scarabR.setAlertMessage( 112 l10n.get("ChangesResultDuplicateNames")); 113 } 114 else if (saved) 115 { 116 scarabR.setConfirmMessage( 117 l10n.get(DEFAULT_MSG)); 118 } 119 else 120 { 121 scarabR.setInfoMessage( 122 l10n.get(NO_CHANGES_MADE)); 123 } 124 } 125 } 126 127 public void doCopy(RunData data, TemplateContext context) 128 throws Exception 129 { 130 Object [] keys = data.getParameters().getKeys(); 131 String key; 132 String id; 133 IssueType issueType; 134 boolean didCopy = false; 135 for (int i =0; i<keys.length; i++) 136 { 137 key = keys[i].toString(); 138 if (key.startsWith("action_")) 139 { 140 id = key.substring(7); 141 issueType = IssueTypeManager.getInstance(new Integer (id)); 142 if (issueType != null) 143 { 144 issueType.copyIssueType(); 145 didCopy = true; 146 } 147 } 148 } 149 ScarabRequestTool scarabR = getScarabRequestTool(context); 150 ScarabLocalizationTool l10n = getLocalizationTool(context); 151 if (didCopy) 152 { 153 scarabR.setConfirmMessage(l10n.get("GlobalArtifactTypeCopied")); 154 } 155 else 156 { 157 scarabR.setInfoMessage(l10n.get(NO_CHANGES_MADE)); 158 } 159 } 160 161 public void doDelete(RunData data, TemplateContext context) 162 throws Exception 163 { 164 String key = null; 165 String id = null; 166 IssueType issueType = null; 167 boolean deleted = false; 168 boolean hasIssues = false; 169 boolean immutable = false; 170 Object [] keys = data.getParameters().getKeys(); 171 ScarabLocalizationTool l10n = getLocalizationTool(context); 172 IntakeTool intake = getIntakeTool(context); 173 for (int i =0; i<keys.length; i++) 174 { 175 key = keys[i].toString(); 176 if (key.startsWith("action_")) 177 { 178 id = key.substring(7); 179 issueType = IssueTypeManager.getInstance(new Integer (id)); 180 if (issueType != null) 181 { 182 Group group = intake.get("IssueType", issueType.getQueryKey()); 183 Field field = group.get("Name"); 184 if (issueType.isSystemDefined()) 185 { 186 field.setMessage("CannotDeleteSystemSpecifiedIssueType"); 187 immutable = true; 188 } 189 else if (issueType.hasIssues()) 190 { 191 field.setMessage("IssueTypeHasIssues"); 192 hasIssues = true; 193 } 194 else 195 { 196 issueType.setDeleted(true); 197 issueType.save(); 198 deleted = true; 199 } 200 } 201 } 202 } 203 ScarabRequestTool scarabR = getScarabRequestTool(context); 204 if (immutable) 205 { 206 scarabR.setAlertMessage(l10n.get("CannotDeleteSystemSpecifiedIssueType")); 207 } 208 else if (hasIssues) 209 { 210 scarabR.setAlertMessage(l10n.get("CannotDeleteIssueTypesWithIssues")); 211 } 212 else if (deleted) 213 { 214 scarabR.setConfirmMessage(l10n.get("GlobalIssueTypesDeleted")); 215 } 216 else 217 { 218 scarabR.setInfoMessage(l10n.get(NO_CHANGES_MADE)); 219 } 220 } 221 222 public void doUndelete(RunData data, TemplateContext context) 223 throws Exception 224 { 225 Object [] keys = data.getParameters().getKeys(); 226 String key; 227 String id; 228 IssueType issueType; 229 boolean saved = false; 230 for (int i =0; i<keys.length; i++) 231 { 232 key = keys[i].toString(); 233 if (key.startsWith("action_")) 234 { 235 id = key.substring(7); 236 issueType = IssueTypeManager.getInstance(new Integer (id)); 237 if (issueType != null) 238 { 239 issueType.setDeleted(false); 240 issueType.save(); 241 saved = true; 242 } 243 } 244 } 245 if (saved) 246 { 247 getScarabRequestTool(context) 248 .setConfirmMessage( 249 getLocalizationTool(context) 250 .get("GlobalIssueTypesUnDeleted")); 251 } 252 } 253 } 254 | Popular Tags |