001: /*
002: * QuestionModel.java
003: *
004: * Created on May 17, 2005, 1:58 PM
005: */
006:
007: package com.sun.portal.app.collab.survey.model;
008:
009: import java.beans.*;
010: import java.io.Serializable;
011: import java.util.ArrayList;
012:
013: /**
014: * @author jerry
015: */
016: public class QuestionModel extends Object implements Serializable {
017:
018: private PropertyChangeSupport propertySupport;
019:
020: public QuestionModel() {
021: propertySupport = new PropertyChangeSupport(this );
022: }
023:
024: public void addPropertyChangeListener(
025: PropertyChangeListener listener) {
026: propertySupport.addPropertyChangeListener(listener);
027: }
028:
029: public void removePropertyChangeListener(
030: PropertyChangeListener listener) {
031: propertySupport.removePropertyChangeListener(listener);
032: }
033:
034: /**
035: * Holds value of property questionId.
036: */
037: private int questionId;
038:
039: /**
040: * Getter for property question_id.
041: * @return Value of property question_id.
042: */
043: public int getQuestionId() {
044:
045: return this .questionId;
046: }
047:
048: /**
049: * Setter for property question_id.
050: * @param question_id New value of property question_id.
051: */
052: public void setQuestionId(int questionId) {
053:
054: this .questionId = questionId;
055: }
056:
057: /**
058: * Holds value of property questionOrder.
059: */
060: private int questionOrder;
061:
062: /**
063: * Getter for property question_order.
064: * @return Value of property question_order.
065: */
066: public int getQuestionOrder() {
067:
068: return this .questionOrder;
069: }
070:
071: /**
072: * Setter for property question_order.
073: * @param question_order New value of property question_order.
074: */
075: public void setQuestionOrder(int questionOrder) {
076:
077: this .questionOrder = questionOrder;
078: }
079:
080: /**
081: * Holds value of property questionText.
082: */
083: private String questionText;
084:
085: /**
086: * Getter for property question_text.
087: * @return Value of property question_text.
088: */
089: public String getQuestionText() {
090:
091: return this .questionText;
092: }
093:
094: /**
095: * Setter for property question_text.
096: * @param question_text New value of property question_text.
097: */
098: public void setQuestionText(String questionText) {
099:
100: this .questionText = questionText;
101: }
102:
103: /**
104: * Holds value of property mandatory.
105: */
106: private boolean mandatory;
107:
108: /**
109: * Getter for property mandatory.
110: * @return Value of property mandatory.
111: */
112: public boolean isMandatory() {
113:
114: return this .mandatory;
115: }
116:
117: /**
118: * Setter for property mandatory.
119: * @param mandatory New value of property mandatory.
120: */
121: public void setMandatory(boolean mandatory) {
122:
123: this .mandatory = mandatory;
124: }
125:
126: /**
127: * Holds value of property open.
128: */
129: private boolean open;
130:
131: /**
132: * Getter for property isOpen.
133: * @return Value of property isOpen.
134: */
135: public boolean isOpen() {
136:
137: return this .open;
138: }
139:
140: /**
141: * Setter for property isOpen.
142: * @param isOpen New value of property isOpen.
143: */
144: public void setOpen(boolean open) {
145:
146: this .open = open;
147: }
148:
149: /**
150: * Holds value of property answers.
151: */
152: private com.sun.portal.app.collab.survey.model.AnswerModel[] answers;
153:
154: /**
155: * Getter for property test.
156: * @return Value of property test.
157: */
158: protected boolean searchanswers = true;
159:
160: public AnswerModel[] getAnswers() throws SurveyException {
161:
162: if (answers == null && searchanswers) {
163: SurveyDB db = new SurveyDB();
164: ArrayList l = db.getAnswers(questionId);
165: if (l != null) {
166: answers = (AnswerModel[]) l.toArray(new AnswerModel[1]);
167: if (answers[0] == null) {
168: // No answers were found: its just an open question
169: answers = null;
170: searchanswers = false;
171: }
172: }
173: }
174:
175: return this .answers;
176: }
177:
178: /**
179: * Setter for property test.
180: * @param test New value of property test.
181: */
182: public void setAnswers(
183: com.sun.portal.app.collab.survey.model.AnswerModel[] answers) {
184:
185: this .answers = answers;
186: }
187:
188: /**
189: * Holds value of property multiselect.
190: */
191: private boolean multiselect;
192:
193: /**
194: * Getter for property multiselect.
195: * @return Value of property multiselect.
196: */
197: public boolean isMultiselect() {
198:
199: return this .multiselect;
200: }
201:
202: /**
203: * Setter for property multiselect.
204: * @param multiselect New value of property multiselect.
205: */
206: public void setMultiselect(boolean multiselect) {
207:
208: this .multiselect = multiselect;
209: }
210:
211: public String toString() {
212: StringBuffer str = new StringBuffer();
213: str.append("QuestionModel: ");
214: str.append("questionId=" + questionId);
215: str.append(",questionText=" + questionText);
216: str.append(",questionOrder=" + questionOrder);
217: str.append(",open=" + open);
218: str.append(",multiselect=" + multiselect);
219: str.append("mandatory=" + mandatory);
220: return str.toString();
221:
222: }
223:
224: public int getResponseCount() throws SurveyException {
225: int count;
226: SurveyDB db = new SurveyDB();
227: count = db.getQuestionResponseCount(questionId);
228: return count;
229: }
230:
231: public int getRespondantCount() throws SurveyException {
232: int count;
233: SurveyDB db = new SurveyDB();
234: count = db.getQuestionRespondantCount(questionId);
235: return count;
236: }
237:
238: public String[] getCustomAnswers() throws SurveyException {
239: String[] arr;
240: SurveyDB db = new SurveyDB();
241: arr = db.getCustomAnswers(questionId);
242: return arr;
243: }
244:
245: public float getCustomAnswerPct() throws SurveyException {
246: if (open) {
247: SurveyDB db = new SurveyDB();
248: String[] arr;
249: arr = db.getCustomAnswers(questionId);
250: if (arr != null) {
251: float aCount = arr.length;
252: float qCount = db.getQuestionResponseCount(questionId);
253: return ((qCount == 0) ? 0 : ((aCount / qCount) * 100));
254: } else {
255: return 0;
256: }
257: } else {
258: return 0;
259: }
260: }
261:
262: public int getCustomAnswerCount() throws SurveyException {
263: if (open) {
264: String[] arr;
265: arr = getCustomAnswers();
266: if (arr != null) {
267: return arr.length;
268: } else {
269: return 0;
270: }
271: } else {
272: return 0;
273: }
274: }
275:
276: public float getResponsePct() throws SurveyException {
277: SurveyDB db = new SurveyDB();
278: float count = db.getQuestionResponsePct(questionId);
279: return count;
280: }
281: }
|