Source Code Cross Referenced for PermissionLevelManagerImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » component » app » messageforums » 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 » ERP CRM Financial » sakai » org.sakaiproject.component.app.messageforums 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/PermissionLevelManagerImpl.java $
003:         * $Id: PermissionLevelManagerImpl.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.component.app.messageforums;
021:
022:        import java.sql.SQLException;
023:        import java.util.Date;
024:        import java.util.HashMap;
025:        import java.util.HashSet;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:        import java.util.ArrayList;
030:        import java.util.Set;
031:
032:        import org.hibernate.Hibernate;
033:        import org.hibernate.HibernateException;
034:        import org.hibernate.Query;
035:        import org.hibernate.Session;
036:
037:        import org.apache.commons.beanutils.PropertyUtils;
038:        import org.apache.commons.logging.Log;
039:        import org.apache.commons.logging.LogFactory;
040:        import org.sakaiproject.api.app.messageforums.AreaManager;
041:        import org.sakaiproject.api.app.messageforums.DBMembershipItem;
042:        import org.sakaiproject.api.app.messageforums.Topic;
043:        import org.sakaiproject.api.app.messageforums.MessageForumsTypeManager;
044:        import org.sakaiproject.api.app.messageforums.PermissionLevel;
045:        import org.sakaiproject.api.app.messageforums.PermissionLevelManager;
046:        import org.sakaiproject.api.app.messageforums.PermissionsMask;
047:        import org.sakaiproject.id.api.IdManager;
048:        import org.sakaiproject.tool.api.SessionManager;
049:        import org.sakaiproject.component.app.messageforums.dao.hibernate.DBMembershipItemImpl;
050:        import org.sakaiproject.component.app.messageforums.dao.hibernate.PermissionLevelImpl;
051:        import org.sakaiproject.event.api.EventTrackingService;
052:        import org.springframework.orm.hibernate3.HibernateCallback;
053:        import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
054:
055:        public class PermissionLevelManagerImpl extends HibernateDaoSupport
056:                implements  PermissionLevelManager {
057:
058:            private static final Log LOG = LogFactory
059:                    .getLog(PermissionLevelManagerImpl.class);
060:            private EventTrackingService eventTrackingService;
061:            private SessionManager sessionManager;
062:            private IdManager idManager;
063:            private MessageForumsTypeManager typeManager;
064:            private AreaManager areaManager;
065:
066:            private Map defaultPermissionsMap;
067:
068:            private static final String QUERY_BY_TYPE_UUID = "findPermissionLevelByTypeUuid";
069:            private static final String QUERY_ORDERED_LEVEL_NAMES = "findOrderedPermissionLevelNames";
070:            private static final String QUERY_BY_AREA_ALL_FORUMS_MEMBERSHIP = "findAllMembershipItemsForForumsForSite";
071:            private static final String QUERY_GET_ALL_TOPICS = "findAllTopicsForSite";
072:            private static final String QUERY_BY_TOPIC_IDS_ALL_TOPIC_MEMBERSHIP = "findAllMembershipItemsForTopicsForSite";
073:            private static final String QUERY_BY_AREA_ID_ALL_MEMBERSHIP = "findAllMembershipItemsForSite";
074:
075:            public void init() {
076:                LOG.info("init()");
077:
078:                try {
079:                    loadInitialDefaultPermissionLevel();
080:                } catch (Exception e) {
081:                    LOG.warn("Error loading initial default permissions", e);
082:                }
083:
084:                /** test creation of permission mask and author level
085:                PermissionsMask mask = new PermissionsMask();
086:                mask.put(PermissionLevel.NEW_FORUM, Boolean.TRUE); 
087:                mask.put(PermissionLevel.NEW_TOPIC, Boolean.TRUE);
088:                mask.put(PermissionLevel.NEW_RESPONSE, Boolean.TRUE);
089:                mask.put(PermissionLevel.RESPONSE_TO_RESPONSE, Boolean.TRUE);
090:                mask.put(PermissionLevel.MOVE_POSTING, Boolean.TRUE);
091:                mask.put(PermissionLevel.CHANGE_SETTINGS, Boolean.TRUE);
092:                mask.put(PermissionLevel.POST_GRADES, Boolean.TRUE);
093:                mask.put(PermissionLevel.READ, Boolean.TRUE);
094:                mask.put(PermissionLevel.MARK_AS_READ, Boolean.TRUE);
095:                mask.put(PermissionLevel.MODERATE_POSTINGS, Boolean.TRUE);
096:                mask.put(PermissionLevel.DELETE_OWN, Boolean.TRUE);
097:                mask.put(PermissionLevel.DELETE_ANY, Boolean.TRUE);
098:                mask.put(PermissionLevel.REVISE_OWN, Boolean.TRUE);
099:                mask.put(PermissionLevel.REVISE_ANY, Boolean.TRUE);
100:                DBMembershipItem membershipItem = createDBMembershipItem("jlannan", DBMembershipItemImpl.TYPE_USER);
101:                PermissionLevel level = createPermissionLevel("Author", typeManager.getAuthorLevelType(), mask);    
102:                Area area = areaManager.createArea(typeManager.getPrivateMessageAreaType());
103:                
104:                membershipItem.setPermissionLevel(level);
105:                
106:                // save DBMembershiptItem here to get an id so we can add to the set
107:                saveDBMembershipItem(membershipItem);
108:                area.addMembershipItem(membershipItem);
109:                       
110:                area.setName("test");
111:                area.setHidden(Boolean.FALSE);
112:                area.setEnabled(Boolean.TRUE);
113:                area.setLocked(Boolean.FALSE);
114:                //area.addPermissionLevel(level);
115:                areaManager.saveArea(area); 
116:                
117:                List l = getOrderedPermissionLevelNames();
118:                 **/
119:
120:            }
121:
122:            public PermissionLevel getPermissionLevelByName(String name) {
123:                if (LOG.isDebugEnabled()) {
124:                    LOG.debug("getPermissionLevelByName executing(" + name
125:                            + ")");
126:                }
127:
128:                if (PERMISSION_LEVEL_NAME_OWNER.equals(name)) {
129:                    return getDefaultOwnerPermissionLevel();
130:                } else if (PERMISSION_LEVEL_NAME_AUTHOR.equals(name)) {
131:                    return getDefaultAuthorPermissionLevel();
132:                } else if (PERMISSION_LEVEL_NAME_NONEDITING_AUTHOR.equals(name)) {
133:                    return getDefaultNoneditingAuthorPermissionLevel();
134:                } else if (PERMISSION_LEVEL_NAME_CONTRIBUTOR.equals(name)) {
135:                    return getDefaultContributorPermissionLevel();
136:                } else if (PERMISSION_LEVEL_NAME_REVIEWER.equals(name)) {
137:                    return getDefaultReviewerPermissionLevel();
138:                } else if (PERMISSION_LEVEL_NAME_NONE.equals(name)) {
139:                    return getDefaultNonePermissionLevel();
140:                } else {
141:                    return null;
142:                }
143:            }
144:
145:            public List getOrderedPermissionLevelNames() {
146:
147:                if (LOG.isDebugEnabled()) {
148:                    LOG.debug("getOrderedPermissionLevelNames executing");
149:                }
150:
151:                HibernateCallback hcb = new HibernateCallback() {
152:                    public Object doInHibernate(Session session)
153:                            throws HibernateException, SQLException {
154:                        Query q = session
155:                                .getNamedQuery(QUERY_ORDERED_LEVEL_NAMES);
156:                        return q.list();
157:                    }
158:                };
159:
160:                return (List) getHibernateTemplate().execute(hcb);
161:            }
162:
163:            public String getPermissionLevelType(PermissionLevel level) {
164:
165:                if (LOG.isDebugEnabled()) {
166:                    LOG
167:                            .debug("getPermissionLevelType executing(" + level
168:                                    + ")");
169:                }
170:
171:                if (level == null) {
172:                    throw new IllegalArgumentException("Null Argument");
173:                }
174:
175:                PermissionLevel ownerLevel = getDefaultOwnerPermissionLevel();
176:                if (level.equals(ownerLevel)) {
177:                    return ownerLevel.getTypeUuid();
178:                }
179:
180:                PermissionLevel authorLevel = getDefaultAuthorPermissionLevel();
181:                if (level.equals(authorLevel)) {
182:                    return authorLevel.getTypeUuid();
183:                }
184:
185:                PermissionLevel noneditingAuthorLevel = getDefaultNoneditingAuthorPermissionLevel();
186:                if (level.equals(noneditingAuthorLevel)) {
187:                    return noneditingAuthorLevel.getTypeUuid();
188:                }
189:
190:                PermissionLevel reviewerLevel = getDefaultReviewerPermissionLevel();
191:                if (level.equals(reviewerLevel)) {
192:                    return reviewerLevel.getTypeUuid();
193:                }
194:
195:                PermissionLevel contributorLevel = getDefaultContributorPermissionLevel();
196:                if (level.equals(contributorLevel)) {
197:                    return contributorLevel.getTypeUuid();
198:                }
199:
200:                PermissionLevel noneLevel = getDefaultNonePermissionLevel();
201:                if (level.equals(noneLevel)) {
202:                    return noneLevel.getTypeUuid();
203:                }
204:
205:                return null;
206:            }
207:
208:            /**
209:             * Populates the permission level data for the case when the default permission levels
210:             * are being created, not the custom levels
211:             * @param name
212:             * @param typeUuid
213:             * @param mask
214:             * @param uuid
215:             * @return
216:             */
217:            private PermissionLevel createDefaultPermissionLevel(String name,
218:                    String typeUuid, PermissionsMask mask) {
219:                if (LOG.isDebugEnabled()) {
220:                    LOG.debug("createDefaultPermissionLevel executing(" + name
221:                            + "," + typeUuid + "," + mask + ")");
222:                }
223:
224:                if (name == null || typeUuid == null || mask == null) {
225:                    throw new IllegalArgumentException("Null Argument");
226:                }
227:
228:                PermissionLevel newPermissionLevel = new PermissionLevelImpl();
229:                Date now = new Date();
230:                newPermissionLevel.setName(name);
231:                newPermissionLevel.setUuid(idManager.createUuid());
232:                newPermissionLevel.setCreated(now);
233:                newPermissionLevel.setCreatedBy("admin");
234:                newPermissionLevel.setModified(now);
235:                newPermissionLevel.setModifiedBy("admin");
236:                newPermissionLevel.setTypeUuid(typeUuid);
237:
238:                // set permission properties using reflection
239:                for (Iterator i = mask.keySet().iterator(); i.hasNext();) {
240:                    String key = (String) i.next();
241:                    Boolean value = (Boolean) mask.get(key);
242:                    try {
243:                        PropertyUtils.setSimpleProperty(newPermissionLevel,
244:                                key, value);
245:                    } catch (Exception e) {
246:                        throw new Error(e);
247:                    }
248:                }
249:
250:                return newPermissionLevel;
251:            }
252:
253:            public PermissionLevel createPermissionLevel(String name,
254:                    String typeUuid, PermissionsMask mask) {
255:
256:                if (LOG.isDebugEnabled()) {
257:                    LOG.debug("createPermissionLevel executing(" + name + ","
258:                            + typeUuid + "," + mask + ")");
259:                }
260:
261:                if (name == null || typeUuid == null || mask == null) {
262:                    throw new IllegalArgumentException("Null Argument");
263:                }
264:
265:                PermissionLevel newPermissionLevel = new PermissionLevelImpl();
266:                Date now = new Date();
267:                String currentUser = getCurrentUser();
268:                newPermissionLevel.setName(name);
269:                newPermissionLevel.setUuid(idManager.createUuid());
270:                newPermissionLevel.setCreated(now);
271:                newPermissionLevel.setCreatedBy(currentUser);
272:                newPermissionLevel.setModified(now);
273:                newPermissionLevel.setModifiedBy(currentUser);
274:                newPermissionLevel.setTypeUuid(typeUuid);
275:
276:                // set permission properties using reflection
277:                for (Iterator i = mask.keySet().iterator(); i.hasNext();) {
278:                    String key = (String) i.next();
279:                    Boolean value = (Boolean) mask.get(key);
280:                    try {
281:                        PropertyUtils.setSimpleProperty(newPermissionLevel,
282:                                key, value);
283:                    } catch (Exception e) {
284:                        throw new Error(e);
285:                    }
286:                }
287:
288:                return newPermissionLevel;
289:            }
290:
291:            public DBMembershipItem createDBMembershipItem(String name,
292:                    String permissionLevelName, Integer type) {
293:
294:                if (LOG.isDebugEnabled()) {
295:                    LOG.debug("createDBMembershipItem executing(" + name + ","
296:                            + type + ")");
297:                }
298:
299:                if (name == null || type == null) {
300:                    throw new IllegalArgumentException("Null Argument");
301:                }
302:
303:                DBMembershipItem newDBMembershipItem = new DBMembershipItemImpl();
304:                Date now = new Date();
305:                String currentUser = getCurrentUser();
306:                newDBMembershipItem.setName(name);
307:                newDBMembershipItem.setPermissionLevelName(permissionLevelName);
308:                newDBMembershipItem.setUuid(idManager.createUuid());
309:                newDBMembershipItem.setCreated(now);
310:                newDBMembershipItem.setCreatedBy(currentUser);
311:                newDBMembershipItem.setModified(now);
312:                newDBMembershipItem.setModifiedBy(currentUser);
313:                newDBMembershipItem.setType(type);
314:
315:                return newDBMembershipItem;
316:            }
317:
318:            public void saveDBMembershipItem(DBMembershipItem item) {
319:                getHibernateTemplate().saveOrUpdate(item);
320:            }
321:
322:            public void savePermissionLevel(PermissionLevel level) {
323:                getHibernateTemplate().saveOrUpdate(level);
324:            }
325:
326:            public PermissionLevel getDefaultOwnerPermissionLevel() {
327:
328:                if (LOG.isDebugEnabled()) {
329:                    LOG.debug("getDefaultOwnerPermissionLevel executing");
330:                }
331:
332:                String typeUuid = typeManager.getOwnerLevelType();
333:
334:                if (typeUuid == null) {
335:                    throw new IllegalStateException("type cannot be null");
336:                }
337:                PermissionLevel level = getDefaultPermissionLevel(typeUuid);
338:
339:                if (level == null) {
340:                    PermissionsMask mask = new PermissionsMask();
341:                    mask.put(PermissionLevel.NEW_FORUM, new Boolean(true));
342:                    mask.put(PermissionLevel.NEW_TOPIC, new Boolean(true));
343:                    mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(true));
344:                    mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
345:                            new Boolean(true));
346:                    mask.put(PermissionLevel.MOVE_POSTING, new Boolean(true));
347:                    mask
348:                            .put(PermissionLevel.CHANGE_SETTINGS, new Boolean(
349:                                    true));
350:                    mask.put(PermissionLevel.POST_TO_GRADEBOOK, new Boolean(
351:                            true));
352:                    mask.put(PermissionLevel.READ, new Boolean(true));
353:                    mask.put(PermissionLevel.MARK_AS_READ, new Boolean(true));
354:                    mask.put(PermissionLevel.MODERATE_POSTINGS, new Boolean(
355:                            true));
356:                    mask.put(PermissionLevel.DELETE_OWN, new Boolean(false));
357:                    mask.put(PermissionLevel.DELETE_ANY, new Boolean(true));
358:                    mask.put(PermissionLevel.REVISE_OWN, new Boolean(false));
359:                    mask.put(PermissionLevel.REVISE_ANY, new Boolean(true));
360:
361:                    return createPermissionLevel(
362:                            PermissionLevelManager.PERMISSION_LEVEL_NAME_OWNER,
363:                            typeUuid, mask);
364:                } else
365:                    return level;
366:            }
367:
368:            public PermissionLevel getDefaultAuthorPermissionLevel() {
369:
370:                if (LOG.isDebugEnabled()) {
371:                    LOG.debug("getDefaultAuthorPermissionLevel executing");
372:                }
373:
374:                String typeUuid = typeManager.getAuthorLevelType();
375:
376:                if (typeUuid == null) {
377:                    throw new IllegalStateException("type cannot be null");
378:                }
379:                PermissionLevel level = getDefaultPermissionLevel(typeUuid);
380:
381:                if (level == null) {
382:
383:                    PermissionsMask mask = new PermissionsMask();
384:                    mask.put(PermissionLevel.NEW_FORUM, new Boolean(true));
385:                    mask.put(PermissionLevel.NEW_TOPIC, new Boolean(true));
386:                    mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(true));
387:                    mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
388:                            new Boolean(true));
389:                    mask.put(PermissionLevel.MOVE_POSTING, new Boolean(true));
390:                    mask
391:                            .put(PermissionLevel.CHANGE_SETTINGS, new Boolean(
392:                                    true));
393:                    mask.put(PermissionLevel.POST_TO_GRADEBOOK, new Boolean(
394:                            true));
395:                    mask.put(PermissionLevel.READ, new Boolean(true));
396:                    mask.put(PermissionLevel.MARK_AS_READ, new Boolean(true));
397:                    mask.put(PermissionLevel.MODERATE_POSTINGS, new Boolean(
398:                            false));
399:                    mask.put(PermissionLevel.DELETE_OWN, new Boolean(true));
400:                    mask.put(PermissionLevel.DELETE_ANY, new Boolean(false));
401:                    mask.put(PermissionLevel.REVISE_OWN, new Boolean(true));
402:                    mask.put(PermissionLevel.REVISE_ANY, new Boolean(false));
403:
404:                    return createPermissionLevel(
405:                            PermissionLevelManager.PERMISSION_LEVEL_NAME_AUTHOR,
406:                            typeUuid, mask);
407:                } else
408:                    return level;
409:            }
410:
411:            public PermissionLevel getDefaultNoneditingAuthorPermissionLevel() {
412:
413:                if (LOG.isDebugEnabled()) {
414:                    LOG
415:                            .debug("getDefaultNoneditingAuthorPermissionLevel executing");
416:                }
417:
418:                String typeUuid = typeManager.getNoneditingAuthorLevelType();
419:
420:                if (typeUuid == null) {
421:                    throw new IllegalStateException("type cannot be null");
422:                }
423:                PermissionLevel level = getDefaultPermissionLevel(typeUuid);
424:
425:                if (level == null) {
426:                    PermissionsMask mask = new PermissionsMask();
427:                    mask.put(PermissionLevel.NEW_FORUM, new Boolean(true));
428:                    mask.put(PermissionLevel.NEW_TOPIC, new Boolean(true));
429:                    mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(true));
430:                    mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
431:                            new Boolean(true));
432:                    mask.put(PermissionLevel.MOVE_POSTING, new Boolean(false));
433:                    mask
434:                            .put(PermissionLevel.CHANGE_SETTINGS, new Boolean(
435:                                    true));
436:                    mask.put(PermissionLevel.POST_TO_GRADEBOOK, new Boolean(
437:                            true));
438:                    mask.put(PermissionLevel.READ, new Boolean(true));
439:                    mask.put(PermissionLevel.MARK_AS_READ, new Boolean(true));
440:                    mask.put(PermissionLevel.MODERATE_POSTINGS, new Boolean(
441:                            false));
442:                    mask.put(PermissionLevel.DELETE_OWN, new Boolean(false));
443:                    mask.put(PermissionLevel.DELETE_ANY, new Boolean(false));
444:                    mask.put(PermissionLevel.REVISE_OWN, new Boolean(true));
445:                    mask.put(PermissionLevel.REVISE_ANY, new Boolean(false));
446:
447:                    return createPermissionLevel(
448:                            PermissionLevelManager.PERMISSION_LEVEL_NAME_NONEDITING_AUTHOR,
449:                            typeUuid, mask);
450:                } else
451:                    return level;
452:            }
453:
454:            public PermissionLevel getDefaultReviewerPermissionLevel() {
455:
456:                if (LOG.isDebugEnabled()) {
457:                    LOG.debug("getDefaultReviewerPermissionLevel executing");
458:                }
459:
460:                String typeUuid = typeManager.getReviewerLevelType();
461:
462:                if (typeUuid == null) {
463:                    throw new IllegalStateException("type cannot be null");
464:                }
465:                PermissionLevel level = getDefaultPermissionLevel(typeUuid);
466:
467:                if (level == null) {
468:                    PermissionsMask mask = new PermissionsMask();
469:                    mask.put(PermissionLevel.NEW_FORUM, new Boolean(false));
470:                    mask.put(PermissionLevel.NEW_TOPIC, new Boolean(false));
471:                    mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(false));
472:                    mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
473:                            new Boolean(false));
474:                    mask.put(PermissionLevel.MOVE_POSTING, new Boolean(false));
475:                    mask.put(PermissionLevel.CHANGE_SETTINGS,
476:                            new Boolean(false));
477:                    mask.put(PermissionLevel.POST_TO_GRADEBOOK, new Boolean(
478:                            false));
479:                    mask.put(PermissionLevel.READ, new Boolean(true));
480:                    mask.put(PermissionLevel.MARK_AS_READ, new Boolean(true));
481:                    mask.put(PermissionLevel.MODERATE_POSTINGS, new Boolean(
482:                            false));
483:                    mask.put(PermissionLevel.DELETE_OWN, new Boolean(false));
484:                    mask.put(PermissionLevel.DELETE_ANY, new Boolean(false));
485:                    mask.put(PermissionLevel.REVISE_OWN, new Boolean(false));
486:                    mask.put(PermissionLevel.REVISE_ANY, new Boolean(false));
487:
488:                    return createPermissionLevel(
489:                            PermissionLevelManager.PERMISSION_LEVEL_NAME_REVIEWER,
490:                            typeUuid, mask);
491:                } else
492:                    return level;
493:
494:            }
495:
496:            public PermissionLevel getDefaultContributorPermissionLevel() {
497:
498:                if (LOG.isDebugEnabled()) {
499:                    LOG.debug("getDefaultContributorPermissionLevel executing");
500:                }
501:
502:                String typeUuid = typeManager.getContributorLevelType();
503:
504:                if (typeUuid == null) {
505:                    throw new IllegalStateException("type cannot be null");
506:                }
507:                PermissionLevel level = getDefaultPermissionLevel(typeUuid);
508:
509:                if (level == null) {
510:                    PermissionsMask mask = new PermissionsMask();
511:                    mask.put(PermissionLevel.NEW_FORUM, new Boolean(false));
512:                    mask.put(PermissionLevel.NEW_TOPIC, new Boolean(false));
513:                    mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(true));
514:                    mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
515:                            new Boolean(true));
516:                    mask.put(PermissionLevel.MOVE_POSTING, new Boolean(false));
517:                    mask.put(PermissionLevel.CHANGE_SETTINGS,
518:                            new Boolean(false));
519:                    mask.put(PermissionLevel.POST_TO_GRADEBOOK, new Boolean(
520:                            false));
521:                    mask.put(PermissionLevel.READ, new Boolean(true));
522:                    mask.put(PermissionLevel.MARK_AS_READ, new Boolean(true));
523:                    mask.put(PermissionLevel.MODERATE_POSTINGS, new Boolean(
524:                            false));
525:                    mask.put(PermissionLevel.DELETE_OWN, new Boolean(false));
526:                    mask.put(PermissionLevel.DELETE_ANY, new Boolean(false));
527:                    mask.put(PermissionLevel.REVISE_OWN, new Boolean(false));
528:                    mask.put(PermissionLevel.REVISE_ANY, new Boolean(false));
529:
530:                    return createPermissionLevel(
531:                            PermissionLevelManager.PERMISSION_LEVEL_NAME_CONTRIBUTOR,
532:                            typeUuid, mask);
533:                } else
534:                    return level;
535:            }
536:
537:            public PermissionLevel getDefaultNonePermissionLevel() {
538:
539:                if (LOG.isDebugEnabled()) {
540:                    LOG.debug("getDefaultNonePermissionLevel executing");
541:                }
542:
543:                String typeUuid = typeManager.getNoneLevelType();
544:
545:                if (typeUuid == null) {
546:                    throw new IllegalStateException("type cannot be null");
547:                }
548:                PermissionLevel level = getDefaultPermissionLevel(typeUuid);
549:
550:                if (level == null) {
551:                    PermissionsMask mask = new PermissionsMask();
552:                    mask.put(PermissionLevel.NEW_FORUM, new Boolean(false));
553:                    mask.put(PermissionLevel.NEW_TOPIC, new Boolean(false));
554:                    mask.put(PermissionLevel.NEW_RESPONSE, new Boolean(false));
555:                    mask.put(PermissionLevel.NEW_RESPONSE_TO_RESPONSE,
556:                            new Boolean(false));
557:                    mask.put(PermissionLevel.MOVE_POSTING, new Boolean(false));
558:                    mask.put(PermissionLevel.CHANGE_SETTINGS,
559:                            new Boolean(false));
560:                    mask.put(PermissionLevel.POST_TO_GRADEBOOK, new Boolean(
561:                            false));
562:                    mask.put(PermissionLevel.READ, new Boolean(false));
563:                    mask.put(PermissionLevel.MARK_AS_READ, new Boolean(false));
564:                    mask.put(PermissionLevel.MODERATE_POSTINGS, new Boolean(
565:                            false));
566:                    mask.put(PermissionLevel.DELETE_OWN, new Boolean(false));
567:                    mask.put(PermissionLevel.DELETE_ANY, new Boolean(false));
568:                    mask.put(PermissionLevel.REVISE_OWN, new Boolean(false));
569:                    mask.put(PermissionLevel.REVISE_ANY, new Boolean(false));
570:
571:                    return createPermissionLevel(
572:                            PermissionLevelManager.PERMISSION_LEVEL_NAME_NONE,
573:                            typeUuid, mask);
574:                } else
575:                    return level;
576:            }
577:
578:            private PermissionLevel getDefaultPermissionLevel(
579:                    final String typeUuid) {
580:
581:                if (typeUuid == null) {
582:                    throw new IllegalArgumentException("Null Argument");
583:                }
584:
585:                if (LOG.isDebugEnabled()) {
586:                    LOG
587:                            .debug("getDefaultPermissionLevel executing with typeUuid: "
588:                                    + typeUuid);
589:                }
590:
591:                if (defaultPermissionsMap != null
592:                        && defaultPermissionsMap.get(typeUuid) != null)
593:                    return ((PermissionLevel) defaultPermissionsMap
594:                            .get(typeUuid)).clone();
595:
596:                HibernateCallback hcb = new HibernateCallback() {
597:                    public Object doInHibernate(Session session)
598:                            throws HibernateException, SQLException {
599:                        Query q = session.getNamedQuery(QUERY_BY_TYPE_UUID);
600:                        q.setParameter("typeUuid", typeUuid);
601:                        return q.uniqueResult();
602:                    }
603:                };
604:
605:                PermissionLevel returnedLevel = (PermissionLevel) getHibernateTemplate()
606:                        .execute(hcb);
607:
608:                return returnedLevel;
609:            }
610:
611:            public Boolean getCustomPermissionByName(String customPermName,
612:                    PermissionLevel permissionLevel) {
613:                if (customPermName == null)
614:                    throw new IllegalArgumentException(
615:                            "Null permissionLevelName passed");
616:                if (permissionLevel == null)
617:                    throw new IllegalArgumentException(
618:                            "Null permissionLevel passed");
619:
620:                if (customPermName.equals(PermissionLevel.NEW_FORUM))
621:                    return permissionLevel.getNewForum();
622:                else if (customPermName.equals(PermissionLevel.NEW_RESPONSE))
623:                    return permissionLevel.getNewResponse();
624:                else if (customPermName
625:                        .equals(PermissionLevel.NEW_RESPONSE_TO_RESPONSE))
626:                    return permissionLevel.getNewResponseToResponse();
627:                else if (customPermName.equals(PermissionLevel.NEW_TOPIC))
628:                    return permissionLevel.getNewTopic();
629:                else if (customPermName
630:                        .equals(PermissionLevel.POST_TO_GRADEBOOK))
631:                    return permissionLevel.getPostToGradebook();
632:                else if (customPermName.equals(PermissionLevel.DELETE_ANY))
633:                    return permissionLevel.getDeleteAny();
634:                else if (customPermName.equals(PermissionLevel.DELETE_OWN))
635:                    return permissionLevel.getDeleteOwn();
636:                else if (customPermName.equals(PermissionLevel.MARK_AS_READ))
637:                    return permissionLevel.getMarkAsRead();
638:                else if (customPermName
639:                        .equals(PermissionLevel.MODERATE_POSTINGS))
640:                    return permissionLevel.getModeratePostings();
641:                else if (customPermName.equals(PermissionLevel.MOVE_POSTING))
642:                    return permissionLevel.getMovePosting();
643:                else if (customPermName.equals(PermissionLevel.READ))
644:                    return permissionLevel.getRead();
645:                else if (customPermName.equals(PermissionLevel.REVISE_ANY))
646:                    return permissionLevel.getReviseAny();
647:                else if (customPermName.equals(PermissionLevel.REVISE_OWN))
648:                    return permissionLevel.getReviseOwn();
649:                else if (customPermName.equals(PermissionLevel.CHANGE_SETTINGS))
650:                    return permissionLevel.getChangeSettings();
651:                else
652:                    return null;
653:            }
654:
655:            public List getCustomPermissions() {
656:                List customPerms = new ArrayList();
657:                customPerms.add(PermissionLevel.NEW_FORUM);
658:                customPerms.add(PermissionLevel.NEW_RESPONSE);
659:                customPerms.add(PermissionLevel.NEW_RESPONSE_TO_RESPONSE);
660:                customPerms.add(PermissionLevel.NEW_TOPIC);
661:                customPerms.add(PermissionLevel.DELETE_ANY);
662:                customPerms.add(PermissionLevel.DELETE_OWN);
663:                customPerms.add(PermissionLevel.MARK_AS_READ);
664:                customPerms.add(PermissionLevel.MODERATE_POSTINGS);
665:                customPerms.add(PermissionLevel.MOVE_POSTING);
666:                customPerms.add(PermissionLevel.POST_TO_GRADEBOOK);
667:                customPerms.add(PermissionLevel.READ);
668:                customPerms.add(PermissionLevel.REVISE_ANY);
669:                customPerms.add(PermissionLevel.REVISE_OWN);
670:                customPerms.add(PermissionLevel.CHANGE_SETTINGS);
671:
672:                return customPerms;
673:            }
674:
675:            private String getCurrentUser() {
676:                String user = sessionManager.getCurrentSessionUserId();
677:                return (user == null) ? "test-user" : user;
678:            }
679:
680:            public void setEventTrackingService(
681:                    EventTrackingService eventTrackingService) {
682:                this .eventTrackingService = eventTrackingService;
683:            }
684:
685:            public void setTypeManager(MessageForumsTypeManager typeManager) {
686:                this .typeManager = typeManager;
687:            }
688:
689:            public void setIdManager(IdManager idManager) {
690:                this .idManager = idManager;
691:            }
692:
693:            public void setSessionManager(SessionManager sessionManager) {
694:                this .sessionManager = sessionManager;
695:            }
696:
697:            public void setAreaManager(AreaManager areaManager) {
698:                this .areaManager = areaManager;
699:            }
700:
701:            public List getAllMembershipItemsForForumsForSite(final Long areaId) {
702:                if (LOG.isDebugEnabled()) {
703:                    LOG
704:                            .debug("getAllMembershipItemsForForumsForSite executing");
705:                }
706:
707:                HibernateCallback hcb = new HibernateCallback() {
708:                    public Object doInHibernate(Session session)
709:                            throws HibernateException, SQLException {
710:                        Query q = session
711:                                .getNamedQuery(QUERY_BY_AREA_ALL_FORUMS_MEMBERSHIP);
712:                        q.setParameter("areaId", areaId, Hibernate.LONG);
713:                        return q.list();
714:                    }
715:                };
716:
717:                return (List) getHibernateTemplate().execute(hcb);
718:            }
719:
720:            private List getAllTopicsForSite(final Long areaId) {
721:                if (LOG.isDebugEnabled()) {
722:                    LOG.debug("getAllTopicsForSite executing");
723:                }
724:
725:                HibernateCallback hcb = new HibernateCallback() {
726:                    public Object doInHibernate(Session session)
727:                            throws HibernateException, SQLException {
728:                        Query q = session.getNamedQuery(QUERY_GET_ALL_TOPICS);
729:                        q.setParameter("areaId", areaId, Hibernate.LONG);
730:                        return q.list();
731:                    }
732:                };
733:                List topicList = (List) getHibernateTemplate().execute(hcb);
734:                List ids = new ArrayList();
735:
736:                try {
737:                    if (topicList != null) {
738:                        for (int i = 0; i < topicList.size(); i++) {
739:                            Object[] this Object = (Object[]) topicList.get(i);
740:                            if (this Object != null) {
741:                                for (int j = 0; j < this Object.length; j++) {
742:                                    Object this Topic = (Object) this Object[j];
743:                                    if (this Topic instanceof  Topic) {
744:                                        ids.add(((Topic) this Topic).getId());
745:                                        break;
746:                                    }
747:                                }
748:                            }
749:                        }
750:                    }
751:                } catch (Exception e) {
752:                    LOG
753:                            .error("PermissionLevelManagerImpl.getAllTopicsForSite--"
754:                                    + e);
755:                }
756:
757:                return ids;
758:            }
759:
760:            public List getAllMembershipItemsForTopicsForSite(final Long areaId) {
761:                final List topicIds = this .getAllTopicsForSite(areaId);
762:
763:                if (topicIds != null && topicIds.size() > 0) {
764:                    HibernateCallback hcb1 = new HibernateCallback() {
765:                        public Object doInHibernate(Session session)
766:                                throws HibernateException, SQLException {
767:                            Query q = session
768:                                    .getNamedQuery(QUERY_BY_TOPIC_IDS_ALL_TOPIC_MEMBERSHIP);
769:                            q.setParameterList("topicIdList", topicIds);
770:                            return q.list();
771:                        }
772:                    };
773:                    return (List) getHibernateTemplate().execute(hcb1);
774:                } else
775:                    return new ArrayList();
776:            }
777:
778:            private void loadInitialDefaultPermissionLevel() {
779:                if (LOG.isDebugEnabled()) {
780:                    LOG.debug("loadInitialDefaultPermissionLevel executing");
781:                }
782:
783:                defaultPermissionsMap = new HashMap();
784:
785:                defaultPermissionsMap.put(typeManager.getOwnerLevelType(),
786:                        getDefaultOwnerPermissionLevel());
787:                defaultPermissionsMap.put(typeManager.getAuthorLevelType(),
788:                        getDefaultAuthorPermissionLevel());
789:                defaultPermissionsMap.put(typeManager
790:                        .getNoneditingAuthorLevelType(),
791:                        getDefaultNoneditingAuthorPermissionLevel());
792:                defaultPermissionsMap.put(
793:                        typeManager.getContributorLevelType(),
794:                        getDefaultContributorPermissionLevel());
795:                defaultPermissionsMap.put(typeManager.getReviewerLevelType(),
796:                        getDefaultReviewerPermissionLevel());
797:                defaultPermissionsMap.put(typeManager.getNoneLevelType(),
798:                        getDefaultNonePermissionLevel());
799:            }
800:
801:            public void deleteMembershipItems(Set membershipSet) {
802:                if (membershipSet != null) {
803:                    Iterator iter = membershipSet.iterator();
804:                    Set permissionLevels = new HashSet();
805:                    while (iter.hasNext()) {
806:                        DBMembershipItem item = (DBMembershipItem) iter.next();
807:                        if (item != null
808:                                && item.getPermissionLevel() != null
809:                                && PermissionLevelManager.PERMISSION_LEVEL_NAME_CUSTOM
810:                                        .equals(item.getPermissionLevelName())) {
811:                            permissionLevels.add((PermissionLevel) item
812:                                    .getPermissionLevel());
813:                        }
814:                    }
815:                    getHibernateTemplate().deleteAll(membershipSet);
816:                    getHibernateTemplate().deleteAll(permissionLevels);
817:                }
818:            }
819:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.