KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.Connection JavaDoc;
50 import java.util.List JavaDoc;
51 import java.util.HashMap JavaDoc;
52
53 import org.apache.torque.TorqueException;
54 import org.apache.torque.om.Persistent;
55 import org.tigris.scarab.util.ScarabConstants;
56
57 /**
58  * This class manages Activity objects.
59  *
60  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
61  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
62  * @version $Id: ActivityManager.java 9104 2004-05-10 21:04:51Z dabbous $
63  */

64 public class ActivityManager
65     extends BaseActivityManager
66 {
67     /**
68      * Creates a new <code>ActivityManager</code> instance.
69      *
70      * @exception TorqueException if an error occurs
71      */

72     public ActivityManager()
73         throws TorqueException
74     {
75         super();
76         validFields = new HashMap JavaDoc();
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 JavaDoc listeners = (List JavaDoc)listenersMap.get(ActivityPeer.ISSUE_ID);
85         notifyListeners(listeners, oldOm, om);
86         return oldOm;
87     }
88
89     /**
90      * Convenience method for getting an Activity instance
91      * with a String primary key (which gets converted to a Integer).
92      */

93     public static Activity getInstance(String JavaDoc id)
94         throws TorqueException
95     {
96         return getInstance(new Long JavaDoc(id));
97     }
98     
99     public static Activity createNumericActivity(Issue issue, Attribute attribute,
100                                                  ActivitySet activitySet,
101                                                  String JavaDoc description,
102                                                  Attachment attachment,
103                                                  Integer JavaDoc oldNumericValue,
104                                                  Integer JavaDoc 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 JavaDoc description,
115                                                  Attachment attachment,
116                                                  Integer JavaDoc oldUserId,
117                                                  Integer JavaDoc newUserId)
118         throws TorqueException
119     {
120         String JavaDoc oldUsername = null;
121         String JavaDoc 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 JavaDoc 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 JavaDoc description,
153                                                  String JavaDoc oldTextValue,
154                                                  String JavaDoc 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 JavaDoc 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 JavaDoc description,
180                                                  Attachment attachment,
181                                                  Integer JavaDoc oldOptionId,
182                                                  Integer JavaDoc 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 JavaDoc description,
195                                                  String JavaDoc 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 JavaDoc 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 JavaDoc description,
221                                                  String JavaDoc oldTextValue,
222                                                  String JavaDoc 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 JavaDoc description,
235                                                  Attachment attachment,
236                                                  String JavaDoc oldTextValue,
237                                                  String JavaDoc 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 JavaDoc description,
250                                                  Attachment attachment,
251                                                  String JavaDoc oldTextValue,
252                                                  String JavaDoc 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     /**
263      * Populates a new Activity object for initial issue creation.
264      */

265     public static Activity createReportIssueActivity(Issue issue,
266                                                      ActivitySet activitySet,
267                                                      String JavaDoc 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     /**
276      * Populates a new Activity object.
277      */

278     public static Activity create(Issue issue, Attribute attribute,
279                        ActivitySet activitySet, String JavaDoc description,
280                        Attachment attachment,
281                        Integer JavaDoc oldNumericValue, Integer JavaDoc newNumericValue,
282                        Integer JavaDoc oldUserId, Integer JavaDoc newUserId,
283                        Integer JavaDoc oldOptionId, Integer JavaDoc newOptionId,
284                        String JavaDoc oldTextValue, String JavaDoc 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     /**
295      * Populates a new Activity object.
296      */

297     public static Activity create(Issue issue, Attribute attribute,
298                        ActivitySet activitySet, String JavaDoc description,
299                        Attachment attachment,
300                        Integer JavaDoc oldNumericValue, Integer JavaDoc newNumericValue,
301                        Integer JavaDoc oldUserId, Integer JavaDoc newUserId,
302                        Integer JavaDoc oldOptionId, Integer JavaDoc newOptionId,
303                        String JavaDoc oldTextValue, String JavaDoc newTextValue,
304                        Connection JavaDoc 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     /**
315      * Populates a new Activity object.
316      */

317     public static Activity create(Issue issue, Attribute attribute,
318                        ActivitySet activitySet, String JavaDoc description,
319                        Attachment attachment, Depend depend,
320                        Integer JavaDoc oldNumericValue, Integer JavaDoc newNumericValue,
321                        Integer JavaDoc oldUserId, Integer JavaDoc newUserId,
322                        Integer JavaDoc oldOptionId, Integer JavaDoc newOptionId,
323                        String JavaDoc oldTextValue, String JavaDoc newTextValue,
324                        Connection JavaDoc 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 JavaDoc e)
356             {
357                 if (e instanceof TorqueException)
358                 {
359                     throw (TorqueException)e; //EXCEPTION
360
}
361                 else
362                 {
363                     throw new TorqueException(e); //EXCEPTION
364
}
365             }
366         }
367         else
368         {
369             activity.save(dbCon);
370         }
371         // Make sure new activity is added to activity cache
372
try
373         {
374             issue.addActivity(activity);
375         }
376         catch (Exception JavaDoc e)
377         {
378             throw new TorqueException(e); //EXCEPTION
379
}
380         return activity;
381     }
382 }
383
Popular Tags