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


001:        /**********************************************************************************
002:         *
003:         * $Id: GradebookDependentBean.java 22044 2007-03-01 20:47:59Z louis@media.berkeley.edu $
004:         *
005:         ***********************************************************************************
006:         *
007:         * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008:         *
009:         * Licensed under the Educational Community License, Version 1.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *      http://www.opensource.org/licenses/ecl1.php
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         *
021:         **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
022:
023:        import java.text.DateFormat;
024:        import java.text.SimpleDateFormat;
025:        import java.util.Date;
026:        import java.util.HashMap;
027:        import java.util.List;
028:        import java.util.Map;
029:
030:        import org.apache.commons.lang.StringUtils;
031:        import org.sakaiproject.section.api.SectionAwareness;
032:        import org.sakaiproject.tool.gradebook.Gradebook;
033:        import org.sakaiproject.tool.gradebook.business.GradebookManager;
034:        import org.sakaiproject.tool.gradebook.facades.Authn;
035:        import org.sakaiproject.tool.gradebook.facades.UserDirectoryService;
036:        import org.sakaiproject.tool.gradebook.jsf.FacesUtil;
037:
038:        public abstract class GradebookDependentBean extends InitializableBean {
039:            private String pageName;
040:
041:            /**
042:             * Marked transient to allow serializable subclasses.
043:             */
044:            private transient GradebookBean gradebookBean;
045:            private transient PreferencesBean preferencesBean;
046:
047:            /**
048:             * Convenience method, for use in calling locally implemented services
049:             * that assume the gradebook ID is an integer.
050:             */
051:            Long getGradebookId() {
052:                return getGradebookBean().getGradebookId();
053:            }
054:
055:            /**
056:             * Convenience method, for use in calling external facades
057:             * that assume the gradebook ID is an string.
058:             */
059:            private transient String gradebookUid;
060:
061:            String getGradebookUid() {
062:                if (gradebookUid == null) {
063:                    gradebookUid = getGradebookManager().getGradebookUid(
064:                            getGradebookId());
065:                }
066:                return gradebookUid;
067:            }
068:
069:            /**
070:             * Convenience method to hide the Authn context object.
071:             */
072:            public String getUserUid() {
073:                return getAuthnService().getUserUid();
074:            }
075:
076:            /**
077:             * Convenience method to load the current gradebook object.
078:             */
079:            Gradebook getGradebook() {
080:                return getGradebookManager().getGradebook(getGradebookId());
081:            }
082:
083:            /**
084:             * Gets a localized message string based on the locale determined by the
085:             * FacesContext.  Useful for adding localized FacesMessages from a backing bean.
086:             *
087:             * TODO Replace with direct calls to FacesUtil.
088:             *
089:             * @param key The key to look up the localized string
090:             */
091:            public String getLocalizedString(String key) {
092:                return FacesUtil.getLocalizedString(key);
093:            }
094:
095:            /**
096:             * Gets a localized message string based on the locale determined by the
097:             * FacesContext.  Useful for adding localized FacesMessages from a backing bean.
098:             *
099:             * TODO Replace with direct calls to FacesUtil.
100:             *
101:             * @param key The key to look up the localized string
102:             * @param params The array of strings to use in replacing the placeholders
103:             * in the localized string
104:             */
105:            public String getLocalizedString(String key, String[] params) {
106:                return FacesUtil.getLocalizedString(key, params);
107:            }
108:
109:            // Still more convenience methods, hiding the bean configuration details.
110:
111:            public GradebookManager getGradebookManager() {
112:                return getGradebookBean().getGradebookManager();
113:            }
114:
115:            public SectionAwareness getSectionAwareness() {
116:                return getGradebookBean().getSectionAwareness();
117:            }
118:
119:            public UserDirectoryService getUserDirectoryService() {
120:                return getGradebookBean().getUserDirectoryService();
121:            }
122:
123:            public Authn getAuthnService() {
124:                return getGradebookBean().getAuthnService();
125:            }
126:
127:            // Because these methods are referred to inside "rendered" tag attributes,
128:            // JSF will call them multiple times in every request. To cut back on
129:            // business logic traffic, cache them in request scope. They need to be
130:            // declared transient, however, so that they aren't copied between
131:            // requests (which would prevent changes in a user's authz status).
132:            private transient Boolean userAbleToEditAssessments;
133:
134:            public boolean isUserAbleToEditAssessments() {
135:                if (userAbleToEditAssessments == null) {
136:                    userAbleToEditAssessments = new Boolean(getGradebookBean()
137:                            .getAuthzService().isUserAbleToEditAssessments(
138:                                    getGradebookUid()));
139:                }
140:                return userAbleToEditAssessments.booleanValue();
141:            }
142:
143:            private transient Boolean userAbleToGradeAll;
144:
145:            public boolean isUserAbleToGradeAll() {
146:                if (userAbleToGradeAll == null) {
147:                    userAbleToGradeAll = new Boolean(getGradebookBean()
148:                            .getAuthzService().isUserAbleToGradeAll(
149:                                    getGradebookUid()));
150:                }
151:                return userAbleToGradeAll.booleanValue();
152:            }
153:
154:            private transient Map userAbleToGradeSectionMap;
155:
156:            public boolean isUserAbleToGradeSection(String sectionUid) {
157:                if (userAbleToGradeSectionMap == null) {
158:                    userAbleToGradeSectionMap = new HashMap();
159:                }
160:                Boolean isAble = (Boolean) userAbleToGradeSectionMap
161:                        .get(sectionUid);
162:                if (isAble == null) {
163:                    isAble = new Boolean(getGradebookBean().getAuthzService()
164:                            .isUserAbleToGradeSection(sectionUid));
165:                    userAbleToGradeSectionMap.put(sectionUid, isAble);
166:                }
167:                return isAble.booleanValue();
168:            }
169:
170:            public List getAvailableEnrollments() {
171:                return getGradebookBean().getAuthzService()
172:                        .getAvailableEnrollments(getGradebookUid());
173:            }
174:
175:            public List getAvailableSections() {
176:                return getGradebookBean().getAuthzService()
177:                        .getAvailableSections(getGradebookUid());
178:            }
179:
180:            public List getSectionEnrollments(String sectionUid) {
181:                return getGradebookBean().getAuthzService()
182:                        .getSectionEnrollments(getGradebookUid(), sectionUid);
183:            }
184:
185:            public List findMatchingEnrollments(String searchString,
186:                    String optionalSectionUid) {
187:                return getGradebookBean().getAuthzService()
188:                        .findMatchingEnrollments(getGradebookUid(),
189:                                searchString, optionalSectionUid);
190:            }
191:
192:            /**
193:             * Get the gradebook context.
194:             */
195:            public GradebookBean getGradebookBean() {
196:                if (gradebookBean == null) {
197:                    // This probably happened because gradebookBean is transient.
198:                    // Just restore it from the session context.
199:                    setGradebookBean((GradebookBean) FacesUtil
200:                            .resolveVariable("gradebookBean"));
201:                }
202:                return gradebookBean;
203:            }
204:
205:            /**
206:             * Set the gradebook context.
207:             */
208:            public void setGradebookBean(GradebookBean gradebookBean) {
209:                this .gradebookBean = gradebookBean;
210:            }
211:
212:            /**
213:             * @return Returns the preferencesBean.
214:             */
215:            public PreferencesBean getPreferencesBean() {
216:                if (preferencesBean == null) {
217:                    setPreferencesBean((PreferencesBean) FacesUtil
218:                            .resolveVariable("preferencesBean"));
219:                }
220:                return preferencesBean;
221:            }
222:
223:            /**
224:             * @param preferencesBean The preferencesBean to set.
225:             */
226:            public void setPreferencesBean(PreferencesBean preferencesBean) {
227:                this .preferencesBean = preferencesBean;
228:            }
229:
230:            /**
231:             * Set up close relations with page and action names for easier control
232:             * of menus.
233:             */
234:            public String getPageName() {
235:                return pageName;
236:            }
237:
238:            public void setPageName(String pageName) {
239:                this .pageName = pageName;
240:            }
241:
242:            /**
243:             * Generates a default filename (minus the extension) for a download from this Gradebook. 
244:             *
245:             * @param   prefix for filename
246:             * @return The appropriate filename for the export
247:             */
248:            public String getDownloadFileName(String prefix) {
249:                Date now = new Date();
250:                DateFormat df = new SimpleDateFormat(
251:                        getLocalizedString("export_filename_date_format"));
252:                StringBuffer fileName = new StringBuffer(prefix);
253:                String gbName = getGradebook().getName();
254:                if (StringUtils.trimToNull(gbName) != null) {
255:                    gbName = gbName.replaceAll("\\s", "_"); // replace whitespace with '_'
256:                    fileName.append("-");
257:                    fileName.append(gbName);
258:                }
259:                fileName.append("-");
260:                fileName.append(df.format(now));
261:                return fileName.toString();
262:            }
263:
264:            /**
265:             * 
266:             * @return
267:             */
268:            public String getAuthzLevel() {
269:                return (getGradebookBean().getAuthzService()
270:                        .isUserAbleToGradeAll(getGradebookUid())) ? "instructor"
271:                        : "TA";
272:            }
273:
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.