001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/facade/AssessmentFacade.java $
003: * $Id: AssessmentFacade.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.facade;
021:
022: import java.util.ArrayList;
023: import java.util.Collections;
024: import java.util.Date;
025: import java.util.HashSet;
026: import java.util.Iterator;
027: import java.util.List;
028: import java.util.Set;
029:
030: import org.osid.assessment.AssessmentException;
031: import org.sakaiproject.tool.assessment.data.dao.assessment.AssessmentData;
032: import org.sakaiproject.tool.assessment.data.dao.assessment.SectionData;
033: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
034: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentAttachmentIfc;
035: import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionDataIfc;
036:
037: /**
038: * <p>Title: </p>
039: * <p>Description: </p>
040: * <p>Copyright: Copyright (c) 2004</p>
041: * <p>Company: </p>
042: * @author not attributable
043: * @version 1.0
044: */
045:
046: public class AssessmentFacade extends AssessmentBaseFacade implements
047: java.io.Serializable, AssessmentIfc {
048: private static final long serialVersionUID = 7526471155622776147L;
049: private AssessmentIfc data;
050: private Long assessmentTemplateId;
051: private Long assessmentId;
052: private Set sectionSet;
053: private Set assessmentAttachmentSet;
054:
055: public AssessmentFacade() {
056: //super();
057: this .data = new AssessmentData();
058: try {
059: // assessment(org.osid.assessment.Assessment) is a protected properties
060: // in AssessmentBaseFacade
061: assessment.updateData(this .data);
062: } catch (AssessmentException ex) {
063: throw new DataFacadeException(ex.getMessage());
064: }
065: }
066:
067: /**
068: * IMPORTANT: this constructor do not have "data", this constructor is
069: * merely used for holding assessmentBaseId (which is the assessmentId), Title
070: * & lastModifiedDate for displaying purpose.
071: * This constructor does not persist data (which it has none) to DB
072: * @param id
073: * @param title
074: * @param lastModifiedDate
075: */
076: public AssessmentFacade(Long id, String title, Date lastModifiedDate) {
077: // in the case of template assessmentBaseId is the assessmentTemplateId
078: super .setAssessmentBaseId(id);
079: super .setTitle(title);
080: super .setLastModifiedDate(lastModifiedDate);
081: }
082:
083: public AssessmentFacade(AssessmentIfc data, Boolean loadSection) {
084: try {
085: // assessment(org.osid.assessment.Assessment) is a protected properties
086: // in AssessmentBaseFacade
087: //assessment.updateData(this.data);
088: super .setData(data);
089: } catch (AssessmentException ex) {
090: throw new DataFacadeException(ex.getMessage());
091: }
092: // super class does not have assessmentTemplateId nor sectionSet and assessmentAttachmentSet,
093: // so we need to set it here
094: this .assessmentTemplateId = data.getAssessmentTemplateId();
095: this .assessmentAttachmentSet = data
096: .getAssessmentAttachmentSet();
097: // sectionSet is a set of SectionFacade
098: this .sectionSet = new HashSet();
099:
100: // check if we need to load section
101: if (loadSection.equals(Boolean.TRUE)) {
102: Set dataSet = data.getSectionSet();
103: Iterator iter = dataSet.iterator();
104: while (iter.hasNext()) {
105: SectionData s = (SectionData) iter.next();
106: this .sectionSet.add(new SectionFacade(s));
107: }
108: }
109: }
110:
111: public AssessmentFacade(AssessmentIfc data) {
112: try {
113: // assessment(org.osid.assessment.Assessment) is a protected properties
114: // in AssessmentBaseFacade
115: //assessment.updateData(this.data);
116: super .setData(data);
117: } catch (AssessmentException ex) {
118: throw new DataFacadeException(ex.getMessage());
119: }
120: // super class does not have assessmentTemplateId nor sectionSet and AssessmentAttachemntSet,
121: // so we need to set it here
122: this .assessmentTemplateId = data.getAssessmentTemplateId();
123: this .assessmentAttachmentSet = data
124: .getAssessmentAttachmentSet();
125: // sectionSet is a set of SectionFacade
126: this .sectionSet = new HashSet();
127: Set dataSet = data.getSectionSet();
128: Iterator iter = dataSet.iterator();
129: while (iter.hasNext()) {
130: SectionData s = (SectionData) iter.next();
131: this .sectionSet.add(new SectionFacade(s));
132: }
133: }
134:
135: public Long getAssessmentId() {
136: try {
137: this .data = (AssessmentIfc) assessment.getData();
138: } catch (AssessmentException ex) {
139: throw new DataFacadeException(ex.getMessage());
140: }
141: return this .data.getAssessmentId();
142: }
143:
144: public Long getAssessmentTemplateId() {
145: try {
146: this .data = (AssessmentIfc) assessment.getData();
147: } catch (AssessmentException ex) {
148: ex.printStackTrace();
149: throw new DataFacadeException(ex.getMessage());
150: }
151: return this .data.getAssessmentTemplateId();
152: }
153:
154: public void setAssessmentTemplateId(Long assessmentTemplateId) {
155: this .assessmentTemplateId = assessmentTemplateId;
156: this .data.setAssessmentTemplateId(assessmentTemplateId);
157: }
158:
159: public Set getSectionSet() {
160: try {
161: this .data = (AssessmentIfc) assessment.getData();
162: } catch (AssessmentException ex) {
163: throw new DataFacadeException(ex.getMessage());
164: }
165: this .sectionSet = new HashSet();
166: Set dataSet = this .data.getSectionSet();
167: Iterator iter = dataSet.iterator();
168: while (iter.hasNext()) {
169: SectionData s = (SectionData) iter.next();
170: this .sectionSet.add(new SectionFacade(s));
171: }
172: return this .sectionSet;
173: }
174:
175: // sectionSet must be a set of SectionFacade
176: public void setSectionSet(Set sectionSet) {
177: this .sectionSet = sectionSet;
178: HashSet set = new HashSet();
179: Iterator iter = sectionSet.iterator();
180: while (iter.hasNext()) {
181: SectionFacade sf = (SectionFacade) iter.next();
182: set.add(sf.getData());
183: }
184: this .data.setSectionSet(set);
185: }
186:
187: public ArrayList getSectionArray() {
188: ArrayList list = new ArrayList();
189: if (this .sectionSet != null) {
190: Iterator iter = this .sectionSet.iterator();
191: while (iter.hasNext()) {
192: SectionFacade s = (SectionFacade) iter.next();
193: list.add(s);
194: }
195: }
196: return list;
197: }
198:
199: public ArrayList getSectionArraySorted() {
200: ArrayList list = getSectionArray();
201: Collections.sort(list);
202: return list;
203: }
204:
205: public SectionDataIfc getSection(Long sequence) {
206: ArrayList list = getSectionArraySorted();
207: if (list == null)
208: return null;
209: else
210: return (SectionDataIfc) list.get(sequence.intValue() - 1);
211: }
212:
213: public SectionDataIfc getDefaultSection() {
214: ArrayList list = getSectionArraySorted();
215: if (list == null)
216: return null;
217: else
218: return (SectionDataIfc) list.get(0);
219: }
220:
221: public Set getAssessmentAttachmentSet() throws DataFacadeException {
222: try {
223: this .data = (AssessmentIfc) assessment.getData();
224: this .assessmentAttachmentSet = data
225: .getAssessmentAttachmentSet();
226: } catch (AssessmentException ex) {
227: throw new DataFacadeException(ex.getMessage());
228: }
229: return assessmentAttachmentSet;
230: }
231:
232: public void setAssessmentAttachmentSet(Set assessmentAttachmentSet) {
233: this .assessmentAttachmentSet = assessmentAttachmentSet;
234: this .data.setAssessmentAttachmentSet(assessmentAttachmentSet);
235: }
236:
237: public List getAssessmentAttachmentList() {
238: ArrayList list = new ArrayList();
239: if (assessmentAttachmentSet != null) {
240: Iterator iter = assessmentAttachmentSet.iterator();
241: while (iter.hasNext()) {
242: AssessmentAttachmentIfc a = (AssessmentAttachmentIfc) iter
243: .next();
244: list.add(a);
245: }
246: }
247: return list;
248: }
249:
250: }
|