1 package org.tigris.scarab.om; 2 3 48 49 import java.util.Collection ; 50 import java.util.List ; 51 import java.util.Iterator ; 52 import java.util.HashSet ; 53 import java.util.Set ; 54 55 import org.apache.torque.TorqueException; 56 import org.apache.torque.util.Criteria; 57 58 import org.apache.turbine.Turbine; 59 import org.apache.torque.om.Persistent; 60 61 import org.tigris.scarab.util.Email; 62 import org.tigris.scarab.util.EmailContext; 63 import org.tigris.scarab.services.cache.ScarabCache; 64 65 73 public class ActivitySet 74 extends BaseActivitySet 75 implements Persistent 76 { 77 private static final String GET_ACTIVITY_LIST = 78 "getActivityList"; 79 80 83 public void setActivityList(List activityList) 84 throws Exception 85 { 86 for (Iterator itr = activityList.iterator();itr.hasNext();) 87 { 88 Activity activity = (Activity) itr.next(); 89 activity.setActivitySet(this); 90 activity.save(); 91 } 92 ScarabCache.put(activityList, this, GET_ACTIVITY_LIST); 93 } 94 95 98 public List getActivityList() throws Exception 99 { 100 List result = null; 101 108 Criteria crit = new Criteria() 109 .add(ActivityPeer.TRANSACTION_ID, getActivitySetId()); 110 result = ActivityPeer.doSelect(crit); 111 ScarabCache.put(result, this, GET_ACTIVITY_LIST); 112 119 return result; 120 } 121 122 126 public List getActivityListForIssue(Issue issue) throws Exception 127 { 128 Criteria crit = new Criteria() 129 .add(ActivityPeer.TRANSACTION_ID, getActivitySetId()); 130 crit.add(ActivityPeer.ISSUE_ID, issue.getIssueId()); 131 return ActivityPeer.doSelect(crit); 132 } 133 134 public ScarabUser getCreator() 135 throws TorqueException 136 { 137 return getScarabUser(); 138 } 139 140 public void sendEmail(Issue issue) 141 throws Exception 142 { 143 sendEmail(null, issue, null, null, null); 144 } 145 146 public void sendEmail(EmailContext context, Issue issue) 147 throws Exception 148 { 149 sendEmail(context, issue, null, null, null); 150 } 151 152 public void sendEmail(Issue issue, String template) 153 throws Exception 154 { 155 sendEmail(null, issue, null, null, template); 156 } 157 158 public void sendEmail(EmailContext context, Issue issue, 159 String template) 160 throws Exception 161 { 162 sendEmail(context, issue, null, null, template); 163 } 164 165 174 public void sendEmail(EmailContext context, Issue issue, 175 Collection toUsers, Collection ccUsers, 176 String template) 177 throws Exception 178 { 179 if (context == null) 180 { 181 context = new EmailContext(); 182 } 183 184 context.setIssue(issue); 186 context.put("attachment", getAttachment()); 187 188 List activityList = getActivityList(); 189 context.put("activityList", activityList); 190 Set set = new HashSet (activityList.size()); 191 for (Iterator itr = activityList.iterator();itr.hasNext();) 192 { 193 Activity activity = (Activity) itr.next(); 194 String desc = activity.getDescription(); 195 set.add(desc); 196 } 197 context.put("uniqueActivityDescriptions", set); 198 199 if (template == null) 200 { 201 template = Turbine.getConfiguration(). 202 getString("scarab.email.modifyissue.template", 203 "ModifyIssue.vm"); 204 } 205 206 if (toUsers == null) 207 { 208 toUsers = issue.getAllUsersToEmail(AttributePeer.EMAIL_TO); 210 } 211 212 if (ccUsers == null) 213 { 214 ccUsers = issue.getAllUsersToEmail(AttributePeer.CC_TO); 216 } 217 218 String [] replyToUser = issue.getModule().getSystemEmail(); 219 220 if(Turbine.getConfiguration().getString("scarab.email.replyto.sender").equals("true")) 221 { 222 Email.sendEmail(context, issue.getModule(), getCreator(), 223 getCreator(), toUsers, ccUsers, template); 224 } 225 else 226 { 227 Email.sendEmail(context, issue.getModule(), getCreator(), 228 replyToUser, toUsers, ccUsers, template); 229 } 230 } 231 } 232 | Popular Tags |