KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > servlet > admin > SuperviseServlet


1 /*
2  * SuperviseServlet.java
3  *
4  * Version: $Revision: 1.3 $
5  *
6  * Date: $Date: 2006/05/26 14:14:03 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.webui.servlet.admin;
42
43 import java.io.IOException JavaDoc;
44 import java.lang.StringBuffer JavaDoc;
45 import java.sql.SQLException JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.List JavaDoc;
48 import javax.servlet.ServletException JavaDoc;
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50 import javax.servlet.http.HttpServletResponse JavaDoc;
51
52 import org.apache.log4j.Logger;
53
54 import org.dspace.app.webui.util.JSPManager;
55 import org.dspace.app.webui.util.UIUtil;
56 import org.dspace.authorize.AuthorizeException;
57 import org.dspace.content.SupervisedItem;
58 import org.dspace.content.WorkspaceItem;
59 import org.dspace.core.Context;
60 import org.dspace.core.LogManager;
61 import org.dspace.eperson.Group;
62 import org.dspace.eperson.Supervisor;
63 import org.dspace.storage.rdbms.TableRow;
64 import org.dspace.storage.rdbms.TableRowIterator;
65
66 /**
67  * Servlet to handle administration of the supervisory system
68  *
69  * @author Richard Jones
70  * @version $Revision: 1.3 $
71  */

