KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > actions > QueryList


1 package org.tigris.scarab.actions;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.List JavaDoc;
50
51 import org.apache.fulcrum.intake.model.Field;
52 import org.apache.fulcrum.intake.model.Group;
53 import org.apache.fulcrum.parser.ParameterParser;
54 import org.apache.torque.om.NumberKey;
55 import org.apache.turbine.RunData;
56 import org.apache.turbine.TemplateContext;
57 import org.apache.turbine.tool.IntakeTool;
58 import org.tigris.scarab.actions.base.RequireLoginFirstAction;
59 import org.tigris.scarab.om.Query;
60 import org.tigris.scarab.om.QueryManager;
61 import org.tigris.scarab.om.RQueryUser;
62 import org.tigris.scarab.om.ScarabUser;
63 import org.tigris.scarab.services.cache.ScarabCache;
64 import org.tigris.scarab.tools.ScarabLocalizationTool;
65 import org.tigris.scarab.tools.ScarabRequestTool;
66
67 /**
68  * This class is responsible for managing the query lists (deleting queries).
69  *
70  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
71  * @version $Id: QueryList.java 9255 2004-11-14 21:07:04Z dep4b $
72  */

73 public class QueryList extends RequireLoginFirstAction
74 {
75
76     /**
77      * This method is not used until subscribed queries is working
78      */

79     public void doSave(RunData data, TemplateContext context)
80         throws Exception JavaDoc
81     {
82         IntakeTool intake = getIntakeTool(context);
83         ScarabRequestTool scarabR = getScarabRequestTool(context);
84         ScarabLocalizationTool l10n = getLocalizationTool(context);
85         ScarabUser user = (ScarabUser)data.getUser();
86        
87         if (intake.isAllValid())
88         {
89             boolean valid = true;
90             List JavaDoc queries = scarabR.getAllQueries();
91             for (int i = 0; i < queries.size(); i++)
92             {
93                 Query query = (Query)queries.get(i);
94                 RQueryUser rqu = query.getRQueryUser(user);
95                 Group queryGroup = intake.get("RQueryUser",
96                                               rqu.getQueryKey(), false);
97                 if (queryGroup != null)
98                 {
99                     Field sub = queryGroup.get("Subscribed");
100                     if (sub.toString().equals("true"))
101                     {
102                         Field freq = queryGroup.get("Frequency");
103                         freq.setRequired(true);
104                         if (!freq.isValid())
105                         {
106                             valid = false;
107                             freq.setMessage("EnterSubscriptionFrequency");
108                         }
109                     }
110                     if (valid)
111                     {
112                         queryGroup.setProperties(rqu);
113                         rqu.save();
114                     }
115                 }
116             }
117        }
118        else
119        {
120            scarabR.setAlertMessage(ERROR_MESSAGE);
121        }
122        ScarabCache.clear();
123     }
124
125
126     public void doDeletequeries(RunData data, TemplateContext context)
127         throws Exception JavaDoc
128     {
129         Object JavaDoc[] keys = data.getParameters().getKeys();
130         String JavaDoc key;
131         String JavaDoc queryId;
132         ScarabUser user = (ScarabUser)data.getUser();
133
134         for (int i =0; i<keys.length; i++)
135         {
136             key = keys[i].toString();
137             if (key.startsWith("action_"))
138             {
139                queryId = key.substring(7);
140                Query query = QueryManager
141                    .getInstance(new NumberKey(queryId), false);
142                try
143                {
144                    query.delete(user);
145                    query.save();
146                }
147                catch (Exception JavaDoc e)
148                {
149                    ScarabLocalizationTool l10n = getLocalizationTool(context);
150                    getScarabRequestTool(context).setAlertMessage(NO_PERMISSION_MESSAGE);
151                }
152
153             }
154         }
155     }
156
157     public void doCopyquery(RunData data, TemplateContext context)
158         throws Exception JavaDoc
159     {
160         ParameterParser pp = data.getParameters();
161         Object JavaDoc[] keys = pp.getKeys();
162         String JavaDoc key;
163         String JavaDoc queryId;
164         Query query;
165
166         for (int i =0; i<keys.length; i++)
167         {
168             key = keys[i].toString();
169             if (key.startsWith("action_"))
170             {
171                queryId = key.substring(7);
172                query = QueryManager
173                    .getInstance(new NumberKey(queryId), false);
174                query.copyQuery((ScarabUser)data.getUser());
175              }
176          }
177      }
178
179     /**
180      * This method is used by the Create new button to go to the AdvancedQuery
181      * page. Since it is a 'create new' option, several of the session persistent
182      * options are reset.
183      */

184     public void doGotoadvancedquery(RunData data, TemplateContext context)
185         throws Exception JavaDoc
186     {
187         // reset the MITList
188
ScarabUser user = (ScarabUser)data.getUser();
189         user.setCurrentMITList(null);
190         // reset selected users map
191
getScarabRequestTool(context).resetSelectedUsers();
192         setTarget(data, user.getQueryTarget());
193     }
194 }
195
Popular Tags