Source Code Cross Referenced for StudentViewBean.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » section » jsf » backingbean » 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.tool.section.jsf.backingbean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/StudentViewBean.java $
003:         * $Id: StudentViewBean.java 29185 2007-04-19 02:34:53Z ajpoland@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
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.tool.section.jsf.backingbean;
021:
022:        import java.io.Serializable;
023:        import java.util.ArrayList;
024:        import java.util.Collections;
025:        import java.util.Iterator;
026:        import java.util.List;
027:
028:        import javax.faces.context.FacesContext;
029:        import javax.faces.event.ActionEvent;
030:
031:        import org.apache.commons.lang.StringUtils;
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.sakaiproject.section.api.coursemanagement.CourseSection;
035:        import org.sakaiproject.section.api.exception.RoleConfigurationException;
036:        import org.sakaiproject.tool.section.decorator.SectionDecorator;
037:        import org.sakaiproject.tool.section.decorator.StudentSectionDecorator;
038:        import org.sakaiproject.tool.section.jsf.JsfUtil;
039:
040:        /**
041:         * Controls the student view page.
042:         * 
043:         * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
044:         *
045:         */
046:        public class StudentViewBean extends EditStudentSectionsBean implements 
047:                Serializable {
048:
049:            private static final long serialVersionUID = 1L;
050:
051:            private static final Log log = LogFactory
052:                    .getLog(StudentViewBean.class);
053:
054:            private boolean externallyManaged;
055:            private boolean joinAllowed;
056:            private boolean switchAllowed;
057:
058:            private String instructions;
059:            private String filter;
060:
061:            // Students don't need a full preferences bean, so we just store the sorting as fields
062:            private String sortColumn;
063:            private boolean sortAscending;
064:
065:            public StudentViewBean() {
066:                super ();
067:                showNegativeSpots = false;
068:                sortColumn = "studentName";
069:                sortAscending = true;
070:            }
071:
072:            public void init() {
073:                // Initialize the sections using the current user's uid
074:                studentUid = getUserUid();
075:                super .init();
076:
077:                // Determine whether this course is externally managed
078:                externallyManaged = getSectionManager().isExternallyManaged(
079:                        getCourse().getUuid());
080:
081:                // Determine whether the sections are joinable and/or switchable
082:                joinAllowed = getSectionManager().isSelfRegistrationAllowed(
083:                        getCourse().getUuid());
084:                switchAllowed = getSectionManager().isSelfSwitchingAllowed(
085:                        getCourse().getUuid());
086:
087:                // Keep track of whether there are joinable Sections
088:                boolean joinableSectionsExist = false;
089:
090:                // Keep track of whether there are switchable Sections
091:                boolean switchableSectionsExist = false;
092:
093:                List<SectionDecorator> sectionCopy = new ArrayList<SectionDecorator>(
094:                        sections);
095:                for (Iterator<SectionDecorator> iter = sectionCopy.iterator(); iter
096:                        .hasNext();) {
097:                    StudentSectionDecorator decoratedSection = (StudentSectionDecorator) iter
098:                            .next();
099:
100:                    // Filter sections
101:                    if (StringUtils.trimToNull(filter) != null) {
102:                        if ("MY".equals(filter) && !decoratedSection.isMember()) {
103:                            sections.remove(decoratedSection);
104:                        }
105:                        if (!"MY".equals(filter)
106:                                && !decoratedSection.getCategory().equals(
107:                                        filter)) {
108:                            sections.remove(decoratedSection);
109:                        }
110:                    }
111:
112:                    if (decoratedSection.isJoinable()) {
113:                        joinableSectionsExist = true;
114:                    } else if (decoratedSection.isSwitchable()) {
115:                        switchableSectionsExist = true;
116:                    }
117:                }
118:                Collections.sort(sections, getComparator());
119:
120:                instructions = generateInstructions(joinableSectionsExist,
121:                        switchableSectionsExist);
122:            }
123:
124:            private String generateInstructions(boolean joinableSectionsExist,
125:                    boolean switchableSectionsExist) {
126:
127:                //This site is externally managed, or joining and switching are both disallowed
128:                if (!joinAllowed && !switchAllowed) {
129:                    return JsfUtil
130:                            .getLocalizedMessage("student_view_instructions_no_join_or_switch");
131:                }
132:
133:                // Joining and switching are both possible
134:                if (switchAllowed && switchableSectionsExist && joinAllowed
135:                        && joinableSectionsExist) {
136:                    return JsfUtil
137:                            .getLocalizedMessage("student_view_instructions_join_or_switch");
138:                }
139:
140:                // Joining is possible, but switching is not
141:                if (joinAllowed && joinableSectionsExist
142:                        && !(switchAllowed && switchableSectionsExist)) {
143:                    return JsfUtil
144:                            .getLocalizedMessage("student_view_instructions_join");
145:                }
146:
147:                // Switching is possible, but joining is not
148:                if (switchAllowed && switchableSectionsExist
149:                        && !(joinAllowed && joinableSectionsExist)) {
150:                    return JsfUtil
151:                            .getLocalizedMessage("student_view_instructions_switch");
152:                }
153:
154:                // No sections can be joined or switched into
155:                return JsfUtil
156:                        .getLocalizedMessage("student_view_instructions_no_sections");
157:            }
158:
159:            public void processJoinSection(ActionEvent event) {
160:                String sectionUuid = (String) FacesContext.getCurrentInstance()
161:                        .getExternalContext().getRequestParameterMap().get(
162:                                "sectionUuid");
163:                //is this section still joinable?
164:                CourseSection section = getSectionManager().getSection(
165:                        sectionUuid);
166:
167:                // The section might have been deleted
168:                if (section == null) {
169:                    // There's nothing we can do in the UI, really.
170:                    return;
171:                }
172:
173:                //check that there are still places available
174:                int maxEnrollments = Integer.MAX_VALUE;
175:                if (section.getMaxEnrollments() != null) {
176:                    maxEnrollments = section.getMaxEnrollments().intValue();
177:                }
178:                int numEnrolled = getSectionManager().getTotalEnrollments(
179:                        section.getUuid());
180:                if (numEnrolled >= maxEnrollments) {
181:                    if (log.isDebugEnabled())
182:                        log.debug("Attempted to join a section with no spaces");
183:                    JsfUtil.addErrorMessage(JsfUtil.getLocalizedMessage(
184:                            "student_view_membership_full",
185:                            new String[] { section.getTitle() }));
186:                    return;
187:                }
188:                try {
189:                    getSectionManager().joinSection(sectionUuid);
190:                } catch (RoleConfigurationException rce) {
191:                    JsfUtil.addErrorMessage(JsfUtil
192:                            .getLocalizedMessage("role_config_error"));
193:                }
194:            }
195:
196:            public void processSwitchSection(ActionEvent event) {
197:                String sectionUuid = (String) FacesContext.getCurrentInstance()
198:                        .getExternalContext().getRequestParameterMap().get(
199:                                "sectionUuid");
200:
201:                // Does the section still exist, and is it still joinable?
202:                CourseSection section = getSectionManager().getSection(
203:                        sectionUuid);
204:
205:                if (section == null) {
206:                    // There's nothing we can do in the UI, really.
207:                    return;
208:                }
209:
210:                //check that there are still places available
211:                int maxEnrollments = Integer.MAX_VALUE;
212:                if (section.getMaxEnrollments() != null) {
213:                    maxEnrollments = section.getMaxEnrollments().intValue();
214:                }
215:                int numEnrolled = getSectionManager().getTotalEnrollments(
216:                        section.getUuid());
217:                if (numEnrolled >= maxEnrollments) {
218:                    if (log.isDebugEnabled())
219:                        log.debug("Attempted to join a section with no spaces");
220:                    JsfUtil.addErrorMessage(JsfUtil.getLocalizedMessage(
221:                            "student_view_membership_full",
222:                            new String[] { section.getTitle() }));
223:                    return;
224:                }
225:                try {
226:                    getSectionManager().switchSection(sectionUuid);
227:                } catch (RoleConfigurationException rce) {
228:                    JsfUtil.addErrorMessage(JsfUtil
229:                            .getLocalizedMessage("role_config_error"));
230:                }
231:            }
232:
233:            public boolean isExternallyManaged() {
234:                return externallyManaged;
235:            }
236:
237:            public boolean isJoinAllowed() {
238:                return joinAllowed;
239:            }
240:
241:            public boolean isSwitchAllowed() {
242:                return switchAllowed;
243:            }
244:
245:            public String getInstructions() {
246:                return instructions;
247:            }
248:
249:            public boolean isSortAscending() {
250:                return sortAscending;
251:            }
252:
253:            public void setSortAscending(boolean sortAscending) {
254:                this .sortAscending = sortAscending;
255:            }
256:
257:            public String getSortColumn() {
258:                return sortColumn;
259:            }
260:
261:            public void setSortColumn(String sortColumn) {
262:                this .sortColumn = sortColumn;
263:            }
264:
265:            public String getFilter() {
266:                return filter;
267:            }
268:
269:            public void setFilter(String filter) {
270:                this.filter = filter;
271:            }
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.