72 public class SuperviseServlet extends org.dspace.app.webui.servlet.DSpaceServlet
73 {
74     
75      /** log4j category */
76     private static Logger log = Logger.getLogger(SuperviseServlet.class);
77     
78     protected void doDSGet(Context c,
79         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
80         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
81     {
82         // pass all requests to the same place for simplicity
83
doDSPost(c, request, response);
84     }
85     
86     protected void doDSPost(Context c,
87         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
88         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
89     {
90         
91         String JavaDoc button = UIUtil.getSubmitButton(request, "submit_base");
92         
93         //direct the request to the relevant set of methods
94
if (button.equals("submit_add"))
95         {
96             showLinkPage(c, request, response);
97         }
98         else if (button.equals("submit_view"))
99         {
100             showListPage(c, request, response);
101         }
102         else if (button.equals("submit_base"))
103         {
104             showMainPage(c, request, response);
105         }
106         else if (button.equals("submit_link"))
107         {
108             // do form validation before anything else
109
if (validateAddForm(c, request, response))
110             {
111                 addSupervisionOrder(c, request, response);
112                 showMainPage(c, request, response);
113             }
114         }
115         else if (button.equals("submit_remove"))
116         {
117             showConfirmRemovePage(c, request, response);
118         }
119         else if (button.equals("submit_doremove"))
120         {
121             removeSupervisionOrder(c, request, response);
122             showMainPage(c, request, response);
123         }
124         else if (button.equals("submit_clean"))
125         {
126             cleanSupervisorDatabase(c, request, response);
127             showMainPage(c, request, response);
128         }
129     }
130     
131     //**********************************************************************
132
//****************** Methods for Page display **************************
133
//**********************************************************************
134

135     /**
136      * Confirms the removal of a supervision order
137      *
138      * @param context the context of the request
139      * @param request the servlet request
140      * @param response the servlet response
141      */

142     private void showConfirmRemovePage(Context context,
143         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
144         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
145     {
146         // get the values from the request
147
int wsItemID = UIUtil.getIntParameter(request,"siID");
148         int groupID = UIUtil.getIntParameter(request,"gID");
149         
150         // get the workspace item and the group from the request values
151
WorkspaceItem wsItem = WorkspaceItem.find(context, wsItemID);
152         Group group = Group.find(context, groupID);
153         
154         // set the attributes for the JSP
155
request.setAttribute("wsItem",wsItem);
156         request.setAttribute("group", group);
157         
158         JSPManager.showJSP(request, response, "/dspace-admin/supervise-confirm-remove.jsp" );
159         
160     }
161     
162     /**
163      * Displays the form to link groups to workspace items
164      *
165      * @param context the context of the request
166      * @param request the servlet request
167      * @param response the servlet response
168      */

169     private void showLinkPage(Context context,
170         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
171         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
172     {
173         // get all the groups
174
Group[] groups = Group.findAll(context,1);
175         
176         // get all the workspace items
177
WorkspaceItem[] wsItems = WorkspaceItem.findAll(context);
178         
179         // set the attributes for the JSP
180
request.setAttribute("groups",groups);
181         request.setAttribute("wsItems",wsItems);
182         
183         JSPManager.showJSP(request, response, "/dspace-admin/supervise-link.jsp" );
184         
185     }
186     
187     /**
188      * Displays the options you have in the supervisor admin area
189      *
190      * @param context the context of the request
191      * @param request the servlet request
192      * @param response the servlet response
193      */

194     private void showMainPage(Context context,
195         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
196         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
197     {
198         JSPManager.showJSP(request, response, "/dspace-admin/supervise-main.jsp");
199     }
200     
201     /**
202      * Displays the list of current settings for supervisors
203      *
204      * @param context the context of the request
205      * @param request the servlet request
206      * @param response the servlet response
207      */

208     private void showListPage(Context context,
209         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
210         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
211     {
212         // get all the supervised items
213
SupervisedItem[] si = SupervisedItem.getAll(context);
214         
215         // set the attributes for the JSP
216
request.setAttribute("supervised",si);
217         
218         JSPManager.showJSP(request, response, "/dspace-admin/supervise-list.jsp" );
219     }
220     
221     //**********************************************************************
222
//*************** Methods for data manipulation ************************
223
//**********************************************************************
224

225     /**
226      * Adds supervisory settings to the database
227      *
228      * @param context the context of the request
229      * @param request the servlet request
230      * @param response the servlet response
231      */

232     void addSupervisionOrder(Context context,
233         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
234     throws SQLException JavaDoc, AuthorizeException, ServletException JavaDoc, IOException JavaDoc
235     {
236         
237         // get the values from the request
238
int groupID = UIUtil.getIntParameter(request,"TargetGroup");
239         int wsItemID = UIUtil.getIntParameter(request,"TargetWSItem");
240         int policyType = UIUtil.getIntParameter(request, "PolicyType");
241         
242         Supervisor.add(context, groupID, wsItemID, policyType);
243         
244         log.info(LogManager.getHeader(context,
245             "Supervision Order Set",
246             "workspace_item_id="+wsItemID+",eperson_group_id="+groupID));
247         
248         context.complete();
249     }
250     
251     /**
252      * Maintains integrity of the supervisory database. Should be more closely
253      * integrated into the workspace code, perhaps
254      *
255      * @param context the context of the request
256      * @param request the servlet request
257      * @param response the servlet response
258      */

259     private void cleanSupervisorDatabase(Context context,
260         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
261         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
262     {
263         // ditch any supervision orders that are no longer relevant
264
Supervisor.removeRedundant(context);
265          
266         context.complete();
267     }
268     
269     
270     /**
271      * Remove the supervisory group and its policies from the database
272      *
273      * @param context the context of the request
274      * @param request the servlet request
275      * @param response the servlet response
276      */

277     void removeSupervisionOrder(Context context,
278         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
279         throws SQLException JavaDoc, AuthorizeException, ServletException JavaDoc, IOException JavaDoc
280     {
281         
282         // get the values from the request
283
int wsItemID = UIUtil.getIntParameter(request,"siID");
284         int groupID = UIUtil.getIntParameter(request,"gID");
285         
286         Supervisor.remove(context, wsItemID, groupID);
287         
288         log.info(LogManager.getHeader(context,
289             "Supervision Order Removed",
290             "workspace_item_id="+wsItemID+",eperson_group_id="+groupID));
291         
292         context.complete();
293     }
294     
295     /**
296      * validate the submitted form to ensure that there is not a supervision
297      * order for this already.
298      *
299      * @param context the context of the request
300      * @param request the servlet request
301      * @param response the servlet response
302      */

303     private boolean validateAddForm(Context context,
304         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
305         throws ServletException JavaDoc, IOException JavaDoc, SQLException JavaDoc, AuthorizeException
306     {
307         int groupID = UIUtil.getIntParameter(request,"TargetGroup");
308         int wsItemID = UIUtil.getIntParameter(request,"TargetWSItem");
309         
310         boolean invalid = Supervisor.isOrder(context, wsItemID, groupID);
311         
312         if (invalid)
313         {
314             JSPManager.showJSP(request, response,
315                 "/dspace-admin/supervise-duplicate.jsp");
316             return false;
317         }
318         else
319         {
320             return true;
321         }
322     }
323    
324 }
325
Popular Tags