1 package org.tigris.scarab.om; 2 3 48 49 import java.util.HashMap ; 50 import java.util.List ; 51 52 import org.apache.torque.TorqueException; 53 import org.apache.torque.om.Persistent; 54 55 62 public class AttachmentManager 63 extends BaseAttachmentManager 64 { 65 70 public AttachmentManager() 71 throws TorqueException 72 { 73 super(); 74 validFields = new HashMap (); 75 validFields.put(AttachmentPeer.ISSUE_ID, null); 76 } 77 78 protected Persistent putInstanceImpl(Persistent om) 79 throws TorqueException 80 { 81 Persistent oldOm = super.putInstanceImpl(om); 82 List listeners = (List )listenersMap.get(AttachmentPeer.ISSUE_ID); 83 notifyListeners(listeners, oldOm, om); 84 return oldOm; 85 } 86 87 public static Attachment getInstance(String id) 88 throws TorqueException 89 { 90 return getInstance(new Long (id)); 91 } 92 93 public static Attachment getComment(Attachment attachment, Issue issue, 94 ScarabUser user) 95 throws Exception 96 { 97 return populate(attachment, issue, Attachment.COMMENT__PK, "comment", 98 user, "text/plain"); 99 } 100 101 public static Attachment getReason(Attachment attachment, Issue issue, 102 ScarabUser user) 103 throws Exception 104 { 105 return populate(attachment, issue, Attachment.MODIFICATION__PK, "reason", 106 user, "text/plain"); 107 } 108 109 112 private static Attachment populate(Attachment attachment, 113 Issue issue, Integer typeId, 114 String name, ScarabUser user, 115 String mimetype) 116 throws Exception 117 { 118 attachment.setIssue(issue); 119 attachment.setTypeId(typeId); 120 attachment.setName(name); 121 attachment.setCreatedBy(user.getUserId()); 122 attachment.setMimeType(mimetype); 123 attachment.save(); 124 return attachment; 125 } 126 } 127 | Popular Tags |