Source Code Cross Referenced for GroupsWebHandler.java in  » Forum » mvnforum-1.1 » com » mvnforum » 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 » Forum » mvnforum 1.1 » com.mvnforum.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/GroupsWebHandler.java,v 1.42 2007/12/17 09:09:40 minhnn Exp $
003:         * $Author: minhnn $
004:         * $Revision: 1.42 $
005:         * $Date: 2007/12/17 09:09:40 $
006:         *
007:         * ====================================================================
008:         *
009:         * Copyright (C) 2002-2007 by MyVietnam.net
010:         *
011:         * All copyright notices regarding mvnForum MUST remain
012:         * intact in the scripts and in the outputted HTML.
013:         * The "powered by" text/logo with a link back to
014:         * http://www.mvnForum.com and http://www.MyVietnam.net in
015:         * the footer of the pages MUST remain visible when the pages
016:         * are viewed on the internet or intranet.
017:         *
018:         * This program is free software; you can redistribute it and/or modify
019:         * it under the terms of the GNU General Public License as published by
020:         * the Free Software Foundation; either version 2 of the License, or
021:         * any later version.
022:         *
023:         * This program is distributed in the hope that it will be useful,
024:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
025:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
026:         * GNU General Public License for more details.
027:         *
028:         * You should have received a copy of the GNU General Public License
029:         * along with this program; if not, write to the Free Software
030:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031:         *
032:         * Support can be obtained from support forums at:
033:         * http://www.mvnForum.com/mvnforum/index
034:         *
035:         * Correspondence and Marketing Questions can be sent to:
036:         * info at MyVietnam net
037:         *
038:         * @author: Minh Nguyen
039:         * @author: Mai  Nguyen
040:         */
041:        package com.mvnforum.admin;
042:
043:        import java.sql.Timestamp;
044:        import java.util.*;
045:
046:        import com.mvnforum.*;
047:        import com.mvnforum.auth.*;
048:        import com.mvnforum.db.DAOFactory;
049:        import com.mvnforum.db.GroupsBean;
050:        import net.myvietnam.mvncore.exception.*;
051:        import net.myvietnam.mvncore.security.SecurityUtil;
052:        import net.myvietnam.mvncore.service.EventLogService;
053:        import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
054:        import net.myvietnam.mvncore.util.*;
055:        import net.myvietnam.mvncore.web.GenericRequest;
056:        import net.myvietnam.mvncore.web.GenericResponse;
057:
058:        public class GroupsWebHandler {
059:
060:            private OnlineUserManager onlineUserManager = OnlineUserManager
061:                    .getInstance();
062:            private EventLogService eventLogService = MvnCoreServiceFactory
063:                    .getMvnCoreService().getEventLogService();
064:
065:            public GroupsWebHandler() {
066:            }
067:
068:            public void processAdd(GenericRequest request,
069:                    GenericResponse response) throws ObjectNotFoundException,
070:                    BadInputException, CreateException, DatabaseException,
071:                    DuplicateKeyException, ForeignKeyNotFoundException,
072:                    AuthenticationException {
073:
074:                SecurityUtil.checkHttpPostMethod(request);
075:
076:                OnlineUser onlineUser = onlineUserManager
077:                        .getOnlineUser(request);
078:                MVNForumPermission permission = onlineUser.getPermission();
079:                permission.ensureCanAdminSystem();
080:
081:                MyUtil.saveVNTyperMode(request, response);
082:                Timestamp now = DateUtil.getCurrentGMTTimestamp();
083:
084:                String groupName = GenericParamUtil.getParameterSafe(request,
085:                        "GroupName", true);
086:                String groupDesc = GenericParamUtil.getParameterSafe(request,
087:                        "GroupDesc", false);
088:                int groupOption = 0;//GenericParamUtil.getParameterInt(request, "GroupOption");
089:
090:                DAOFactory.getGroupsDAO().create(""/*groupOwnerName*/,
091:                        groupName, groupDesc, groupOption,
092:                        now/*groupCreationDate*/, now/*groupModifiedDate*/);
093:
094:                //now add owner to group if there is owner for this group
095:                String groupOwnerName = GenericParamUtil.getParameterSafe(
096:                        request, "GroupOwnerName", false);
097:                if (groupOwnerName.length() > 0) {
098:                    int groupID = DAOFactory.getGroupsDAO()
099:                            .getGroupIDFromGroupName(groupName);
100:                    int privilege = 0;//@todo review and support it later, should be GroupAdmin
101:                    try {
102:                        DAOFactory.getGroupsDAO().updateOwner(groupID, // primary key
103:                                groupOwnerName, now/*groupModifiedDate*/);
104:                        DAOFactory.getMemberGroupDAO().create(groupID,
105:                                groupOwnerName, privilege, now, now);
106:                    } catch (ForeignKeyNotFoundException ex) {
107:                        // what should do when member not found ???
108:                        // now, I just do nothing
109:                    } catch (DuplicateKeyException ex) {
110:                        // do nothing, it is not an error (member already in this group)
111:                    }
112:                }
113:            }
114:
115:            public void prepareDelete(GenericRequest request)
116:                    throws ObjectNotFoundException, BadInputException,
117:                    DatabaseException, AuthenticationException {
118:
119:                OnlineUser onlineUser = onlineUserManager
120:                        .getOnlineUser(request);
121:                MVNForumPermission permission = onlineUser.getPermission();
122:                permission.ensureCanAdminSystem();
123:
124:                Locale locale = I18nUtil.getLocaleInRequest(request);
125:
126:                // primary key column(s)
127:                int groupID = GenericParamUtil
128:                        .getParameterInt(request, "group");
129:
130:                //make sure reserved groups are never deleted (like "Registered Members" group)
131:                if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
132:                    String localizedMessage = MVNForumResourceBundle
133:                            .getString(locale,
134:                                    "mvncore.exception.BadInputException.cannot_delete_group.id_less_than");
135:                    throw new BadInputException(localizedMessage);
136:                    //throw new BadInputException("Cannot delete group with id <= " + Integer.toString(MVNForumConstant.LAST_RESERVED_GROUP_ID));
137:                }
138:
139:                GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(
140:                        groupID);
141:
142:                request.setAttribute("GroupsBean", groupsBean);
143:            }
144:
145:            public void processDelete(GenericRequest request)
146:                    throws BadInputException, ObjectNotFoundException,
147:                    DatabaseException, AuthenticationException {
148:
149:                SecurityUtil.checkHttpPostMethod(request);
150:
151:                OnlineUser onlineUser = onlineUserManager
152:                        .getOnlineUser(request);
153:                MVNForumPermission permission = onlineUser.getPermission();
154:                permission.ensureCanAdminSystem();
155:
156:                Locale locale = I18nUtil.getLocaleInRequest(request);
157:
158:                // primary key column(s)
159:                int groupID = GenericParamUtil
160:                        .getParameterInt(request, "group");
161:
162:                //make sure reserved groups are never deleted (like "Registered Members" group)
163:                if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
164:                    String localizedMessage = MVNForumResourceBundle
165:                            .getString(
166:                                    locale,
167:                                    "mvncore.exception.BadInputException.cannot_delete_group.id_less_than",
168:                                    new Object[] { Integer
169:                                            .toString(MVNForumConstant.LAST_RESERVED_GROUP_ID) });
170:                    throw new BadInputException(localizedMessage);
171:                    //throw new BadInputException("Cannot delete group with id <= " + Integer.toString(MVNForumConstant.LAST_RESERVED_GROUP_ID));
172:                }
173:
174:                // now check the password
175:                MyUtil.ensureCorrectCurrentPassword(request);
176:
177:                DAOFactory.getGroupForumDAO().delete_inGroup(groupID);
178:
179:                DAOFactory.getGroupPermissionDAO().delete_inGroup(groupID);
180:
181:                DAOFactory.getMemberGroupDAO().delete_inGroup(groupID);
182:
183:                DAOFactory.getGroupsDAO().delete(groupID);
184:
185:                String actionDesc = MVNForumResourceBundle.getString(
186:                        MVNForumConfig.getEventLogLocale(),
187:                        "mvnforum.eventlog.desc.DeleteGroupProcess",
188:                        new Object[] { new Integer(groupID) });
189:                eventLogService.logEvent(onlineUser.getMemberName(), request
190:                        .getRemoteAddr(),
191:                        MVNForumConstant.EVENT_LOG_MAIN_MODULE,
192:                        MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
193:                        "delete group", actionDesc, EventLogService.HIGH);
194:
195:            }
196:
197:            public void processUpdate(GenericRequest request,
198:                    GenericResponse response) throws BadInputException,
199:                    ObjectNotFoundException, DatabaseException,
200:                    DuplicateKeyException, AuthenticationException {
201:
202:                SecurityUtil.checkHttpPostMethod(request);
203:
204:                OnlineUser onlineUser = onlineUserManager
205:                        .getOnlineUser(request);
206:                MVNForumPermission permission = onlineUser.getPermission();
207:                permission.ensureCanAdminSystem();
208:
209:                MyUtil.saveVNTyperMode(request, response);
210:                Timestamp now = DateUtil.getCurrentGMTTimestamp();
211:
212:                // primary key column(s)
213:                int groupID = GenericParamUtil
214:                        .getParameterInt(request, "group");
215:
216:                // column(s) to update
217:                String groupName = GenericParamUtil.getParameterSafe(request,
218:                        "GroupName", true);
219:                String groupDesc = GenericParamUtil.getParameterSafe(request,
220:                        "GroupDesc", true);
221:
222:                DAOFactory.getGroupsDAO().update(groupID, // primary key
223:                        groupName, groupDesc, now/*groupModifiedDate*/);
224:            }
225:
226:            public void processUpdateGroupOwner(GenericRequest request)
227:                    throws ObjectNotFoundException, BadInputException,
228:                    DatabaseException, ForeignKeyNotFoundException,
229:                    CreateException, AuthenticationException {
230:
231:                SecurityUtil.checkHttpPostMethod(request);
232:
233:                OnlineUser onlineUser = onlineUserManager
234:                        .getOnlineUser(request);
235:                MVNForumPermission permission = onlineUser.getPermission();
236:                permission.ensureCanAdminSystem();
237:
238:                // now check the password
239:                MyUtil.ensureCorrectCurrentPassword(request);
240:
241:                Locale locale = I18nUtil.getLocaleInRequest(request);
242:
243:                Timestamp now = DateUtil.getCurrentGMTTimestamp();
244:
245:                // primary key column(s)
246:                int groupID = GenericParamUtil
247:                        .getParameterInt(request, "group");
248:
249:                //make sure group owners for reserved groups can't be changed
250:                if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
251:                    String localizedMessage = MVNForumResourceBundle
252:                            .getString(
253:                                    locale,
254:                                    "mvncore.exception.BadInputException.cannot_delete_group_owner_for_reserved_groups");
255:                    throw new BadInputException(localizedMessage);
256:                    //throw new BadInputException("Cannot update group owner for reserved (virtual) groups.");
257:                }
258:                //@todo: Igor: Why don't we allow changing of GroupOwner for reserved groups? I think we have no reason to disallow that.
259:
260:                // column(s) to update
261:                String groupOwnerName = GenericParamUtil.getParameterSafe(
262:                        request, "GroupOwnerName", false);
263:
264:                DAOFactory.getGroupsDAO().updateOwner(groupID, // primary key
265:                        groupOwnerName, now/*groupModifiedDate*/);
266:
267:                /*
268:                 * now add owner to group if there is owner for this group
269:                 * if member already in the group, we dont throw Exception (DuplicateKeyException)
270:                 */
271:                if (groupOwnerName.length() > 0) {
272:                    int privilege = 0;//@todo review and support it later
273:                    try {
274:                        DAOFactory.getMemberGroupDAO().create(groupID,
275:                                groupOwnerName, privilege, now, now);
276:                    } catch (DuplicateKeyException ex) {
277:                        // do nothing, it is not an error (member already in this group)
278:                    }
279:                }
280:            }
281:
282:            public void prepareView(GenericRequest request)
283:                    throws BadInputException, ObjectNotFoundException,
284:                    DatabaseException, AuthenticationException {
285:
286:                OnlineUser onlineUser = onlineUserManager
287:                        .getOnlineUser(request);
288:                MVNForumPermission permission = onlineUser.getPermission();
289:                permission.ensureCanAdminSystem();
290:
291:                // primary key column(s)
292:                int groupID = GenericParamUtil
293:                        .getParameterInt(request, "group");
294:
295:                GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(
296:                        groupID);
297:
298:                request.setAttribute("GroupsBean", groupsBean);
299:            }
300:
301:            public void prepareList(GenericRequest request)
302:                    throws DatabaseException, AuthenticationException {
303:
304:                OnlineUser onlineUser = onlineUserManager
305:                        .getOnlineUser(request);
306:                MVNForumPermission permission = onlineUser.getPermission();
307:                permission.ensureCanAdminSystem();
308:
309:                Collection groupsBeans = DAOFactory.getGroupsDAO().getGroups();
310:
311:                // now count the number of members in each group
312:                Iterator iterator = groupsBeans.iterator();
313:                while (iterator.hasNext()) {
314:                    GroupsBean groupsBean = (GroupsBean) iterator.next();
315:                    int groupID = groupsBean.getGroupID();
316:                    if (groupID == MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS) {
317:                        int memberCount = DAOFactory.getMemberDAO()
318:                                .getNumberOfMembers();
319:                        if (MVNForumConfig.isGuestUserInDatabase()) {
320:                            //"Registered Members" group. Exclude virtual guest from count.
321:                            memberCount--;
322:                        }
323:                        groupsBean.setGroupMemberCount(memberCount);
324:                    } else if (groupID <= MVNForumConstant.LAST_RESERVED_GROUP_ID) {
325:                        //other reserved groups
326:                        groupsBean.setGroupMemberCount(0);
327:                    } else {
328:                        groupsBean.setGroupMemberCount(DAOFactory
329:                                .getMemberGroupDAO().getNumberOfBeans_inGroup(
330:                                        groupID));
331:                    }
332:                }
333:
334:                request.setAttribute("GroupsBeans", groupsBeans);
335:            }
336:
337:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.