1 40 package org.dspace.app.webui.servlet.admin; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 45 import javax.servlet.ServletException ; 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.servlet.http.HttpServletResponse ; 48 49 import org.apache.log4j.Logger; 50 import org.dspace.app.webui.servlet.DSpaceServlet; 51 import org.dspace.app.webui.util.JSPManager; 52 import org.dspace.app.webui.util.UIUtil; 53 import org.dspace.authorize.AuthorizeException; 54 import org.dspace.core.Context; 55 import org.dspace.eperson.EPerson; 56 import org.dspace.eperson.Group; 57 import org.dspace.eperson.EPersonDeletionException; 58 59 65 public class EPersonAdminServlet extends DSpaceServlet 66 { 67 68 private static Logger log = Logger.getLogger(EPersonAdminServlet.class); 69 70 protected void doDSGet(Context context, HttpServletRequest request, 71 HttpServletResponse response) throws ServletException , IOException , 72 SQLException , AuthorizeException 73 { 74 showMain(context, request, response); 75 } 76 77 protected void doDSPost(Context context, HttpServletRequest request, 78 HttpServletResponse response) throws ServletException , IOException , 79 SQLException , AuthorizeException 80 { 81 String button = UIUtil.getSubmitButton(request, "submit"); 82 83 if (button.equals("submit_add")) 84 { 85 EPerson e = EPerson.create(context); 87 88 e.setEmail("newuser" + e.getID()); 90 e.update(); 91 92 request.setAttribute("eperson", e); 93 94 JSPManager.showJSP(request, response, 95 "/dspace-admin/eperson-edit.jsp"); 96 97 context.complete(); 98 } 99 else if (button.equals("submit_edit")) 100 { 101 EPerson e = EPerson.find(context, UIUtil.getIntParameter(request, 103 "eperson_id")); 104 105 if (e == null) 107 { 108 request.setAttribute("no_eperson_selected", new Boolean (true)); 109 showMain(context, request, response); 110 } 111 else 112 { 113 Group[] groupMemberships = Group.allMemberGroups(context, e); 115 116 request.setAttribute("eperson", e); 117 request.setAttribute("group.memberships", groupMemberships); 118 119 JSPManager.showJSP(request, response, 120 "/dspace-admin/eperson-edit.jsp"); 121 122 context.complete(); 123 } 124 } 125 else if (button.equals("submit_save")) 126 { 127 EPerson e = EPerson.find(context, UIUtil.getIntParameter(request, 129 "eperson_id")); 130 131 String oldEmail = e.getEmail(); 134 String newEmail = request.getParameter("email").trim(); 135 String netid = request.getParameter("netid"); 136 137 if (!newEmail.equals(oldEmail)) 138 { 139 if (EPerson.findByEmail(context, newEmail) == null) 141 { 142 e.setEmail(newEmail); 144 145 e 146 .setFirstName(request.getParameter("firstname") 147 .equals("") ? null : request 148 .getParameter("firstname")); 149 150 e 151 .setLastName(request.getParameter("lastname") 152 .equals("") ? null : request 153 .getParameter("lastname")); 154 155 if (netid != null) 156 { 157 e.setNetid(netid.equals("") ? null : netid); 158 } 159 else 160 { 161 e.setNetid(null); 162 } 163 164 e.setMetadata("phone", request.getParameter("phone") 166 .equals("") ? null : request.getParameter("phone")); 167 168 e.setCanLogIn((request.getParameter("can_log_in") != null) 169 && request.getParameter("can_log_in") 170 .equals("true")); 171 172 e.setRequireCertificate((request 173 .getParameter("require_certificate") != null) 174 && request.getParameter("require_certificate") 175 .equals("true")); 176 177 e.update(); 178 179 showMain(context, request, response); 180 context.complete(); 181 } 182 else 183 { 184 request.setAttribute("eperson", e); 186 request.setAttribute("email_exists", new Boolean (true)); 187 188 JSPManager.showJSP(request, response, 189 "/dspace-admin/eperson-edit.jsp"); 190 191 context.complete(); 192 } 193 } 194 else 195 { 196 if (netid != null) 198 { 199 e.setNetid(netid.equals("") ? null : netid); 200 } 201 else 202 { 203 e.setNetid(null); 204 } 205 206 e 207 .setFirstName(request.getParameter("firstname").equals( 208 "") ? null : request.getParameter("firstname")); 209 210 e 211 .setLastName(request.getParameter("lastname") 212 .equals("") ? null : request 213 .getParameter("lastname")); 214 215 e.setMetadata("phone", 217 request.getParameter("phone").equals("") ? null 218 : request.getParameter("phone")); 219 220 e.setCanLogIn((request.getParameter("can_log_in") != null) 221 && request.getParameter("can_log_in").equals("true")); 222 223 e.setRequireCertificate((request 224 .getParameter("require_certificate") != null) 225 && request.getParameter("require_certificate").equals( 226 "true")); 227 228 e.update(); 229 230 showMain(context, request, response); 231 context.complete(); 232 } 233 } 234 else if (button.equals("submit_delete")) 235 { 236 EPerson e = EPerson.find(context, UIUtil.getIntParameter(request, 238 "eperson_id")); 239 240 if (e == null) 242 { 243 request.setAttribute("no_eperson_selected", new Boolean (true)); 244 showMain(context, request, response); 245 } 246 else 247 { 248 request.setAttribute("eperson", e); 249 250 JSPManager.showJSP(request, response, 251 "/dspace-admin/eperson-confirm-delete.jsp"); 252 } 253 } 254 else if (button.equals("submit_confirm_delete")) 255 { 256 EPerson e = EPerson.find(context, UIUtil.getIntParameter(request, 258 "eperson_id")); 259 260 try 261 { 262 e.delete(); 263 } 264 catch (EPersonDeletionException ex) 265 { 266 request.setAttribute("eperson", e); 267 request.setAttribute("tableList", ex.getTables()); 268 JSPManager.showJSP(request, response, 269 "/dspace-admin/eperson-deletion-error.jsp"); 270 } 271 272 showMain(context, request, response); 273 context.complete(); 274 } 275 else 276 { 277 showMain(context, request, response); 279 } 280 } 281 282 private void showMain(Context c, HttpServletRequest request, 283 HttpServletResponse response) throws ServletException , IOException , 284 SQLException , AuthorizeException 285 { 286 JSPManager.showJSP(request, response, "/dspace-admin/eperson-main.jsp"); 287 } 288 } 289 | Popular Tags |