KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > ActivitySet


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.Collection JavaDoc;
50 import java.util.List JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import java.util.HashSet JavaDoc;
53 import java.util.Set JavaDoc;
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 /**
66  * This object represents a ActivitySet. It is used as a container
67  * for one or more Activity objects.
68  *
69  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
70  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
71  * @version $Id: ActivitySet.java 9222 2004-11-02 10:22:39Z dabbous $
72  */

73 public class ActivitySet
74     extends BaseActivitySet
75     implements Persistent
76 {
77     private static final String JavaDoc GET_ACTIVITY_LIST =
78         "getActivityList";
79     
80     /**
81      * Sets the activity list for this activitySet.
82      */

83     public void setActivityList(List JavaDoc activityList)
84         throws Exception JavaDoc
85     {
86         for (Iterator JavaDoc 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     /**
96      * Returns a list of Activity objects associated with this ActivitySet.
97      */

98     public List JavaDoc getActivityList() throws Exception JavaDoc
99     {
100         List JavaDoc result = null;
101 /* FIXME: caching is disabled here because new Activities can be
102           added to this activityset and the addition does not trigger
103           a reset of this cache (JSS).
104         Object obj = ScarabCache.get(this, GET_ACTIVITY_LIST);
105         if (obj == null)
106         {
107 */

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 /*
113         }
114         else
115         {
116             result = (List)obj;
117         }
118 */

119         return result;
120     }
121
122     /**
123      * Returns a list of Activity objects associated with this ActivitySet
124      * And this issue.
125      */

126     public List JavaDoc getActivityListForIssue(Issue issue) throws Exception JavaDoc
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 JavaDoc
142     {
143         sendEmail(null, issue, null, null, null);
144     }
145
146     public void sendEmail(EmailContext context, Issue issue)
147          throws Exception JavaDoc
148     {
149         sendEmail(context, issue, null, null, null);
150     }
151
152     public void sendEmail(Issue issue, String JavaDoc template)
153          throws Exception JavaDoc
154     {
155         sendEmail(null, issue, null, null, template);
156     }
157
158     public void sendEmail(EmailContext context, Issue issue,
159                              String JavaDoc template)
160          throws Exception JavaDoc
161     {
162         sendEmail(context, issue, null, null, template);
163     }
164
165     /**
166      * Sends email to the users associated with the issue.
167      * That is associated with this activitySet.
168      * If no subject and template specified, assume modify issue action.
169      * throws Exception
170      *
171      * @param context Any contextual information for the message.
172      * @param issue The issue
173      */

174     public void sendEmail(EmailContext context, Issue issue,
175                              Collection JavaDoc toUsers, Collection JavaDoc ccUsers,
176                              String JavaDoc template)
177          throws Exception JavaDoc
178     {
179         if (context == null)
180         {
181             context = new EmailContext();
182         }
183         
184         // add data to context
185
context.setIssue(issue);
186         context.put("attachment", getAttachment());
187
188         List JavaDoc activityList = getActivityList();
189         context.put("activityList", activityList);
190         Set JavaDoc set = new HashSet JavaDoc(activityList.size());
191         for (Iterator JavaDoc itr = activityList.iterator();itr.hasNext();)
192         {
193             Activity activity = (Activity) itr.next();
194             String JavaDoc 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             // Then add users who are assigned to "email-to" attributes
209
toUsers = issue.getAllUsersToEmail(AttributePeer.EMAIL_TO);
210         }
211         
212         if (ccUsers == null)
213         {
214             // add users to cc field of email
215
ccUsers = issue.getAllUsersToEmail(AttributePeer.CC_TO);
216         }
217
218         String JavaDoc[] 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