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/PublishedAssessmentData.java $
003: * $Id: PublishedAssessmentData.java 16922 2006-10-09 21:56:09Z ktsao@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.List;
028: import java.util.Iterator;
029: import java.util.Set;
030:
031: import org.apache.log4j.Category;
032:
033: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentAccessControlIfc;
034: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentAttachmentIfc;
035: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentFeedbackIfc; //import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
036: import org.sakaiproject.tool.assessment.data.ifc.assessment.EvaluationModelIfc;
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.AgentFacade;
041: //import org.sakaiproject.tool.assessment.facade.TypeFacadeQueriesAPI;
042: //import org.sakaiproject.tool.assessment.services.PersistenceService;
043: //import org.sakaiproject.tool.assessment.services.assessment.PublishedAssessmentService;
044:
045: public class PublishedAssessmentData
046: implements
047: java.io.Serializable,
048: org.sakaiproject.tool.assessment.data.ifc.assessment.PublishedAssessmentIfc {
049: static Category errorLogger = Category.getInstance("errorLogger");
050:
051: private static final long serialVersionUID = 7526471155622776147L;
052:
053: private Long assessmentId; // this is the core assessment Id
054: private Long assessmentBaseId; // this is the published AssessmentId
055: //// private AssessmentIfc assessment;
056: private String title;
057: private String description;
058: private String comments;
059: private Long typeId;
060: private Integer instructorNotification;
061: private Integer testeeNotification;
062: private Integer multipartAllowed;
063: private Integer status;
064: private String createdBy;
065: private Date createdDate;
066: private String lastModifiedBy;
067: private Date lastModifiedDate;
068: private AssessmentAccessControlIfc assessmentAccessControl;
069: private EvaluationModelIfc evaluationModel;
070: private AssessmentFeedbackIfc assessmentFeedback;
071: private Set assessmentMetaDataSet;
072: private Set securedIPAddressSet;
073: private HashMap assessmentMetaDataMap = new HashMap();
074: private Set sectionSet;
075: // the following properties is added for the "Convenient Constructor"
076: private String releaseTo;
077: private Date startDate;
078: private Date dueDate;
079: private Date retractDate;
080: private int submissionSize;
081: private Integer lateHandling;
082: private Boolean unlimitedSubmissions;
083: private Integer submissionsAllowed;
084: private Integer feedbackDelivery;
085: private Integer feedbackAuthoring;
086: private Date feedbackDate;
087: //private String ownerSiteName;
088: private Set assessmentAttachmentSet;
089:
090: public PublishedAssessmentData() {
091: }
092:
093: /**
094: * "Convenient Constructor"
095: * This is a cheap object created for holding just the Id, title. This object is merely used for validation of assessmentTitleIsUniqueForAll. It is not used
096: * for persistence.
097: */
098: public PublishedAssessmentData(Long id, String title,
099: Date lastModifiedDate) {
100: this .assessmentBaseId = id;
101: this .title = title;
102: this .lastModifiedDate = lastModifiedDate;
103: }
104:
105: /**
106: * "Convenient Constructor"
107: * This is a cheap object created for holding just the Id, title &
108: * delivery dates. This object is merely used for display. It is not used
109: * for persistence.
110: */
111: public PublishedAssessmentData(Long id, String title,
112: String releaseTo, Date startDate, Date dueDate,
113: Date retractDate) {
114: this .assessmentBaseId = id;
115: this .title = title;
116: this .releaseTo = releaseTo;
117: this .startDate = startDate;
118: this .dueDate = dueDate;
119: this .retractDate = retractDate;
120: }
121:
122: /**
123: * Someone forgot to check this in, so I'm adding it.
124: */
125: public PublishedAssessmentData(Long id, String title,
126: String releaseTo, Date startDate, Date dueDate,
127: Date retractDate, Integer lateHandling,
128: Boolean unlimitedSubmissions, Integer submissionsAllowed) {
129: this .assessmentBaseId = id;
130: this .title = title;
131: this .releaseTo = releaseTo;
132: this .startDate = startDate;
133: this .dueDate = dueDate;
134: this .retractDate = retractDate;
135: this .lateHandling = lateHandling;
136: if (unlimitedSubmissions != null)
137: this .unlimitedSubmissions = unlimitedSubmissions;
138: else
139: this .unlimitedSubmissions = Boolean.TRUE;
140: if (submissionsAllowed == null)
141: this .submissionsAllowed = new Integer(0);
142: else
143: this .submissionsAllowed = submissionsAllowed;
144: }
145:
146: public PublishedAssessmentData(Long id, String title,
147: PublishedAccessControl assessmentAccessControl) {
148: this .assessmentBaseId = id;
149: this .title = title;
150: this .assessmentAccessControl = assessmentAccessControl;
151: }
152:
153: public PublishedAssessmentData(Long id, String title,
154: String releaseTo, Date startDate, Date dueDate,
155: Date retractDate, Date feedbackDate,
156: Integer feedbackDelivery, Integer feedbackAuthoring,
157: Integer lateHandling, Boolean unlimitedSubmissions,
158: Integer submissionsAllowed) {
159: this .assessmentBaseId = id;
160: this .title = title;
161: this .releaseTo = releaseTo;
162: this .startDate = startDate;
163: this .dueDate = dueDate;
164: this .retractDate = retractDate;
165: this .feedbackDelivery = feedbackDelivery; //=publishedFeedback.feedbackDelivery
166: this .feedbackAuthoring = feedbackAuthoring; //=publishedFeedback.feedbackAuthoring
167: this .feedbackDate = feedbackDate;
168: this .lateHandling = lateHandling;
169: if (unlimitedSubmissions != null)
170: this .unlimitedSubmissions = unlimitedSubmissions;
171: else
172: this .unlimitedSubmissions = Boolean.TRUE;
173: if (submissionsAllowed == null)
174: this .submissionsAllowed = new Integer(0);
175: else
176: this .submissionsAllowed = submissionsAllowed;
177: }
178:
179: public PublishedAssessmentData(Long id, int submissionSize) {
180: this .assessmentBaseId = id;
181: this .submissionSize = submissionSize;
182: }
183:
184: public PublishedAssessmentData(String title, String description,
185: String comments, Long typeId,
186: Integer instructorNotification, Integer testeeNotification,
187: Integer multipartAllowed, Integer status, String createdBy,
188: Date createdDate, String lastModifiedBy,
189: Date lastModifiedDate) {
190: this .title = title;
191: this .description = description;
192: this .comments = comments;
193: this .typeId = typeId;
194: this .instructorNotification = instructorNotification;
195: this .testeeNotification = testeeNotification;
196: this .multipartAllowed = multipartAllowed;
197: this .status = status;
198: this .createdBy = createdBy;
199: this .createdDate = createdDate;
200: this .lastModifiedBy = lastModifiedBy;
201: this .lastModifiedDate = lastModifiedDate;
202: }
203:
204: public Long getAssessmentId() {
205: return this .assessmentId;
206: }
207:
208: public void setAssessmentId(Long assessmentId) {
209: this .assessmentId = assessmentId;
210: }
211:
212: public Long getPublishedAssessmentId() {
213: return this .assessmentBaseId;
214: }
215:
216: public void setPublishedAssessmentId(Long assessmentBaseId) {
217: this .assessmentBaseId = assessmentBaseId;
218: }
219:
220: /* public AssessmentIfc getAssessment() {
221: return assessment;
222: }
223:
224: public void setAssessment(AssessmentIfc assessment) {
225: this.assessment = assessment;
226: }
227: */
228: public String getTitle() {
229: return this .title;
230: }
231:
232: public void setTitle(String title) {
233: this .title = title;
234: }
235:
236: public String getDescription() {
237: return this .description;
238: }
239:
240: public void setDescription(String description) {
241: this .description = description;
242: }
243:
244: public String getComments() {
245: return this .comments;
246: }
247:
248: public void setComments(String comments) {
249: this .comments = comments;
250: }
251:
252: public Integer getInstructorNotification() {
253: return this .instructorNotification;
254: }
255:
256: public void setInstructorNotification(Integer instructorNotification) {
257: this .instructorNotification = instructorNotification;
258: }
259:
260: public Integer getTesteeNotification() {
261: return this .testeeNotification;
262: }
263:
264: public void setTesteeNotification(Integer testeeNotification) {
265: this .testeeNotification = testeeNotification;
266: }
267:
268: public Integer getMultipartAllowed() {
269: return this .multipartAllowed;
270: }
271:
272: public void setMultipartAllowed(Integer multipartAllowed) {
273: this .multipartAllowed = multipartAllowed;
274: }
275:
276: public Long getTypeId() {
277: return this .typeId;
278: }
279:
280: public void setTypeId(Long typeId) {
281: this .typeId = typeId;
282: }
283:
284: public Integer getStatus() {
285: return this .status;
286: }
287:
288: public void setStatus(Integer status) {
289: this .status = status;
290: }
291:
292: public String getCreatedBy() {
293: return this .createdBy;
294: }
295:
296: public void setCreatedBy(String createdBy) {
297: this .createdBy = createdBy;
298: }
299:
300: public Date getCreatedDate() {
301: return this .createdDate;
302: }
303:
304: public void setCreatedDate(Date createdDate) {
305: this .createdDate = createdDate;
306: }
307:
308: public String getLastModifiedBy() {
309: return this .lastModifiedBy;
310: }
311:
312: public void setLastModifiedBy(String lastModifiedBy) {
313: this .lastModifiedBy = lastModifiedBy;
314: }
315:
316: public Date getLastModifiedDate() {
317: return this .lastModifiedDate;
318: }
319:
320: public void setLastModifiedDate(Date lastModifiedDate) {
321: this .lastModifiedDate = lastModifiedDate;
322: }
323:
324: public AssessmentAccessControlIfc getAssessmentAccessControl() {
325: return this .assessmentAccessControl;
326: }
327:
328: public void setAssessmentAccessControl(
329: AssessmentAccessControlIfc assessmentAccessControl) {
330: this .assessmentAccessControl = assessmentAccessControl;
331: }
332:
333: public EvaluationModelIfc getEvaluationModel() {
334: return this .evaluationModel;
335: }
336:
337: public void setEvaluationModel(EvaluationModelIfc evaluationModel) {
338: this .evaluationModel = evaluationModel;
339: }
340:
341: public AssessmentFeedbackIfc getAssessmentFeedback() {
342: return this .assessmentFeedback;
343: }
344:
345: public void setAssessmentFeedback(
346: AssessmentFeedbackIfc assessmentFeedback) {
347: this .assessmentFeedback = assessmentFeedback;
348: }
349:
350: public Set getAssessmentMetaDataSet() {
351: return assessmentMetaDataSet;
352: }
353:
354: public void setAssessmentMetaDataSet(Set assessmentMetaDataSet) {
355: this .assessmentMetaDataSet = assessmentMetaDataSet;
356: this .assessmentMetaDataMap = getAssessmentMetaDataMap(assessmentMetaDataSet);
357: }
358:
359: public Set getSecuredIPAddressSet() {
360: return securedIPAddressSet;
361: }
362:
363: public void setSecuredIPAddressSet(Set securedIPAddressSet) {
364: this .securedIPAddressSet = securedIPAddressSet;
365: }
366:
367: public HashMap getAssessmentMetaDataMap(Set assessmentMetaDataSet) {
368: HashMap assessmentMetaDataMap = new HashMap();
369: if (assessmentMetaDataSet != null) {
370: for (Iterator i = assessmentMetaDataSet.iterator(); i
371: .hasNext();) {
372: PublishedMetaData assessmentMetaData = (PublishedMetaData) i
373: .next();
374: assessmentMetaDataMap.put(
375: assessmentMetaData.getLabel(),
376: assessmentMetaData.getEntry());
377: }
378: }
379: return assessmentMetaDataMap;
380: }
381:
382: public HashMap getAssessmentMetaDataMap() {
383: HashMap assessmentMetaDataMap = new HashMap();
384: if (this .assessmentMetaDataSet != null) {
385: for (Iterator i = this .assessmentMetaDataSet.iterator(); i
386: .hasNext();) {
387: PublishedMetaData assessmentMetaData = (PublishedMetaData) i
388: .next();
389: assessmentMetaDataMap.put(
390: assessmentMetaData.getLabel(),
391: assessmentMetaData.getEntry());
392: }
393: }
394: return assessmentMetaDataMap;
395: }
396:
397: public String getAssessmentMetaDataByLabel(String label) {
398: return (String) this .assessmentMetaDataMap.get(label);
399: }
400:
401: public void addAssessmentMetaData(String label, String entry) {
402: if (this .assessmentMetaDataMap.get(label) != null) {
403: // just update
404: Iterator iter = this .assessmentMetaDataSet.iterator();
405: while (iter.hasNext()) {
406: AssessmentMetaData metadata = (AssessmentMetaData) iter
407: .next();
408: if (metadata.getLabel().equals(label)) {
409: metadata.setEntry(entry);
410: }
411: }
412: } else { // add
413: AssessmentMetaData metadata = null;
414: if (!("").equals(entry.trim())) {
415: metadata = new AssessmentMetaData(this , label, entry);
416: this .assessmentMetaDataSet.add(metadata);
417: }
418: setAssessmentMetaDataSet(this .assessmentMetaDataSet);
419: }
420: }
421:
422: public void updateAssessmentMetaData(String label, String entry) {
423: addAssessmentMetaData(label, entry);
424: }
425:
426: public Set getSectionSet() {
427: return sectionSet;
428: }
429:
430: public void setSectionSet(Set sectionSet) {
431: this .sectionSet = sectionSet;
432: }
433:
434: private void writeObject(java.io.ObjectOutputStream out)
435: throws IOException {
436: out.defaultWriteObject();
437: }
438:
439: private void readObject(java.io.ObjectInputStream in)
440: throws IOException, ClassNotFoundException {
441: in.defaultReadObject();
442: }
443:
444: public Long getAssessmentBaseId() {
445: return getAssessmentId();
446: }
447:
448: public void setAssessmentBaseId(Long assessmentBaseId) {
449: setAssessmentId(assessmentBaseId);
450: }
451:
452: public Boolean getIsTemplate() {
453: return Boolean.FALSE;
454: }
455:
456: public void setIsTemplate(Boolean isTemplate) {
457: }
458:
459: // axed it, published assessment don't have parent
460: public Long getParentId() {
461: return null;
462: }
463:
464: public void setParentId(Long parentId) {
465: }
466:
467: public Long getAssessmentTemplateId() {
468: return null;
469: }
470:
471: public void setAssessmentTemplateId(Long assessmentTemplateId) {
472: }
473:
474: public TypeIfc getType() {
475: /*
476: TypeFacadeQueriesAPI typeFacadeQueries = PersistenceService.getInstance().
477: getTypeFacadeQueries();
478: TypeIfc type = typeFacadeQueries.getTypeFacadeById(this.typeId);
479: TypeD typeD = new TypeD(type.getAuthority(), type.getDomain(),
480: type.getKeyword(), type.getDescription());
481: typeD.setTypeId(this.typeId);
482: return typeD;
483: */
484: return null;
485: }
486:
487: public String getReleaseTo() {
488: return this .releaseTo;
489: }
490:
491: public Date getStartDate() {
492: return this .startDate;
493: }
494:
495: public Date getDueDate() {
496: return this .dueDate;
497: }
498:
499: public Date getRetractDate() {
500: return this .retractDate;
501: }
502:
503: public int getSubmissionSize() {
504: return this .submissionSize;
505: }
506:
507: public ArrayList getSectionArray() {
508: ArrayList list = new ArrayList();
509: Iterator iter = sectionSet.iterator();
510: while (iter.hasNext()) {
511: list.add(iter.next());
512: }
513: return list;
514: }
515:
516: public ArrayList getSectionArraySorted() {
517: ArrayList list = getSectionArray();
518: Collections.sort(list);
519: return list;
520: }
521:
522: public SectionDataIfc getSection(Long sequence) {
523: ArrayList list = getSectionArraySorted();
524: if (list == null) {
525: return null;
526: } else {
527: return (SectionDataIfc) list.get(sequence.intValue() - 1);
528: }
529:
530: }
531:
532: public SectionDataIfc getDefaultSection() {
533: ArrayList list = getSectionArraySorted();
534: if (list == null) {
535: return null;
536: } else {
537: return (SectionDataIfc) list.get(0);
538: }
539: }
540:
541: public Integer getLateHandling() {
542: return lateHandling;
543: }
544:
545: public Boolean getUnlimitedSubmissions() {
546: return this .unlimitedSubmissions;
547: }
548:
549: public Integer getSubmissionsAllowed() {
550: return submissionsAllowed;
551: }
552:
553: public Integer getFeedbackDelivery() {
554: return feedbackDelivery;
555: }
556:
557: public Integer getFeedbackAuthoring() {
558: return feedbackAuthoring;
559: }
560:
561: public Date getFeedbackDate() {
562: return this .feedbackDate;
563: }
564:
565: public Float getTotalScore() {
566: float total = 0;
567: Iterator iter = this .sectionSet.iterator();
568: while (iter.hasNext()) {
569: PublishedSectionData s = (PublishedSectionData) iter.next();
570: ArrayList list = s.getItemArray();
571: Iterator iter2 = null;
572: if ((s
573: .getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE) != null)
574: && (s
575: .getSectionMetaDataByLabel(SectionDataIfc.AUTHOR_TYPE)
576: .equals(SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL
577: .toString()))) {
578: ArrayList randomsample = new ArrayList();
579: Integer numberToBeDrawn = null;
580: if (s
581: .getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN) != null) {
582: numberToBeDrawn = new Integer(
583: s
584: .getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN));
585: }
586:
587: int samplesize = numberToBeDrawn.intValue();
588: for (int i = 0; i < samplesize; i++) {
589: randomsample.add(list.get(i));
590: }
591: iter2 = randomsample.iterator();
592: } else {
593: iter2 = list.iterator();
594: }
595:
596: while (iter2.hasNext()) {
597: PublishedItemData item = (PublishedItemData) iter2
598: .next();
599: total = total + item.getScore().floatValue();
600: }
601: }
602: return new Float(total);
603: }
604:
605: public Set getAssessmentAttachmentSet() {
606: return assessmentAttachmentSet;
607: }
608:
609: public void setAssessmentAttachmentSet(Set assessmentAttachmentSet) {
610: this .assessmentAttachmentSet = assessmentAttachmentSet;
611: }
612:
613: public List getAssessmentAttachmentList() {
614: ArrayList list = new ArrayList();
615: if (assessmentAttachmentSet != null) {
616: Iterator iter = assessmentAttachmentSet.iterator();
617: while (iter.hasNext()) {
618: AssessmentAttachmentIfc a = (AssessmentAttachmentIfc) iter
619: .next();
620: list.add(a);
621: }
622: }
623: return list;
624: }
625:
626: }
|