Source Code Cross Referenced for CourseOfferingRoleResolver.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » coursemanagement » impl » provider » 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.coursemanagement.impl.provider 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/providers/tags/sakai_2-4-1/cm/cm-authz-provider/src/java/org/sakaiproject/coursemanagement/impl/provider/CourseOfferingRoleResolver.java $
003:         * $Id: CourseOfferingRoleResolver.java 20453 2007-01-19 00:26:56Z jholtzman@berkeley.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 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.coursemanagement.impl.provider;
021:
022:        import java.util.HashMap;
023:        import java.util.HashSet;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:        import java.util.Set;
027:
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.sakaiproject.coursemanagement.api.CourseManagementService;
031:        import org.sakaiproject.coursemanagement.api.CourseOffering;
032:        import org.sakaiproject.coursemanagement.api.Membership;
033:        import org.sakaiproject.coursemanagement.api.Section;
034:
035:        /**
036:         * Resolves user roles in CourseOfferings.
037:         * 
038:         * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
039:         *
040:         */
041:        public class CourseOfferingRoleResolver implements  RoleResolver {
042:            private static final Log log = LogFactory
043:                    .getLog(CourseOfferingRoleResolver.class);
044:
045:            /** Map of CM course offering roles to Sakai roles */
046:            Map roleMap;
047:
048:            /**
049:             * {@inheritDoc}
050:             */
051:            public Map<String, String> getUserRoles(
052:                    CourseManagementService cmService, Section section) {
053:                Map<String, String> userRoleMap = new HashMap<String, String>();
054:                String coEid = section.getCourseOfferingEid();
055:
056:                // Get the members of this course offering
057:                Set<Membership> coMembers = cmService
058:                        .getCourseOfferingMemberships(coEid);
059:                Set<Membership> equivMembers = new HashSet<Membership>();
060:
061:                // Get the members of equivalent course offerings, and add them to the set of equivalent memberships
062:                Set<CourseOffering> equivalentCourseOfferings = cmService
063:                        .getEquivalentCourseOfferings(coEid);
064:                for (Iterator<CourseOffering> iter = equivalentCourseOfferings
065:                        .iterator(); iter.hasNext();) {
066:                    CourseOffering equivCo = iter.next();
067:                    equivMembers.addAll(cmService
068:                            .getCourseOfferingMemberships(equivCo.getEid()));
069:                }
070:
071:                // Add the course offering memebers
072:                addMemberRoles(userRoleMap, coMembers);
073:
074:                // Add the equivalent course offering members (but don't override any roles in the original course offering)
075:                addMemberRoles(userRoleMap, equivMembers);
076:
077:                if (coMembers != null) {
078:                }
079:                return userRoleMap;
080:            }
081:
082:            private void addMemberRoles(Map<String, String> userRoleMap,
083:                    Set<Membership> coMembers) {
084:                for (Iterator<Membership> iter = coMembers.iterator(); iter
085:                        .hasNext();) {
086:                    Membership membership = iter.next();
087:                    if (userRoleMap.containsKey(membership.getUserId())) {
088:                        // Don't override existing roles in the map.
089:                    } else {
090:                        String sakaiRole = convertRole(membership.getRole());
091:                        if (sakaiRole != null) {
092:                            userRoleMap.put(membership.getUserId(), sakaiRole);
093:                        }
094:                    }
095:                }
096:            }
097:
098:            /**
099:             * {@inheritDoc}
100:             */
101:            public Map<String, String> getGroupRoles(
102:                    CourseManagementService cmService, String userEid) {
103:                Map<String, String> sectionRoles = new HashMap<String, String>();
104:
105:                // Find all of the course offerings for which this user is a member
106:                Map<String, String> courseOfferingRoles = cmService
107:                        .findCourseOfferingRoles(userEid);
108:                if (log.isDebugEnabled())
109:                    log.debug("Found " + courseOfferingRoles.size()
110:                            + " course offering roles for " + userEid);
111:
112:                // Add all of the equivalent course offerings-> role mappings for this user
113:                Set<String> coEids = new HashSet(courseOfferingRoles.keySet());
114:                for (Iterator<String> coIter = coEids.iterator(); coIter
115:                        .hasNext();) {
116:                    String coEid = coIter.next();
117:                    Set<CourseOffering> equivOfferings = cmService
118:                            .getEquivalentCourseOfferings(coEid);
119:                    for (Iterator<CourseOffering> equivIter = equivOfferings
120:                            .iterator(); equivIter.hasNext();) {
121:                        CourseOffering equiv = equivIter.next();
122:                        // Use the role in the original course offering for this equivalent course offering
123:                        courseOfferingRoles.put(equiv.getEid(),
124:                                courseOfferingRoles.get(coEid));
125:                    }
126:                }
127:
128:                for (Iterator<String> coIter = courseOfferingRoles.keySet()
129:                        .iterator(); coIter.hasNext();) {
130:                    String coEid = coIter.next();
131:                    String coRole = courseOfferingRoles.get(coEid);
132:
133:                    // If this role shouldn't be part of the site, ignore the membership in this course offering
134:                    String sakaiRole = convertRole(coRole);
135:                    if (sakaiRole == null) {
136:                        if (log.isDebugEnabled())
137:                            log
138:                                    .debug("Course offering role "
139:                                            + coRole
140:                                            + " is not mapped to a sakai role.  Skipping this membership.");
141:                        continue;
142:                    }
143:
144:                    if (log.isDebugEnabled())
145:                        log.debug(userEid + " has role=" + coRole
146:                                + " in course offering " + coEid);
147:                    // Get the sections in each course offering
148:                    Set<Section> sections = cmService.getSections(coEid);
149:                    for (Iterator<Section> secIter = sections.iterator(); secIter
150:                            .hasNext();) {
151:                        // Add the section EIDs and the converted *CourseOffering* role to the sectionRoles map
152:                        Section section = secIter.next();
153:                        sectionRoles.put(section.getEid(), sakaiRole);
154:                    }
155:                }
156:                return sectionRoles;
157:            }
158:
159:            public String convertRole(String cmRole) {
160:                if (cmRole == null) {
161:                    log.warn("Can not convert CM role 'null' to a sakai role.");
162:                    return null;
163:                }
164:                String sakaiRole = (String) roleMap.get(cmRole);
165:                if (sakaiRole == null) {
166:                    log.warn("Unable to find sakai role for CM role " + cmRole);
167:                    return null;
168:                } else {
169:                    return sakaiRole;
170:                }
171:            }
172:
173:            // Dependency injection
174:
175:            public void setRoleMap(Map roleMap) {
176:                this.roleMap = roleMap;
177:            }
178:
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.