001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/author/AssessmentBean.java $
003: * $Id: AssessmentBean.java 14496 2006-09-13 02:54:43Z 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.ui.bean.author;
021:
022: import java.io.Serializable;
023: import java.util.ArrayList;
024: import java.util.List;
025: import javax.faces.context.FacesContext;
026: import javax.faces.model.SelectItem;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionDataIfc;
032: import org.sakaiproject.tool.assessment.data.ifc.shared.TypeIfc;
033: import org.sakaiproject.tool.assessment.facade.AssessmentFacade;
034: import org.sakaiproject.tool.assessment.services.shared.TypeService;
035: import org.sakaiproject.tool.assessment.ui.bean.delivery.ItemContentsBean;
036: import org.sakaiproject.tool.assessment.ui.bean.delivery.SectionContentsBean;
037:
038: /**
039: * @author rshastri
040: *
041: * To change the template for this generated type comment go to
042: * Window>Preferences>Java>Code Generation>Code and Comments
043: *
044: * Used to be org.navigoproject.ui.web.asi.author.assessment.AssessmentActionForm.java
045: */
046: public class AssessmentBean implements Serializable {
047: private static Log log = LogFactory.getLog(AssessmentBean.class);
048:
049: /** Use serialVersionUID for interoperability. */
050: private final static long serialVersionUID = -630950053380808339L;
051: private AssessmentFacade assessment;
052: private String assessmentId;
053: private String title;
054: // ArrayList of SectionContentsBean
055: private ArrayList sections = new ArrayList(); // this contains list of SectionFacde
056: private ArrayList sectionList = new ArrayList(); // this contains list of javax.faces.model.SelectItem
057: private ArrayList otherSectionList = new ArrayList(); // contains SectionItem of section except the current section
058: private ArrayList partNumbers = new ArrayList();
059: private int questionSize = 0;
060: private float totalScore = 0;
061: private String newQuestionTypeId;
062: private String firstSectionId;
063: private boolean hasRandomDrawPart;
064:
065: /*
066: * Creates a new AssessmentBean object.
067: */
068: public AssessmentBean() {
069: }
070:
071: public AssessmentFacade getAssessment() {
072: return assessment;
073: }
074:
075: public void setAssessment(AssessmentFacade assessment) {
076: try {
077: this .assessment = assessment;
078: this .assessmentId = assessment.getAssessmentId().toString();
079: this .title = assessment.getTitle();
080:
081: // work out the question side & total point
082: this .sections = new ArrayList();
083: ArrayList sectionArray = assessment.getSectionArraySorted();
084: for (int i = 0; i < sectionArray.size(); i++) {
085: SectionDataIfc section = (SectionDataIfc) sectionArray
086: .get(i);
087: SectionContentsBean sectionBean = new SectionContentsBean(
088: section);
089: this .sections.add(sectionBean);
090: }
091: setPartNumbers();
092: setQuestionSizeAndTotalScore();
093: setSectionList(sectionArray);
094: } catch (Exception ex) {
095: ex.printStackTrace();
096: }
097: }
098:
099: // properties from Assessment
100: public String getAssessmentId() {
101: return this .assessmentId;
102: }
103:
104: public void setAssessmentId(String assessmentId) {
105: this .assessmentId = assessmentId;
106: }
107:
108: public String getTitle() {
109: return this .title;
110: }
111:
112: public void setTitle(String title) {
113: this .title = title;
114: }
115:
116: public ArrayList getSections() {
117: return sections;
118: }
119:
120: public void setSections(ArrayList sections) {
121: this .sections = sections;
122: }
123:
124: public ArrayList getPartNumbers() {
125: return partNumbers;
126: }
127:
128: public void setPartNumbers() {
129: this .partNumbers = new ArrayList();
130: for (int i = 1; i <= this .sections.size(); i++) {
131: this .partNumbers.add(new SelectItem(i + ""));
132: }
133: }
134:
135: public int getQuestionSize() {
136: return this .questionSize;
137: }
138:
139: public void setQuestionSizeAndTotalScore() {
140: this .questionSize = 0;
141: this .totalScore = 0;
142: int randomPartCount = 0;
143: for (int i = 0; i < this .sections.size(); i++) {
144: SectionContentsBean sectionBean = (SectionContentsBean) sections
145: .get(i);
146: ArrayList items = sectionBean.getItemContents();
147:
148: int itemsInThisSection = 0;
149: if (sectionBean.getSectionAuthorType().equals(
150: SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL)) {
151: // for random draw parts, add
152: randomPartCount++;
153: itemsInThisSection = sectionBean.getNumberToBeDrawn()
154: .intValue();
155: } else {
156: itemsInThisSection = items.size();
157: }
158:
159: this .questionSize += itemsInThisSection;
160: for (int j = 0; j < itemsInThisSection; j++) {
161: ItemContentsBean item = (ItemContentsBean) items.get(j);
162: if (item.getItemData().getScore() != null) {
163: this .totalScore += item.getItemData().getScore()
164: .floatValue();
165: }
166: }
167: }
168: if (randomPartCount > 0) {
169: setHasRandomDrawPart(true);
170: } else {
171: setHasRandomDrawPart(false);
172: }
173: }
174:
175: public float getTotalScore() {
176: return this .totalScore;
177: }
178:
179: public String getNewQuestionTypeId() {
180: return this .newQuestionTypeId;
181: }
182:
183: public void setNewQuestionTypeId(String newQuestionTypeId) {
184: this .newQuestionTypeId = newQuestionTypeId;
185: }
186:
187: public SelectItem[] getItemTypes() {
188: // return list of TypeD
189: TypeService service = new TypeService();
190: List list = service.getFacadeItemTypes();
191: SelectItem[] itemTypes = new SelectItem[list.size()];
192: for (int i = 0; i < list.size(); i++) {
193: TypeIfc t = (TypeIfc) list.get(i);
194: itemTypes[i] = new SelectItem(t.getTypeId().toString(), t
195: .getKeyword());
196: }
197: return itemTypes;
198: }
199:
200: /**
201: * This set a list of SelectItem (sectionId, title) for selection box
202: * @param list
203: */
204: public void setSectionList(ArrayList list) {
205: //this.assessmentTemplateIter = new AssessmentTemplateIteratorFacade(list);
206: this .sectionList = new ArrayList();
207: try {
208: for (int i = 0; i < list.size(); i++) {
209: SectionDataIfc f = (SectionDataIfc) list.get(i);
210: // sorry, cannot do f.getAssessmentTemplateId() 'cos such call requires
211: // "data" which we do not have in this case. The template list parsed
212: // to this method contains merely assesmentBaseId (in this case is the templateId)
213: // & title (see constructor AssessmentTemplateFacade(id, title))
214: this .sectionList.add(new SelectItem(f.getSectionId()
215: .toString(), f.getTitle()));
216: if (i == 0) {
217: this .firstSectionId = f.getSectionId().toString();
218: }
219: }
220: } catch (Exception e) {
221: log.warn(e.getMessage());
222: }
223: }
224:
225: public ArrayList getSectionList() {
226: return sectionList;
227: }
228:
229: public String getFirstSectionId() {
230: return firstSectionId;
231: }
232:
233: /**
234: * @param string the title
235: */
236: public void setFirstSectionId(String firstSectionId) {
237: this .firstSectionId = firstSectionId;
238: }
239:
240: public ArrayList getOtherSectionList() {
241: return otherSectionList;
242: }
243:
244: public void setOtherSectionList(ArrayList list) {
245: this .otherSectionList = list; // list contains javax.faces.model.SelectItem
246: }
247:
248: public boolean getHasRandomDrawPart() {
249: return this .hasRandomDrawPart;
250: }
251:
252: public void setHasRandomDrawPart(boolean param) {
253: this.hasRandomDrawPart = param;
254: }
255:
256: }
|