KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
50
51 // Turbine classes
52
import org.apache.torque.TorqueException;
53 import org.apache.torque.om.Persistent;
54 import org.apache.torque.util.Criteria;
55 import java.sql.Connection JavaDoc;
56
57 import org.tigris.scarab.om.Attachment;
58 import org.tigris.scarab.services.cache.ScarabCache;
59
60 /**
61  * This class represents Activity records.
62  *
63  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
64  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
65  * @version $Id: Activity.java 8901 2004-02-01 14:06:36Z dep4b $
66  */

67 public class Activity
68     extends BaseActivity
69     implements Persistent
70 {
71     private AttributeOption oldAttributeOption;
72     private AttributeOption newAttributeOption;
73
74     protected static final String JavaDoc GET_ATTACHMENT =
75         "getAttachment";
76
77     /**
78      * This method properly handles the case where there may not be
79      * any rows selected and returns null in that case.
80      */

81     public Attachment getAttachment()
82     {
83         Attachment attachment = null;
84         Object JavaDoc obj = ScarabCache.get(this, GET_ATTACHMENT);
85         if (obj == null)
86         {
87             try
88             {
89                 Criteria crit = new Criteria();
90                 crit.add(ActivityPeer.ACTIVITY_ID, this.getActivityId());
91                 crit.addJoin(AttachmentPeer.ATTACHMENT_ID, ActivityPeer.ATTACHMENT_ID);
92                 List JavaDoc results = AttachmentPeer.doSelect(crit);
93                 if (!results.isEmpty())
94                 {
95                     attachment = (Attachment) results.get(0);
96                     ScarabCache.put(attachment, this, GET_ATTACHMENT);
97                 }
98             }
99             catch (Exception JavaDoc e)
100             {
101                 getLog().error("Activity.getAttachment(): ", e);
102             }
103         }
104         else
105         {
106             attachment = (Attachment)obj;
107         }
108         return attachment;
109     }
110
111     /**
112      * Gets the AttributeOption object associated with the Old Value field
113      * (i.e., the old value for the attribute before the change.)
114      */

115     public AttributeOption getOldAttributeOption() throws Exception JavaDoc
116     {
117         if (oldAttributeOption==null && (getOldValue() != null))
118         {
119             oldAttributeOption = AttributeOptionManager
120                 .getInstance(new Integer JavaDoc(getOldValue()));
121         }
122         return oldAttributeOption;
123     }
124
125     /**
126      * Gets the AttributeOption object associated with the New Value field
127      * (i.e., the new value for the attribute after the change.)
128      */

129     public AttributeOption getNewAttributeOption() throws Exception JavaDoc
130     {
131         if (newAttributeOption==null && (getNewValue() != null))
132         {
133             newAttributeOption = AttributeOptionManager
134                 .getInstance(new Integer JavaDoc(getNewValue()));
135         }
136         return newAttributeOption;
137     }
138
139     public void save(Connection JavaDoc dbCon)
140         throws TorqueException
141     {
142         if (isNew())
143         {
144             Criteria crit = new Criteria();
145             // If there are previous activities on this attribute and value
146
// Set End Date
147
if (this.getOldValue() != null)
148             {
149                 crit.add(ActivityPeer.ISSUE_ID, getIssueId());
150                 crit.add(ActivityPeer.ATTRIBUTE_ID, getAttributeId());
151                 crit.add(ActivityPeer.END_DATE, null);
152                 crit.add(ActivityPeer.NEW_VALUE, this.getOldValue());
153                 List JavaDoc result = ActivityPeer.doSelect(crit);
154                 int resultSize = result.size();
155                 if (resultSize > 0)
156                 {
157                     for (int i=0; i<resultSize;i++)
158                     {
159                         Activity a = (Activity)result.get(i);
160                         a.setEndDate(getActivitySet().getCreatedDate());
161                         a.save(dbCon);
162                     }
163                 }
164             }
165         }
166         // If they have just deleted a user assignment, set end date
167
if (getAttribute().isUserAttribute() && this.getNewUserId() == null && this.getOldUserId() != null)
168         {
169             this.setEndDate(getActivitySet().getCreatedDate());
170         }
171         super.save(dbCon);
172     }
173
174     public String JavaDoc getDescription()
175     {
176         String JavaDoc desc = super.getDescription();
177         if (desc != null && desc.length() > 255)
178         {
179             char[] chDesc = new char[255];
180             desc.getChars(0, 251, chDesc, 0);
181             chDesc[252] = chDesc[253] = chDesc[254] = '.';
182             desc = new String JavaDoc(chDesc);
183         }
184         return desc;
185     }
186
187     public Activity copy(Issue issue, ActivitySet activitySet)
188         throws Exception JavaDoc
189     {
190         Activity newA = new Activity();
191         newA.setIssueId(issue.getIssueId());
192         newA.setDescription(getDescription());
193         newA.setAttributeId(getAttributeId());
194         newA.setTransactionId(activitySet.getActivitySetId());
195         newA.setOldNumericValue(getOldNumericValue());
196         newA.setNewNumericValue(getNewNumericValue());
197         newA.setOldUserId(getOldUserId());
198         newA.setNewUserId(getNewUserId());
199         newA.setOldValue(getOldValue());
200         newA.setNewValue(getNewValue());
201         newA.setDependId(getDependId());
202         newA.setEndDate(getEndDate());
203         newA.setAttachmentId(getAttachmentId());
204         newA.save();
205         return newA;
206     }
207 }
208
Popular Tags