001: /**********************************************************************************
002: * $URL$
003: * $Id$
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.queue.delivery;
021:
022: import org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAssessmentData;
023: import org.sakaiproject.tool.assessment.data.dao.grading.AssessmentGradingData;
024: import org.sakaiproject.tool.assessment.data.ifc.assessment.PublishedAssessmentIfc;
025: import org.sakaiproject.tool.assessment.data.ifc.grading.AssessmentGradingIfc;
026: import org.sakaiproject.tool.assessment.ui.queue.delivery.TimedAssessmentQueue;
027: import org.sakaiproject.tool.assessment.ui.model.delivery.TimedAssessmentGradingModel;
028: import org.sakaiproject.tool.assessment.services.GradingService;
029: import org.sakaiproject.tool.assessment.services.assessment.PublishedAssessmentService;
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import java.util.Date;
033: import java.util.Iterator;
034: import java.util.TimerTask;
035:
036: /**
037: * <p>Title: Samigo</p>
038: * <p>Description: Sakai Assessment Manager</p>
039: * <p>Copyright: Copyright (c) 2004 Sakai Project</p>
040: * <p>Organization: Sakai Project</p>
041: * @version $Id: SubmitTimedAssessmentThread.java 1294 2005-08-19 17:22:35Z esmiley@stanford.edu $
042: */
043:
044: public class SubmitTimedAssessmentThread extends TimerTask {
045:
046: private static Log log = LogFactory
047: .getLog(SubmitTimedAssessmentThread.class);
048:
049: public SubmitTimedAssessmentThread() {
050: }
051:
052: public void run() {
053: // get the queue, go through the queue till it is empty
054: TimedAssessmentQueue queue = TimedAssessmentQueue.getInstance();
055: Iterator iter = queue.iterator();
056: while (iter.hasNext()) {
057: TimedAssessmentGradingModel timedAG = (TimedAssessmentGradingModel) iter
058: .next();
059: log.debug("****** going through timedAG in queue, timedAG"
060: + timedAG);
061: boolean submitted = timedAG.getSubmittedForGrade();
062: long bufferedExpirationTime = timedAG
063: .getBufferedExpirationDate().getTime(); // in millesec
064: long currentTime = (new Date()).getTime(); // in millisec
065:
066: log.debug("****** submitted=" + submitted);
067: log.debug("****** currentTime=" + currentTime);
068: log.debug("****** bufferedExpirationTime="
069: + bufferedExpirationTime);
070: log.debug("****** expired="
071: + (currentTime > bufferedExpirationTime));
072: if (!submitted) {
073: if (currentTime > bufferedExpirationTime) { // time's up, i.e. timeLeft + latency buffer reached
074: timedAG.setSubmittedForGrade(true);
075: // set all the properties right and persist status to DB
076: GradingService service = new GradingService();
077: AssessmentGradingData ag = service.load(timedAG
078: .getAssessmentGradingId().toString());
079: ag.setForGrade(Boolean.TRUE);
080: ag.setTimeElapsed(new Integer(timedAG
081: .getTimeLimit()));
082: ag.setStatus(AssessmentGradingIfc.AUTO_GRADED); // this will change status 0 -> 1
083: ag.setIsLate(islate(ag.getPublishedAssessmentId()));
084: ag.setSubmittedDate(new Date());
085: // SAK-7302, users taking a timed assessment may exit without completing the assessment
086: // set these two scores to 0 instaed of null
087: if (ag.getFinalScore() == null)
088: ag.setFinalScore(new Float("0"));
089: if (ag.getTotalAutoScore() == null)
090: ag.setTotalAutoScore(new Float("0"));
091: service.saveOrUpdateAssessmentGrading(ag);
092: log
093: .debug("**** 4a. time's up, timeLeft+latency buffer reached, saved to DB");
094: }
095: } else { //submitted, remove from queue if transaction buffer is also reached
096: if (currentTime > (bufferedExpirationTime + timedAG
097: .getTransactionBuffer() * 1000)) {
098: queue.remove(timedAG);
099: log.debug("**** 4b. transaction buffer reached");
100: }
101: }
102: }
103: }
104:
105: private Boolean islate(Long publishedId) {
106: PublishedAssessmentService service = new PublishedAssessmentService();
107: PublishedAssessmentData pub = service
108: .getBasicInfoOfPublishedAssessment(publishedId
109: .toString());
110: if (pub.getDueDate() != null
111: && pub.getDueDate().before(new Date()))
112: return Boolean.TRUE;
113: else
114: return Boolean.FALSE;
115: }
116:
117: }
|