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.Module; 62 import org.tigris.scarab.om.RIssueTypeAttribute; 63 import org.tigris.scarab.om.RModuleAttribute; 64 import org.tigris.scarab.om.RModuleOption; 65 import org.tigris.scarab.services.cache.ScarabCache; 66 import org.tigris.scarab.tools.ScarabLocalizationTool; 67 import org.tigris.scarab.tools.ScarabRequestTool; 68 import org.tigris.scarab.workflow.WorkflowFactory; 69 70 74 public class ModuleAttributeEdit extends RequireLoginFirstAction 75 { 76 79 public synchronized void doSave (RunData data, TemplateContext context) 80 throws Exception 81 { 82 ScarabRequestTool scarabR = getScarabRequestTool(context); 83 ScarabLocalizationTool l10n = getLocalizationTool(context); 84 Module module = scarabR.getCurrentModule(); 85 IssueType issueType = scarabR.getIssueType(); 86 87 if (issueType.getLocked()) 88 { 89 scarabR.setAlertMessage(l10n.get("LockedIssueType")); 90 return; 91 } 92 Attribute attribute = scarabR.getAttribute(); 93 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute); 94 if (ria != null && ria.getLocked()) 95 { 96 scarabR.setAlertMessage(l10n.format("LockedAttribute", attribute.getName())); 97 return; 98 } 99 100 101 IntakeTool intake = getIntakeTool(context); 102 if (intake.isAllValid()) 103 { 104 List rmos = module.getRModuleOptions(attribute, issueType, false); 105 if (areThereDupeSequences(rmos, intake, "RModuleOption", "Order", 0)) 107 108 { 109 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound", 110 l10n.get("AttributeOptions").toLowerCase())); 111 return; 112 } 113 if (rmos != null) 114 { 115 for (int i=rmos.size()-1; i>=0; i--) 116 { 117 RModuleOption rmo = (RModuleOption)rmos.get(i); 118 Group rmoGroup = intake.get("RModuleOption", 119 rmo.getQueryKey(), false); 120 if (rmoGroup != null) 122 { 123 String newActive = rmoGroup.get("Active").toString(); 124 String oldActive = String.valueOf(rmo.getActive()); 125 if (newActive.equals("false") && oldActive.equals("true")) 126 { 127 WorkflowFactory.getInstance().deleteWorkflowsForOption( 128 rmo.getAttributeOption(), 129 module, issueType); 130 } 131 rmoGroup.setProperties(rmo); 132 rmo.save(); 133 } 134 ScarabCache.clear(); 135 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 136 } 137 } 138 } 139 if (attribute.isOptionAttribute()) 140 { 141 List options = module.getRModuleOptions(attribute, issueType, true); 142 if (options == null || options.isEmpty()) 143 { 144 RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType); 145 if (rma.getRequired()) 146 { 147 rma.setRequired(false); 148 rma.save(); 149 scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute")); 150 } 151 } 152 } 153 } 154 155 158 public void doDeleteattributeoptions(RunData data, 159 TemplateContext context) 160 throws Exception 161 { 162 ScarabRequestTool scarabR = getScarabRequestTool(context); 163 ScarabLocalizationTool l10n = getLocalizationTool(context); 164 IssueType issueType = scarabR.getIssueType(); 165 if (issueType.getLocked()) 166 { 167 scarabR.setAlertMessage(l10n.get("LockedIssueType")); 168 return; 169 } 170 Attribute attribute = scarabR.getAttribute(); 171 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute); 172 if (ria != null && ria.getLocked()) 173 { 174 scarabR.setAlertMessage(l10n.format("LockedAttribute", attribute.getName())); 175 return; 176 } 177 178 Module module = scarabR.getCurrentModule(); 179 ParameterParser params = data.getParameters(); 180 Object [] keys = params.getKeys(); 181 String key; 182 String optionId; 183 184 for (int i =0; i<keys.length; i++) 185 { 186 key = keys[i].toString(); 187 if (key.startsWith("delete_")) 188 { 189 optionId = key.substring(7); 190 AttributeOption option = AttributeOptionManager 191 .getInstance(new Integer (optionId)); 192 193 RModuleOption rmo = module.getRModuleOption(option, issueType); 194 rmo.delete(); 195 196 RModuleOption rmo2 = module.getRModuleOption(option, 198 scarabR.getIssueType(issueType.getTemplateId().toString())); 199 rmo2.delete(); 200 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 201 ScarabCache.clear(); 202 getIntakeTool(context).removeAll(); 203 data.getParameters().add("att_0id", option.getAttribute().getAttributeId().toString()); 204 } 205 } 206 if (attribute.isOptionAttribute()) 207 { 208 List options = module.getRModuleOptions(attribute, issueType, true); 209 if (options == null || options.isEmpty()) 210 { 211 RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType); 212 if (rma.getRequired()) 213 { 214 rma.setRequired(false); 215 rma.save(); 216 scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute")); 217 } 218 } 219 } 220 } 221 222 225 public void doSelectattributeoption(RunData data, 226 TemplateContext context) 227 throws Exception 228 { 229 ScarabRequestTool scarabR = getScarabRequestTool(context); 230 ScarabLocalizationTool l10n = getLocalizationTool(context); 231 IssueType issueType = scarabR.getIssueType(); 232 if (issueType.getLocked()) 233 { 234 scarabR.setAlertMessage(l10n.get("LockedIssueType")); 235 return; 236 } 237 Attribute attribute = scarabR.getAttribute(); 238 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute); 239 if (ria != null && ria.getLocked()) 240 { 241 scarabR.setAlertMessage(l10n.format("LockedAttribute", attribute.getName())); 242 return; 243 } 244 Module module = scarabR.getCurrentModule(); 245 246 String [] optionIds = data.getParameters().getStrings("option_ids"); 247 248 if (optionIds == null || optionIds.length <= 0) 249 { 250 scarabR.setAlertMessage(l10n.get("SelectOption")); 251 return; 252 } 253 else 254 { 255 for (int i=0; i < optionIds.length; i++) 256 { 257 AttributeOption option = null; 258 try 259 { 260 option = scarabR.getAttributeOption(new Integer (optionIds[i])); 261 module.addAttributeOption(issueType, option); 262 } 263 catch(Exception e) 264 { 265 e.printStackTrace(); 266 } 267 } 268 ScarabCache.clear(); 269 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 270 doCancel(data, context); 271 } 272 } 273 276 public void doDone( RunData data, TemplateContext context ) 277 throws Exception 278 { 279 doSave(data, context); 280 if (getScarabRequestTool(context).getAlertMessage() == null) 281 { 282 doCancel( data, context); 283 } 284 } 285 } 286 | Popular Tags |