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/PublishedAssessmentBeanie.java $
003: * $Id: PublishedAssessmentBeanie.java 11181 2006-06-26 08:13:58Z lydial@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:
026: import javax.faces.model.SelectItem;
027:
028: import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionDataIfc;
029: import org.sakaiproject.tool.assessment.data.ifc.shared.TypeIfc;
030: import org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacade;
031: import org.sakaiproject.tool.assessment.services.shared.TypeService;
032: import org.sakaiproject.tool.assessment.ui.bean.delivery.ItemContentsBean;
033: import org.sakaiproject.tool.assessment.ui.bean.delivery.SectionContentsBean;
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: /**
038: * <p>Description: Backing bean for Published Assessment</p>
039: *
040: *
041: */
042: public class PublishedAssessmentBeanie implements Serializable {
043: private static Log log = LogFactory
044: .getLog(PublishedAssessmentBeanie.class);
045:
046: /** Use serialVersionUID for interoperability. */
047: private final static long serialVersionUID = -630950053380808339L;
048: private PublishedAssessmentFacade assessment;
049: private String assessmentId;
050: private String title;
051: // ArrayList of SectionContentsBean
052: private ArrayList sections = new ArrayList();
053: private ArrayList partNumbers = new ArrayList();
054: private int questionSize = 0;
055: private float totalScore = 0;
056: private String newQuestionTypeId;
057:
058: /*
059: * Creates a new AssessmentBean object.
060: */
061: public PublishedAssessmentBeanie() {
062: }
063:
064: public PublishedAssessmentFacade getAssessment() {
065: return assessment;
066: }
067:
068: public void setAssessment(PublishedAssessmentFacade assessment) {
069: try {
070: this .assessment = assessment;
071: this .assessmentId = assessment.getAssessmentId().toString();
072: this .title = assessment.getTitle();
073:
074: // work out the question side & total point
075: this .sections = new ArrayList();
076: ArrayList sectionArray = assessment.getSectionArraySorted();
077: for (int i = 0; i < sectionArray.size(); i++) {
078: SectionDataIfc section = (SectionDataIfc) sectionArray
079: .get(i);
080: SectionContentsBean sectionBean = new SectionContentsBean(
081: section);
082: this .sections.add(sectionBean);
083: }
084: setPartNumbers();
085: setQuestionSizeAndTotalScore();
086: } catch (Exception ex) {
087: log.warn(ex.getMessage());
088: }
089: }
090:
091: // properties from Assessment
092: public String getAssessmentId() {
093: return this .assessmentId;
094: }
095:
096: public void setAssessmentId(String assessmentId) {
097: this .assessmentId = assessmentId;
098: }
099:
100: public String getTitle() {
101: return this .title;
102: }
103:
104: public void setTitle(String title) {
105: this .title = title;
106: }
107:
108: public ArrayList getSections() {
109: return sections;
110: }
111:
112: public void setSections(ArrayList sections) {
113: this .sections = sections;
114: }
115:
116: public ArrayList getPartNumbers() {
117: return partNumbers;
118: }
119:
120: public void setPartNumbers() {
121: this .partNumbers = new ArrayList();
122: for (int i = 1; i <= this .sections.size(); i++) {
123: this .partNumbers.add(new SelectItem(i + ""));
124: }
125: }
126:
127: public int getQuestionSize() {
128: return this .questionSize;
129: }
130:
131: public void setQuestionSizeAndTotalScore() {
132: this .questionSize = 0;
133: this .totalScore = 0;
134: for (int i = 0; i < this .sections.size(); i++) {
135: SectionContentsBean sectionBean = (SectionContentsBean) sections
136: .get(i);
137: ArrayList items = sectionBean.getItemContents();
138: this .questionSize += items.size();
139: for (int j = 0; j < items.size(); j++) {
140: ItemContentsBean item = (ItemContentsBean) items.get(j);
141: if (item.getItemData().getScore() != null) {
142: this .totalScore += item.getItemData().getScore()
143: .floatValue();
144: }
145: }
146: }
147: }
148:
149: public float getTotalScore() {
150: return this .totalScore;
151: }
152:
153: public String getNewQuestionTypeId() {
154: return this .newQuestionTypeId;
155: }
156:
157: public void setNewQuestionTypeId(String newQuestionTypeId) {
158: this .newQuestionTypeId = newQuestionTypeId;
159: }
160:
161: public SelectItem[] getItemTypes() {
162: // return list of TypeD
163: TypeService service = new TypeService();
164: List list = service.getFacadeItemTypes();
165: SelectItem[] itemTypes = new SelectItem[list.size()];
166: for (int i = 0; i < list.size(); i++) {
167: TypeIfc t = (TypeIfc) list.get(i);
168: itemTypes[i] = new SelectItem(t.getTypeId().toString(), t
169: .getKeyword());
170: }
171: return itemTypes;
172: }
173:
174: }
|