001: package org.tigris.scarab.om;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2005 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: import java.util.List;
050: import java.util.ArrayList;
051: import org.apache.torque.TorqueException;
052:
053: import org.apache.torque.om.Persistent;
054: import org.apache.torque.util.Criteria;
055: import org.tigris.scarab.util.Log;
056:
057: /**
058: * You should add additional methods to this class to meet the
059: * application requirements. This class will only be generated as
060: * long as it does not already exist in the output directory.
061: */
062: public class RIssueTypeAttribute extends BaseRIssueTypeAttribute
063: implements Persistent {
064: /**
065: * This method sets the defaultTextFlag property and also makes sure
066: * that no other related RIA is defined as the default. It should be
067: * used instead of setDefaultTextFlag in application code.
068: *
069: * @param b a <code>boolean</code> value
070: */
071: public void setIsDefaultText(boolean b) throws TorqueException {
072: if (b && !getDefaultTextFlag()) {
073: // get related RIAs
074: List rias = getIssueType().getRIssueTypeAttributes(false);
075:
076: // make sure no other rma is selected
077: for (int i = 0; i < rias.size(); i++) {
078: RIssueTypeAttribute ria = (RIssueTypeAttribute) rias
079: .get(i);
080: if (ria.getDefaultTextFlag()) {
081: ria.setDefaultTextFlag(false);
082: ria.save();
083: break;
084: }
085: }
086: }
087: setDefaultTextFlag(b);
088: }
089:
090: /**
091: * Avoids a problem with intake and not having a getter. It always
092: * returns false, but the method is not used in code. Assuming some
093: * logic should be used here, see RModuleAttribute for a similar
094: * method that is functional.
095: *
096: * @return false
097: */
098: public boolean getIsDefaultText() throws TorqueException {
099: boolean isDefault = getDefaultTextFlag();
100: if (!isDefault && getAttribute().isTextAttribute()) {
101: // get related RIAs
102: List rias = getIssueType().getRIssueTypeAttributes();
103:
104: // check if another is chosen
105: boolean anotherIsDefault = false;
106: for (int i = 0; i < rias.size(); i++) {
107: RIssueTypeAttribute ria = (RIssueTypeAttribute) rias
108: .get(i);
109: if (ria.getDefaultTextFlag()) {
110: anotherIsDefault = true;
111: break;
112: }
113: }
114:
115: if (!anotherIsDefault) {
116: // locate the default text attribute
117: for (int i = 0; i < rias.size(); i++) {
118: RIssueTypeAttribute ria = (RIssueTypeAttribute) rias
119: .get(i);
120: if (ria.getAttribute().isTextAttribute()) {
121: if (ria.getAttributeId().equals(
122: getAttributeId())) {
123: isDefault = true;
124: } else {
125: anotherIsDefault = true;
126: }
127:
128: break;
129: }
130: }
131: }
132: }
133: return isDefault;
134: }
135:
136: public void delete() throws TorqueException {
137: if (Log.get().isDebugEnabled()) {
138: Log.get().debug(
139: "Deleting SCARAB_R_ISSUETYPE_ATTRIBUTE where issuetype id="
140: + getIssueTypeId() + " and attribute id="
141: + getAttributeId());
142: }
143: Criteria c = new Criteria()
144: .add(RIssueTypeAttributePeer.ISSUE_TYPE_ID,
145: getIssueTypeId()).add(
146: RIssueTypeAttributePeer.ATTRIBUTE_ID,
147: getAttributeId());
148: RIssueTypeAttributePeer.doDelete(c);
149: Attribute attr = getAttribute();
150: String attributeType = null;
151: attributeType = (attr.isUserAttribute() ? IssueType.USER
152: : IssueType.NON_USER);
153: getIssueType().getRIssueTypeAttributes(false, attributeType)
154: .remove(this );
155:
156: // delete issuetype-option mappings
157: if (attr.isOptionAttribute()) {
158: List optionList = getIssueType().getRIssueTypeOptions(attr,
159: false);
160: if (optionList != null && !optionList.isEmpty()) {
161: ArrayList optionIdList = new ArrayList(optionList
162: .size());
163: for (int i = 0; i < optionList.size(); i++) {
164: optionIdList.add(((RIssueTypeOption) optionList
165: .get(i)).getOptionId());
166: }
167: Criteria c2 = new Criteria().add(
168: RIssueTypeOptionPeer.ISSUE_TYPE_ID,
169: getIssueTypeId()).addIn(
170: RIssueTypeOptionPeer.OPTION_ID, optionIdList);
171: RIssueTypeOptionPeer.doDelete(c2);
172: }
173: }
174: }
175:
176: /**
177: * Copies this object's properties.
178: */
179: public RIssueTypeAttribute copyRia() throws TorqueException {
180: RIssueTypeAttribute ria = new RIssueTypeAttribute();
181: ria.setIssueTypeId(getIssueTypeId());
182: ria.setAttributeId(getAttributeId());
183: ria.setActive(getActive());
184: ria.setRequired(getRequired());
185: ria.setOrder(getOrder());
186: ria.setQuickSearch(getQuickSearch());
187: ria.setDefaultTextFlag(getDefaultTextFlag());
188: return ria;
189: }
190: }
|