1 package org.nextime.ion.backoffice.action.security; 2 3 import java.io.IOException ; 4 import java.util.Collections ; 5 import java.util.Vector ; 6 7 import javax.servlet.ServletException ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nextime.ion.backoffice.action.BaseAction; 15 import org.nextime.ion.backoffice.exception.BackofficeSecurityException; 16 import org.nextime.ion.backoffice.security.SecurityManagerImpl; 17 18 import org.nextime.ion.framework.business.PublicationVersion; 19 import org.nextime.ion.framework.business.User; 20 import org.nextime.ion.framework.mapping.Mapping; 21 22 public class DeleteUserAction extends BaseAction { 23 24 public ActionForward perform( 25 ActionMapping mapping, 26 ActionForm form, 27 HttpServletRequest request, 28 HttpServletResponse response) 29 throws IOException , ServletException { 30 31 checkUser(request); 33 34 try { 36 Mapping.begin(); 37 if (!new SecurityManagerImpl().canAdminSecurity(User.getInstance(request.getSession().getAttribute("userLogin")+"")) ) { 38 throw new Exception (); 39 } 40 } catch (Exception e) { 41 throw new BackofficeSecurityException(); 42 } finally { 43 Mapping.rollback(); 44 } 45 46 if (request.getParameter("cancel") != null) { 48 return (mapping.findForward("cancel")); 50 } 51 52 53 String id = 55 (request.getAttribute("id") != null) 56 ? request.getAttribute("id").toString() 57 : request.getParameter("id").toString(); 58 59 if (request.getParameter("newUser") == null) { 61 try { 62 Mapping.begin(); 63 Vector users = User.listAll(); 64 Collections.sort(users); 65 Collections.reverse(users); 66 request.setAttribute("users",users); 67 Mapping.rollback(); 68 } catch (Exception e) { 69 Mapping.rollback(); 70 throw new ServletException (e); 71 } 72 73 return (mapping.findForward("view")); 75 } 76 77 try { 79 Mapping.begin(); 80 User user = User.getInstance(id); 81 User newUser = User.getInstance(request.getParameter("newUser")); 82 83 Vector publis = user.listPublications(); 84 for( int i=0; i<publis.size(); i++ ) { 85 PublicationVersion pv = (PublicationVersion)publis.get(i); 86 pv.setAuthor(newUser); 87 pv.getWorkflow().getVariables().put("author", newUser.getLogin()); 88 } 89 90 user.remove(); 91 Mapping.commit(); 92 93 if( id.equals( request.getSession().getAttribute("userLogin")) ){ 94 request.getSession().removeAttribute("userLogin"); 95 } 96 97 } catch (Exception e) { 98 Mapping.rollback(); 99 throw new ServletException (e); 100 } 101 102 return (mapping.findForward("ok")); 104 } 105 106 } 107 | Popular Tags |