001: package org.tigris.scarab.actions;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 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:
051: import org.apache.fulcrum.intake.model.Field;
052: import org.apache.fulcrum.intake.model.Group;
053: import org.apache.fulcrum.parser.ParameterParser;
054: import org.apache.torque.om.NumberKey;
055: import org.apache.turbine.RunData;
056: import org.apache.turbine.TemplateContext;
057: import org.apache.turbine.tool.IntakeTool;
058: import org.tigris.scarab.actions.base.RequireLoginFirstAction;
059: import org.tigris.scarab.om.Query;
060: import org.tigris.scarab.om.QueryManager;
061: import org.tigris.scarab.om.RQueryUser;
062: import org.tigris.scarab.om.ScarabUser;
063: import org.tigris.scarab.services.cache.ScarabCache;
064: import org.tigris.scarab.tools.ScarabLocalizationTool;
065: import org.tigris.scarab.tools.ScarabRequestTool;
066:
067: /**
068: * This class is responsible for managing the query lists (deleting queries).
069: *
070: * @author <a href="mailto:elicia@collab.net">Elicia David</a>
071: * @version $Id: QueryList.java 9255 2004-11-14 21:07:04Z dep4b $
072: */
073: public class QueryList extends RequireLoginFirstAction {
074:
075: /**
076: * This method is not used until subscribed queries is working
077: */
078: public void doSave(RunData data, TemplateContext context)
079: throws Exception {
080: IntakeTool intake = getIntakeTool(context);
081: ScarabRequestTool scarabR = getScarabRequestTool(context);
082: ScarabLocalizationTool l10n = getLocalizationTool(context);
083: ScarabUser user = (ScarabUser) data.getUser();
084:
085: if (intake.isAllValid()) {
086: boolean valid = true;
087: List queries = scarabR.getAllQueries();
088: for (int i = 0; i < queries.size(); i++) {
089: Query query = (Query) queries.get(i);
090: RQueryUser rqu = query.getRQueryUser(user);
091: Group queryGroup = intake.get("RQueryUser", rqu
092: .getQueryKey(), false);
093: if (queryGroup != null) {
094: Field sub = queryGroup.get("Subscribed");
095: if (sub.toString().equals("true")) {
096: Field freq = queryGroup.get("Frequency");
097: freq.setRequired(true);
098: if (!freq.isValid()) {
099: valid = false;
100: freq
101: .setMessage("EnterSubscriptionFrequency");
102: }
103: }
104: if (valid) {
105: queryGroup.setProperties(rqu);
106: rqu.save();
107: }
108: }
109: }
110: } else {
111: scarabR.setAlertMessage(ERROR_MESSAGE);
112: }
113: ScarabCache.clear();
114: }
115:
116: public void doDeletequeries(RunData data, TemplateContext context)
117: throws Exception {
118: Object[] keys = data.getParameters().getKeys();
119: String key;
120: String queryId;
121: ScarabUser user = (ScarabUser) data.getUser();
122:
123: for (int i = 0; i < keys.length; i++) {
124: key = keys[i].toString();
125: if (key.startsWith("action_")) {
126: queryId = key.substring(7);
127: Query query = QueryManager.getInstance(new NumberKey(
128: queryId), false);
129: try {
130: query.delete(user);
131: query.save();
132: } catch (Exception e) {
133: ScarabLocalizationTool l10n = getLocalizationTool(context);
134: getScarabRequestTool(context).setAlertMessage(
135: NO_PERMISSION_MESSAGE);
136: }
137:
138: }
139: }
140: }
141:
142: public void doCopyquery(RunData data, TemplateContext context)
143: throws Exception {
144: ParameterParser pp = data.getParameters();
145: Object[] keys = pp.getKeys();
146: String key;
147: String queryId;
148: Query query;
149:
150: for (int i = 0; i < keys.length; i++) {
151: key = keys[i].toString();
152: if (key.startsWith("action_")) {
153: queryId = key.substring(7);
154: query = QueryManager.getInstance(
155: new NumberKey(queryId), false);
156: query.copyQuery((ScarabUser) data.getUser());
157: }
158: }
159: }
160:
161: /**
162: * This method is used by the Create new button to go to the AdvancedQuery
163: * page. Since it is a 'create new' option, several of the session persistent
164: * options are reset.
165: */
166: public void doGotoadvancedquery(RunData data,
167: TemplateContext context) throws Exception {
168: // reset the MITList
169: ScarabUser user = (ScarabUser) data.getUser();
170: user.setCurrentMITList(null);
171: // reset selected users map
172: getScarabRequestTool(context).resetSelectedUsers();
173: setTarget(data, user.getQueryTarget());
174: }
175: }
|