001: package org.tigris.scarab.actions;
002:
003: /* ================================================================
004: * Copyright (c) 2000 Collab.Net. 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.ArrayList;
050: import java.util.Collections;
051: import java.util.Comparator;
052: import java.util.HashMap;
053: import java.util.List;
054: import java.util.Map;
055:
056: import org.apache.fulcrum.parser.ParameterParser;
057: import org.apache.fulcrum.security.util.TurbineSecurityException;
058: import org.apache.turbine.RunData;
059: import org.apache.turbine.TemplateContext;
060: import org.tigris.scarab.actions.base.RequireLoginFirstAction;
061: import org.tigris.scarab.om.Attribute;
062: import org.tigris.scarab.om.AttributeManager;
063: import org.tigris.scarab.om.MITList;
064: import org.tigris.scarab.om.RModuleUserAttribute;
065: import org.tigris.scarab.om.RModuleUserAttributeManager;
066: import org.tigris.scarab.om.ScarabUser;
067: import org.tigris.scarab.tools.ScarabRequestTool;
068: import org.tigris.scarab.tools.localization.L10NKeySet;
069: import org.tigris.scarab.util.ScarabConstants;
070:
071: /**
072: * This class is responsible for the user configuration of the issue list.
073: *
074: * @author <a href="mailto:elicia@collab.net">Elicia David</a>
075: * @version $Id: ConfigureIssueList.java 10082 2006-04-30 23:45:13Z jorgeuriarte $
076: */
077: public class ConfigureIssueList extends RequireLoginFirstAction {
078: public void doSave(RunData data, TemplateContext context)
079: throws Exception {
080: ScarabRequestTool scarabR = getScarabRequestTool(context);
081:
082: // Add user's new selection of attributes
083: ParameterParser params = data.getParameters();
084: String[] ids = params.getStrings("attid");
085: String[] orders = params.getStrings("attorder");
086: MITList mitlist = ((ScarabUser) data.getUser())
087: .getCurrentMITList();
088: boolean isSingleModuleIssueType = mitlist
089: .isSingleModuleIssueType();
090:
091: if (ids != null) {
092: List attributes = new ArrayList(ids.length);
093: final Map orderMap = new HashMap();
094: for (int i = 0; i < ids.length; i++) {
095: RModuleUserAttribute pref = RModuleUserAttributeManager
096: .getInstance();
097: pref.setUserId(((ScarabUser) data.getUser())
098: .getUserId());
099: if (!orders[i].equals("hidden")) {
100: Integer order = new Integer(orders[i]);
101: try {
102: Attribute attribute = AttributeManager
103: .getInstance(new Integer(ids[i]));
104: if (isSingleModuleIssueType) {
105: //String value = mitlist.getModule().getRModuleAttribute(attribute, mitlist.getIssueType()).getDisplayValue();
106: pref.setAttribute(attribute);
107: pref.setIssueType(mitlist.getIssueType());
108: } else {
109: pref.setMITList(mitlist);
110: pref.setAttribute(attribute);
111: }
112: orderMap.put(pref.getAttributeId(), order);
113: } catch (NumberFormatException nfe) {
114: pref.setInternalAttribute(ids[i]);
115: orderMap
116: .put(pref.getInternalAttribute(), order);
117: }
118: attributes.add(pref);
119: }
120: }
121:
122: if (attributes.isEmpty()) {
123: scarabR
124: .setAlertMessage(L10NKeySet.MustSelectAtLeastOneAttribute);
125: setTarget(data, data.getParameters().getString(
126: ScarabConstants.TEMPLATE,
127: "ConfigureIssueList.vm"));
128: return;
129: } else if (((ScarabUser) data.getUser())
130: .getCurrentMITList() == null) {
131: scarabR.setAlertMessage(L10NKeySet.NoIssueTypeList);
132: return;
133: } else {
134: Comparator c = new Comparator() {
135: public int compare(Object o1, Object o2) {
136: RModuleUserAttribute a1 = (RModuleUserAttribute) o1;
137: RModuleUserAttribute a2 = (RModuleUserAttribute) o2;
138: int order1, order2;
139: if (a1.isInternal()) {
140: order1 = ((Integer) orderMap.get(a1
141: .getInternalAttribute()))
142: .intValue();
143: } else {
144: order1 = ((Integer) orderMap.get(a1
145: .getAttributeId())).intValue();
146: }
147: if (a2.isInternal()) {
148: order2 = ((Integer) orderMap.get(a2
149: .getInternalAttribute()))
150: .intValue();
151: } else {
152: order2 = ((Integer) orderMap.get(a2
153: .getAttributeId())).intValue();
154: }
155:
156: int result = order1 - order2;
157: if (result == 0) {
158: result = a1.getName().compareTo(
159: a2.getName());
160: }
161: return result;
162: }
163: };
164: Collections.sort(attributes, c);
165: context.put("attributepreferences", attributes);
166: scarabR.setConfirmMessage(DEFAULT_MSG);
167: try {
168: ((ScarabUser) data.getUser())
169: .updateIssueListAttributes(attributes);
170: // scarabR.setConfirmMessage(DEFAULT_MSG);
171: } catch (TurbineSecurityException tse) {
172: scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
173: }
174: }
175: }
176: doCancel(data, context);
177: }
178:
179: /**
180: * Resets back to default values for module.
181: */
182: public void doUsedefaults(RunData data, TemplateContext context)
183: throws Exception {
184: data.getParameters().add("usedefaults", "true");
185: }
186:
187: }
|