001: package org.tigris.scarab.actions;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2003 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:
052: // Turbine Stuff
053: import org.apache.turbine.TemplateContext;
054: import org.apache.turbine.RunData;
055:
056: import org.apache.turbine.tool.IntakeTool;
057: import org.apache.fulcrum.intake.model.Group;
058: import org.apache.torque.TorqueException;
059:
060: // Scarab Stuff
061: import org.tigris.scarab.actions.base.RequireLoginFirstAction;
062: import org.tigris.scarab.om.ScarabUser;
063: import org.tigris.scarab.om.Module;
064: import org.tigris.scarab.om.MITList;
065: import org.tigris.scarab.om.MITListManager;
066: import org.tigris.scarab.om.IssueType;
067: import org.tigris.scarab.om.RModuleIssueType;
068: import org.tigris.scarab.om.RModuleIssueTypeManager;
069: import org.tigris.scarab.om.IssueTypeManager;
070: import org.tigris.scarab.om.Scope;
071: import org.tigris.scarab.reports.ReportBridge;
072: import org.tigris.scarab.reports.IncompatibleMITListException;
073: import org.tigris.scarab.util.Log;
074: import org.tigris.scarab.util.ScarabConstants;
075: import org.tigris.scarab.tools.ScarabRequestTool;
076: import org.tigris.scarab.tools.ScarabLocalizationTool;
077: import org.tigris.scarab.tools.localization.L10NKeySet;
078:
079: /**
080: * This class is responsible for building a list of Module/IssueTypes.
081: *
082: * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
083: * @version $Id: DefineXModuleList.java 9290 2004-12-03 15:57:52Z dep4b $
084: */
085: public class DefineXModuleList extends RequireLoginFirstAction {
086: public void doGotoquerywithinternallist(RunData data,
087: TemplateContext context) throws Exception {
088: ScarabRequestTool scarabR = getScarabRequestTool(context);
089: ScarabLocalizationTool l10n = getLocalizationTool(context);
090: String listId = data.getParameters().getString("pd_list_id");
091: if (listId == null || listId.length() == 0) {
092: scarabR
093: .setAlertMessage(L10NKeySet.NoPredefinedXModuleListSelected);
094: } else {
095: MITList list = null;
096: ScarabUser user = (ScarabUser) data.getUser();
097: if ("allmits".equals(listId)) {
098: list = MITListManager
099: .getAllModulesAllIssueTypesList(user);
100: } else {
101: IssueType issueType = IssueTypeManager
102: .getInstance(new Integer(listId.substring(13)));
103: if (issueType.getDeleted()) {
104:
105: scarabR
106: .setAlertMessage(L10NKeySet.GlobalIssueTypesDeleted);
107: } else {
108: list = MITListManager
109: .getAllModulesSingleIssueTypeList(
110: issueType, user);
111: }
112: }
113: user.setCurrentMITList(list);
114: // reset selected users map
115: scarabR.resetSelectedUsers();
116: setTarget(data, data.getParameters().getString(
117: ScarabConstants.NEXT_TEMPLATE));
118: }
119: }
120:
121: public void doFinished(RunData data, TemplateContext context)
122: throws Exception {
123: // add any last minute additions
124: addSelectedRMITs(data, context);
125: ScarabUser user = (ScarabUser) data.getUser();
126: MITList currentList = user.getCurrentMITList();
127: // reset selected users map
128: getScarabRequestTool(context).resetSelectedUsers();
129:
130: if (currentList != null && !currentList.isEmpty()) {
131: setTarget(data, user.getQueryTarget());
132: } else {
133: ScarabRequestTool scarabR = getScarabRequestTool(context);
134: ScarabLocalizationTool l10n = getLocalizationTool(context);
135: scarabR
136: .setAlertMessage(L10NKeySet.ListWithAtLeastOneMITRequired);
137: }
138: }
139:
140: public void doFinishedreportlist(RunData data,
141: TemplateContext context) throws Exception {
142: doFinished(data, context);
143: ScarabLocalizationTool l10n = getLocalizationTool(context);
144: ScarabUser user = (ScarabUser) data.getUser();
145: ScarabRequestTool scarabR = getScarabRequestTool(context);
146: ReportBridge report = scarabR.getReport();
147: if (!report.isEditable(user)) {
148: scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
149: setTarget(data, "reports,ReportList.vm");
150: return;
151: }
152:
153: MITList mitList = user.getCurrentMITList();
154: try {
155: report.setMITList(mitList);
156: scarabR.setConfirmMessage(DEFAULT_MSG);
157:
158: if (!mitList.isSingleModule()
159: && Scope.MODULE__PK.equals(report.getScopeId())) {
160: report.setScopeId(Scope.PERSONAL__PK);
161: scarabR
162: .setInfoMessage(L10NKeySet.ScopeChangedToPersonal);
163: }
164: setTarget(data, "reports,Info.vm");
165: } catch (IncompatibleMITListException e) {
166: scarabR
167: .setAlertMessage(L10NKeySet.IncompatibleMITListReport);
168: setTarget(data, "reports,XModuleList.vm");
169: }
170: }
171:
172: public void doRemoveSavedlist(RunData data, TemplateContext context)
173: throws Exception {
174: ScarabRequestTool scarabR = getScarabRequestTool(context);
175: String listId = data.getParameters().getString("list_id");
176: if (listId == null || listId.length() == 0) {
177: ScarabLocalizationTool l10n = getLocalizationTool(context);
178: scarabR
179: .setAlertMessage(L10NKeySet.NoSavedXModuleQuerySelected);
180: } else {
181: // TODO: implement
182: }
183: }
184:
185: public void doRemoveitemsfromlist(RunData data,
186: TemplateContext context) throws Exception {
187: ScarabRequestTool scarabR = getScarabRequestTool(context);
188: ScarabLocalizationTool l10n = getLocalizationTool(context);
189: ScarabUser user = (ScarabUser) data.getUser();
190: String[] mitids = data.getParameters()
191: .getStrings("mitlistitem");
192: if (mitids == null || mitids.length == 0) {
193: scarabR
194: .setAlertMessage(L10NKeySet.NoItemsSelectedForRemoval);
195: } else {
196: user.removeItemsFromCurrentMITList(mitids);
197: scarabR.setConfirmMessage(l10n.format("NumberItemsRemoved",
198: String.valueOf(mitids.length)));
199: }
200: }
201:
202: public void doGotosavelist(RunData data, TemplateContext context)
203: throws Exception {
204: ScarabRequestTool scarabR = getScarabRequestTool(context);
205: ScarabLocalizationTool l10n = getLocalizationTool(context);
206: ScarabUser user = (ScarabUser) data.getUser();
207: MITList list = user.getCurrentMITList();
208: if (list == null) {
209: scarabR
210: .setAlertMessage(L10NKeySet.ApplicationErrorListWasNull);
211: Log
212: .get()
213: .error(
214: "Current list was null in DefineXModuleList.doGotosavelist.");
215: } else if (list.isAnonymous()) {
216: list.save();
217: scarabR.setConfirmMessage(DEFAULT_MSG);
218: String queryId = data.getParameters().getString("queryId");
219: if (queryId != null && queryId.length() > 0) {
220: setTarget(data, "EditQuery.vm");
221: }
222: } else {
223: list.setName(null);
224: setTarget(data, "EditXModuleList.vm");
225: }
226: }
227:
228: public void doStartover(RunData data, TemplateContext context)
229: throws Exception {
230: ((ScarabUser) data.getUser()).setCurrentMITList(null);
231: }
232:
233: public void doSavelist(RunData data, TemplateContext context)
234: throws Exception {
235: IntakeTool intake = getIntakeTool(context);
236: ScarabRequestTool scarabR = getScarabRequestTool(context);
237: ScarabLocalizationTool l10n = getLocalizationTool(context);
238:
239: if (intake.isAllValid()) {
240: ScarabUser user = (ScarabUser) data.getUser();
241: MITList list = user.getCurrentMITList();
242: Group group = intake.get("MITList", list.getQueryKey(),
243: false);
244: group.setProperties(list);
245: // check if the name already exists and inactivate the old list
246: MITList oldList = MITListManager.getInstanceByName(list
247: .getName(), user);
248: if (oldList != null) {
249: // oldList should not be the same as the new, but checking
250: // will not hurt
251: if (!list.equals(oldList)) {
252: oldList.setActive(false);
253: oldList.save();
254: }
255: }
256: // save the new list
257: list.save();
258:
259: // Setting the current list to null
260: // So that on IssueTypeList screen can select a saved list
261: user.setCurrentMITList(null);
262:
263: scarabR.setConfirmMessage(DEFAULT_MSG);
264: setTarget(data, data.getParameters().getString(
265: ScarabConstants.LAST_TEMPLATE));
266: }
267: }
268:
269: public void doAddselectedrmits(RunData data, TemplateContext context)
270: throws Exception {
271: ScarabRequestTool scarabR = getScarabRequestTool(context);
272: ScarabLocalizationTool l10n = getLocalizationTool(context);
273: String[] rmitIds = data.getParameters().getStrings("rmitid");
274: String listId = data.getParameters().getString("list_id");
275: if ((listId == null || listId.length() == 0)
276: && (rmitIds == null || rmitIds.length == 0)
277: && !data.getParameters().getBoolean("allit")) {
278: scarabR
279: .setAlertMessage(L10NKeySet.MustSelectAtLeastOneIssueType);
280: return;
281: } else {
282: addSelectedRMITs(data, context);
283: }
284: }
285:
286: private void addToUsersList(ScarabUser user, MITList list)
287: throws TorqueException {
288: MITList currentList = user.getCurrentMITList();
289: if (currentList == null) {
290: user.setCurrentMITList(list);
291: } else {
292: currentList.addAll(list);
293: }
294: }
295:
296: private void addSelectedRMITs(RunData data, TemplateContext context)
297: throws Exception {
298: ScarabRequestTool scarabR = getScarabRequestTool(context);
299: ScarabLocalizationTool l10n = getLocalizationTool(context);
300:
301: String listId = data.getParameters().getString("list_id");
302: if (listId != null && listId.length() != 0) {
303: setAndGetCurrentList(listId, data, context);
304: }
305:
306: ScarabUser user = (ScarabUser) data.getUser();
307: if (data.getParameters().getBoolean("allit")) {
308: Module module = user.getCurrentModule();
309: List issueTypes = module.getIssueTypes(false);
310: if (issueTypes == null || issueTypes.isEmpty()) {
311: scarabR
312: .setAlertMessage(L10NKeySet.IssueTypeUnavailable);
313: return;
314: }
315: MITList list = MITListManager
316: .getSingleModuleAllIssueTypesList(module, user);
317: addToUsersList(user, list.copy());
318: }
319:
320: String[] rmitIds = data.getParameters().getStrings("rmitid");
321: if (rmitIds != null && rmitIds.length != 0) {
322: List rmits = new ArrayList(rmitIds.length);
323: boolean isIssueTypeAvailable = true;
324: for (int i = 0; i < rmitIds.length && isIssueTypeAvailable; i++) {
325: try {
326: RModuleIssueType rmit = RModuleIssueTypeManager
327: .getInstance(rmitIds[i]);
328: if (rmit == null
329: || rmit.getIssueType().getDeleted()) {
330: isIssueTypeAvailable = false;
331: } else {
332: rmits.add(rmit);
333: }
334: } catch (Exception e) {
335: // would probably be a hack of the form
336: scarabR
337: .setAlertMessage(L10NKeySet.IssueTypeUnavailable);
338: Log.get().debug("", e);
339: return;
340: }
341: }
342: if (isIssueTypeAvailable) {
343: user.addRMITsToCurrentMITList(rmits);
344: } else {
345: scarabR
346: .setAlertMessage(L10NKeySet.IssueTypeUnavailable);
347: }
348: }
349:
350: // Another oddity due to ScarabUserImpl not extending
351: // AbstractScarabUser
352: MITList mitlist = user.getCurrentMITList();
353: if (mitlist != null) {
354: mitlist.setScarabUser(user);
355: }
356: }
357:
358: private void setAndGetCurrentList(String listId, RunData data,
359: TemplateContext context)
360:
361: {
362: ScarabRequestTool scarabR = getScarabRequestTool(context);
363: ScarabLocalizationTool l10n = getLocalizationTool(context);
364: try {
365: MITList list = MITListManager.getInstance(new Long(listId));
366: if (list == null) {
367: scarabR.setAlertMessage(L10NKeySet.InvalidId);
368: Log.get().warn("An invalid id was entered: " + listId);
369: } else {
370: addToUsersList((ScarabUser) data.getUser(), list.copy());
371: }
372: } catch (Exception e) {
373: scarabR.setAlertMessage(L10NKeySet.InvalidId);
374: Log.get().warn("An invalid id was entered: " + listId);
375: }
376: }
377:
378: public void doToggleothermodules(RunData data,
379: TemplateContext context) throws Exception {
380: String flag = data.getParameters().getString(
381: "eventSubmit_doToggleothermodules");
382: ((ScarabUser) data.getUser())
383: .setShowOtherModulesInIssueTypeList("show".equals(flag));
384: }
385: }
|