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/SectionData.java $
003: * $Id: SectionData.java 14341 2006-09-11 19:57:30Z 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 java.io.IOException;
023: import java.util.ArrayList;
024: import java.util.Collections;
025: import java.util.Date;
026: import java.util.HashMap;
027: import java.util.HashSet;
028: import java.util.Iterator;
029: import java.util.Set;
030: import java.util.List;
031:
032: import org.apache.log4j.Category;
033: import org.sakaiproject.tool.assessment.data.dao.shared.TypeD;
034: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
035: import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
036: import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionAttachmentIfc;
037: import org.sakaiproject.tool.assessment.data.ifc.assessment.SectionDataIfc;
038: import org.sakaiproject.tool.assessment.data.ifc.shared.TypeIfc;
039:
040: //import org.sakaiproject.tool.assessment.facade.TypeFacadeQueriesAPI;
041: //import org.sakaiproject.tool.assessment.services.PersistenceService;
042:
043: public class SectionData implements java.io.Serializable,
044: SectionDataIfc, Comparable {
045: static Category errorLogger = Category.getInstance("errorLogger");
046:
047: private static final long serialVersionUID = 7526471155622776147L;
048: public static final Integer ACTIVE_STATUS = new Integer(1);
049: public static final Integer INACTIVE_STATUS = new Integer(0);
050: public static final Integer ANY_STATUS = new Integer(2);
051:
052: private Long id;
053: private Long assessmentId;
054: private AssessmentIfc assessment;
055: private Integer duration;
056: private Integer sequence;
057: private String title;
058: private String description;
059: private Long typeId;
060: private Integer status;
061: private String createdBy;
062: private Date createdDate;
063: private String lastModifiedBy;
064: private Date lastModifiedDate;
065: private Set itemSet;
066: private Set sectionMetaDataSet;
067: private HashMap sectionMetaDataMap;
068: private Set sectionAttachmentSet;
069:
070: public SectionData() {
071: }
072:
073: public SectionData(Integer duration, Integer sequence,
074: String title, String description, Long typeId,
075: Integer status, String createdBy, Date createdDate,
076: String lastModifiedBy, Date lastModifiedDate) {
077: this .duration = duration;
078: this .sequence = sequence;
079: this .title = title;
080: this .description = description;
081: this .typeId = typeId;
082: this .status = status;
083: this .createdBy = createdBy;
084: this .createdDate = createdDate;
085: this .lastModifiedBy = lastModifiedBy;
086: this .lastModifiedDate = lastModifiedDate;
087: }
088:
089: public Long getSectionId() {
090: return this .id;
091: }
092:
093: public void setSectionId(Long id) {
094: this .id = id;
095: }
096:
097: public Long getAssessmentId() {
098: return this .assessmentId;
099: }
100:
101: public void setAssessmentId(Long assessmentId) {
102: this .assessmentId = assessmentId;
103: }
104:
105: public void setAssessment(AssessmentIfc assessment) {
106: this .assessment = assessment;
107: }
108:
109: public AssessmentIfc getAssessment() {
110: return assessment;
111: }
112:
113: /**
114: public AssessmentDataIfc getAssessment()
115: {
116: return (AssessmentDataIfc)assessment;
117: }
118: */
119: public Integer getDuration() {
120: return this .duration;
121: }
122:
123: public void setDuration(Integer duration) {
124: this .duration = duration;
125: }
126:
127: public Integer getSequence() {
128: return this .sequence;
129: }
130:
131: public void setSequence(Integer sequence) {
132: this .sequence = sequence;
133: }
134:
135: public String getTitle() {
136: return this .title;
137: }
138:
139: public void setTitle(String title) {
140: this .title = title;
141: }
142:
143: public String getDescription() {
144: return this .description;
145: }
146:
147: public void setDescription(String description) {
148: this .description = description;
149: }
150:
151: public Long getTypeId() {
152: return this .typeId;
153: }
154:
155: public void setTypeId(Long typeId) {
156: this .typeId = typeId;
157: }
158:
159: public Integer getStatus() {
160: return this .status;
161: }
162:
163: public void setStatus(Integer status) {
164: this .status = status;
165: }
166:
167: public String getCreatedBy() {
168: return this .createdBy;
169: }
170:
171: public void setCreatedBy(String createdBy) {
172: this .createdBy = createdBy;
173: }
174:
175: public Date getCreatedDate() {
176: return this .createdDate;
177: }
178:
179: public void setCreatedDate(Date createdDate) {
180: this .createdDate = createdDate;
181: }
182:
183: public String getLastModifiedBy() {
184: return this .lastModifiedBy;
185: }
186:
187: public void setLastModifiedBy(String lastModifiedBy) {
188: this .lastModifiedBy = lastModifiedBy;
189: }
190:
191: public Date getLastModifiedDate() {
192: return this .lastModifiedDate;
193: }
194:
195: public void setLastModifiedDate(Date lastModifiedDate) {
196: this .lastModifiedDate = lastModifiedDate;
197: }
198:
199: public Set getItemSet() {
200: return itemSet;
201: }
202:
203: public void setItemSet(Set itemSet) {
204: this .itemSet = itemSet;
205: }
206:
207: public Set getSectionMetaDataSet() {
208: return sectionMetaDataSet;
209: }
210:
211: public void setSectionMetaDataSet(Set param) {
212: this .sectionMetaDataSet = param;
213: this .sectionMetaDataMap = getSectionMetaDataMap(sectionMetaDataSet);
214: }
215:
216: public HashMap getSectionMetaDataMap(Set metaDataSet) {
217: HashMap metaDataMap = new HashMap();
218: if (metaDataSet != null) {
219: for (Iterator i = metaDataSet.iterator(); i.hasNext();) {
220: SectionMetaData metaData = (SectionMetaData) i.next();
221: metaDataMap.put(metaData.getLabel(), metaData
222: .getEntry());
223: }
224: }
225: return metaDataMap;
226: }
227:
228: public void addSectionMetaData(String label, String entry) {
229: if (this .sectionMetaDataSet == null) {
230: setSectionMetaDataSet(new HashSet());
231: this .sectionMetaDataMap = new HashMap();
232: }
233: this .sectionMetaDataMap.put(label, entry);
234: this .sectionMetaDataSet.add(new SectionMetaData(this , label,
235: entry));
236: }
237:
238: public String getSectionMetaDataByLabel(String label) {
239: return (String) this .sectionMetaDataMap.get(label);
240: }
241:
242: public ArrayList getItemArray() {
243: ArrayList list = new ArrayList();
244: Iterator iter = itemSet.iterator();
245: while (iter.hasNext()) {
246: list.add(iter.next());
247: }
248: return list;
249: }
250:
251: public ArrayList getItemArraySortedForGrading() {
252: // placeholder for now, need to have it 'cuz they are in ifc.
253: ArrayList list = getItemArray();
254: Collections.sort(list);
255: return list;
256: }
257:
258: public ArrayList getItemArraySorted() {
259: ArrayList list = getItemArray();
260: Collections.sort(list);
261: return list;
262: }
263:
264: public ArrayList getItemArraySortedWithRandom(long seed) {
265: // placeholder for now, need to have it 'cuz they are in ifc.
266: ArrayList list = getItemArray();
267: Collections.sort(list);
268: return list;
269: }
270:
271: public void addItem(ItemDataIfc item) {
272: if (itemSet == null)
273: itemSet = new HashSet();
274: itemSet.add((ItemData) item);
275: }
276:
277: private void writeObject(java.io.ObjectOutputStream out)
278: throws IOException {
279: out.defaultWriteObject();
280: }
281:
282: private void readObject(java.io.ObjectInputStream in)
283: throws IOException, ClassNotFoundException {
284: in.defaultReadObject();
285: }
286:
287: public TypeIfc getType() {
288: /*
289: TypeFacadeQueriesAPI typeFacadeQueries = PersistenceService.getInstance().getTypeFacadeQueries();
290: TypeIfc type = typeFacadeQueries.getTypeFacadeById(this.typeId);
291: return new TypeD(type.getAuthority(), type.getDomain(),
292: type.getKeyword(), type.getDescription());
293: */
294: return null;
295: }
296:
297: public int compareTo(Object o) {
298: SectionData a = (SectionData) o;
299: return sequence.compareTo(a.sequence);
300: }
301:
302: public Set getSectionAttachmentSet() {
303: return sectionAttachmentSet;
304: }
305:
306: public void setSectionAttachmentSet(Set sectionAttachmentSet) {
307: this .sectionAttachmentSet = sectionAttachmentSet;
308: }
309:
310: public List getSectionAttachmentList() {
311: ArrayList list = new ArrayList();
312: if (sectionAttachmentSet != null) {
313: Iterator iter = sectionAttachmentSet.iterator();
314: while (iter.hasNext()) {
315: SectionAttachmentIfc a = (SectionAttachmentIfc) iter
316: .next();
317: list.add(a);
318: }
319: }
320: return list;
321: }
322:
323: }
|