01: /*
02: * argun 1.0
03: * Web 2.0 delivery framework
04: * Copyright (C) 2007 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.biz
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.xbank;
24:
25: import java.sql.SQLException;
26: import java.util.Collection;
27:
28: import javax.servlet.http.HttpServletRequest;
29: import javax.servlet.http.HttpServletResponse;
30:
31: import biz.hammurapi.web.ActionServlet;
32: import biz.hammurapi.xbank.sql.BankEngine;
33: import biz.hammurapi.xbank.sql.BankUserImpl;
34:
35: /**
36: * Web actions class
37: * @author Pavel Vlasov
38: * @version $Revision$
39: */
40: public class UserActions extends ActionsBase {
41:
42: /**
43: * Retrieves list of users
44: * @param request
45: * @param response
46: * @param servlet
47: * @return
48: */
49: public Collection list(HttpServletRequest request,
50: HttpServletResponse response, ActionServlet servlet) {
51: return ((BankEngine) getGlobal(request, "db/Engine"))
52: .getBankUser();
53: }
54:
55: public Object get(HttpServletRequest request,
56: HttpServletResponse response, ActionServlet servlet)
57: throws SQLException {
58: if ("yes".equals(request.getParameter("new"))) {
59: BankUserImpl ret = new BankUserImpl();
60: ret.setAttribute("new", "yes");
61: return ret;
62: }
63:
64: String name = request.getParameter("name");
65: if (name == null) {
66: return "User name parameter is missing";
67: }
68: BankEngine engine = getEngine(request);
69: BankUserImpl bankUser = (BankUserImpl) engine.getBankUser(name);
70: if (bankUser == null) {
71: return "Invalid user name";
72: }
73:
74: bankUser.setAttribute("accounts", engine
75: .getAccountByOwner(name));
76: return bankUser;
77: }
78: }
|