KickJava   Java API By Example, From Geeks To Geeks.

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


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

49
50 import java.util.List JavaDoc;
51 import java.util.ArrayList JavaDoc;
52
53 import org.apache.torque.om.Persistent;
54 import org.apache.torque.util.Criteria;
55 import org.tigris.scarab.util.Log;
56
57 /**
58  * You should add additional methods to this class to meet the
59  * application requirements. This class will only be generated as
60  * long as it does not already exist in the output directory.
61  */

62 public class RIssueTypeAttribute
63     extends org.tigris.scarab.om.BaseRIssueTypeAttribute
64     implements Persistent
65 {
66     /**
67      * This method sets the defaultTextFlag property and also makes sure
68      * that no other related RIA is defined as the default. It should be
69      * used instead of setDefaultTextFlag in application code.
70      *
71      * @param b a <code>boolean</code> value
72      */

73     public void setIsDefaultText(boolean b)
74         throws Exception JavaDoc
75     {
76         if (b && !getDefaultTextFlag())
77         {
78             // get related RIAs
79
List JavaDoc rias = getIssueType().getRIssueTypeAttributes(false);
80             
81             // make sure no other rma is selected
82
for (int i=0; i<rias.size(); i++)
83             {
84                 RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i);
85                 if (ria.getDefaultTextFlag())
86                 {
87                     ria.setDefaultTextFlag(false);
88                     ria.save();
89                     break;
90                 }
91             }
92         }
93         setDefaultTextFlag(b);
94     }
95
96     /**
97      * Avoids a problem with intake and not having a getter. It always
98      * returns false, but the method is not used in code. Assuming some
99      * logic should be used here, see RModuleAttribute for a similar
100      * method that is functional.
101      *
102      * @return false
103      */

104     public boolean getIsDefaultText()
105         throws Exception JavaDoc
106     {
107         boolean isDefault = getDefaultTextFlag();
108         if (!isDefault && getAttribute().isTextAttribute())
109         {
110             // get related RIAs
111
List JavaDoc rias = getIssueType().getRIssueTypeAttributes();
112             
113             // check if another is chosen
114
boolean anotherIsDefault = false;
115             for (int i=0; i<rias.size(); i++)
116             {
117                 RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i);
118                 if (ria.getDefaultTextFlag())
119                 {
120                     anotherIsDefault = true;
121                     break;
122                 }
123             }
124             
125             if (!anotherIsDefault)
126             {
127                 // locate the default text attribute
128
for (int i=0; i<rias.size(); i++)
129                 {
130                     RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i);
131                     if (ria.getAttribute().isTextAttribute())
132                     {
133                         if (ria.getAttributeId().equals(getAttributeId()))
134                         {
135                             isDefault = true;
136                         }
137                         else
138                         {
139                             anotherIsDefault = true;
140                         }
141                         
142                         break;
143                     }
144                 }
145             }
146         }
147         return isDefault;
148     }
149
150     public void delete()
151          throws Exception JavaDoc
152     {
153         if (Log.get().isDebugEnabled())
154         {
155             Log.get().debug(
156                 "Deleting SCARAB_R_ISSUETYPE_ATTRIBUTE where issuetype id="
157                 + getIssueTypeId() + " and attribute id=" + getAttributeId());
158         }
159         Criteria c = new Criteria()
160             .add(RIssueTypeAttributePeer.ISSUE_TYPE_ID, getIssueTypeId())
161             .add(RIssueTypeAttributePeer.ATTRIBUTE_ID, getAttributeId());
162         RIssueTypeAttributePeer.doDelete(c);
163         Attribute attr = getAttribute();
164         String JavaDoc attributeType = null;
165         attributeType = (attr.isUserAttribute() ? IssueType.USER : IssueType.NON_USER);
166         getIssueType().getRIssueTypeAttributes(false, attributeType).remove(this);
167
168         // delete issuetype-option mappings
169
if (attr.isOptionAttribute())
170         {
171             List JavaDoc optionList = getIssueType().getRIssueTypeOptions(attr, false);
172             if (optionList != null && !optionList.isEmpty())
173             {
174                 ArrayList JavaDoc optionIdList = new ArrayList JavaDoc(optionList.size());
175                 for (int i =0; i<optionList.size(); i++)
176                 {
177                     optionIdList.add(((RIssueTypeOption)optionList.get(i)).getOptionId());
178                 }
179                 Criteria c2 = new Criteria()
180                     .add(RIssueTypeOptionPeer.ISSUE_TYPE_ID, getIssueTypeId())
181                     .addIn(RIssueTypeOptionPeer.OPTION_ID, optionIdList);
182                 RIssueTypeOptionPeer.doDelete(c2);
183             }
184         }
185     }
186
187     /**
188      * Copies this object's properties.
189      */

190     public RIssueTypeAttribute copyRia()
191          throws Exception JavaDoc
192     {
193         RIssueTypeAttribute ria = new RIssueTypeAttribute();
194         ria.setIssueTypeId(getIssueTypeId());
195         ria.setAttributeId(getAttributeId());
196         ria.setActive(getActive());
197         ria.setRequired(getRequired());
198         ria.setOrder(getOrder());
199         ria.setQuickSearch(getQuickSearch());
200         ria.setDefaultTextFlag(getDefaultTextFlag());
201         return ria;
202     }
203 }
204
Popular Tags