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


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/SectionContentsBean.java $
003:         * $Id: SectionContentsBean.java 19642 2006-12-17 22:52:19Z ktsao@stanford.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 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.tool.assessment.ui.bean.delivery;
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:        import java.util.Random;
028:        import java.util.Set;
029:        import javax.faces.model.SelectItem;
030:
031:        import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
032:        import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionDataIfc;
033:        import org.sakaiproject.tool.assessment.facade.AgentFacade;
034:        import org.sakaiproject.tool.assessment.facade.QuestionPoolFacade;
035:        import org.sakaiproject.tool.assessment.services.QuestionPoolService;
036:
037:        /**
038:         * <p>This bean represents a Part in an assessment </p>
039:         */
040:
041:        public class SectionContentsBean implements  Serializable {
042:            /**
043:             * 
044:             */
045:            private static final long serialVersionUID = 5959692528847396966L;
046:            private String text;
047:            private String nonDefaultText;
048:            private java.util.ArrayList itemContents;
049:            private String sectionId;
050:            private String number;
051:            private float maxPoints;
052:            private float points;
053:            private int questions;
054:            private int numbering;
055:            private String numParts;
056:            private String description;
057:            private int unansweredQuestions; // ItemContentsBeans
058:            private ArrayList questionNumbers = new ArrayList();
059:
060:            // added section Type , question ordering
061:            private Integer sectionAuthorType;
062:            private Integer questionOrdering;
063:            private Integer numberToBeDrawn;
064:            private Long poolIdToBeDrawn;
065:            private String poolNameToBeDrawn;
066:            private List attachmentList;
067:            private boolean noQuestions;
068:
069:            public SectionContentsBean() {
070:            }
071:
072:            /**
073:             * Part description.
074:             * @return Part description.
075:             */
076:
077:            public String getText() {
078:                return text;
079:            }
080:
081:            public String getNonDefaultText() {
082:
083:                if ("Default".equals(text) || "default".equals(text)) {
084:                    return "";
085:                }
086:                return text;
087:            }
088:
089:            /**
090:             * Part description.
091:             * @param text Part description.
092:             */
093:            public void setText(String text) {
094:                this .text = text;
095:            }
096:
097:            /**
098:             *   Points earned thus far for part.
099:             *
100:             * @return the points
101:             */
102:            public float getPoints() {
103:                return points;
104:            }
105:
106:            /**
107:             * Points earned thus far for part.
108:             * @param points
109:             */
110:            public void setPoints(float points) {
111:                this .points = points;
112:            }
113:
114:            /**
115:             * Number unanswered.
116:             * @return total unanswered.
117:             */
118:            public int getUnansweredQuestions() {
119:                Iterator i = itemContents.iterator();
120:                int num = 0;
121:                while (i.hasNext()) {
122:                    ItemContentsBean next = (ItemContentsBean) i.next();
123:                    if (next.isUnanswered()) {
124:                        num++;
125:                    }
126:                }
127:                return num;
128:            }
129:
130:            /**
131:             * Number unanswered.
132:             * @param unansweredQuestions
133:             */
134:            public void setUnansweredQuestions(int unansweredQuestions) {
135:                this .unansweredQuestions = unansweredQuestions;
136:            }
137:
138:            /**
139:             * Total points the part is worth.
140:             * @return max total points for part
141:             */
142:            public float getMaxPoints() {
143:                return maxPoints;
144:            }
145:
146:            public float getRoundedMaxPoints() {
147:                // only show 2 decimal places 
148:
149:                return roundTo2Decimals(maxPoints);
150:            }
151:
152:            /**
153:             * Total points the part is worth.
154:             * @param maxPoints points the part is worth.
155:             */
156:            public void setMaxPoints(float maxPoints) {
157:                this .maxPoints = maxPoints;
158:            }
159:
160:            /**
161:             * Total number of questions.
162:             * @return total number of questions
163:             */
164:            public int getQuestions() {
165:                return questions;
166:            }
167:
168:            /**
169:             * Total number of questions.
170:             * @param questions number of questions
171:             */
172:            public void setQuestions(int questions) {
173:                this .questions = questions;
174:            }
175:
176:            /**
177:             * Total number of questions to list, based on numbering scheme
178:             * @return total number of questions
179:             */
180:            public int getNumbering() {
181:                return numbering;
182:            }
183:
184:            /**
185:             * Total number of questions to list, based on numbering scheme
186:             * @param questions number of questions
187:             */
188:            public void setNumbering(int newNumbering) {
189:                numbering = newNumbering;
190:            }
191:
192:            /**
193:             * Contents of part.
194:             * @return item contents of part.
195:             */
196:            public java.util.ArrayList getItemContents() {
197:                /*
198:                    if( (sectionAuthorType!= null) && (sectionAuthorType.equals(SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL) ))
199:                      return getItemContentsForRandomDraw();
200:                    else if( (sectionAuthorType!= null) && (questionOrdering!=null ) && (sectionAuthorType.equals(SectionDataIfc.QUESTIONS_AUTHORED_ONE_BY_ONE)) && (questionOrdering.equals(SectionDataIfc.RANDOM_WITHIN_PART)))
201:                      return getItemContentsForRandomQuestionOrdering();
202:                    else
203:                      return itemContents;
204:                 */
205:                return itemContents;
206:            }
207:
208:            public java.util.ArrayList getItemContentsForRandomDraw() {
209:                // same ordering for each student
210:                ArrayList randomsample = new ArrayList();
211:                long seed = (long) AgentFacade.getAgentString().hashCode();
212:                Collections.shuffle(itemContents, new Random(seed));
213:                int samplesize = numberToBeDrawn.intValue();
214:                for (int i = 0; i < samplesize; i++) {
215:                    randomsample.add(itemContents.get(i));
216:                }
217:                return randomsample;
218:            }
219:
220:            public java.util.ArrayList getItemContentsForRandomQuestionOrdering() {
221:                // same ordering for each student
222:                long seed = (long) AgentFacade.getAgentString().hashCode();
223:                Collections.shuffle(itemContents, new Random(seed));
224:                return itemContents;
225:            }
226:
227:            /**
228:             * Contents of part.
229:             * @param itemContents item contents of part.
230:             */
231:            public void setItemContents(java.util.ArrayList itemContents) {
232:                this .itemContents = itemContents;
233:            }
234:
235:            /**
236:             * Get the size of the contents
237:             */
238:            public String getItemContentsSize() {
239:                if (itemContents == null) {
240:                    return "0";
241:                }
242:                return Integer.toString(itemContents.size());
243:            }
244:
245:            /**
246:             * Set the size of the contents
247:             */
248:            public void setItemContentsSize(String dummy) {
249:                // noop
250:            }
251:
252:            /**
253:             * Display part number.
254:             * @return display numbering
255:             */
256:            public String getNumber() {
257:                return number;
258:            }
259:
260:            /**
261:             * Display part number.
262:             * @param number display numbering
263:             */
264:            public void setNumber(String number) {
265:                this .number = number;
266:            }
267:
268:            // added by daisyf on 11/22/04
269:            private String title;
270:            private String sequence;
271:
272:            // for display/hide score
273:            // private boolean showStudentScore;   // show student Assessment Score
274:            // Chage showStudentScore to showStudentQuestionScore for SAK-7290
275:            // We consider the display/hide of part(section) score same as question score 
276:            // We used to consider them as assessment score as you can see above line and 
277:            // comment (private boolean showStudentScore;   // show student Assessment Score)
278:            private boolean showStudentQuestionScore; // show student Assessment Score
279:            private String pointsDisplayString;
280:
281:            public String getTitle() {
282:                return this .title;
283:            }
284:
285:            public void setTitle(String title) {
286:                this .title = title;
287:            }
288:
289:            public ArrayList getQuestionNumbers() {
290:                return questionNumbers;
291:            }
292:
293:            public void setQuestionNumbers() {
294:                this .questionNumbers = new ArrayList();
295:                for (int i = 1; i <= this .itemContents.size(); i++) {
296:                    this .questionNumbers.add(new SelectItem(new Integer(i)));
297:                }
298:            }
299:
300:            public SectionContentsBean(SectionDataIfc section) {
301:                try {
302:                    this .itemContents = new ArrayList();
303:                    setSectionId(section.getSectionId().toString());
304:                    setTitle(section.getTitle());
305:                    setDescription(section.getDescription());
306:                    Integer sequence = section.getSequence();
307:                    if (sequence != null) {
308:                        setNumber(sequence.toString());
309:                    } else {
310:                        setNumber("1");
311:                    }
312:                    setNumber(section.getSequence().toString());
313:                    // do teh rest later
314:                    Set itemSet = section.getItemSet();
315:                    if (itemSet != null) {
316:                        setQuestions(itemSet.size());
317:                        Iterator i = itemSet.iterator();
318:                        while (i.hasNext()) {
319:                            ItemDataIfc item = (ItemDataIfc) i.next();
320:                            ItemContentsBean itemBean = new ItemContentsBean(
321:                                    item);
322:                            this .itemContents.add(itemBean);
323:                        }
324:                    }
325:                    // set questionNumbers now
326:                    setQuestionNumbers();
327:                    setMetaData(section);
328:                    this .attachmentList = section.getSectionAttachmentList();
329:                    if (this .attachmentList != null
330:                            && this .attachmentList.size() > 0)
331:                        this .hasAttachment = true;
332:                } catch (Exception e) {
333:                    e.printStackTrace();
334:                    throw new RuntimeException(e);
335:                }
336:            }
337:
338:            public void setMetaData(SectionDataIfc section) {
339:
340:                if (section
341:                        .getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE) != null) {
342:                    Integer authortype = new Integer(
343:                            section
344:                                    .getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE));
345:                    setSectionAuthorType(authortype);
346:
347:                    if (section.getSectionMetaDataByLabel(
348:                            SectionDataIfc.AUTHOR_TYPE).equals(
349:                            SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL
350:                                    .toString())) {
351:                        if (section
352:                                .getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN) != null) {
353:                            Integer numberdrawn = new Integer(
354:                                    section
355:                                            .getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN));
356:                            setNumberToBeDrawn(numberdrawn);
357:                        }
358:
359:                        if (section
360:                                .getSectionMetaDataByLabel(SectionDataIfc.POOLID_FOR_RANDOM_DRAW) != null) {
361:                            Long poolid = new Long(
362:                                    section
363:                                            .getSectionMetaDataByLabel(SectionDataIfc.POOLID_FOR_RANDOM_DRAW));
364:                            setPoolIdToBeDrawn(poolid);
365:                        }
366:                        if (section
367:                                .getSectionMetaDataByLabel(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW) != null) {
368:                            String poolname = new String(
369:                                    section
370:                                            .getSectionMetaDataByLabel(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW));
371:                            setPoolNameToBeDrawn(poolname);
372:                        }
373:                    }
374:
375:                } else {
376:
377:                    setSectionAuthorType(SectionDataIfc.QUESTIONS_AUTHORED_ONE_BY_ONE);
378:                }
379:                if (section
380:                        .getSectionMetaDataByLabel(SectionDataIfc.QUESTIONS_ORDERING) != null) {
381:                    Integer questionorder = new Integer(
382:                            section
383:                                    .getSectionMetaDataByLabel(SectionDataIfc.QUESTIONS_ORDERING));
384:                    setQuestionOrdering(questionorder);
385:                } else {
386:                    setQuestionOrdering(SectionDataIfc.AS_LISTED_ON_ASSESSMENT_PAGE);
387:                }
388:
389:            }
390:
391:            public String getSectionId() {
392:                return sectionId;
393:            }
394:
395:            /**
396:             * Part description.
397:             * @param text Part description.
398:             */
399:            public void setSectionId(String sectionId) {
400:                this .sectionId = sectionId;
401:            }
402:
403:            public String getNumParts() {
404:                return numParts;
405:            }
406:
407:            public void setNumParts(String newNum) {
408:                numParts = newNum;
409:            }
410:
411:            public String getDescription() {
412:                return description;
413:            }
414:
415:            public void setDescription(String newDesc) {
416:                description = newDesc;
417:            }
418:
419:            public Integer getSectionAuthorType() {
420:                return sectionAuthorType;
421:            }
422:
423:            public String getSectionAuthorTypeString() {
424:                return sectionAuthorType.toString();
425:            }
426:
427:            public void setSectionAuthorType(Integer param) {
428:                sectionAuthorType = param;
429:            }
430:
431:            public Integer getQuestionOrdering() {
432:                return questionOrdering;
433:            }
434:
435:            public String getQuestionOrderingString() {
436:                return questionOrdering.toString();
437:            }
438:
439:            public void setQuestionOrdering(Integer param) {
440:                questionOrdering = param;
441:            }
442:
443:            public Integer getNumberToBeDrawn() {
444:                return numberToBeDrawn;
445:            }
446:
447:            public String getNumberToBeDrawnString() {
448:                return numberToBeDrawn.toString();
449:            }
450:
451:            public void setNumberToBeDrawn(Integer param) {
452:                numberToBeDrawn = param;
453:            }
454:
455:            public Long getPoolIdToBeDrawn() {
456:                return poolIdToBeDrawn;
457:            }
458:
459:            public String getPoolIdToBeDrawnString() {
460:                return poolIdToBeDrawn.toString();
461:            }
462:
463:            public void setPoolIdToBeDrawn(Long param) {
464:                poolIdToBeDrawn = param;
465:            }
466:
467:            public void setPoolNameToBeDrawn(String param) {
468:                poolNameToBeDrawn = param;
469:            }
470:
471:            public String getPoolNameToBeDrawn() {
472:                if ((sectionAuthorType != null)
473:                        && (sectionAuthorType
474:                                .equals(SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL))) {
475:
476:                    if ("".equals(poolNameToBeDrawn)) {
477:
478:                        // after 2.2. poolNameToBeDrawn should not be an empty string
479:                        // This is for backward compatibility, for versions prior 2.2,  
480:                        // we didn't store poolname in metadata so when a user deletes a pool used for random draw assessment, exception occurs when viewing the assessment. The items are still there, but it still needs to the original pool object to get the poolname for JSF display.  
481:                        // After 2.2 we save this information in section metadata.  If users delete the pools we can now still retrive the random draw pool names used in an assessment.             
482:
483:                        QuestionPoolService qpservice = new QuestionPoolService();
484:                        QuestionPoolFacade poolfacade = qpservice.getPool(
485:                                poolIdToBeDrawn, AgentFacade.getAgentString());
486:                        if (poolfacade != null) {
487:                            return poolfacade.getTitle();
488:                        }
489:                        // else the pool is no longer there
490:                        return "";
491:                    } else {
492:                        // get poolname from section metadata
493:                        return poolNameToBeDrawn;
494:                    }
495:
496:                }
497:                return "";
498:
499:            }
500:
501:            /**
502:             * Show the student score currently earned?
503:             * @return the score
504:             */
505:            public boolean isShowStudentQuestionScore() {
506:                return showStudentQuestionScore;
507:            }
508:
509:            /**
510:             * Set the student score currently earned.
511:             * @param setShowStudentQuestionScore true/false Show the student score currently earned?
512:             */
513:            public void setShowStudentQuestionScore(
514:                    boolean showStudentQuestionScore) {
515:                this .showStudentQuestionScore = showStudentQuestionScore;
516:            }
517:
518:            /**
519:             * If we display the score, return it, followed by a slash.
520:             * @return either, a) the score followed by a slash, or, b) "" (empty string)
521:             */
522:            public String getPointsDisplayString() {
523:                String pointsDisplayString = "";
524:                if (showStudentQuestionScore) {
525:                    pointsDisplayString = roundTo2Decimals(points) + "/";
526:                }
527:                return pointsDisplayString;
528:            }
529:
530:            public static float roundTo2Decimals(float points) {
531:                int tmp = Math.round(points * 100.0f);
532:                points = (float) tmp / 100.0f;
533:                return points;
534:            }
535:
536:            public List getAttachmentList() {
537:                return attachmentList;
538:            }
539:
540:            public void setAttachmentList(List attachmentList) {
541:                this .attachmentList = attachmentList;
542:            }
543:
544:            private boolean hasAttachment = false;
545:
546:            public boolean getHasAttachment() {
547:                boolean hasAttachment = false;
548:                if (attachmentList != null && attachmentList.size() > 0) {
549:                    hasAttachment = true;
550:                }
551:                return hasAttachment;
552:            }
553:
554:            public boolean getNoQuestions() {
555:                return noQuestions;
556:            }
557:
558:            public void setNoQuestions(boolean noQuestions) {
559:                this.noQuestions = noQuestions;
560:            }
561:        }
w_w_w.j__a_v__a_2__s__.c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.