01: /**
02: * LibreSource
03: * Copyright (C) 2004-2008 Artenum SARL / INRIA
04: * http://www.libresource.org - contact@artenum.com
05: *
06: * This file is part of the LibreSource software,
07: * which can be used and distributed under license conditions.
08: * The license conditions are provided in the LICENSE.TXT file
09: * at the root path of the packaging that enclose this file.
10: * More information can be found at
11: * - http://dev.libresource.org/home/license
12: *
13: * Initial authors :
14: *
15: * Guillaume Bort / INRIA
16: * Francois Charoy / Universite Nancy 2
17: * Julien Forest / Artenum
18: * Claude Godart / Universite Henry Poincare
19: * Florent Jouille / INRIA
20: * Sebastien Jourdain / INRIA / Artenum
21: * Yves Lerumeur / Artenum
22: * Pascal Molli / Universite Henry Poincare
23: * Gerald Oster / INRIA
24: * Mariarosa Penzi / Artenum
25: * Gerard Sookahet / Artenum
26: * Raphael Tani / INRIA
27: *
28: * Contributors :
29: *
30: * Stephane Bagnier / Artenum
31: * Amadou Dia / Artenum-IUP Blois
32: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33: */package org.libresource.web.controllers.membership;
34:
35: import org.libresource.Libresource;
36: import org.libresource.LibresourceResourceValue;
37:
38: import org.libresource.kernel.URINotExistException;
39:
40: import org.libresource.membership.MembershipConstants;
41: import org.libresource.membership.MembershipServiceException;
42: import org.libresource.membership.ejb.model.GroupResourceValue;
43: import org.libresource.membership.interfaces.MembershipService;
44:
45: import org.libresource.web.Controller;
46:
47: import java.net.URI;
48:
49: import javax.servlet.http.HttpServletRequest;
50: import javax.servlet.http.HttpServletResponse;
51:
52: public class AddMemberController implements Controller {
53: public Object process(URI uri, HttpServletRequest request,
54: HttpServletResponse response) throws Exception {
55: MembershipService membershipService = (MembershipService) Libresource
56: .getService(MembershipConstants.SERVICE);
57: URI member = new URI(request.getParameter("newMember"));
58:
59: try {
60: membershipService.addMemberInGroup(uri, member);
61: } catch (URINotExistException e) {
62: GroupResourceValue group = membershipService.getGroup(uri);
63: LibresourceResourceValue[] members = membershipService
64: .listMembers(uri);
65: request.setAttribute("group", group);
66: request.setAttribute("members", members);
67: request.setAttribute("error", "Member does not exist");
68:
69: return "/pages/modules/membership/viewGroup.jsp";
70: } catch (MembershipServiceException e) {
71: GroupResourceValue group = membershipService.getGroup(uri);
72: LibresourceResourceValue[] members = membershipService
73: .listMembers(uri);
74: request.setAttribute("group", group);
75: request.setAttribute("members", members);
76: request.setAttribute("error", e.getMessage());
77:
78: return "/pages/modules/membership/viewGroup.jsp";
79: }
80:
81: return uri;
82: }
83: }
|