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

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 915

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())) {
915 dev 38
			User user = (User)request.getSession().getAttribute("user");
39
			initUserList(request, user);
911 dev 40
		}
41
	}
42
 
899 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())) {
914 dev 50
			List list = new ArrayList(SystemUserManager.getInstance().listSystemUsers(user));
899 dev 51
			Collections.sort(list, SystemUserManager.NAME_COMPARATOR);
52
			request.setAttribute("users", list);
914 dev 53
			request.setAttribute("allowedToCreate",
54
				new Boolean(SystemUserManager.getInstance().allowedToCreate(user)));
899 dev 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(
904 dev 62
				this, request, "ak.hostcaptain.core.form.SystemUserEditForm");
899 dev 63
 
64
			if(userId == null) {
913 dev 65
				showForm.set("enabled", new Boolean(true));
899 dev 66
			}
67
			else {
914 dev 68
				SystemUser u = SystemUserManager.getInstance().get(user, userId);
911 dev 69
            	showForm.set("uid",   StringConverter.toString(u.getUid()));
70
            	showForm.set("name",  u.getName());
71
                if(u.getOwner() != null)
72
            	    showForm.set("owner", StringConverter.toString(u.getOwner().getId()));
913 dev 73
				showForm.set("enabled", u.getEnabled());
74
				showForm.set("comment", u.getComment());
899 dev 75
			}
76
 
915 dev 77
			initUserList(request, user);
899 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"));
914 dev 83
			SystemUser     u        = SystemUserManager.getInstance().get(user, userId);
899 dev 84
 
914 dev 85
			SystemUserManager.getInstance().delete(user, u);
899 dev 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) {
914 dev 95
				u = SystemUserManager.getInstance().create(user);
899 dev 96
			}
97
			else {
914 dev 98
				u = SystemUserManager.getInstance().get(user, userId);
899 dev 99
			}
100
 
101
            u.setUid(StringConverter.parseInteger(theForm.get("uid")));
102
            u.setName((String)theForm.get("name"));
913 dev 103
 
911 dev 104
            Long ownerId = StringConverter.parseLong(theForm.get("owner"));
105
            if(ownerId == null)
106
                u.setOwner(null);
107
            else
915 dev 108
                u.setOwner(UserManager.getInstance().get(user, ownerId));
899 dev 109
 
913 dev 110
			u.setEnabled((Boolean)theForm.get("enabled"));
111
			u.setComment((String)theForm.get("comment"));
112
 
914 dev 113
			SystemUserManager.getInstance().save(user, u);
899 dev 114
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
115
			return null;
116
		}
117
		else {
118
			throw new Exception("unknown mapping parameter");
119
		}
120
	}
911 dev 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
	}
899 dev 129
}