Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247
WebSVN – general – Blame – /hostadmiral/trunk/src/ak/hostadmiral/core/action/SystemUserAction.java/ – Rev 911

Subversion Repositories general

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
904 dev 1
package ak.hostcaptain.core.action;
899 dev 2
 
3
import java.util.List;
4
import java.util.Collections;
5
import java.util.ArrayList;
6
 
7
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletResponse;
9
 
10
import org.apache.struts.action.Action;
11
import org.apache.struts.action.ActionMapping;
12
import org.apache.struts.action.ActionForm;
13
import org.apache.struts.action.DynaActionForm;
14
import org.apache.struts.action.ActionForward;
15
import org.apache.struts.action.ActionMessages;
16
import org.apache.struts.action.ActionErrors;
17
import org.apache.struts.action.ActionError;
18
 
19
import ak.strutsx.RequestUtilsX;
911 dev 20
import ak.strutsx.ErrorHandlerX;
899 dev 21
import ak.backpath.BackPath;
22
 
904 dev 23
import ak.hostcaptain.util.StringConverter;
24
import ak.hostcaptain.core.model.User;
911 dev 25
import ak.hostcaptain.core.model.UserManager;
904 dev 26
import ak.hostcaptain.core.model.SystemUser;
27
import ak.hostcaptain.core.model.SystemUserManager;
899 dev 28
 
29
public final class SystemUserAction
30
	extends Action
911 dev 31
	implements ErrorHandlerX
899 dev 32
{
911 dev 33
	public void handleErrors(ActionMapping mapping, ActionForm form,
34
			 HttpServletRequest request, HttpServletResponse response)
35
		throws Exception
36
	{
37
		if("submit".equals(mapping.getParameter())) {
38
			initUserList(request);
39
		}
40
	}
41
 
899 dev 42
	public ActionForward execute(ActionMapping mapping, ActionForm form,
43
			HttpServletRequest request, HttpServletResponse response)
44
		throws Exception
45
	{
46
		User user = (User)request.getSession().getAttribute("user");
47
 
48
		if("list".equals(mapping.getParameter())) {
49
			List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers());
50
			Collections.sort(list, SystemUserManager.NAME_COMPARATOR);
51
			request.setAttribute("users", list);
52
 
53
			return mapping.findForward("default");
54
		}
55
		else if("edit".equals(mapping.getParameter())) {
56
			DynaActionForm theForm  = (DynaActionForm)form;
57
			Long           userId   = StringConverter.parseLong(theForm.get("id"));
58
			DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
904 dev 59
				this, request, "ak.hostcaptain.core.form.SystemUserEditForm");
899 dev 60
 
61
			if(userId == null) {
62
 
63
			}
64
			else {
65
				SystemUser u = SystemUserManager.getInstance().get(userId);
911 dev 66
            	showForm.set("uid",   StringConverter.toString(u.getUid()));
67
            	showForm.set("name",  u.getName());
68
                if(u.getOwner() != null)
69
            	    showForm.set("owner", StringConverter.toString(u.getOwner().getId()));
899 dev 70
			}
71
 
911 dev 72
			initUserList(request);
899 dev 73
			return mapping.findForward("default");
74
		}
75
		else if("delete".equals(mapping.getParameter())) {
76
			DynaActionForm theForm  = (DynaActionForm)form;
77
			Long           userId   = StringConverter.parseLong(theForm.get("id"));
78
			SystemUser     u        = SystemUserManager.getInstance().get(userId);
79
 
80
			SystemUserManager.getInstance().delete(u);
81
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
82
			return null;
83
		}
84
		else if("submit".equals(mapping.getParameter())) {
85
			DynaActionForm theForm  = (DynaActionForm)form;
86
			Long           userId   = StringConverter.parseLong(theForm.get("id"));
87
			SystemUser     u;
88
 
89
			if(userId == null) {
90
				u = SystemUserManager.getInstance().create();
91
			}
92
			else {
93
				u = SystemUserManager.getInstance().get(userId);
94
			}
95
 
96
            u.setUid(StringConverter.parseInteger(theForm.get("uid")));
97
            u.setName((String)theForm.get("name"));
911 dev 98
 
99
            Long ownerId = StringConverter.parseLong(theForm.get("owner"));
100
            if(ownerId == null)
101
                u.setOwner(null);
102
            else
103
                u.setOwner(UserManager.getInstance().get(ownerId));
899 dev 104
 
105
			SystemUserManager.getInstance().save(u);
106
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
107
			return null;
108
		}
109
		else {
110
			throw new Exception("unknown mapping parameter");
111
		}
112
	}
911 dev 113
 
114
	private void initUserList(HttpServletRequest request)
115
		throws Exception
116
	{
117
		List list = new ArrayList(UserManager.getInstance().listUsers());
118
		Collections.sort(list, UserManager.LOGIN_COMPARATOR);
119
		request.setAttribute("users", list);
120
	}
899 dev 121
}