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


0001:        /* $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/facade/ItemFacade.java $
0002:         * $Id: ItemFacade.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
0003:         ***********************************************************************************
0004:         *
0005:         * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
0006:         *
0007:         * Licensed under the Educational Community License, Version 1.0 (the"License");
0008:         * you may not use this file except in compliance with the License.
0009:         * You may obtain a copy of the License at
0010:         *
0011:         *      http://www.opensource.org/licenses/ecl1.php
0012:         *
0013:         * Unless required by applicable law or agreed to in writing, software
0014:         * distributed under the License is distributed on an "AS IS" BASIS,
0015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016:         * See the License for the specific language governing permissions and
0017:         * limitations under the License.
0018:         *
0019:         **********************************************************************************/
0020:
0021:        package org.sakaiproject.tool.assessment.facade;
0022:
0023:        import java.io.IOException;
0024:        import java.io.Serializable;
0025:        import java.util.ArrayList;
0026:        import java.util.Collections;
0027:        import java.util.Date;
0028:        import java.util.HashMap;
0029:        import java.util.HashSet;
0030:        import java.util.Iterator;
0031:        import java.util.List;
0032:        import java.util.Set;
0033:
0034:        import org.apache.commons.logging.Log;
0035:        import org.apache.commons.logging.LogFactory;
0036:        import org.osid.assessment.AssessmentException;
0037:        import org.osid.assessment.Item;
0038:        import org.osid.shared.Type;
0039:        import org.sakaiproject.tool.assessment.data.dao.assessment.ItemData;
0040:        import org.sakaiproject.tool.assessment.data.dao.assessment.ItemFeedback;
0041:        import org.sakaiproject.tool.assessment.data.dao.assessment.ItemMetaData;
0042:        import org.sakaiproject.tool.assessment.data.dao.assessment.ItemText;
0043:        import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
0044:        import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemAttachmentIfc;
0045:        import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemFeedbackIfc;
0046:        import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemMetaDataIfc;
0047:        import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionDataIfc;
0048:        import org.sakaiproject.tool.assessment.data.ifc.shared.TypeIfc;
0049:        import org.sakaiproject.tool.assessment.osid.assessment.impl.ItemImpl;
0050:        import org.sakaiproject.tool.assessment.services.PersistenceService;
0051:
0052:        /**
0053:         *
0054:         * ItemFacade implements ItemDataIfc that encapsulates our out of bound (OOB)
0055:         * agreement.
0056:         */
0057:        public class ItemFacade implements  Serializable, ItemDataIfc,
0058:                Comparable {
0059:            private static Log log = LogFactory.getLog(ItemFacade.class);
0060:
0061:            private static final long serialVersionUID = 7526471155622776147L;
0062:
0063:            public static final Integer ACTIVE_STATUS = new Integer(1);
0064:            public static final Integer INACTIVE_STATUS = new Integer(0);
0065:
0066:            private org.osid.assessment.Item item;
0067:            // We have 2 sets of properties:
0068:            // #1) properties according to org.osid.assessment.Item. However, we will
0069:            // not have property "displayName" because I am not sure what it is.
0070:            // Properties "description" will be persisted through data - daisyf 07/28/04
0071:            private org.osid.shared.Id id;
0072:            private String description;
0073:            private ItemDataIfc data;
0074:            private org.osid.shared.Type itemType;
0075:            // #2) properties according to ItemDataIfc
0076:            private Long itemId;
0077:            private String itemIdString;
0078:            private SectionFacade section;
0079:            private Integer sequence;
0080:            private Integer duration;
0081:            private Integer triesAllowed;
0082:            private String instruction;
0083:            private Long typeId;
0084:            private String grade;
0085:            private Float score;
0086:            private String hint;
0087:            private Boolean hasRationale;
0088:            private Integer status;
0089:            private String createdBy;
0090:            private Date createdDate;
0091:            private String lastModifiedBy;
0092:            private Date lastModifiedDate;
0093:            private Set itemTextSet;
0094:            private Set itemMetaDataSet;
0095:            private Set itemFeedbackSet;
0096:            private HashMap itemMetaDataMap = new HashMap();
0097:            private HashMap itemFeedbackMap = new HashMap();
0098:            private TypeFacade itemTypeFacade;
0099:            private Set itemAttachmentSet;
0100:            private String itemAttachmentMetaData;
0101:
0102:            /** ItemFacade is the class that is exposed to developer
0103:             *  It contains some of the useful methods specified in
0104:             *  org.osid.assessment.Item and it implements
0105:             *  org.sakaiproject.tool.assessment.ifc.
0106:             *  When new methods is added to osid api, this code is still workable.
0107:             *  If signature in any of the osid methods that we mirrored changes,
0108:             *  we only need to modify those particular methods.
0109:             *  - daisyf
0110:             */
0111:
0112:            public ItemFacade() {
0113:                // need to hook ItemFacade.data to ItemData, our POJO for Hibernate
0114:                // persistence
0115:                this .data = new ItemData();
0116:                ItemImpl itemImpl = new ItemImpl(); //<-- place holder
0117:                item = (Item) itemImpl;
0118:                try {
0119:                    item.updateData(this .data);
0120:                } catch (AssessmentException ex) {
0121:                    throw new DataFacadeException(ex.getMessage());
0122:                }
0123:            }
0124:
0125:            /**
0126:             * This is a very important constructor. Please make sure that you have
0127:             * set all the properties (declared above as private) of ItemFacade using
0128:             * the "data" supplied. "data" is a org.osid.assessment.Item properties
0129:             * and I use it to store info about an item.
0130:             * @param data
0131:             */
0132:            public ItemFacade(ItemDataIfc data) {
0133:                this .data = data;
0134:                ItemImpl itemImpl = new ItemImpl(); // place holder
0135:                item = (Item) itemImpl;
0136:                try {
0137:                    item.updateData(this .data);
0138:                } catch (AssessmentException ex) {
0139:                    throw new DataFacadeException(ex.getMessage());
0140:                }
0141:                this .id = getId();
0142:                this .description = getDescription();
0143:                this .itemType = getItemType();
0144:                this .itemTextSet = getItemTextSet();
0145:                this .itemMetaDataSet = getItemMetaDataSet();
0146:                this .itemMetaDataMap = getItemMetaDataMap(this .itemMetaDataSet);
0147:                this .itemFeedbackSet = getItemFeedbackSet();
0148:                this .itemFeedbackMap = getItemFeedbackMap(this .itemFeedbackSet);
0149:                this .hasRationale = data.getHasRationale();//rshastri :SAK-1824
0150:                this .itemAttachmentSet = getItemAttachmentSet();
0151:            }
0152:
0153:            /*
0154:            public Object clone() throws CloneNotSupportedException{
0155:                ItemData itemdataOrig = (ItemData) this.data;
0156:            ItemData cloneditemdata = (ItemData) itemdataOrig.clone();
0157:            // set itemId and itemIdString = 0
0158:                cloneditemdata.setItemId(new Long(0));
0159:                cloneditemdata.setItemIdString("0");
0160:                Object cloned = new ItemFacade(cloneditemdata);
0161:                return cloned;
0162:            }
0163:             */
0164:
0165:            // the following method's signature has a one to one relationship to
0166:            // org.sakaiproject.tool.assessment.osid.item.ItemImpl
0167:            // which implements org.osid.assessment.Item
0168:            /**
0169:             * Get the Id for this ItemFacade.
0170:             * @return org.osid.shared.Id
0171:             */
0172:            org.osid.shared.Id getId() {
0173:                try {
0174:                    this .data = (ItemDataIfc) item.getData();
0175:                } catch (AssessmentException ex) {
0176:                    throw new DataFacadeException(ex.getMessage());
0177:                }
0178:                ItemFacadeQueriesAPI itemFacadeQueries = new ItemFacadeQueries();
0179:                return itemFacadeQueries.getItemId(this .data.getItemId());
0180:            }
0181:
0182:            /**
0183:             * Get the Type for this ItemFacade.
0184:             * @return org.osid.shared.Type
0185:             */
0186:            Type getItemType() {
0187:                try {
0188:                    this .data = (ItemDataIfc) item.getData();
0189:                } catch (AssessmentException ex) {
0190:                    throw new DataFacadeException(ex.getMessage());
0191:                }
0192:                TypeFacadeQueriesAPI typeFacadeQueries = PersistenceService
0193:                        .getInstance().getTypeFacadeQueries();
0194:                return typeFacadeQueries.getTypeById(this .data.getTypeId());
0195:            }
0196:
0197:            public TypeIfc getType() {
0198:                return getItemTypeFacade();
0199:            }
0200:
0201:            public TypeFacade getItemTypeFacade() {
0202:                try {
0203:                    this .data = (ItemDataIfc) item.getData();
0204:                } catch (AssessmentException ex) {
0205:                    throw new DataFacadeException(ex.getMessage());
0206:                }
0207:                TypeFacadeQueriesAPI typeFacadeQueries = PersistenceService
0208:                        .getInstance().getTypeFacadeQueries();
0209:                return typeFacadeQueries.getTypeFacadeById(this .data
0210:                        .getTypeId());
0211:            }
0212:
0213:            /**
0214:             * Get the data for this ItemFacade.
0215:             * @return ItemDataIfc
0216:             */
0217:            public ItemDataIfc getData() {
0218:                return this .data;
0219:            }
0220:
0221:            /**
0222:             * Call setDate() to update data in ItemFacade
0223:             * @param data
0224:             */
0225:            public void updateData(ItemDataIfc data) {
0226:                setData(data);
0227:            }
0228:
0229:            /**
0230:             * Set data for ItemFacade
0231:             * @param data
0232:             */
0233:            public void setData(ItemDataIfc data) {
0234:                this .data = data;
0235:            }
0236:
0237:            // the following methods implements
0238:            // org.sakaiproject.tool.assessment.ifc.ItemDataIfc
0239:            public Long getItemId() throws DataFacadeException {
0240:                try {
0241:                    this .data = (ItemDataIfc) item.getData();
0242:                } catch (AssessmentException ex) {
0243:                    throw new DataFacadeException(ex.getMessage());
0244:                }
0245:                return this .data.getItemId();
0246:            }
0247:
0248:            /**
0249:             * Set itemId for ItemFacade
0250:             * @param itemId
0251:             */
0252:            public void setItemId(Long itemId) {
0253:                this .itemId = itemId;
0254:                this .data.setItemId(itemId);
0255:                setItemIdString(itemId.toString());
0256:            }
0257:
0258:            // the following methods implements
0259:            // org.sakaiproject.tool.assessment.ifc.ItemDataIfc
0260:            public String getItemIdString() throws DataFacadeException {
0261:                try {
0262:                    this .data = (ItemDataIfc) item.getData();
0263:                } catch (AssessmentException ex) {
0264:                    throw new DataFacadeException(ex.getMessage());
0265:                }
0266:                return this .data.getItemIdString();
0267:            }
0268:
0269:            /**
0270:             * Set itemId for ItemFacade
0271:             * @param itemId
0272:             */
0273:            public void setItemIdString(String itemIdString) {
0274:                this .itemIdString = itemIdString;
0275:                this .data.setItemIdString(itemIdString);
0276:            }
0277:
0278:            // expect a return of SectionFacade from this method
0279:            public SectionDataIfc getSection() throws DataFacadeException {
0280:                try {
0281:                    this .data = (ItemDataIfc) item.getData();
0282:                } catch (AssessmentException ex) {
0283:                    throw new DataFacadeException(ex.getMessage());
0284:                }
0285:                if (this .data.getSection() != null) {
0286:                    return new SectionFacade(this .data.getSection());
0287:                } else {
0288:                    return null;
0289:                }
0290:            }
0291:
0292:            // section is SectionFacade not SectionData
0293:            public void setSection(SectionDataIfc section) {
0294:                this .section = (SectionFacade) section;
0295:                if (this .section != null) {
0296:                    this .data.setSection(this .section.getData());
0297:                } else {
0298:                    this .data.setSection(null);
0299:                }
0300:            }
0301:
0302:            public Integer getSequence() throws DataFacadeException {
0303:                try {
0304:                    this .data = (ItemDataIfc) item.getData();
0305:                } catch (AssessmentException ex) {
0306:                    throw new DataFacadeException(ex.getMessage());
0307:                }
0308:                return this .data.getSequence();
0309:            }
0310:
0311:            public void setSequence(Integer sequence) {
0312:                this .sequence = sequence;
0313:                this .data.setSequence(sequence);
0314:            }
0315:
0316:            public Integer getDuration() throws DataFacadeException {
0317:                try {
0318:                    this .data = (ItemDataIfc) item.getData();
0319:                } catch (AssessmentException ex) {
0320:                    throw new DataFacadeException(ex.getMessage());
0321:                }
0322:                return this .data.getDuration();
0323:            }
0324:
0325:            /**
0326:             * Set duration for ItemFacade
0327:             * @param duration
0328:             */
0329:            public void setDuration(Integer duration) {
0330:                this .duration = duration;
0331:                this .data.setDuration(duration);
0332:            }
0333:
0334:            public String getInstruction() throws DataFacadeException {
0335:                try {
0336:                    this .data = (ItemDataIfc) item.getData();
0337:                } catch (AssessmentException ex) {
0338:                    throw new DataFacadeException(ex.getMessage());
0339:                }
0340:                return this .data.getInstruction();
0341:            }
0342:
0343:            /**
0344:             * Set instruction for ItemFacade
0345:             * e.g. "Match the following sentences", "In the score between 1-5, specify
0346:             * your preference"
0347:             * @param instruction
0348:             */
0349:            public void setInstruction(String instruction) {
0350:                this .instruction = instruction;
0351:                this .data.setInstruction(instruction);
0352:            }
0353:
0354:            public String getDescription() throws DataFacadeException {
0355:                try {
0356:                    this .data = (ItemDataIfc) item.getData();
0357:                } catch (AssessmentException ex) {
0358:                    throw new DataFacadeException(ex.getMessage());
0359:                }
0360:                return this .data.getDescription();
0361:            }
0362:
0363:            /**
0364:             * Set description for ItemFacade
0365:             * @param description
0366:             */
0367:            public void setDescription(String description) {
0368:                this .description = description;
0369:                this .data.setDescription(description);
0370:            }
0371:
0372:            public Long getTypeId() throws DataFacadeException {
0373:                try {
0374:                    this .data = (ItemDataIfc) item.getData();
0375:                } catch (AssessmentException ex) {
0376:                    throw new DataFacadeException(ex.getMessage());
0377:                }
0378:                return this .data.getTypeId();
0379:            }
0380:
0381:            /**
0382:             * Set TypeId for ItemType. This property is used to indicate question type.
0383:             * e.g. 1 = Multiple Choice, 2 = Multiple Correct. Please check out
0384:             * ddl/02_TypeData.sql and table "type".
0385:             * @param typeId
0386:             */
0387:            public void setTypeId(Long typeId) {
0388:                this .typeId = typeId;
0389:                this .data.setTypeId(typeId);
0390:            }
0391:
0392:            /**
0393:             * Get Grade for ItemFacade
0394:             * @return
0395:             * @throws DataFacadeException
0396:             */
0397:            public String getGrade() throws DataFacadeException {
0398:                try {
0399:                    this .data = (ItemDataIfc) item.getData();
0400:                } catch (AssessmentException ex) {
0401:                    throw new DataFacadeException(ex.getMessage());
0402:                }
0403:                return this .data.getGrade();
0404:            }
0405:
0406:            /**
0407:             * Set Grade for ItemFacade
0408:             * @param grade
0409:             */
0410:            public void setGrade(String grade) {
0411:                this .grade = grade;
0412:                this .data.setGrade(grade);
0413:            }
0414:
0415:            /**
0416:             * Get Score for ItemFacade
0417:             * @return
0418:             * @throws DataFacadeException
0419:             */
0420:            public Float getScore() throws DataFacadeException {
0421:                try {
0422:                    this .data = (ItemDataIfc) item.getData();
0423:                } catch (AssessmentException ex) {
0424:                    throw new DataFacadeException(ex.getMessage());
0425:                }
0426:                return this .data.getScore();
0427:            }
0428:
0429:            /**
0430:             * Set Score for ItemFacade
0431:             * @param score
0432:             */
0433:            public void setScore(Float score) {
0434:                this .score = score;
0435:                this .data.setScore(score);
0436:            }
0437:
0438:            /**
0439:             * Get Hint for ItemFacade
0440:             * @return
0441:             * @throws DataFacadeException
0442:             */
0443:            public String getHint() throws DataFacadeException {
0444:                try {
0445:                    this .data = (ItemDataIfc) item.getData();
0446:                } catch (AssessmentException ex) {
0447:                    throw new DataFacadeException(ex.getMessage());
0448:                }
0449:                return this .data.getHint();
0450:            }
0451:
0452:            /**
0453:             * Set Hint for ItemFacade
0454:             * @param hint
0455:             */
0456:            public void setHint(String hint) {
0457:                this .hint = hint;
0458:                this .data.setHint(hint);
0459:            }
0460:
0461:            /**
0462:             * Check if item (question) require rationale in answer
0463:             * @return
0464:             * @throws DataFacadeException
0465:             */
0466:            public Boolean getHasRationale() throws DataFacadeException {
0467:                try {
0468:                    this .data = (ItemDataIfc) item.getData();
0469:                } catch (AssessmentException ex) {
0470:                    throw new DataFacadeException(ex.getMessage());
0471:                }
0472:                return this .data.getHasRationale();
0473:            }
0474:
0475:            /**
0476:             * Set preference if rationale should be collected in answer
0477:             * @param hasRationale
0478:             */
0479:            public void setHasRationale(Boolean hasRationale) {
0480:                this .hasRationale = hasRationale;
0481:                this .data.setHasRationale(hasRationale);
0482:            }
0483:
0484:            /**
0485:             * Get status of ItemFacade. 1 = active, 0 = inactive
0486:             * @return
0487:             * @throws DataFacadeException
0488:             */
0489:            public Integer getStatus() throws DataFacadeException {
0490:                try {
0491:                    this .data = (ItemDataIfc) item.getData();
0492:                } catch (AssessmentException ex) {
0493:                    throw new DataFacadeException(ex.getMessage());
0494:                }
0495:                return this .data.getStatus();
0496:            }
0497:
0498:            /**
0499:             * Set status for ItemFacade. 1 = active, 0 = inactive
0500:             * @param status
0501:             */
0502:            public void setStatus(Integer status) {
0503:                this .status = status;
0504:                this .data.setStatus(status);
0505:            }
0506:
0507:            /**
0508:             * Get createdBy for ItemFacade. This represents the agentId of the person
0509:             * who created the record
0510:             * @return
0511:             * @throws DataFacadeException
0512:             */
0513:            public String getCreatedBy() throws DataFacadeException {
0514:                try {
0515:                    this .data = (ItemDataIfc) item.getData();
0516:                } catch (AssessmentException ex) {
0517:                    throw new DataFacadeException(ex.getMessage());
0518:                }
0519:                return this .data.getCreatedBy();
0520:            }
0521:
0522:            /**
0523:             * Set createdBy for ItemFacade. This represents the agentId of the person
0524:             * who created the record
0525:             * @param createdBy
0526:             */
0527:            public void setCreatedBy(String createdBy) {
0528:                this .createdBy = createdBy;
0529:                this .data.setCreatedBy(createdBy);
0530:            }
0531:
0532:            /**
0533:             * Get the creation date of ItemFacade.
0534:             * @return
0535:             * @throws DataFacadeException
0536:             */
0537:            public Date getCreatedDate() throws DataFacadeException {
0538:                try {
0539:                    this .data = (ItemDataIfc) item.getData();
0540:                } catch (AssessmentException ex) {
0541:                    throw new DataFacadeException(ex.getMessage());
0542:                }
0543:                return this .data.getCreatedDate();
0544:            }
0545:
0546:            /**
0547:             * Set the creation date of ItemFacade
0548:             * @param createdDate
0549:             */
0550:            public void setCreatedDate(Date createdDate) {
0551:                this .createdDate = createdDate;
0552:                this .data.setCreatedDate(createdDate);
0553:            }
0554:
0555:            /**
0556:             * Get the agentId of the person who last modified ItemFacade
0557:             * @return
0558:             * @throws DataFacadeException
0559:             */
0560:            public String getLastModifiedBy() throws DataFacadeException {
0561:                try {
0562:                    this .data = (ItemDataIfc) item.getData();
0563:                } catch (AssessmentException ex) {
0564:                    throw new DataFacadeException(ex.getMessage());
0565:                }
0566:                return this .data.getLastModifiedBy();
0567:            }
0568:
0569:            /**
0570:             * set the agentId of the person who last modified itemFacade
0571:             * @param lastModifiedBy
0572:             */
0573:            public void setLastModifiedBy(String lastModifiedBy) {
0574:                this .lastModifiedBy = lastModifiedBy;
0575:                this .data.setLastModifiedBy(lastModifiedBy);
0576:            }
0577:
0578:            /**
0579:             * Get the date when ItemFacade where last modified By
0580:             * @return
0581:             * @throws DataFacadeException
0582:             */
0583:            public Date getLastModifiedDate() throws DataFacadeException {
0584:                try {
0585:                    this .data = (ItemDataIfc) item.getData();
0586:                } catch (AssessmentException ex) {
0587:                    throw new DataFacadeException(ex.getMessage());
0588:                }
0589:                return this .data.getLastModifiedDate();
0590:            }
0591:
0592:            /**
0593:             * Set the last modified date
0594:             * @param lastModifiedBy
0595:             */
0596:            public void setLastModifiedDate(Date lastModifiedDate) {
0597:                this .lastModifiedDate = lastModifiedDate;
0598:                this .data.setLastModifiedDate(lastModifiedDate);
0599:            }
0600:
0601:            /**
0602:             * Get item text set (question text set) from ItemFacade.data
0603:             * @return
0604:             * @throws DataFacadeException
0605:             */
0606:            public Set getItemTextSet() throws DataFacadeException {
0607:                try {
0608:                    this .data = (ItemDataIfc) item.getData();
0609:                } catch (AssessmentException ex) {
0610:                    throw new DataFacadeException(ex.getMessage());
0611:                }
0612:                return this .data.getItemTextSet();
0613:            }
0614:
0615:            /**
0616:             * Set item text (question text) in ItemFacade.data
0617:             * @param itemTextSet
0618:             */
0619:            public void setItemTextSet(Set itemTextSet) {
0620:                this .itemTextSet = itemTextSet;
0621:                this .data.setItemTextSet(itemTextSet);
0622:            }
0623:
0624:            public Set getItemMetaDataSet() throws DataFacadeException {
0625:                try {
0626:                    this .data = (ItemDataIfc) item.getData();
0627:                } catch (AssessmentException ex) {
0628:                    throw new DataFacadeException(ex.getMessage());
0629:                }
0630:                return this .data.getItemMetaDataSet();
0631:            }
0632:
0633:            /**
0634:             * Set item metadata set in ItemFacade and ItemFacade.data
0635:             * @param itemMetaDataSet
0636:             */
0637:            public void setItemMetaDataSet(Set itemMetaDataSet) {
0638:                this .itemMetaDataSet = itemMetaDataSet;
0639:                this .data.setItemMetaDataSet(itemMetaDataSet);
0640:                this .itemMetaDataMap = getItemMetaDataMap(itemMetaDataSet);
0641:            }
0642:
0643:            /**
0644:             * Get item metadata in HashMap (String Label, ItemMetaData itemMetaData) of
0645:             * ItemFacade
0646:             * @param itemMetaDataSet
0647:             * @return
0648:             */
0649:            public HashMap getItemMetaDataMap(Set itemMetaDataSet) {
0650:                HashMap itemMetaDataMap = new HashMap();
0651:                if (itemMetaDataSet != null) {
0652:                    for (Iterator i = itemMetaDataSet.iterator(); i.hasNext();) {
0653:                        ItemMetaData itemMetaData = (ItemMetaData) i.next();
0654:                        itemMetaDataMap.put(itemMetaData.getLabel(),
0655:                                itemMetaData.getEntry());
0656:                    }
0657:                }
0658:                return itemMetaDataMap;
0659:            }
0660:
0661:            /**
0662:             * Set the item feedback set for ItemFacade using the "data"
0663:             * @return
0664:             */
0665:            public Set getItemFeedbackSet() {
0666:                try {
0667:                    this .data = (ItemDataIfc) item.getData();
0668:                } catch (AssessmentException ex) {
0669:                    throw new DataFacadeException(ex.getMessage());
0670:                }
0671:                return this .data.getItemFeedbackSet();
0672:            }
0673:
0674:            /**
0675:             * Set the item feedback set for ItemFacade and ItemFacade.data
0676:             * @param itemFeedbackSet
0677:             */
0678:            public void setItemFeedbackSet(Set itemFeedbackSet) {
0679:                this .itemFeedbackSet = itemFeedbackSet;
0680:                this .data.setItemFeedbackSet(itemFeedbackSet);
0681:                this .itemFeedbackMap = getItemFeedbackMap(itemFeedbackSet);
0682:            }
0683:
0684:            /**
0685:             * Get a HashMap (Long feedbackTypeId, ItemFeedback itemFeedback) of item
0686:             * feedback for ItemFacade
0687:             * @param itemFeedbackSet
0688:             * @return
0689:             */
0690:            public HashMap getItemFeedbackMap(Set itemFeedbackSet) {
0691:                HashMap itemFeedbackMap = new HashMap();
0692:                if (itemFeedbackSet != null) {
0693:                    for (Iterator i = itemFeedbackSet.iterator(); i.hasNext();) {
0694:                        ItemFeedback itemFeedback = (ItemFeedback) i.next();
0695:                        itemFeedbackMap.put(itemFeedback.getTypeId(),
0696:                                itemFeedback.getText());
0697:                    }
0698:                }
0699:                return itemFeedbackMap;
0700:            }
0701:
0702:            /**
0703:             * implements Serializable method
0704:             * @param out
0705:             * @throws IOException
0706:             */
0707:            private void writeObject(java.io.ObjectOutputStream out)
0708:                    throws IOException {
0709:                out.defaultWriteObject();
0710:            }
0711:
0712:            /**
0713:             * implements Serializable method
0714:             * @param in
0715:             * @throws IOException
0716:             * @throws java.lang.ClassNotFoundException
0717:             */
0718:            private void readObject(java.io.ObjectInputStream in)
0719:                    throws IOException, ClassNotFoundException {
0720:                in.defaultReadObject();
0721:            }
0722:
0723:            /**
0724:             * Add item text (question text) to ItemFacade (question). For multiple
0725:             * choice, multiple correct, survey, matching & fill in the blank, you can
0726:             * specify a set of acceptable answers. Usually, the purpose for this is
0727:             * to facilitate auto-grading.
0728:             * @param text
0729:             * @param answerSet
0730:             */
0731:            public void addItemText(String text, Set answerSet) {
0732:                if (this .data.getItemTextSet() == null) {
0733:                    this .data.setItemTextSet(new HashSet());
0734:                }
0735:                Long sequence = new Long(this .data.getItemTextSet().size() + 1);
0736:                ItemText itemText = new ItemText((ItemData) this .data,
0737:                        sequence, text, answerSet);
0738:                this .data.getItemTextSet().add(itemText);
0739:                this .itemTextSet = this .data.getItemTextSet();
0740:            }
0741:
0742:            /**
0743:             * Get meta data by label
0744:             * @param label
0745:             * @return
0746:             */
0747:            public String getItemMetaDataByLabel(String label) {
0748:                return (String) this .itemMetaDataMap.get(label);
0749:            }
0750:
0751:            /**
0752:             * Add a Meta Data to ItemFacade
0753:             * @param label
0754:             * @param entry
0755:             */
0756:            public void addItemMetaData(String label, String entry) {
0757:                if (this .itemMetaDataSet == null) {
0758:                    setItemMetaDataSet(new HashSet());
0759:                    this .itemMetaDataMap = new HashMap();
0760:                }
0761:                this .itemMetaDataMap.put(label, entry);
0762:                this .data.getItemMetaDataSet().add(
0763:                        new ItemMetaData((ItemData) this .data, label, entry));
0764:                this .itemMetaDataSet = this .data.getItemMetaDataSet();
0765:            }
0766:
0767:            /**
0768:             * Get General Feedback
0769:             * @return
0770:             */
0771:            public String getGeneralItemFeedback() {
0772:                return getItemFeedback(ItemFeedbackIfc.GENERAL_FEEDBACK);
0773:            }
0774:
0775:            /**
0776:             * Set General Feedback
0777:             * @param text
0778:             */
0779:            public void setGeneralItemFeedback(String text) {
0780:                removeFeedbackByType(ItemFeedbackIfc.GENERAL_FEEDBACK);
0781:                addItemFeedback(ItemFeedbackIfc.GENERAL_FEEDBACK, text);
0782:            }
0783:
0784:            /**
0785:             * Get Correct Feedback
0786:             * @return
0787:             */
0788:            public String getCorrectItemFeedback() {
0789:                return getItemFeedback(ItemFeedbackIfc.CORRECT_FEEDBACK);
0790:            }
0791:
0792:            /**
0793:             * Set Correct Feedback
0794:             * @param text
0795:             */
0796:            public void setCorrectItemFeedback(String text) {
0797:                removeFeedbackByType(ItemFeedbackIfc.CORRECT_FEEDBACK);
0798:                addItemFeedback(ItemFeedbackIfc.CORRECT_FEEDBACK, text);
0799:            }
0800:
0801:            /**
0802:             * Get Incorrect Feedback
0803:             * @return
0804:             */
0805:            public String getInCorrectItemFeedback() {
0806:                return getItemFeedback(ItemFeedbackIfc.INCORRECT_FEEDBACK);
0807:            }
0808:
0809:            /**
0810:             * Set InCorrect Feedback
0811:             * @param text
0812:             */
0813:            public void setInCorrectItemFeedback(String text) {
0814:                removeFeedbackByType(ItemFeedbackIfc.INCORRECT_FEEDBACK);
0815:                addItemFeedback(ItemFeedbackIfc.INCORRECT_FEEDBACK, text);
0816:            }
0817:
0818:            /**
0819:             * Get feedback based on feedback type (e.g. CORRECT, INCORRECT)
0820:             * @param feedbackTypeId
0821:             * @return
0822:             */
0823:            public String getItemFeedback(String feedbackTypeId) {
0824:                return (String) this .itemFeedbackMap.get(feedbackTypeId);
0825:            }
0826:
0827:            /**
0828:             * Add feedback of a specified feedback type (e.g. CORRECT, INCORRECT)
0829:             * to ItemFacade
0830:             * @param feedbackTypeId
0831:             * @param text
0832:             */
0833:            public void addItemFeedback(String feedbackTypeId, String text) {
0834:                if (this .itemFeedbackSet == null) {
0835:                    setItemFeedbackSet(new HashSet());
0836:                    this .itemFeedbackMap = new HashMap();
0837:                }
0838:                this .itemFeedbackMap.put(feedbackTypeId, text);
0839:                this .data.getItemFeedbackSet().add(
0840:                        new ItemFeedback((ItemData) this .data, feedbackTypeId,
0841:                                text));
0842:                this .itemFeedbackSet = this .data.getItemFeedbackSet();
0843:            }
0844:
0845:            /**
0846:             * Remove Feedback by feedback typeId (e.g. CORRECT, INCORRECT)
0847:             * @param feedbackTypeId
0848:             */
0849:            public void removeFeedbackByType(String feedbackTypeId) {
0850:                this .itemFeedbackSet = this .data.getItemFeedbackSet();
0851:                if (this .itemFeedbackSet != null) {
0852:                    for (Iterator i = this .itemFeedbackSet.iterator(); i
0853:                            .hasNext();) {
0854:                        ItemFeedback itemFeedback = (ItemFeedback) i.next();
0855:                        if (itemFeedback.getTypeId().equals(feedbackTypeId)) {
0856:                            this .itemFeedbackSet.remove(itemFeedback);
0857:                        }
0858:                    }
0859:                }
0860:            }
0861:
0862:            /**
0863:             * If this is a true-false question return true if it is true, else false.
0864:             * If it is not a true-false question return false.
0865:             * @return true if this is a true true-false question
0866:             */
0867:            public Boolean getIsTrue() throws DataFacadeException {
0868:                try {
0869:                    this .data = (ItemDataIfc) item.getData();
0870:                } catch (AssessmentException ex) {
0871:                    throw new DataFacadeException(ex.getMessage());
0872:                }
0873:                return this .data.getIsTrue();
0874:            }
0875:
0876:            /**
0877:             * Utility method.
0878:             * In the case of an ordinary question, this will obtain the a set of text with
0879:             * one element and return it; in FIB or FIN return multiple elements separated by
0880:             * underscores.
0881:             * @return text of question
0882:             */
0883:
0884:            public String getText() throws DataFacadeException {
0885:                try {
0886:                    this .data = (ItemDataIfc) item.getData();
0887:                } catch (AssessmentException ex) {
0888:                    throw new DataFacadeException(ex.getMessage());
0889:                }
0890:                return this .data.getText();
0891:            }
0892:
0893:            /**
0894:             * Utility method.
0895:             * Obeys the semantics and rules of the getText() but removes
0896:             * HTML tags.
0897:             *
0898:             * @see getText()
0899:             * @return text of question, removes
0900:             * HTML tags.
0901:             * @throws DataFacadeException
0902:             */
0903:            public String getTextHtmlStripped() throws DataFacadeException {
0904:                String regex = "\\<.*?\\>";
0905:                return getText().replaceAll(regex, " ");
0906:            }
0907:
0908:            /**
0909:             * Utility method.
0910:             * Obeys the semantics and rules of the getText() but removes
0911:             * HTML tags. The differency of getTextHtmlStripped() is this
0912:             * API doesn't replace HTMLtags by white space.
0913:             *
0914:             * @see getText()
0915:             * @return text of question, removes
0916:             * HTML tags.
0917:             * @throws DataFacadeException
0918:             */
0919:            public String getTextHtmlStrippedAll() throws DataFacadeException {
0920:                String regex = "\\<.*?\\>|\\n|\\r\\n";
0921:                return getText().replaceAll(regex, "");
0922:            }
0923:
0924:            public ArrayList getItemTextArray() {
0925:                ArrayList list = new ArrayList();
0926:                Iterator iter = itemTextSet.iterator();
0927:                while (iter.hasNext()) {
0928:                    list.add(iter.next());
0929:                }
0930:                return list;
0931:            }
0932:
0933:            public ArrayList getItemTextArraySorted() {
0934:                ArrayList list = getItemTextArray();
0935:                Collections.sort(list);
0936:                return list;
0937:            }
0938:
0939:            public Integer getTriesAllowed() throws DataFacadeException {
0940:                try {
0941:                    this .data = (ItemDataIfc) item.getData();
0942:                } catch (AssessmentException ex) {
0943:                    throw new DataFacadeException(ex.getMessage());
0944:                }
0945:                return this .data.getTriesAllowed();
0946:            }
0947:
0948:            /**
0949:             * Set duration for ItemFacade
0950:             * @param duration
0951:             */
0952:            public void setTriesAllowed(Integer triesAllowed) {
0953:                this .triesAllowed = triesAllowed;
0954:                this .data.setTriesAllowed(triesAllowed);
0955:            }
0956:
0957:            public void removeMetaDataByType(String label) {
0958:                try {
0959:                    if (itemMetaDataSet != null) {
0960:                        for (Iterator i = this .itemMetaDataSet.iterator(); i
0961:                                .hasNext();) {
0962:                            ItemMetaDataIfc itemMetaData = (ItemMetaDataIfc) i
0963:                                    .next();
0964:                            if (itemMetaData.getLabel().equals(label)) {
0965:                                //this.itemMetaDataSet.remove(itemMetaData);
0966:                                i.remove();
0967:                            }
0968:                        }
0969:                    }
0970:                } catch (Exception e) {
0971:                    e.printStackTrace();
0972:                }
0973:            }
0974:
0975:            /**
0976:             * This method return the answerKey for a matching question
0977:             * e.g. A:2, B:3, C:1, D:4 (where A, B & C is the answer label and 1,2 &3
0978:             * are the itemText sequence
0979:             */
0980:            public String getAnswerKey() {
0981:                return ((ItemData) this .data).getAnswerKey();
0982:            }
0983:
0984:            public int compareTo(Object o) {
0985:                ItemFacade a = (ItemFacade) o;
0986:                return sequence.compareTo(a.sequence);
0987:            }
0988:
0989:            public Set getItemAttachmentSet() {
0990:                try {
0991:                    this .data = (ItemDataIfc) item.getData();
0992:                } catch (AssessmentException ex) {
0993:                    throw new DataFacadeException(ex.getMessage());
0994:                }
0995:                return this .data.getItemAttachmentSet();
0996:            }
0997:
0998:            public void setItemAttachmentSet(Set itemAttachmentSet) {
0999:                this .itemAttachmentSet = itemAttachmentSet;
1000:                this .data.setItemAttachmentSet(itemAttachmentSet);
1001:            }
1002:
1003:            public List getItemAttachmentList() {
1004:                ArrayList list = new ArrayList();
1005:                Set set = getItemAttachmentSet();
1006:                if (set != null) {
1007:                    Iterator iter = set.iterator();
1008:                    while (iter.hasNext()) {
1009:                        ItemAttachmentIfc a = (ItemAttachmentIfc) iter.next();
1010:                        list.add(a);
1011:                    }
1012:                }
1013:                return list;
1014:            }
1015:
1016:            public void addItemAttachmentMetaData(String entry) {
1017:                itemAttachmentMetaData = entry;
1018:            }
1019:
1020:            public String getItemAttachmentMetaData() {
1021:                return itemAttachmentMetaData;
1022:            }
1023:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.