1 package org.tigris.scarab.om; 2 3 48 49 import java.util.List ; 50 import java.util.Iterator ; 51 import org.apache.torque.TorqueException; 52 import org.apache.torque.util.Criteria; 53 import org.apache.fulcrum.localization.Localization; 54 55 import org.tigris.scarab.util.Log; 56 import org.tigris.scarab.util.ScarabConstants; 57 import org.tigris.scarab.om.ScarabUser; 58 59 62 public class MITListManager 63 extends BaseMITListManager 64 { 65 70 public MITListManager() 71 throws TorqueException 72 { 73 super(); 74 } 75 76 public static MITList getSingleItemList(Module module, IssueType issueType, 77 ScarabUser user) 78 throws TorqueException 79 { 80 MITList list = getInstance(); 81 if (user != null) 82 { 83 list.setScarabUser(user); 84 } 85 MITListItem item = MITListItemManager.getInstance(); 86 item.setModule(module); 87 item.setIssueType(issueType); 88 list.addMITListItem(item); 89 return list; 90 } 91 92 public static MITList getSingleModuleAllIssueTypesList(Module module, 93 ScarabUser user) 94 throws TorqueException 95 { 96 MITList list = MITListManager.getInstance(); 97 list.setModifiable(false); 98 list.setScarabUser(user); 99 list.setName(Localization.format(ScarabConstants.DEFAULT_BUNDLE_NAME, 100 user.getLocale(), 101 "AllIssueTypesCurrentModule", 102 module.getRealName())); 103 104 MITListItem item = MITListItemManager.getInstance(); 105 item.setModule(module); 106 item.setIssueTypeId(MITListItem.MULTIPLE_KEY); 107 list.addMITListItem(item); 108 return list; 109 } 110 111 public static MITList getAllModulesAllIssueTypesList(ScarabUser user) 112 throws TorqueException 113 { 114 MITList list = MITListManager.getInstance(); 115 list.setModifiable(false); 116 list.setScarabUser(user); 117 list.setName(Localization.getString(ScarabConstants.DEFAULT_BUNDLE_NAME, 118 user.getLocale(), 119 "AllModulesAndIssueTypes")); 120 121 MITListItem item = MITListItemManager.getInstance(); 122 item.setModuleId(MITListItem.MULTIPLE_KEY); 123 list.addMITListItem(item); 124 item.setIssueTypeId(MITListItem.MULTIPLE_KEY); 125 return list; 126 } 127 128 public static MITList getAllModulesSingleIssueTypeList(IssueType issueType, 129 ScarabUser user) 130 throws TorqueException 131 { 132 MITList list = MITListManager.getInstance(); 133 list.setModifiable(false); 134 list.setScarabUser(user); 135 list.setName(Localization.format(ScarabConstants.DEFAULT_BUNDLE_NAME, 136 user.getLocale(), 137 "CurrentIssueTypeAllModules", 138 issueType.getName())); 139 140 MITListItem item = MITListItemManager.getInstance(); 141 item.setModuleId(MITListItem.MULTIPLE_KEY); 142 item.setIssueType(issueType); 143 list.addMITListItem(item); 144 return list; 145 } 146 147 156 public static MITList getInstanceFromIssueList(List issues, 157 ScarabUser user) 158 throws TorqueException 159 { 160 if (issues == null) 161 { 162 throw new IllegalArgumentException ("Null issue list is not allowed."); } 164 if (user == null) 165 { 166 throw new IllegalArgumentException ("Null user is not allowed."); } 168 169 MITList list = getInstance(); 170 list.setScarabUser(user); 171 List dupeCheck = list.getMITListItems(); 172 Iterator i = issues.iterator(); 173 if (i.hasNext()) 174 { 175 Issue issue = (Issue)i.next(); 176 MITListItem item = MITListItemManager.getInstance(); 177 item.setModule(issue.getModule()); 178 item.setIssueType(issue.getIssueType()); 179 if (!dupeCheck.contains(item)) 180 { 181 list.addMITListItem(item); 182 } 183 } 184 185 return list; 186 } 187 188 public static MITList getInstanceByName(String name, ScarabUser user) 189 throws TorqueException 190 { 191 MITList result = null; 192 Criteria crit = new Criteria(); 193 crit.add(MITListPeer.NAME, name); 194 crit.add(MITListPeer.ACTIVE, true); 195 crit.add(MITListPeer.USER_ID, user.getUserId()); 196 List mitLists = MITListPeer.doSelect(crit); 197 if (mitLists != null && !mitLists.isEmpty()) 198 { 199 result = (MITList)mitLists.get(0); 200 Log.get().error("Multiple active lists exist with list name=" 205 + name + " for user=" + user.getUserName() + 206 "("+user.getUserId()+")"); 207 } 208 return result; 209 } 210 } 211 212 213 214 215 216 | Popular Tags |