1 package org.tigris.scarab.om; 2 3 48 49 import java.sql.Connection ; 50 import java.util.List ; 51 import java.util.HashMap ; 52 53 import org.apache.torque.TorqueException; 54 import org.apache.torque.om.Persistent; 55 import org.tigris.scarab.util.ScarabConstants; 56 57 64 public class ActivityManager 65 extends BaseActivityManager 66 { 67 72 public ActivityManager() 73 throws TorqueException 74 { 75 super(); 76 validFields = new HashMap (); 77 validFields.put(ActivityPeer.ISSUE_ID, null); 78 } 79 80 protected Persistent putInstanceImpl(Persistent om) 81 throws TorqueException 82 { 83 Persistent oldOm = super.putInstanceImpl(om); 84 List listeners = (List )listenersMap.get(ActivityPeer.ISSUE_ID); 85 notifyListeners(listeners, oldOm, om); 86 return oldOm; 87 } 88 89 93 public static Activity getInstance(String id) 94 throws TorqueException 95 { 96 return getInstance(new Long (id)); 97 } 98 99 public static Activity createNumericActivity(Issue issue, Attribute attribute, 100 ActivitySet activitySet, 101 String description, 102 Attachment attachment, 103 Integer oldNumericValue, 104 Integer newNumericValue) 105 throws TorqueException 106 { 107 return create(issue,attribute,activitySet,description,attachment, 108 oldNumericValue, newNumericValue, 109 null, null, null, null, null, null); 110 } 111 112 public static Activity createUserActivity(Issue issue, Attribute attribute, 113 ActivitySet activitySet, 114 String description, 115 Attachment attachment, 116 Integer oldUserId, 117 Integer newUserId) 118 throws TorqueException 119 { 120 String oldUsername = null; 121 String newUsername = null; 122 if (oldUserId != null) 123 { 124 oldUsername = ScarabUserManager.getInstance(oldUserId).getUserName(); 125 } 126 if (newUserId != null) 127 { 128 newUsername = ScarabUserManager.getInstance(newUserId).getUserName(); 129 } 130 return create(issue,attribute,activitySet,description,attachment, 131 null, null, 132 oldUserId, newUserId, 133 null, null, oldUsername, newUsername); 134 } 135 136 public static Activity createAddDependencyActivity(Issue issue, 137 ActivitySet activitySet, 138 Depend depend, 139 String description) 140 throws TorqueException 141 { 142 return create(issue,null,activitySet,description,null,depend, 143 null, null, 144 null, null, 145 null, null, 146 null, depend.getDependType().getName(), null); 147 } 148 149 public static Activity createChangeDependencyActivity(Issue issue, 150 ActivitySet activitySet, 151 Depend depend, 152 String description, 153 String oldTextValue, 154 String newTextValue) 155 throws TorqueException 156 { 157 return create(issue,null,activitySet,description,null,depend, 158 null, null, 159 null, null, 160 null, null, 161 oldTextValue, newTextValue, null); 162 } 163 164 public static Activity createDeleteDependencyActivity(Issue issue, 165 ActivitySet activitySet, 166 Depend depend, 167 String description) 168 throws TorqueException 169 { 170 return create(issue,null,activitySet,description,null,depend, 171 null, null, 172 null, null, 173 null, null, 174 depend.getDependType().getName(), null, null); 175 } 176 177 public static Activity createOptionActivity(Issue issue, Attribute attribute, 178 ActivitySet activitySet, 179 String description, 180 Attachment attachment, 181 Integer oldOptionId, 182 Integer newOptionId) 183 throws TorqueException 184 { 185 return create(issue,attribute,activitySet,description,attachment, 186 null, null, 187 null, null, 188 oldOptionId, newOptionId, 189 null, null); 190 } 191 192 public static Activity createTextActivity(Issue issue, 193 ActivitySet activitySet, 194 String description, 195 String newTextValue) 196 throws TorqueException 197 { 198 return create(issue,null,activitySet,description,null, 199 null, null, 200 null, null, 201 null, null, 202 null, newTextValue); 203 } 204 205 public static Activity createTextActivity(Issue issue, 206 ActivitySet activitySet, 207 String description, 208 Attachment attachment) 209 throws TorqueException 210 { 211 return create(issue,null,activitySet,description,attachment, 212 null, null, 213 null, null, 214 null, null, 215 null, null); 216 } 217 218 public static Activity createTextActivity(Issue issue, Attribute attribute, 219 ActivitySet activitySet, 220 String description, 221 String oldTextValue, 222 String newTextValue) 223 throws TorqueException 224 { 225 return create(issue,attribute,activitySet,description,null, 226 null, null, 227 null, null, 228 null, null, 229 oldTextValue, newTextValue); 230 } 231 232 public static Activity createTextActivity(Issue issue, 233 ActivitySet activitySet, 234 String description, 235 Attachment attachment, 236 String oldTextValue, 237 String newTextValue) 238 throws TorqueException 239 { 240 return create(issue,null,activitySet,description,attachment, 241 null, null, 242 null, null, 243 null, null, 244 oldTextValue, newTextValue); 245 } 246 247 public static Activity createTextActivity(Issue issue, Attribute attribute, 248 ActivitySet activitySet, 249 String description, 250 Attachment attachment, 251 String oldTextValue, 252 String newTextValue) 253 throws TorqueException 254 { 255 return create(issue,attribute,activitySet,description,attachment, 256 null, null, 257 null, null, 258 null, null, 259 oldTextValue, newTextValue); 260 } 261 262 265 public static Activity createReportIssueActivity(Issue issue, 266 ActivitySet activitySet, 267 String message) 268 throws TorqueException 269 { 270 return create(issue, AttributeManager.getInstance(ScarabConstants.INTEGER_0), 271 activitySet, message, null, 272 null, null, null, null, null, null, null, null); 273 } 274 275 278 public static Activity create(Issue issue, Attribute attribute, 279 ActivitySet activitySet, String description, 280 Attachment attachment, 281 Integer oldNumericValue, Integer newNumericValue, 282 Integer oldUserId, Integer newUserId, 283 Integer oldOptionId, Integer newOptionId, 284 String oldTextValue, String newTextValue) 285 throws TorqueException 286 { 287 return create(issue,attribute,activitySet,description,attachment,null, 288 oldNumericValue, newNumericValue, 289 oldUserId, newUserId, 290 oldOptionId, newOptionId, 291 oldTextValue, newTextValue, null); 292 } 293 294 297 public static Activity create(Issue issue, Attribute attribute, 298 ActivitySet activitySet, String description, 299 Attachment attachment, 300 Integer oldNumericValue, Integer newNumericValue, 301 Integer oldUserId, Integer newUserId, 302 Integer oldOptionId, Integer newOptionId, 303 String oldTextValue, String newTextValue, 304 Connection dbCon) 305 throws TorqueException 306 { 307 return create(issue,attribute,activitySet,description,attachment,null, 308 oldNumericValue, newNumericValue, 309 oldUserId, newUserId, 310 oldOptionId, newOptionId, 311 oldTextValue, newTextValue, dbCon); 312 } 313 314 317 public static Activity create(Issue issue, Attribute attribute, 318 ActivitySet activitySet, String description, 319 Attachment attachment, Depend depend, 320 Integer oldNumericValue, Integer newNumericValue, 321 Integer oldUserId, Integer newUserId, 322 Integer oldOptionId, Integer newOptionId, 323 String oldTextValue, String newTextValue, 324 Connection dbCon) 325 throws TorqueException 326 { 327 Activity activity = ActivityManager.getInstance(); 328 activity.setIssue(issue); 329 if (attribute == null) 330 { 331 attribute = Attribute.getInstance(0); 332 } 333 activity.setAttribute(attribute); 334 activity.setDescription(description); 335 activity.setActivitySet(activitySet); 336 activity.setOldNumericValue(oldNumericValue); 337 activity.setNewNumericValue(newNumericValue); 338 activity.setOldUserId(oldUserId); 339 activity.setNewUserId(newUserId); 340 activity.setOldOptionId(oldOptionId); 341 activity.setNewOptionId(newOptionId); 342 activity.setOldValue(oldTextValue); 343 activity.setNewValue(newTextValue); 344 activity.setDepend(depend); 345 if (attachment != null) 346 { 347 activity.setAttachment(attachment); 348 } 349 if (dbCon == null) 350 { 351 try 352 { 353 activity.save(); 354 } 355 catch (Exception e) 356 { 357 if (e instanceof TorqueException) 358 { 359 throw (TorqueException)e; } 361 else 362 { 363 throw new TorqueException(e); } 365 } 366 } 367 else 368 { 369 activity.save(dbCon); 370 } 371 try 373 { 374 issue.addActivity(activity); 375 } 376 catch (Exception e) 377 { 378 throw new TorqueException(e); } 380 return activity; 381 } 382 } 383 | Popular Tags |