001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-hibernate/src/java/org/sakaiproject/tool/assessment/data/dao/assessment/Answer.java $
003: * $Id: Answer.java 9273 2006-05-10 22:34:28Z daisyf@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.data.dao.assessment;
021:
022: import org.sakaiproject.tool.assessment.data.ifc.assessment.AnswerIfc;
023: import org.sakaiproject.tool.assessment.data.ifc.assessment.AnswerFeedbackIfc;
024: import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemTextIfc;
025: import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
026: import org.sakaiproject.tool.assessment.data.dao.assessment.ItemData;
027: import org.apache.log4j.*;
028: import java.io.Serializable;
029: import java.io.IOException;
030: import java.util.Set;
031: import java.util.ArrayList;
032: import java.util.Iterator;
033: import java.util.HashMap;
034:
035: public class Answer implements Serializable, AnswerIfc, Comparable {
036: static Category errorLogger = Category.getInstance("errorLogger");
037:
038: private static final long serialVersionUID = 7526471155622776147L;
039:
040: private Long id;
041: private ItemTextIfc itemText;
042: private ItemDataIfc item;
043: private String text;
044: private Long sequence;
045: private String label;
046: private Boolean isCorrect;
047: private String grade;
048: private Float score;
049: private Set answerFeedbackSet;
050: private HashMap answerFeedbackMap;
051: private ItemData dat = new ItemData();
052:
053: public Answer() {
054: }
055:
056: public Answer(ItemTextIfc itemText, String text, Long sequence,
057: String label, Boolean isCorrect, String grade, Float score) {
058: this .itemText = itemText;
059: this .item = itemText.getItem();
060: this .text = text;
061: this .sequence = sequence;
062: this .label = label;
063: this .isCorrect = isCorrect;
064: this .grade = grade;
065: this .score = score;
066: }
067:
068: public Answer(ItemTextIfc itemText, String text, Long sequence,
069: String label, Boolean isCorrect, String grade, Float score,
070: Set answerFeedbackSet) {
071: this .itemText = itemText;
072: this .item = itemText.getItem();
073: this .text = text;
074: this .sequence = sequence;
075: this .label = label;
076: this .isCorrect = isCorrect;
077: this .grade = grade;
078: this .score = score;
079: this .answerFeedbackSet = answerFeedbackSet;
080: }
081:
082: public Long getId() {
083: return id;
084: }
085:
086: public void setId(Long id) {
087: this .id = id;
088: }
089:
090: public ItemTextIfc getItemText() {
091: return itemText;
092: }
093:
094: public void setItemText(ItemTextIfc itemText) {
095: this .itemText = itemText;
096: }
097:
098: public ItemDataIfc getItem() {
099: return item;
100: }
101:
102: public void setItem(ItemDataIfc item) {
103: this .item = item;
104: }
105:
106: public String getText() {
107: return text;
108: }
109:
110: public void setText(String text) {
111: this .text = text;
112: }
113:
114: public Long getSequence() {
115: return sequence;
116: }
117:
118: public void setSequence(Long sequence) {
119: this .sequence = sequence;
120: }
121:
122: public String getLabel() {
123: return label;
124: }
125:
126: public void setLabel(String label) {
127: this .label = label;
128: }
129:
130: public Boolean getIsCorrect() {
131: return isCorrect;
132: }
133:
134: public void setIsCorrect(Boolean isCorrect) {
135: this .isCorrect = isCorrect;
136: }
137:
138: public String getGrade() {
139: return grade;
140: }
141:
142: public void setGrade(String grade) {
143: this .grade = grade;
144: }
145:
146: public Float getScore() {
147: return score;
148: }
149:
150: public void setScore(Float score) {
151: this .score = score;
152: }
153:
154: public Set getAnswerFeedbackSet() {
155: return answerFeedbackSet;
156: }
157:
158: public ArrayList getAnswerFeedbackArray() {
159: ArrayList list = new ArrayList();
160: Iterator iter = answerFeedbackSet.iterator();
161: while (iter.hasNext()) {
162: list.add(iter.next());
163: }
164: return list;
165: }
166:
167: public void setAnswerFeedbackSet(Set answerFeedbackSet) {
168: this .answerFeedbackSet = answerFeedbackSet;
169: }
170:
171: private void writeObject(java.io.ObjectOutputStream out)
172: throws IOException {
173: out.defaultWriteObject();
174: }
175:
176: private void readObject(java.io.ObjectInputStream in)
177: throws IOException, ClassNotFoundException {
178: in.defaultReadObject();
179: }
180:
181: public String getAnswerFeedback(String typeId) {
182: if (this .answerFeedbackMap == null)
183: this .answerFeedbackMap = getAnswerFeedbackMap();
184: return (String) this .answerFeedbackMap.get(typeId);
185: }
186:
187: public HashMap getAnswerFeedbackMap() {
188: HashMap answerFeedbackMap = new HashMap();
189: if (this .answerFeedbackSet != null) {
190: for (Iterator i = this .answerFeedbackSet.iterator(); i
191: .hasNext();) {
192: AnswerFeedback answerFeedback = (AnswerFeedback) i
193: .next();
194: answerFeedbackMap.put(answerFeedback.getTypeId(),
195: answerFeedback.getText());
196: }
197: }
198: return answerFeedbackMap;
199: }
200:
201: public String getCorrectAnswerFeedback() {
202: return getAnswerFeedback(AnswerFeedbackIfc.CORRECT_FEEDBACK);
203: }
204:
205: public String getInCorrectAnswerFeedback() {
206: return getAnswerFeedback(AnswerFeedbackIfc.INCORRECT_FEEDBACK);
207: }
208:
209: public String getGeneralAnswerFeedback() {
210: return getAnswerFeedback(AnswerFeedbackIfc.GENERAL_FEEDBACK);
211: }
212:
213: public String getTheAnswerFeedback() {
214: return getAnswerFeedback(AnswerFeedbackIfc.ANSWER_FEEDBACK);
215: }
216:
217: public int compareTo(Object o) {
218: Answer a = (Answer) o;
219: return sequence.compareTo(a.sequence);
220: }
221:
222: //Huong's adding for checking not empty feedback
223: public boolean getGeneralAnswerFbIsNotEmpty() {
224:
225: return dat.isNotEmpty(getGeneralAnswerFeedback());
226:
227: }
228:
229: public boolean getCorrectAnswerFbIsNotEmpty() {
230:
231: return dat.isNotEmpty(getCorrectAnswerFeedback());
232:
233: }
234:
235: public boolean getIncorrectAnswerFbIsNotEmpty() {
236:
237: return dat.isNotEmpty(getInCorrectAnswerFeedback());
238:
239: }
240:
241: public boolean getTextIsNotEmpty() {
242:
243: return dat.isNotEmpty(getText());
244: }
245:
246: }
|