1 package org.tigris.scarab.actions.admin; 2 3 48 49 import java.util.List ; 50 51 import org.apache.fulcrum.intake.model.Group; 52 import org.apache.fulcrum.parser.ParameterParser; 53 import org.apache.turbine.RunData; 54 import org.apache.turbine.TemplateContext; 55 import org.apache.turbine.tool.IntakeTool; 56 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 57 import org.tigris.scarab.om.Attribute; 58 import org.tigris.scarab.om.AttributeOption; 59 import org.tigris.scarab.om.AttributeOptionManager; 60 import org.tigris.scarab.om.IssueType; 61 import org.tigris.scarab.om.RIssueTypeAttribute; 62 import org.tigris.scarab.om.RIssueTypeOption; 63 import org.tigris.scarab.om.ScarabUser; 64 import org.tigris.scarab.services.cache.ScarabCache; 65 import org.tigris.scarab.tools.ScarabLocalizationTool; 66 import org.tigris.scarab.tools.ScarabRequestTool; 67 import org.tigris.scarab.util.ScarabConstants; 68 69 73 public class IssueTypeAttributeEdit extends RequireLoginFirstAction 74 { 75 78 public synchronized void doSave(RunData data, TemplateContext context) 79 throws Exception 80 { 81 IntakeTool intake = getIntakeTool(context); 82 ScarabRequestTool scarabR = getScarabRequestTool(context); 83 ScarabLocalizationTool l10n = getLocalizationTool(context); 84 Attribute attribute = scarabR.getAttribute(); 85 IssueType issueType = scarabR.getIssueType(); 86 if (issueType.isSystemDefined()) 87 { 88 scarabR.setAlertMessage(getLocalizationTool(context) 89 .get("SystemSpecifiedIssueType")); 90 return; 91 } 92 if (intake.isAllValid()) 93 { 94 List rios = issueType.getRIssueTypeOptions(attribute, false); 95 if (areThereDupeSequences(rios, intake, 97 "RIssueTypeOption","Order", 0)) 98 { 99 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound", 100 l10n.get("AttributeOptions").toLowerCase())); 101 return; 102 } 103 104 if (rios != null) 105 { 106 for (int i=rios.size()-1; i>=0; i--) 107 { 108 RIssueTypeOption rio = (RIssueTypeOption)rios.get(i); 109 Group rioGroup = intake.get("RIssueTypeOption", 110 rio.getQueryKey(), false); 111 rioGroup.setProperties(rio); 112 rio.save(); 113 ScarabCache.clear(); 114 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 115 } 116 } 117 } 118 if (attribute.isOptionAttribute()) 119 { 120 List options = issueType.getRIssueTypeOptions(attribute, true); 121 if (options == null || options.isEmpty()) 122 { 123 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute); 124 if (ria.getRequired()) 125 { 126 ria.setRequired(false); 127 ria.save(); 128 scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute")); 129 } 130 } 131 } 132 } 133 134 137 public void doDeleteissuetypeoptions(RunData data, 138 TemplateContext context) 139 throws Exception 140 { 141 ScarabRequestTool scarabR = getScarabRequestTool(context); 142 ScarabLocalizationTool l10n = getLocalizationTool(context); 143 ScarabUser user = (ScarabUser)data.getUser(); 144 IssueType issueType = scarabR.getIssueType(); 145 Attribute attribute = scarabR.getAttribute(); 146 147 if (issueType.isSystemDefined()) 148 { 149 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 150 return; 151 } 152 ParameterParser params = data.getParameters(); 153 Object [] keys = params.getKeys(); 154 String key; 155 String optionId; 156 157 for (int i =0; i<keys.length; i++) 158 { 159 key = keys[i].toString(); 160 if (key.startsWith("delete_")) 161 { 162 optionId = key.substring(7); 163 AttributeOption option = AttributeOptionManager 164 .getInstance(new Integer (optionId)); 165 166 RIssueTypeOption rio = issueType.getRIssueTypeOption(option); 167 List rios = issueType.getRIssueTypeOptions(attribute, 168 false); 169 try 170 { 171 rio.delete(user, scarabR.getCurrentModule()); 172 rios.remove(rio); 173 } 174 catch (Exception e) 175 { 176 scarabR.setAlertMessage(ScarabConstants.NO_PERMISSION_MESSAGE); 177 } 178 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 179 } 180 } 181 if (attribute.isOptionAttribute()) 182 { 183 List options = issueType.getRIssueTypeOptions(attribute, true); 184 if (options == null || options.isEmpty()) 185 { 186 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute); 187 if (ria.getRequired()) 188 { 189 ria.setRequired(false); 190 ria.save(); 191 scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute")); 192 } 193 } 194 } 195 } 196 197 198 201 public void doSelectissuetypeoption(RunData data, 202 TemplateContext context) 203 throws Exception 204 { 205 ScarabRequestTool scarabR = getScarabRequestTool(context); 206 ScarabLocalizationTool l10n = getLocalizationTool(context); 207 IssueType issueType = scarabR.getIssueType(); 208 if (issueType.isSystemDefined()) 209 { 210 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 211 return; 212 } 213 String [] optionIds = data.getParameters().getStrings("option_ids"); 214 215 if (optionIds == null || optionIds.length <= 0) 216 { 217 scarabR.setAlertMessage(l10n.get("SelectOption")); 218 return; 219 } 220 else 221 { 222 for (int i=0; i < optionIds.length; i++) 223 { 224 AttributeOption option = null; 225 try 226 { 227 option = scarabR.getAttributeOption(new Integer (optionIds[i])); 228 issueType.addRIssueTypeOption(option); 229 } 230 catch(Exception e) 231 { 232 e.printStackTrace(); 233 } 234 } 235 doCancel(data, context); 236 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 237 } 238 } 239 243 244 public void doGotoothertemplate(RunData data, 245 TemplateContext context) 246 throws Exception 247 { 248 ScarabRequestTool scarabR = getScarabRequestTool(context); 249 IssueType issueType = scarabR.getIssueType(); 250 ScarabLocalizationTool l10n = getLocalizationTool(context); 251 if (issueType.isSystemDefined()) 252 { 253 scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType")); 254 return; 255 } 256 super.doGotoothertemplate(data,context); 257 } 258 259 262 public void doDone( RunData data, TemplateContext context ) 263 throws Exception 264 { 265 doSave(data, context); 266 if (getScarabRequestTool(context).getAlertMessage() == null) 267 { 268 doCancel( data, context); 269 } 270 } 271 272 } 273 | Popular Tags |