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

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 921

Subversion Repositories general

Rev

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

Rev Author Line No. Line
919 dev 1
package ak.hostcaptain.core.action;
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;
919 dev 21
import ak.backpath.BackPath;
22
 
23
import ak.hostcaptain.util.StringConverter;
24
import ak.hostcaptain.core.model.User;
25
import ak.hostcaptain.core.model.UserManager;
26
import ak.hostcaptain.core.model.SystemUser;
27
import ak.hostcaptain.core.model.SystemUserManager;
28
 
29
public final class SystemUserAction
30
	extends Action
911 dev 31
	implements ErrorHandlerX
919 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())) {
919 dev 38
			User user = (User)request.getSession().getAttribute("user");
915 dev 39
			initUserList(request, user);
911 dev 40
		}
41
	}
42
 
919 dev 43
	public ActionForward execute(ActionMapping mapping, ActionForm form,
44
			HttpServletRequest request, HttpServletResponse response)
45
		throws Exception
46
	{
47
		User user = (User)request.getSession().getAttribute("user");
48
 
49
		if("list".equals(mapping.getParameter())) {
50
			List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers(user));
51
			Collections.sort(list, SystemUserManager.NAME_COMPARATOR);
52
			request.setAttribute("users", list);
53
			request.setAttribute("allowedToCreate",
54
				new Boolean(SystemUserManager.getInstance().allowedToCreate(user)));
55
 
56
			return mapping.findForward("default");
57
		}
58
		else if("edit".equals(mapping.getParameter())) {
59
			DynaActionForm theForm  = (DynaActionForm)form;
60
			Long           userId   = StringConverter.parseLong(theForm.get("id"));
61
			DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
62
				this, request, "ak.hostcaptain.core.form.SystemUserEditForm");
63
 
64
			if(userId == null) {
65
				showForm.set("enabled", new Boolean(true));
66
			}
67
			else {
68
				SystemUser u = SystemUserManager.getInstance().get(user, userId);
69
            	showForm.set("uid",   StringConverter.toString(u.getUid()));
70
            	showForm.set("name",  u.getName());
911 dev 71
                if(u.getOwner() != null)
919 dev 72
            	    showForm.set("owner", StringConverter.toString(u.getOwner().getId()));
73
				showForm.set("enabled", u.getEnabled());
74
				showForm.set("comment", u.getComment());
75
			}
76
 
915 dev 77
			initUserList(request, user);
919 dev 78
			return mapping.findForward("default");
79
		}
80
		else if("delete".equals(mapping.getParameter())) {
81
			DynaActionForm theForm  = (DynaActionForm)form;
82
			Long           userId   = StringConverter.parseLong(theForm.get("id"));
83
			SystemUser     u        = SystemUserManager.getInstance().get(user, userId);
84
 
85
			SystemUserManager.getInstance().delete(user, u);
86
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
87
			return null;
88
		}
89
		else if("submit".equals(mapping.getParameter())) {
90
			DynaActionForm theForm  = (DynaActionForm)form;
91
			Long           userId   = StringConverter.parseLong(theForm.get("id"));
92
			SystemUser     u;
93
 
94
			if(userId == null) {
95
				u = SystemUserManager.getInstance().create(user);
96
			}
97
			else {
98
				u = SystemUserManager.getInstance().get(user, userId);
99
			}
100
 
921 dev 101
            u.setUid(user, StringConverter.parseInteger(theForm.get("uid")));
102
            u.setName(user, (String)theForm.get("name"));
919 dev 103
 
911 dev 104
            Long ownerId = StringConverter.parseLong(theForm.get("owner"));
105
            if(ownerId == null)
921 dev 106
                u.setOwner(user, null);
911 dev 107
            else
921 dev 108
                u.setOwner(user, UserManager.getInstance().get(user, ownerId));
911 dev 109
 
921 dev 110
			u.setEnabled(user, (Boolean)theForm.get("enabled"));
111
			u.setComment(user, (String)theForm.get("comment"));
919 dev 112
 
113
			SystemUserManager.getInstance().save(user, u);
114
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
115
			return null;
116
		}
117
		else {
118
			throw new Exception("unknown mapping parameter");
119
		}
120
	}
121
 
915 dev 122
	private void initUserList(HttpServletRequest request, User user)
911 dev 123
		throws Exception
124
	{
915 dev 125
		List list = new ArrayList(UserManager.getInstance().listUsers(user));
911 dev 126
		Collections.sort(list, UserManager.LOGIN_COMPARATOR);
127
		request.setAttribute("users", list);
128
	}
919 dev 129
}