Source Code Cross Referenced for GroupEditServlet.java in  » Content-Management-System » dspace » org » dspace » app » webui » servlet » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » dspace » org.dspace.app.webui.servlet.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GroupEditServlet.java
003:         *
004:         * Version: $Revision: 1538 $
005:         *
006:         * Date: $Date: 2006-07-05 14:55:31 -0500 (Wed, 05 Jul 2006) $
007:         *
008:         * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009:         * Institute of Technology.  All rights reserved.
010:         *
011:         * Redistribution and use in source and binary forms, with or without
012:         * modification, are permitted provided that the following conditions are
013:         * met:
014:         *
015:         * - Redistributions of source code must retain the above copyright
016:         * notice, this list of conditions and the following disclaimer.
017:         *
018:         * - Redistributions in binary form must reproduce the above copyright
019:         * notice, this list of conditions and the following disclaimer in the
020:         * documentation and/or other materials provided with the distribution.
021:         *
022:         * - Neither the name of the Hewlett-Packard Company nor the name of the
023:         * Massachusetts Institute of Technology nor the names of their
024:         * contributors may be used to endorse or promote products derived from
025:         * this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028:         * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031:         * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033:         * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034:         * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036:         * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037:         * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038:         * DAMAGE.
039:         */
040:        package org.dspace.app.webui.servlet.admin;
041:
042:        import java.io.IOException;
043:        import java.sql.SQLException;
044:
045:        import javax.servlet.ServletException;
046:        import javax.servlet.http.HttpServletRequest;
047:        import javax.servlet.http.HttpServletResponse;
048:
049:        import java.util.HashSet;
050:        import java.util.Iterator;
051:        import java.util.Set;
052:
053:        import org.dspace.app.webui.servlet.DSpaceServlet;
054:        import org.dspace.app.webui.util.JSPManager;
055:        import org.dspace.app.webui.util.UIUtil;
056:        import org.dspace.authorize.AuthorizeException;
057:        import org.dspace.authorize.AuthorizeManager;
058:        import org.dspace.core.Constants;
059:        import org.dspace.core.Context;
060:        import org.dspace.eperson.EPerson;
061:        import org.dspace.eperson.Group;
062:
063:        /**
064:         * Servlet for editing groups
065:         * 
066:         * @author dstuve
067:         * @version $Revision: 1538 $
068:         */
069:        public class GroupEditServlet extends DSpaceServlet {
070:            protected void doDSGet(Context c, HttpServletRequest request,
071:                    HttpServletResponse response) throws ServletException,
072:                    IOException, SQLException, AuthorizeException {
073:                doDSPost(c, request, response);
074:            }
075:
076:            protected void doDSPost(Context c, HttpServletRequest request,
077:                    HttpServletResponse response) throws ServletException,
078:                    IOException, SQLException, AuthorizeException {
079:                // Find out if there's a group parameter
080:                int groupID = UIUtil.getIntParameter(request, "group_id");
081:                Group group = null;
082:
083:                if (groupID >= 0) {
084:                    group = Group.find(c, groupID);
085:                }
086:
087:                // group is set
088:                if (group != null) {
089:                    // is this user authorized to edit this group?
090:                    AuthorizeManager.authorizeAction(c, group, Constants.ADD);
091:
092:                    boolean submit_edit = (request.getParameter("submit_edit") != null);
093:                    boolean submit_group_update = (request
094:                            .getParameter("submit_group_update") != null);
095:                    boolean submit_group_delete = (request
096:                            .getParameter("submit_group_delete") != null);
097:
098:                    // just chosen a group to edit - get group and pass it to
099:                    // group-edit.jsp
100:                    if (submit_edit && !submit_group_update
101:                            && !submit_group_delete) {
102:                        request.setAttribute("group", group);
103:                        request.setAttribute("members", group.getMembers());
104:                        request.setAttribute("membergroups", group
105:                                .getMemberGroups());
106:
107:                        JSPManager.showJSP(request, response,
108:                                "/tools/group-edit.jsp");
109:                    }
110:                    // update the members of the group
111:                    else if (submit_group_update) {
112:                        // first off, did we change the group name?
113:                        String newName = request.getParameter("group_name");
114:
115:                        if (!newName.equals(group.getName())) {
116:                            group.setName(newName);
117:                            group.update();
118:                        }
119:
120:                        int[] eperson_ids = UIUtil.getIntParameters(request,
121:                                "eperson_id");
122:                        int[] group_ids = UIUtil.getIntParameters(request,
123:                                "group_ids");
124:
125:                        // now get members, and add new ones and remove missing ones
126:                        EPerson[] members = group.getMembers();
127:                        Group[] membergroups = group.getMemberGroups();
128:
129:                        if (eperson_ids != null) {
130:                            // some epeople were listed, now make group's epeople match
131:                            // given epeople
132:                            Set memberSet = new HashSet();
133:                            Set epersonIDSet = new HashSet();
134:
135:                            // add all members to a set
136:                            for (int x = 0; x < members.length; x++) {
137:                                Integer epersonID = new Integer(members[x]
138:                                        .getID());
139:                                memberSet.add(epersonID);
140:                            }
141:
142:                            // now all eperson_ids are put in a set
143:                            for (int x = 0; x < eperson_ids.length; x++) {
144:                                epersonIDSet.add(new Integer(eperson_ids[x]));
145:                            }
146:
147:                            // process eperson_ids, adding those to group not already
148:                            // members
149:                            Iterator i = epersonIDSet.iterator();
150:
151:                            while (i.hasNext()) {
152:                                Integer currentID = (Integer) i.next();
153:
154:                                if (!memberSet.contains(currentID)) {
155:                                    group.addMember(EPerson.find(c, currentID
156:                                            .intValue()));
157:                                }
158:                            }
159:
160:                            // process members, removing any that aren't in eperson_ids
161:                            for (int x = 0; x < members.length; x++) {
162:                                EPerson e = members[x];
163:
164:                                if (!epersonIDSet.contains(new Integer(e
165:                                        .getID()))) {
166:                                    group.removeMember(e);
167:                                }
168:                            }
169:                        } else {
170:                            // no members found (ids == null), remove them all!
171:
172:                            for (int y = 0; y < members.length; y++) {
173:                                group.removeMember(members[y]);
174:                            }
175:                        }
176:
177:                        if (group_ids != null) {
178:                            // some groups were listed, now make group's member groups
179:                            // match given group IDs
180:                            Set memberSet = new HashSet();
181:                            Set groupIDSet = new HashSet();
182:
183:                            // add all members to a set
184:                            for (int x = 0; x < membergroups.length; x++) {
185:                                Integer myID = new Integer(membergroups[x]
186:                                        .getID());
187:                                memberSet.add(myID);
188:                            }
189:
190:                            // now all eperson_ids are put in a set
191:                            for (int x = 0; x < group_ids.length; x++) {
192:                                groupIDSet.add(new Integer(group_ids[x]));
193:                            }
194:
195:                            // process group_ids, adding those to group not already
196:                            // members
197:                            Iterator i = groupIDSet.iterator();
198:
199:                            while (i.hasNext()) {
200:                                Integer currentID = (Integer) i.next();
201:
202:                                if (!memberSet.contains(currentID)) {
203:                                    group.addMember(Group.find(c, currentID
204:                                            .intValue()));
205:                                }
206:                            }
207:
208:                            // process members, removing any that aren't in eperson_ids
209:                            for (int x = 0; x < membergroups.length; x++) {
210:                                Group g = membergroups[x];
211:
212:                                if (!groupIDSet
213:                                        .contains(new Integer(g.getID()))) {
214:                                    group.removeMember(g);
215:                                }
216:                            }
217:
218:                        } else {
219:                            // no members found (ids == null), remove them all!
220:                            for (int y = 0; y < membergroups.length; y++) {
221:                                group.removeMember(membergroups[y]);
222:                            }
223:                        }
224:
225:                        group.update();
226:
227:                        request.setAttribute("group", group);
228:                        request.setAttribute("members", group.getMembers());
229:                        request.setAttribute("membergroups", group
230:                                .getMemberGroups());
231:
232:                        JSPManager.showJSP(request, response,
233:                                "/tools/group-edit.jsp");
234:                        c.complete();
235:                    } else if (submit_group_delete) {
236:                        // phony authorize, only admins can do this
237:                        AuthorizeManager.authorizeAction(c, group,
238:                                Constants.WRITE);
239:
240:                        // delete group, return to group-list.jsp
241:                        group.delete();
242:
243:                        showMainPage(c, request, response);
244:                    } else {
245:                        // unknown action, show edit page
246:                        request.setAttribute("group", group);
247:                        request.setAttribute("members", group.getMembers());
248:                        request.setAttribute("membergroups", group
249:                                .getMemberGroups());
250:
251:                        JSPManager.showJSP(request, response,
252:                                "/tools/group-edit.jsp");
253:                    }
254:                } else
255:                // no group set
256:                {
257:                    // want to add a group - create a blank one, and pass to
258:                    // group_edit.jsp
259:                    String button = UIUtil.getSubmitButton(request, "submit");
260:
261:                    if (button.equals("submit_add")) {
262:                        group = Group.create(c);
263:
264:                        group.setName("new group" + group.getID());
265:                        group.update();
266:
267:                        request.setAttribute("group", group);
268:                        request.setAttribute("members", group.getMembers());
269:                        request.setAttribute("membergroups", group
270:                                .getMemberGroups());
271:
272:                        JSPManager.showJSP(request, response,
273:                                "/tools/group-edit.jsp");
274:                        c.complete();
275:                    } else {
276:                        // show the main page (select groups)
277:                        showMainPage(c, request, response);
278:                    }
279:                }
280:            }
281:
282:            private void showMainPage(Context c, HttpServletRequest request,
283:                    HttpServletResponse response) throws ServletException,
284:                    IOException, SQLException, AuthorizeException {
285:                Group[] groups = Group.findAll(c, Group.NAME);
286:
287:                // if( groups == null ) { System.out.println("groups are null"); }
288:                // else System.out.println("# of groups: " + groups.length);
289:                request.setAttribute("groups", groups);
290:
291:                JSPManager.showJSP(request, response, "/tools/group-list.jsp");
292:                c.complete();
293:            }
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.