Skip to content

Commit

Permalink
SAM-3224 - Events from timer thread should have a session that matche…
Browse files Browse the repository at this point in the history
…s the user who submitted (sakaiproject#4510)
  • Loading branch information
jonespm authored Jun 21, 2017
1 parent 0c9d99e commit ade4fa5
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.event.api.UsageSession;
import org.sakaiproject.event.cover.EventTrackingService;
import org.sakaiproject.event.cover.NotificationService;
import org.sakaiproject.event.cover.UsageSessionService;
import org.sakaiproject.samigo.util.SamigoConstants;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.assessment.data.dao.assessment.EventLogData;
Expand All @@ -42,6 +46,7 @@
import org.sakaiproject.tool.assessment.services.GradingService;
import org.sakaiproject.tool.assessment.ui.model.delivery.TimedAssessmentGradingModel;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.user.cover.UserDirectoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -68,6 +73,8 @@ public TimedAssessmentRunnable(long id){
public void run(){
try {
TimedAssessmentGradingModel timedAG = this.queue.get(this.timedAGId);
String serverName = ServerConfigurationService.getServerName();

boolean submitted = timedAG.getSubmittedForGrade();
long bufferedExpirationTime = timedAG.getBufferedExpirationDate().getTime(); // in millesec
long currentTime = (new Date()).getTime(); // in millisec
Expand All @@ -92,11 +99,20 @@ public void run(){
log.info("SAMIGO_TIMED_ASSESSMENT:SUBMIT:FORGRADE ID:" + this.timedAGId +
" userId:" + ag.getAgentId());


// Create a new session here so this is associated in the database with the correct userid
UsageSession usageSession = UsageSessionService.startSession(ag.getAgentId(), serverName, "TimedAssessmentRunnable");

// Change user id for the Gradebook update (if required) and so the event is associated with the correct userid
Session s = SessionManager.getCurrentSession();
if (s != null) {
s.setUserId(ag.getAgentId());
Session session = SessionManager.getCurrentSession();
if (session == null) {
session = SessionManager.startSession();
}

session.setUserId(ag.getAgentId());
session.setUserEid(UserDirectoryService.getUserEid(ag.getAgentId()));


ag.setForGrade(Boolean.TRUE);
ag.setTimeElapsed(timedAG.getTimeLimit());
ag.setStatus(AssessmentGradingData.SUBMITTED); // this will change status 0 -> 1
Expand Down Expand Up @@ -130,7 +146,7 @@ public void run(){
String siteId = publishedAssessmentService.getPublishedAssessmentOwner(ag.getPublishedAssessmentId());

EventTrackingService.post(EventTrackingService.newEvent(SamigoConstants.EVENT_ASSESSMENT_SUBMITTED_THREAD,
"siteId=" + AgentFacade.getCurrentSiteId() + ", submissionId=" + ag.getAssessmentGradingId(),
"siteId=" + siteId + ", submissionId=" + ag.getAssessmentGradingId(),
siteId,
true,
NotificationService.NOTI_REQUIRED));
Expand Down Expand Up @@ -162,6 +178,8 @@ public void run(){
" userEid:" + eventLogData.getUserEid() +
" siteId:" + siteId +
" submissionId:" + ag.getAssessmentGradingId());
//Invalidate the session
UsageSessionService.logout();
}
}
} else { //submitted, remove from queue if transaction buffer is also reached
Expand Down

0 comments on commit ade4fa5

Please sign in to comment.