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 org.apache.torque.TorqueException;
052: import org.apache.torque.util.Criteria;
053: import org.apache.fulcrum.localization.Localization;
054:
055: import org.tigris.scarab.util.Log;
056: import org.tigris.scarab.util.ScarabConstants;
057: import org.tigris.scarab.om.ScarabUser;
058:
059: /**
060: * This class manages MITList objects.
061: */
062: public class MITListManager extends BaseMITListManager {
063: /**
064: * Creates a new <code>MITListManager</code> instance.
065: *
066: * @exception TorqueException if an error occurs
067: */
068: public MITListManager() throws TorqueException {
069: super ();
070: }
071:
072: public static MITList getSingleItemList(Module module,
073: IssueType issueType, ScarabUser user)
074: throws TorqueException {
075: MITList list = getInstance();
076: if (user != null) {
077: list.setScarabUser(user);
078: }
079: MITListItem item = MITListItemManager.getInstance();
080: item.setModule(module);
081: item.setIssueType(issueType);
082: list.addMITListItem(item);
083: return list;
084: }
085:
086: public static MITList getSingleModuleAllIssueTypesList(
087: Module module, ScarabUser user) throws TorqueException {
088: MITList list = MITListManager.getInstance();
089: list.setModifiable(false);
090: list.setScarabUser(user);
091: list.setName(Localization.format(
092: ScarabConstants.DEFAULT_BUNDLE_NAME, user.getLocale(),
093: "AllIssueTypesCurrentModule", module.getRealName()));
094:
095: MITListItem item = MITListItemManager.getInstance();
096: item.setModule(module);
097: item.setIssueTypeId(MITListItem.MULTIPLE_KEY);
098: list.addMITListItem(item);
099: return list;
100: }
101:
102: public static MITList getAllModulesAllIssueTypesList(ScarabUser user)
103: throws TorqueException {
104: MITList list = MITListManager.getInstance();
105: list.setModifiable(false);
106: list.setScarabUser(user);
107: list.setName(Localization.getString(
108: ScarabConstants.DEFAULT_BUNDLE_NAME, user.getLocale(),
109: "AllModulesAndIssueTypes"));
110:
111: MITListItem item = MITListItemManager.getInstance();
112: item.setModuleId(MITListItem.MULTIPLE_KEY);
113: list.addMITListItem(item);
114: item.setIssueTypeId(MITListItem.MULTIPLE_KEY);
115: return list;
116: }
117:
118: public static MITList getAllModulesSingleIssueTypeList(
119: IssueType issueType, ScarabUser user)
120: throws TorqueException {
121: MITList list = MITListManager.getInstance();
122: list.setModifiable(false);
123: list.setScarabUser(user);
124: list.setName(Localization.format(
125: ScarabConstants.DEFAULT_BUNDLE_NAME, user.getLocale(),
126: "CurrentIssueTypeAllModules", issueType.getName()));
127:
128: MITListItem item = MITListItemManager.getInstance();
129: item.setModuleId(MITListItem.MULTIPLE_KEY);
130: item.setIssueType(issueType);
131: list.addMITListItem(item);
132: return list;
133: }
134:
135: /**
136: * An issue has an associated Module and IssueType, this method takes
137: * a list of issues and creates an MITList from these associations.
138: *
139: * @param issues a <code>List</code> value
140: * @param user a <code>ScarabUser</code> value
141: * @return a <code>MITList</code> value
142: * @exception TorqueException if an error occurs
143: */
144: public static MITList getInstanceFromIssueList(List issues,
145: ScarabUser user) throws TorqueException {
146: if (issues == null) {
147: throw new IllegalArgumentException(
148: "Null issue list is not allowed."); //EXCEPTION
149: }
150: if (user == null) {
151: throw new IllegalArgumentException(
152: "Null user is not allowed."); //EXCEPTION
153: }
154:
155: MITList list = getInstance();
156: list.setScarabUser(user);
157: List dupeCheck = list.getMITListItems();
158: Iterator i = issues.iterator();
159: if (i.hasNext()) {
160: Issue issue = (Issue) i.next();
161: MITListItem item = MITListItemManager.getInstance();
162: item.setModule(issue.getModule());
163: item.setIssueType(issue.getIssueType());
164: if (!dupeCheck.contains(item)) {
165: list.addMITListItem(item);
166: }
167: }
168:
169: return list;
170: }
171:
172: public static MITList getInstanceByName(String name, ScarabUser user)
173: throws TorqueException {
174: MITList result = null;
175: Criteria crit = new Criteria();
176: crit.add(MITListPeer.NAME, name);
177: crit.add(MITListPeer.ACTIVE, true);
178: crit.add(MITListPeer.USER_ID, user.getUserId());
179: List mitLists = MITListPeer.doSelect(crit);
180: if (mitLists != null && !mitLists.isEmpty()) {
181: result = (MITList) mitLists.get(0);
182: // it is not good if more than one active list has the
183: // same name (per user). We could throw an exception here
184: // but its possible the system can still function under
185: // this circumstance, so just log it for now.
186: Log.get().error(
187: "Multiple active lists exist with list name="
188: + name + " for user=" + user.getUserName()
189: + "(" + user.getUserId() + ")");
190: }
191: return result;
192: }
193: }
|