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.Iterator;
051: import java.util.HashSet;
052: import java.util.Set;
053:
054: import org.apache.torque.TorqueException;
055: import org.apache.torque.util.Criteria;
056:
057: import org.apache.torque.om.Persistent;
058:
059: import org.tigris.scarab.om.ScarabUser;
060: import org.tigris.scarab.om.ScarabUserManager;
061: import org.tigris.scarab.tools.ScarabLocalizationTool;
062: import org.tigris.scarab.tools.localization.L10NKeySet;
063: import org.tigris.scarab.util.ScarabException;
064: import org.tigris.scarab.services.cache.ScarabCache;
065:
066: /**
067: * This object represents a ActivitySet. It is used as a container
068: * for one or more Activity objects.
069: *
070: * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
071: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
072: * @version $Id: ActivitySet.java 10360 2006-11-15 12:17:21Z ronvoe122 $
073: */
074: public class ActivitySet extends BaseActivitySet implements Persistent {
075: private static final String GET_ACTIVITY_LIST = "getActivityList";
076:
077: /**
078: * Sets the activity list for this activitySet.
079: */
080: public void setActivityList(List activityList)
081: throws TorqueException {
082: for (Iterator itr = activityList.iterator(); itr.hasNext();) {
083: Activity activity = (Activity) itr.next();
084: activity.setActivitySet(this );
085: activity.save();
086: }
087: ScarabCache.put(activityList, this , GET_ACTIVITY_LIST);
088: }
089:
090: /**
091: * Returns a list of Activity objects associated with this ActivitySet.
092: */
093: public List getActivityList() throws ScarabException {
094: List result = null;
095: /* FIXME: caching is disabled here because new Activities can be
096: added to this activityset and the addition does not trigger
097: a reset of this cache (JSS).
098: Object obj = ScarabCache.get(this, GET_ACTIVITY_LIST);
099: if (obj == null)
100: {
101: */
102: Criteria crit = new Criteria().add(ActivityPeer.TRANSACTION_ID,
103: getActivitySetId());
104: try {
105: result = ActivityPeer.doSelect(crit);
106: } catch (TorqueException e) {
107: throw new ScarabException(
108: L10NKeySet.ExceptionTorqueGeneric, e);
109: }
110: ScarabCache.put(result, this , GET_ACTIVITY_LIST);
111: /*
112: }
113: else
114: {
115: result = (List)obj;
116: }
117: */
118: return result;
119: }
120:
121: /**
122: * Returns a list of Activity objects associated with this ActivitySet
123: * And this issue.
124: */
125: public List getActivityListForIssue(Issue issue)
126: throws TorqueException {
127: Criteria crit = new Criteria().add(ActivityPeer.TRANSACTION_ID,
128: getActivitySetId());
129: crit.add(ActivityPeer.ISSUE_ID, issue.getIssueId());
130: return ActivityPeer.doSelect(crit);
131: }
132:
133: public ScarabUser getCreator() throws TorqueException {
134: return getScarabUser();
135: }
136:
137: public String getActivityReason(ScarabLocalizationTool l10n)
138: throws TorqueException {
139: String reason = null;
140: Attachment attachment = this .getAttachment();
141: if (attachment != null) {
142: String data = attachment.getData();
143: // Reason is the attachment entered for this transaction
144: if (data != null && data.length() > 0) {
145: reason = data;
146: } else {
147: reason = l10n.get(L10NKeySet.NotProvided);
148: }
149: }
150: // No reasons given for initial issue entry
151: else if (this .getTypeId().equals(
152: ActivitySetTypePeer.CREATE_ISSUE__PK)) {
153: reason = l10n.get(L10NKeySet.InitialEntry);
154: } else {
155: reason = l10n.get(L10NKeySet.NotProvided);
156: }
157: return reason;
158: }
159:
160: /**
161: * Returns a set of ScarabUsers which are removed from changedIssue
162: * in this ActivitySet
163: */
164: public Set getRemovedUsers(Issue changedIssue)
165: throws TorqueException {
166: Set removedUsers = new HashSet();
167: for (Iterator it = getActivityListForIssue(changedIssue)
168: .iterator(); it.hasNext();) {
169: Activity act = (Activity) it.next();
170: if (act.getOldUserId() != null
171: && act.getNewUserId() == null) {
172: ScarabUser removedUser = ScarabUserManager
173: .getInstance(act.getOldUserId());
174: removedUsers.add(removedUser);
175: }
176: }
177: return removedUsers;
178: }
179: }
|