1 40 41 package org.dspace.app.webui.servlet.admin; 42 43 import java.io.IOException ; 44 import java.lang.StringBuffer ; 45 import java.sql.SQLException ; 46 import java.util.ArrayList ; 47 import java.util.List ; 48 import javax.servlet.ServletException ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 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 72 public class SuperviseServlet extends org.dspace.app.webui.servlet.DSpaceServlet 73 { 74 75 76 private static Logger log = Logger.getLogger(SuperviseServlet.class); 77 78 protected void doDSGet(Context c, 79 HttpServletRequest request, HttpServletResponse response) 80 throws ServletException , IOException , SQLException , AuthorizeException 81 { 82 doDSPost(c, request, response); 84 } 85 86 protected void doDSPost(Context c, 87 HttpServletRequest request, HttpServletResponse response) 88 throws ServletException , IOException , SQLException , AuthorizeException 89 { 90 91 String button = UIUtil.getSubmitButton(request, "submit_base"); 92 93 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 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 135 142 private void showConfirmRemovePage(Context context, 143 HttpServletRequest request, HttpServletResponse response) 144 throws ServletException , IOException , SQLException , AuthorizeException 145 { 146 int wsItemID = UIUtil.getIntParameter(request,"siID"); 148 int groupID = UIUtil.getIntParameter(request,"gID"); 149 150 WorkspaceItem wsItem = WorkspaceItem.find(context, wsItemID); 152 Group group = Group.find(context, groupID); 153 154 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 169 private void showLinkPage(Context context, 170 HttpServletRequest request, HttpServletResponse response) 171 throws ServletException , IOException , SQLException , AuthorizeException 172 { 173 Group[] groups = Group.findAll(context,1); 175 176 WorkspaceItem[] wsItems = WorkspaceItem.findAll(context); 178 179 request.setAttribute("groups",groups); 181 request.setAttribute("wsItems",wsItems); 182 183 JSPManager.showJSP(request, response, "/dspace-admin/supervise-link.jsp" ); 184 185 } 186 187 194 private void showMainPage(Context context, 195 HttpServletRequest request, HttpServletResponse response) 196 throws ServletException , IOException , SQLException , AuthorizeException 197 { 198 JSPManager.showJSP(request, response, "/dspace-admin/supervise-main.jsp"); 199 } 200 201 208 private void showListPage(Context context, 209 HttpServletRequest request, HttpServletResponse response) 210 throws ServletException , IOException , SQLException , AuthorizeException 211 { 212 SupervisedItem[] si = SupervisedItem.getAll(context); 214 215 request.setAttribute("supervised",si); 217 218 JSPManager.showJSP(request, response, "/dspace-admin/supervise-list.jsp" ); 219 } 220 221 225 232 void addSupervisionOrder(Context context, 233 HttpServletRequest request, HttpServletResponse response) 234 throws SQLException , AuthorizeException, ServletException , IOException 235 { 236 237 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 259 private void cleanSupervisorDatabase(Context context, 260 HttpServletRequest request, HttpServletResponse response) 261 throws ServletException , IOException , SQLException , AuthorizeException 262 { 263 Supervisor.removeRedundant(context); 265 266 context.complete(); 267 } 268 269 270 277 void removeSupervisionOrder(Context context, 278 HttpServletRequest request, HttpServletResponse response) 279 throws SQLException , AuthorizeException, ServletException , IOException 280 { 281 282 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 303 private boolean validateAddForm(Context context, 304 HttpServletRequest request, HttpServletResponse response) 305 throws ServletException , IOException , SQLException , 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 |