KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.om;
2
3 /* ================================================================
4  * Copyright (c) 2000-2004 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.ArrayList JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52
53 import org.apache.fulcrum.security.entity.Role;
54 import org.apache.fulcrum.security.impl.db.entity.TurbineRolePeer;
55 import org.apache.torque.NoRowsException;
56 import org.apache.torque.TooManyRowsException;
57 import org.apache.torque.TorqueException;
58 import org.apache.torque.manager.CacheListener;
59 import org.apache.torque.om.Persistent;
60 import org.apache.torque.util.Criteria;
61 import org.tigris.scarab.tools.ScarabLocalizationTool;
62 import org.tigris.scarab.tools.localization.L10NKeySet;
63
64 /**
65  * Every transition declare the ability of a role to change the value of an
66  * attribute from one of its options to another.
67  *
68  * @see org.tigris.scarab.workflow.CheapWorkflow
69  *
70  * @author Diego Martinez Velasco
71  * @author Jorge Uriarte Aretxaga
72  */

73 public class Transition extends org.tigris.scarab.om.BaseTransition
74         implements
75             Persistent, Conditioned
76 {
77     public Role getRole()
78     {
79         Role role = null;
80         try
81         {
82             role = TurbineRolePeer.retrieveByPK(this.getRoleId());
83         }
84         catch (NoRowsException e)
85         {
86             //Nothing to do, just ignore it
87
}
88         catch (TooManyRowsException e)
89         {
90             //Nothing to do, just ignore it
91
}
92         catch (TorqueException e)
93         {
94             e.printStackTrace();
95         }
96         return role;
97     }
98
99     public AttributeOption getFrom()
100     {
101         AttributeOption from = null;
102         if (null != this.getFromOptionId())
103         {
104             try
105             {
106                 from = AttributeOptionPeer.retrieveByPK(this.getFromOptionId());
107             }
108             catch (NoRowsException e)
109             {
110                 //Nothing to do, just ignore it
111
}
112             catch (TooManyRowsException e)
113             {
114                 //Nothing to do, just ignore it
115
}
116             catch (TorqueException e)
117             {
118                 e.printStackTrace();
119             }
120         }
121         return from;
122     }
123
124     public AttributeOption getTo()
125     {
126         AttributeOption to = null;
127         try
128         {
129             to = AttributeOptionPeer.retrieveByPK(this.getToOptionId());
130         }
131         catch (NoRowsException e)
132         {
133             //Nothing to do, just ignore it
134
}
135         catch (TooManyRowsException e)
136         {
137             //Nothing to do, just ignore it
138
}
139         catch (TorqueException e)
140         {
141             e.printStackTrace();
142         }
143         return to;
144     }
145
146     public boolean isRequiredIf(Integer JavaDoc optionID) throws TorqueException
147     {
148         Condition cond = new Condition();
149         cond.setAttributeId(null);
150         cond.setOptionId(optionID);
151         cond.setModuleId(null);
152         cond.setIssueTypeId(null);
153         cond.setTransitionId(this.getTransitionId());
154         return this.getConditions().contains(cond);
155     }
156     
157     public String JavaDoc getFromName()
158     {
159         String JavaDoc fromName = null;
160         AttributeOption from = this.getFrom();
161         if (from == null)
162         {
163             ScarabLocalizationTool l10n = new ScarabLocalizationTool();
164             fromName = l10n.get(L10NKeySet.TransitionsAnyOption);
165         }
166         else
167         {
168             fromName = from.getName();
169         }
170         return fromName;
171     }
172
173     public String JavaDoc getToName()
174     {
175         String JavaDoc toName = null;
176         AttributeOption to = this.getTo();
177         if (to == null)
178         {
179             ScarabLocalizationTool l10n = new ScarabLocalizationTool();
180             toName = l10n.get(L10NKeySet.TransitionsAnyOption);
181         }
182         else
183         {
184             toName = to.getName();
185         }
186         return toName;
187     }
188     
189     public String JavaDoc getRoleName()
190     {
191         String JavaDoc roleName = null;
192         Role role = this.getRole();
193         if (role == null)
194         {
195             ScarabLocalizationTool l10n = new ScarabLocalizationTool();
196             roleName = l10n.get(L10NKeySet.TransitionsAnyRole);
197         }
198         else
199         {
200             roleName = role.getName();
201         }
202         return roleName;
203     }
204
205     /**
206      * Returns the array of attributeOptionIds that will force the requiment of this
207      * attribute if set. Used by templates to load the combo.
208      * @return
209      */

210     public Integer JavaDoc[] getConditionsArray()
211     {
212         List JavaDoc conditions = new ArrayList JavaDoc();
213         Integer JavaDoc[] aIDs = null;
214         try
215         {
216             
217             conditions = this.getConditions();
218             aIDs = new Integer JavaDoc[conditions.size()];
219             int i=0;
220             for (Iterator JavaDoc iter = conditions.iterator(); iter.hasNext(); i++)
221             {
222                 aIDs[i] = (Integer JavaDoc)iter.next();
223             }
224         }
225         catch (TorqueException e)
226         {
227             this.getLog().error("getConditionsArray: " + e);
228         }
229         return aIDs;
230     }
231     /**
232      * Load the attribute options' IDs from the template combo.
233      * @param aOptionId
234      * @throws Exception
235      */

236     public void setConditionsArray(Integer JavaDoc aOptionId[]) throws Exception JavaDoc
237     {
238         Criteria crit = new Criteria();
239         crit.add(ConditionPeer.ATTRIBUTE_ID, null);
240         crit.add(ConditionPeer.MODULE_ID, null);
241         crit.add(ConditionPeer.ISSUE_TYPE_ID, null);
242         crit.add(ConditionPeer.TRANSITION_ID, this.getTransitionId());
243         ConditionPeer.doDelete(crit);
244         this.getConditions().clear();
245         ConditionManager.clear();
246         if (aOptionId != null)
247         {
248             for (int i=0; i<aOptionId.length; i++)
249             {
250                 if (aOptionId[i].intValue() != 0)
251                 {
252                     Condition cond = new Condition();
253                     cond.setTransitionId(this.getTransitionId());
254                     cond.setOptionId(aOptionId[i]);
255                     cond.setAttributeId(null);
256                     cond.setModuleId(null);
257                     cond.setIssueTypeId(null);
258                     this.addCondition(cond);
259                     cond.save();
260                 }
261             }
262         }
263     }
264
265     public boolean isConditioned()
266     {
267         boolean bRdo = false;
268         try {
269             bRdo = this.getConditions().size()>0;
270         } catch (TorqueException te)
271         {
272             // Nothing to do
273
}
274         return bRdo;
275     }
276     
277     public String JavaDoc toString()
278     {
279         return this.getFromOptionId() + " -> " + this.getToOptionId()
280                 + " (role: " + this.getRoleId() + ")";
281     }
282
283     /* (non-Javadoc)
284      * @see org.apache.torque.manager.CacheListener#addedObject(org.apache.torque.om.Persistent)
285      */

286     public void addedObject(Persistent arg0)
287     {
288         // TODO Auto-generated method stub
289

290     }
291
292     /* (non-Javadoc)
293      * @see org.apache.torque.manager.CacheListener#refreshedObject(org.apache.torque.om.Persistent)
294      */

295     public void refreshedObject(Persistent arg0)
296     {
297         // TODO Auto-generated method stub
298

299     }
300
301     /* (non-Javadoc)
302      * @see org.apache.torque.manager.CacheListener#getInterestedFields()
303      */

304     public List JavaDoc getInterestedFields()
305     {
306         // TODO Auto-generated method stub
307
return null;
308     }
309
310 }
311
312
Popular Tags