1 package org.tigris.scarab.om; 2 3 48 49 import java.util.Iterator ; 50 import java.util.List ; 51 import java.util.ArrayList ; 52 53 import org.apache.torque.TorqueException; 54 import org.apache.torque.om.Persistent; 55 import org.apache.torque.util.Criteria; 56 import org.tigris.scarab.tools.localization.L10NKeySet; 57 58 import org.tigris.scarab.services.security.ScarabSecurity; 59 import org.tigris.scarab.util.ScarabException; 60 import org.tigris.scarab.om.Module; 61 import org.tigris.scarab.om.ModuleManager; 62 import org.tigris.scarab.om.QueryPeer; 63 import org.tigris.scarab.om.MITListItem; 64 import org.tigris.scarab.om.MITListItemPeer; 65 import org.tigris.scarab.workflow.WorkflowFactory; 66 67 73 public class RModuleIssueType 74 extends org.tigris.scarab.om.BaseRModuleIssueType 75 implements Persistent, Conditioned 76 { 77 78 84 public ScarabModule getScarabModule() 85 { 86 throw new UnsupportedOperationException ( 87 "Should use getModule"); } 89 90 95 public void setScarabModule(ScarabModule module) 96 { 97 throw new UnsupportedOperationException ( 98 "Should use setModule(Module). Note module cannot be new."); } 100 101 104 public void setModule(Module me) 105 throws TorqueException 106 { 107 Integer id = me.getModuleId(); 108 if (id == null) 109 { 110 throw new TorqueException("Modules must be saved prior to " + 111 "being associated with other objects."); } 113 setModuleId(id); 114 } 115 116 121 public Module getModule() 122 throws TorqueException 123 { 124 Module module = null; 125 Integer id = getModuleId(); 126 if ( id != null ) 127 { 128 module = ModuleManager.getInstance(id); 129 } 130 131 return module; 132 } 133 134 135 138 public void delete(ScarabUser user) 139 throws Exception 140 { 141 Module module = getModule(); 142 IssueType issueType = getIssueType(); 143 144 if (user.hasPermission(ScarabSecurity.MODULE__CONFIGURE, module)) 145 { 146 List attGroups = issueType.getAttributeGroups(module, false); 148 for (int j=0; j<attGroups.size(); j++) 149 { 150 AttributeGroup attGroup = 152 (AttributeGroup)attGroups.get(j); 153 attGroup.delete(); 154 } 155 156 List rmas = module.getRModuleAttributes(issueType); 158 for (int i=0; i<rmas.size(); i++) 159 { 160 ((RModuleAttribute)rmas.get(i)).delete(); 161 } 162 IssueType templateType = issueType.getTemplateIssueType(); 164 rmas = module.getRModuleAttributes(templateType); 165 for (int i=0; i<rmas.size(); i++) 166 { 167 ((RModuleAttribute)rmas.get(i)).delete(); 168 } 169 170 WorkflowFactory.getInstance().resetAllWorkflowsForIssueType(module, 172 issueType); 173 Criteria c = new Criteria() 175 .add(IssuePeer.TYPE_ID, templateType.getIssueTypeId()); 176 List result = IssuePeer.doSelect(c); 177 List issueIdList = new ArrayList (result.size()); 178 for (int i=0; i < result.size(); i++) 179 { 180 Issue issue = (Issue)result.get(i); 181 issueIdList.add(issue.getIssueId()); 182 } 183 IssuePeer.doDelete(c); 184 if (!issueIdList.isEmpty()) 185 { 186 c = new Criteria() 187 .addIn(IssueTemplateInfoPeer.ISSUE_ID, issueIdList); 188 IssueTemplateInfoPeer.doDelete(c); 189 } 190 191 c = new Criteria() 193 .add(MITListItemPeer.MODULE_ID, module.getModuleId()) 194 .add(MITListItemPeer.ISSUE_TYPE_ID, issueType.getIssueTypeId()); 195 List listItems = MITListItemPeer.doSelect(c); 196 List listIds = new ArrayList (listItems.size()); 197 198 for (int i=0; i < listItems.size(); i++) 199 { 200 MITList list = ((MITListItem)listItems.get(i)).getMITList(); 201 Long listId = list.getListId(); 202 if (list.isSingleModuleIssueType() && !listIds.contains(listId)) 203 { 204 listIds.add(listId); 205 } 206 } 207 MITListItemPeer.doDelete(c); 208 209 if (!listIds.isEmpty()) 210 { 211 c = new Criteria() 213 .addIn(MITListPeer.LIST_ID, listIds); 214 MITListPeer.doDelete(c); 215 216 c = new Criteria() 218 .addIn(QueryPeer.LIST_ID, listIds); 219 QueryPeer.doDelete(c); 220 } 221 222 c = new Criteria() 223 .add(RModuleIssueTypePeer.MODULE_ID, getModuleId()) 224 .add(RModuleIssueTypePeer.ISSUE_TYPE_ID, getIssueTypeId()); 225 RModuleIssueTypePeer.doDelete(c); 226 RModuleIssueTypeManager.removeFromCache(this); 227 List rmits = module.getRModuleIssueTypes(); 228 rmits.remove(this); 229 } 230 else 231 { 232 throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction); 233 } 234 } 235 236 242 public String getDisplayName() 243 { 244 String display = super.getDisplayName(); 245 if (display == null) 246 { 247 try 248 { 249 display = getIssueType().getName(); 250 } 251 catch (TorqueException e) 252 { 253 getLog().error("Error getting the issue type name: ", e); 254 } 255 } 256 return display; 257 } 258 259 266 public String getDisplayText() 267 { 268 return this.getDisplayName(); 269 } 270 271 public String getDisplayDescription() 272 { 273 String display = super.getDisplayDescription(); 274 if (display == null) 275 { 276 try 277 { 278 display = getIssueType().getDescription(); 279 } 280 catch (TorqueException e) 281 { 282 getLog().error("Error getting the issue type description: ", e); 283 } 284 } 285 return display; 286 } 287 288 291 public RModuleIssueType copy() 292 throws TorqueException 293 { 294 RModuleIssueType rmit2 = new RModuleIssueType(); 295 rmit2.setModuleId(getModuleId()); 296 rmit2.setIssueTypeId(getIssueTypeId()); 297 rmit2.setActive(getActive()); 298 rmit2.setDisplay(getDisplay()); 299 rmit2.setDisplayDescription(getDisplayDescription()); 300 rmit2.setOrder(getOrder()); 301 rmit2.setDedupe(getDedupe()); 302 rmit2.setHistory(getHistory()); 303 rmit2.setComments(getComments()); 304 return rmit2; 305 } 306 307 313 public List getConditions(Criteria criteria) throws TorqueException 314 { 315 criteria.add(ConditionPeer.ATTRIBUTE_ID, (Object )(ConditionPeer.ATTRIBUTE_ID + " IS NULL"), Criteria.CUSTOM); 316 return super.getConditions(criteria); 317 } 318 319 322 public Integer [] getConditionsArray() 323 { 324 List conditions = new ArrayList (); 325 Integer [] aIDs = null; 326 try 327 { 328 329 conditions = this.getConditions(); 330 aIDs = new Integer [conditions.size()]; 331 int i=0; 332 for (Iterator iter = conditions.iterator(); iter.hasNext(); i++) 333 { 334 aIDs[i] = (Integer )iter.next(); 335 } 336 } 337 catch (TorqueException e) 338 { 339 this.getLog().error("getConditionsArray: " + e); 340 } 341 return aIDs; 342 } 343 344 347 public void setConditionsArray(Integer [] aOptionId) throws Exception 348 { 349 Criteria crit = new Criteria(); 350 crit.add(ConditionPeer.ATTRIBUTE_ID, null); 351 crit.add(ConditionPeer.MODULE_ID, this.getModuleId()); 352 crit.add(ConditionPeer.ISSUE_TYPE_ID, this.getIssueTypeId()); 353 crit.add(ConditionPeer.TRANSITION_ID, null); 354 ConditionPeer.doDelete(crit); 355 this.save(); 356 this.getConditions().clear(); 357 ConditionManager.clear(); 358 if (aOptionId != null) 359 for (int i = 0; i < aOptionId.length; i++) 360 { 361 if (aOptionId[i].intValue() != 0) 362 { 363 Condition cond = new Condition(); 364 cond.setAttributeId(null); 365 cond.setOptionId(aOptionId[i]); 366 cond.setModuleId(this.getModuleId()); 367 cond.setIssueTypeId(this.getIssueTypeId()); 368 cond.setTransitionId(null); 369 this.addCondition(cond); 370 cond.save(); 371 } 372 } 373 } 374 375 378 public boolean isRequiredIf(Integer optionID) throws TorqueException 379 { 380 Condition cond = new Condition(); 381 cond.setAttributeId(null); 382 cond.setOptionId(optionID); 383 cond.setModuleId(this.getModuleId()); 384 cond.setIssueTypeId(this.getIssueTypeId()); 385 cond.setTransitionId(null); 386 return this.getConditions().contains(cond); 387 388 } 389 390 393 public boolean isConditioned() 394 { 395 boolean bRdo = false; 396 try { 397 bRdo = this.getConditions().size()>0; 398 } catch (TorqueException te) 399 { 400 } 402 return bRdo; 403 } 404 405 412 public void addCondition(Condition cond) throws TorqueException 413 { 414 getConditions().add(cond); 415 cond.setRModuleIssueType(this); 416 } 417 } 418 | Popular Tags |