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: // Turbine classes
050: import java.util.Locale;
051:
052: import org.apache.torque.om.Persistent;
053: import org.apache.torque.TorqueException;
054: import org.apache.fulcrum.localization.Localization;
055:
056: // Scarab classes
057: import org.tigris.scarab.om.Module;
058: import org.tigris.scarab.tools.localization.L10NKeySet;
059: import org.tigris.scarab.util.ScarabException;
060:
061: /**
062: * This class represents a Dependency object from the SCARAB_DEPEND table.
063: *
064: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
065: * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
066: * @author <a href="mailto:elicia@collab.net">Elicia David</a>
067: * @version $Id: Depend.java 9977 2005-12-09 00:40:59Z hair $
068: */
069: public class Depend extends BaseDepend implements Persistent {
070:
071: /**
072: * A Module object which represents the default module.
073: */
074: private Module defaultModule = null;
075:
076: /**
077: * A Module object which represents the default module.
078: */
079: private String observerUniqueId = null;
080:
081: /**
082: * a user based comment about why this dependency is the way it is.
083: */
084: private String description = null;
085:
086: /**
087: * The selection state (used from Frontend to kep info about
088: * wether the issue is currently selected for an operation.
089: * This field is NOT stored in the Database!
090: */
091: private boolean selected = false;
092:
093: /**
094: * Get the selection state (typically the state of a checkbox).
095: * @return
096: */
097: public boolean getSelected() {
098: return selected;
099: }
100:
101: /**
102: * Set the selection state. Used via the Frontend, typically
103: * contains the state of a checkbox.
104: * @param theSelectState
105: */
106: public void setSelected(boolean theSelectState) {
107: selected = theSelectState;
108: }
109:
110: /**
111: * A new Depend object
112: * @deprecated See DependManager.getInstance()
113: */
114: public static Depend getInstance() throws TorqueException {
115: return DependManager.getInstance();
116: }
117:
118: /**
119: * Sets default module.
120: */
121: public void setDefaultModule(Module me) {
122: this .defaultModule = me;
123: }
124:
125: /**
126: * Returns default module.
127: */
128: public Module getDefaultModule() {
129: return defaultModule;
130: }
131:
132: /**
133: * Gets the description of the message given
134: * by the user for the reason for this dependency.
135: * Can be null. Saves the attachment to the database if
136: * there is data to be saved.
137: */
138: public Attachment getDescriptionAsAttachment(ScarabUser user,
139: Issue issue) throws TorqueException {
140: if (description == null || description.length() == 0) {
141: return null;
142: }
143: Attachment comment = AttachmentManager.getInstance();
144: comment.setTextFields(user, issue, Attachment.MODIFICATION__PK);
145: comment.setData(getDescription());
146: comment.setName("modification");
147: comment.save();
148: return comment;
149: }
150:
151: /**
152: * Gets the description of the message given
153: * by the user for the reason for this dependency.
154: * Can be null.
155: */
156: public String getDescription() {
157: return this .description;
158: }
159:
160: /**
161: * Sets the description of the message given
162: * by the user for the reason for this dependency.
163: * Can be null.
164: */
165: public void setDescription(String description) {
166: this .description = description;
167: }
168:
169: /**
170: * Getter method to get observerId as a String
171: */
172: public String getObserverUniqueId() throws TorqueException {
173: return observerUniqueId;
174: }
175:
176: public void setDependType(String type) throws TorqueException {
177: super .setDependType(DependTypeManager.getInstance(type));
178: }
179:
180: /**
181: * Setter method which takes a String - the unique id.
182: */
183: public void setObserverUniqueId(String uniqueId)
184: throws TorqueException, ScarabException {
185: if (getDefaultModule() == null) {
186: throw new ScarabException(
187: L10NKeySet.ExceptionDependInternalWorkflow,
188: "setDefaultModule()", "setObserverUniqueId()");
189: }
190: Issue childIssue = IssueManager.getIssueById(uniqueId.trim());
191: if (childIssue == null) {
192: String code = getDefaultModule().getCode();
193: uniqueId = code + uniqueId;
194: childIssue = IssueManager.getIssueById(uniqueId);
195: }
196: super .setObserverId(childIssue.getIssueId());
197: }
198:
199: /**
200: * Copies the properties from the passed in object
201: * onto this object.
202: */
203: public void setProperties(Depend depend) throws TorqueException {
204: this .setObservedId(depend.getObservedId());
205: this .setObserverId(depend.getObserverId());
206: this .setTypeId(depend.getTypeId());
207: }
208:
209: /**
210: * Returns phrase describing this dependency's type.
211: */
212: public String getAction(Locale locale) {
213: Integer typeId = getTypeId();
214: String action = null;
215: if (typeId.equals(DependTypePeer.BLOCKING__PK)) {
216: action = Localization.getString(locale, "depend_blocking");
217: } else if (typeId.equals(DependTypePeer.DUPLICATE__PK)) {
218: action = Localization.getString(locale, "depend_duplicate");
219: } else {
220: action = Localization.getString(locale,
221: "depend_nonblocking");
222: }
223: return action;
224: }
225:
226: /**
227: * Exchange Observer and Observed roles...
228: * @throws TorqueException
229: */
230: public void exchangeRoles() throws TorqueException {
231: Long observerId = getObserverId();
232: Long observedId = getObservedId();
233: setObserverId(observedId);
234: setObservedId(observerId);
235: }
236: }
|