001: /*
002: * SuperviseServlet.java
003: *
004: * Version: $Revision: 1520 $
005: *
006: * Date: $Date: 2006-05-26 09:14:03 -0500 (Fri, 26 May 2006) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.webui.servlet.admin;
042:
043: import java.io.IOException;
044: import java.lang.StringBuffer;
045: import java.sql.SQLException;
046: import java.util.ArrayList;
047: import java.util.List;
048: import javax.servlet.ServletException;
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051:
052: import org.apache.log4j.Logger;
053:
054: import org.dspace.app.webui.util.JSPManager;
055: import org.dspace.app.webui.util.UIUtil;
056: import org.dspace.authorize.AuthorizeException;
057: import org.dspace.content.SupervisedItem;
058: import org.dspace.content.WorkspaceItem;
059: import org.dspace.core.Context;
060: import org.dspace.core.LogManager;
061: import org.dspace.eperson.Group;
062: import org.dspace.eperson.Supervisor;
063: import org.dspace.storage.rdbms.TableRow;
064: import org.dspace.storage.rdbms.TableRowIterator;
065:
066: /**
067: * Servlet to handle administration of the supervisory system
068: *
069: * @author Richard Jones
070: * @version $Revision: 1520 $
071: */
072: public class SuperviseServlet extends
073: org.dspace.app.webui.servlet.DSpaceServlet {
074:
075: /** log4j category */
076: private static Logger log = Logger
077: .getLogger(SuperviseServlet.class);
078:
079: protected void doDSGet(Context c, HttpServletRequest request,
080: HttpServletResponse response) throws ServletException,
081: IOException, SQLException, AuthorizeException {
082: // pass all requests to the same place for simplicity
083: doDSPost(c, request, response);
084: }
085:
086: protected void doDSPost(Context c, HttpServletRequest request,
087: HttpServletResponse response) throws ServletException,
088: IOException, SQLException, AuthorizeException {
089:
090: String button = UIUtil.getSubmitButton(request, "submit_base");
091:
092: //direct the request to the relevant set of methods
093: if (button.equals("submit_add")) {
094: showLinkPage(c, request, response);
095: } else if (button.equals("submit_view")) {
096: showListPage(c, request, response);
097: } else if (button.equals("submit_base")) {
098: showMainPage(c, request, response);
099: } else if (button.equals("submit_link")) {
100: // do form validation before anything else
101: if (validateAddForm(c, request, response)) {
102: addSupervisionOrder(c, request, response);
103: showMainPage(c, request, response);
104: }
105: } else if (button.equals("submit_remove")) {
106: showConfirmRemovePage(c, request, response);
107: } else if (button.equals("submit_doremove")) {
108: removeSupervisionOrder(c, request, response);
109: showMainPage(c, request, response);
110: } else if (button.equals("submit_clean")) {
111: cleanSupervisorDatabase(c, request, response);
112: showMainPage(c, request, response);
113: }
114: }
115:
116: //**********************************************************************
117: //****************** Methods for Page display **************************
118: //**********************************************************************
119:
120: /**
121: * Confirms the removal of a supervision order
122: *
123: * @param context the context of the request
124: * @param request the servlet request
125: * @param response the servlet response
126: */
127: private void showConfirmRemovePage(Context context,
128: HttpServletRequest request, HttpServletResponse response)
129: throws ServletException, IOException, SQLException,
130: AuthorizeException {
131: // get the values from the request
132: int wsItemID = UIUtil.getIntParameter(request, "siID");
133: int groupID = UIUtil.getIntParameter(request, "gID");
134:
135: // get the workspace item and the group from the request values
136: WorkspaceItem wsItem = WorkspaceItem.find(context, wsItemID);
137: Group group = Group.find(context, groupID);
138:
139: // set the attributes for the JSP
140: request.setAttribute("wsItem", wsItem);
141: request.setAttribute("group", group);
142:
143: JSPManager.showJSP(request, response,
144: "/dspace-admin/supervise-confirm-remove.jsp");
145:
146: }
147:
148: /**
149: * Displays the form to link groups to workspace items
150: *
151: * @param context the context of the request
152: * @param request the servlet request
153: * @param response the servlet response
154: */
155: private void showLinkPage(Context context,
156: HttpServletRequest request, HttpServletResponse response)
157: throws ServletException, IOException, SQLException,
158: AuthorizeException {
159: // get all the groups
160: Group[] groups = Group.findAll(context, 1);
161:
162: // get all the workspace items
163: WorkspaceItem[] wsItems = WorkspaceItem.findAll(context);
164:
165: // set the attributes for the JSP
166: request.setAttribute("groups", groups);
167: request.setAttribute("wsItems", wsItems);
168:
169: JSPManager.showJSP(request, response,
170: "/dspace-admin/supervise-link.jsp");
171:
172: }
173:
174: /**
175: * Displays the options you have in the supervisor admin area
176: *
177: * @param context the context of the request
178: * @param request the servlet request
179: * @param response the servlet response
180: */
181: private void showMainPage(Context context,
182: HttpServletRequest request, HttpServletResponse response)
183: throws ServletException, IOException, SQLException,
184: AuthorizeException {
185: JSPManager.showJSP(request, response,
186: "/dspace-admin/supervise-main.jsp");
187: }
188:
189: /**
190: * Displays the list of current settings for supervisors
191: *
192: * @param context the context of the request
193: * @param request the servlet request
194: * @param response the servlet response
195: */
196: private void showListPage(Context context,
197: HttpServletRequest request, HttpServletResponse response)
198: throws ServletException, IOException, SQLException,
199: AuthorizeException {
200: // get all the supervised items
201: SupervisedItem[] si = SupervisedItem.getAll(context);
202:
203: // set the attributes for the JSP
204: request.setAttribute("supervised", si);
205:
206: JSPManager.showJSP(request, response,
207: "/dspace-admin/supervise-list.jsp");
208: }
209:
210: //**********************************************************************
211: //*************** Methods for data manipulation ************************
212: //**********************************************************************
213:
214: /**
215: * Adds supervisory settings to the database
216: *
217: * @param context the context of the request
218: * @param request the servlet request
219: * @param response the servlet response
220: */
221: void addSupervisionOrder(Context context,
222: HttpServletRequest request, HttpServletResponse response)
223: throws SQLException, AuthorizeException, ServletException,
224: IOException {
225:
226: // get the values from the request
227: int groupID = UIUtil.getIntParameter(request, "TargetGroup");
228: int wsItemID = UIUtil.getIntParameter(request, "TargetWSItem");
229: int policyType = UIUtil.getIntParameter(request, "PolicyType");
230:
231: Supervisor.add(context, groupID, wsItemID, policyType);
232:
233: log.info(LogManager.getHeader(context, "Supervision Order Set",
234: "workspace_item_id=" + wsItemID + ",eperson_group_id="
235: + groupID));
236:
237: context.complete();
238: }
239:
240: /**
241: * Maintains integrity of the supervisory database. Should be more closely
242: * integrated into the workspace code, perhaps
243: *
244: * @param context the context of the request
245: * @param request the servlet request
246: * @param response the servlet response
247: */
248: private void cleanSupervisorDatabase(Context context,
249: HttpServletRequest request, HttpServletResponse response)
250: throws ServletException, IOException, SQLException,
251: AuthorizeException {
252: // ditch any supervision orders that are no longer relevant
253: Supervisor.removeRedundant(context);
254:
255: context.complete();
256: }
257:
258: /**
259: * Remove the supervisory group and its policies from the database
260: *
261: * @param context the context of the request
262: * @param request the servlet request
263: * @param response the servlet response
264: */
265: void removeSupervisionOrder(Context context,
266: HttpServletRequest request, HttpServletResponse response)
267: throws SQLException, AuthorizeException, ServletException,
268: IOException {
269:
270: // get the values from the request
271: int wsItemID = UIUtil.getIntParameter(request, "siID");
272: int groupID = UIUtil.getIntParameter(request, "gID");
273:
274: Supervisor.remove(context, wsItemID, groupID);
275:
276: log.info(LogManager.getHeader(context,
277: "Supervision Order Removed", "workspace_item_id="
278: + wsItemID + ",eperson_group_id=" + groupID));
279:
280: context.complete();
281: }
282:
283: /**
284: * validate the submitted form to ensure that there is not a supervision
285: * order for this already.
286: *
287: * @param context the context of the request
288: * @param request the servlet request
289: * @param response the servlet response
290: */
291: private boolean validateAddForm(Context context,
292: HttpServletRequest request, HttpServletResponse response)
293: throws ServletException, IOException, SQLException,
294: AuthorizeException {
295: int groupID = UIUtil.getIntParameter(request, "TargetGroup");
296: int wsItemID = UIUtil.getIntParameter(request, "TargetWSItem");
297:
298: boolean invalid = Supervisor
299: .isOrder(context, wsItemID, groupID);
300:
301: if (invalid) {
302: JSPManager.showJSP(request, response,
303: "/dspace-admin/supervise-duplicate.jsp");
304: return false;
305: } else {
306: return true;
307: }
308: }
309:
310: }
|