Skip to content

Commit

Permalink
SAM-1074 Adding Delete test submission attempt feature for samigo, we…
Browse files Browse the repository at this point in the history
… used this feature at Texas State Univ from 2006 till now for sakai10.4
  • Loading branch information
yuanhuaqu committed Apr 1, 2016
1 parent 8accd2e commit b057d3d
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**********************************************************************************
*
*
***********************************************************************************
*
* Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
*
* Licensed under the Educational Community License, Version 1.0 (the"License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ecl1.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************************/



package org.sakaiproject.tool.assessment.ui.listener.evaluation;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;

import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.tool.assessment.data.dao.grading.AssessmentGradingData;
import org.sakaiproject.tool.assessment.services.GradingService;
import org.sakaiproject.tool.assessment.services.shared.MediaService;
import org.sakaiproject.tool.assessment.ui.bean.delivery.DeliveryBean;
import org.sakaiproject.tool.assessment.ui.bean.evaluation.AgentResults;
import org.sakaiproject.tool.assessment.ui.bean.evaluation.TotalScoresBean;
import org.sakaiproject.tool.assessment.ui.listener.delivery.DeliveryActionListener;
import org.sakaiproject.tool.assessment.ui.listener.evaluation.util.EvaluationListenerUtil;
import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
import org.sakaiproject.tool.assessment.util.BeanSort;
import org.sakaiproject.tool.assessment.data.dao.grading.MediaData;


/**
* <p>
* This handles the deletion of student submission on the Score page.
* </p>
* <p>Description: Action Listener for deletion of student's submission on the Score page</p>
* <p>Organization: Sakai Project</p>
* @author Texas State University
*/

public class GrantSubmissionListener
implements ActionListener
{
private static Log log = LogFactory.getLog(StudentScoreListener.class);
private static EvaluationListenerUtil util;
private static BeanSort bs;

/**
* Increases submissions remaining by 1.
* Gives students an additional attempt.
*
* @param ae ActionEvent
* @throws AbortProcessingException
*/
public void processAction(ActionEvent ae) throws
AbortProcessingException
{
log.debug("GrantSubmission LISTENER.");

TotalScoresBean totalScores = (TotalScoresBean) ContextUtil.lookupBean("totalScores");
String deletedStudentId = null;
// delivery.setSubmissionsRemaining(delivery.getSubmissionsRemaining() + 1);

String gradingIdParam = ContextUtil.lookupParam("gradingData");
Long gradingId = new Long(gradingIdParam);
String publishedAssessmentId = ContextUtil.lookupParam("publishedId");

GradingService gradingService = new GradingService();
MediaService mediaService = new MediaService();

List itemGradingIds = gradingService.getItemGradingIds(gradingId);

for(int i = 0; i < itemGradingIds.size(); i++){
Long itemGradingId = (Long) itemGradingIds.get(i);
//for each grading item, check if question is file upload type
if(gradingService.getTypeId(itemGradingId).intValue() == 6){
//if is file upload type, check if there is file uploaded
ArrayList mediaDatas = gradingService.getMediaArray(itemGradingId.toString());
for(int j = 0; j < mediaDatas.size(); j++) {
//if there are file(s) uploaded, delete them
String mediaId = ((MediaData)mediaDatas.get(j)).getMediaId().toString();
mediaService.remove(mediaId);
}
}
}

AssessmentGradingData ag = (AssessmentGradingData) gradingService.load(gradingIdParam);
Collection collectionOfOne = new ArrayList();
collectionOfOne.add(ag);
gradingService.deleteAll(collectionOfOne);

Collection agentList = totalScores.getAgents();
for(Iterator i = agentList.iterator(); i.hasNext();) {
AgentResults a = (AgentResults)i.next();
if (a.getAssessmentGradingId().equals(gradingId)) {
deletedStudentId = a.getAgentId();
i.remove();
}
}

ArrayList gradingList = totalScores.getAssessmentGradingList();
//Get the list of submission for this student
ArrayList deletedStudentGradingList = new ArrayList();
for(int i = 0; i < gradingList.size(); i++){
if (((AssessmentGradingData)gradingList.get(i)).getAgentId().equals(deletedStudentId)) {
deletedStudentGradingList.add(gradingList.get(i));
}
}
//Need to do a check to see if this is the only submission for that student
if(deletedStudentGradingList.size() == 1){
//if deleted the last one submission of this student, reset the grading data to have no grade and notify gradebook
gradingList.clear();
gradingList.add(deletedStudentGradingList.get(0));
((AssessmentGradingData)gradingList.get(0)).setFinalScore(null);
}
else {
for(int i = 0;i < gradingList.size();i++) {
if (((AssessmentGradingData)gradingList.get(i)).getAssessmentGradingId().equals(gradingId)) {
gradingList.remove(i);
}
}
}

totalScores.setAssessmentGradingList(gradingList);
totalScores.setAgents(agentList);

gradingService.notifyDeleteToGradebook(gradingList, totalScores.getPublishedAssessment(), deletedStudentId);

}
}
38 changes: 38 additions & 0 deletions samigo/samigo-app/src/webapp/jsf/evaluation/totalScores.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ function disableIt()
}
}
}
$(document).ready(function(){
$("a.sam-scoretable-deleteattempt").each(function(){
this.existingOnclick = this.onclick;
this.onclick = null;
$(this).click(function(){
if ( confirm("Are you sure you want to delete this attempt?") ) {
this.existingOnclick();
} else {
return false;
}
});
});
});
</script>
</head>
<body onload="disableIt();<%= request.getAttribute("html.body.onload") %>">
Expand Down Expand Up @@ -286,6 +300,30 @@ function disableIt()
<!-- note that we will have to hook up with the back end to get N at a time -->
<div class="table-responsive">
<h:dataTable id="totalScoreTable" value="#{totalScores.agents}" var="description" styleClass="table table-striped table-bordered" columnClasses="textTable">

<!-- Add Submission Attempt Deleter-->
<h:column rendered="true">
<f:facet name="header">
<h:outputText value="Delete" rendered="true" />
</f:facet>
<h:panelGroup> <span class="tier2">
<h:outputText value="<a name=\"" escape="false" />
<h:outputText value="#{description.lastInitial}" />
<h:outputText value="\"></a>" escape="false" />

<h:commandLink styleClass="sam-scoretable-deleteattempt" title="delete attempt" action="totalScores" immediate="true" rendered="true" >
<h:outputText value="X" rendered="#{description.submittedDate!=null && description.assessmentGradingId ne '-1'}" />
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.evaluation.GrantSubmissionListener" />
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.evaluation.ResetTotalScoreListener" />
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.evaluation.TotalScoreListener" />
<f:actionListener type="org.sakaiproject.tool.assessment.ui.listener.author.AuthorActionListener" />
<f:param name="studentid" value="#{description.idString}" />
<f:param name="publishedIdd" value="#{totalScores.publishedId}" />
<f:param name="gradingData" value="#{description.assessmentGradingId}" />
</h:commandLink>
</span>
</h:panelGroup>
</h:column>

<!-- NAME/SUBMISSION ID -->
<h:column rendered="#{totalScores.anonymous eq 'false' && totalScores.sortType ne 'lastName'}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/**********************************************************************************
* $URL$
* $Id$
Expand Down Expand Up @@ -260,6 +261,9 @@ public Object doInHibernate(Session session) throws HibernateException, SQLExcep
return list;
}
else {
if(list.isEmpty()) {
return new ArrayList();
}
// only take highest or latest
Iterator items = list.iterator();
ArrayList newlist = new ArrayList();
Expand Down Expand Up @@ -1978,6 +1982,18 @@ public Object doInHibernate(Session session) throws HibernateException, SQLExcep
return getHibernateTemplate().executeFind(hcb);
}

public List getItemGradingIds(final Long assessmentGradingId){
final HibernateCallback hcb = new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query q = session.createQuery("select i.itemGradingId from "+
" ItemGradingData i where i.assessmentGradingId=?");
q.setLong(0, assessmentGradingId.longValue());
return q.list();
};
};
return getHibernateTemplate().executeFind(hcb);
}

public HashSet getItemSet(final Long publishedAssessmentId, final Long sectionId) {
HashSet itemSet = new HashSet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public AssessmentGradingData getHighestSubmittedAssessmentGrading(

public List getPublishedItemIds(Long assessmentGradingId);

public List getItemGradingIds(Long assessmentGradingId);

public HashSet getItemSet(Long publishedAssessmentId, Long sectionId);

public Long getTypeId(Long itemGradingId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**********************************************************************************
* $URL$
* $Id$
* $URL: https://source.sakaiproject.org/svn/sam/tags/sakai-10.4/samigo-services/src/java/org/sakaiproject/tool/assessment/integration/helper/integrated/GradebookServiceHelperImpl.java $
* $Id: GradebookServiceHelperImpl.java 127473 2013-07-21 00:04:12Z [email protected] $
***********************************************************************************
*
* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009 The Sakai Foundation
Expand Down Expand Up @@ -259,22 +259,36 @@ public void updateExternalAssessmentScore(AssessmentGradingData ag,
//log.info("GradebookService instance=" + g);
PublishedAssessmentService pubService = new PublishedAssessmentService();
GradingService gradingService = new GradingService();
PublishedAssessmentIfc pub = (PublishedAssessmentIfc) gradingService.getPublishedAssessmentByAssessmentGradingId(ag.getAssessmentGradingId().toString());

//Following line seems just for the need of getting publishedAssessmentId
//use ag.getPublishedAssessmentId() instead of pub.getPublishedAssessmentId() to
//get publishedAssessmentId
//comment out following 3 lines since it returns null for not submitted students which we
//need not save to assessmentgrading table but will need to notify gradebook only

/* PublishedAssessmentIfc pub = (PublishedAssessmentIfc) gradingService.getPublishedAssessmentByAssessmentGradingId(ag.getAssessmentGradingId().toString());
String gradebookUId = pubService.getPublishedAssessmentOwner(
pub.getPublishedAssessmentId());
pub.getPublishedAssessmentId());*/
String gradebookUId = pubService.getPublishedAssessmentOwner(
ag.getPublishedAssessmentId());
if (gradebookUId == null)
{
return;
}

//SAM-1562 We need to round the double score and covert to a double -DH
double fScore = MathUtils.round(ag.getFinalScore(), 2);
Double score = Double.valueOf(fScore).doubleValue();
log.info("rounded: " + ag.getFinalScore() + " to: " + score.toString() );
//Will pass to null value when last submission is deleted
String points = null;
if(ag.getFinalScore() != null) {
//SAM-1562 We need to round the double score and covert to a double -DH
double fScore = MathUtils.round(ag.getFinalScore(), 2);
Double score = Double.valueOf(fScore).doubleValue();
points = score.toString();
log.info("rounded: " + ag.getFinalScore() + " to: " + score.toString() );
}
g.updateExternalAssessmentScore(gradebookUId,
ag.getPublishedAssessmentId().toString(),
ag.getAgentId(), score.toString());
ag.getAgentId(), points);
if (testErrorHandling){
throw new Exception("Encountered an error in update ExternalAssessmentScore.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,50 @@ public void saveTotalScores(ArrayList gdataList, PublishedAssessmentIfc pub)
}
}

/**
* This method is added to update student's total score to gradebook
* after submit attept is deleted in assessment.
* @param gdataList a list of AssessmentGradingData
* @param pub PublishedAssessment object
* @param studentId
*/

public void notifyDeleteToGradebook(ArrayList gdataList, PublishedAssessmentIfc pub, String studentId){
try {
AssessmentGradingData gdata = null;
if (gdataList.size()>0) {
gdata = (AssessmentGradingData) gdataList.get(0);
}
else {
return;
}

Integer scoringType = getScoringType(pub);
ArrayList fullList = getAssessmentGradingsByScoringType(
scoringType, gdata.getPublishedAssessmentId());

ArrayList l = new ArrayList();
for (int i=0; i< fullList.size(); i++){
AssessmentGradingData ag = (AssessmentGradingData)fullList.get(i);
if (ag.getAgentId().equals(studentId))
l.add(ag);
}

//When there is no more submission left for this student, update
//this student's grade on gradebook as null(the initial state).
if(l.size() == 0)
l.add(gdata);

notifyGradebook(l, pub);
} catch (GradebookServiceException ge) {
ge.printStackTrace();
throw ge;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}

}

private ArrayList getListForGradebookNotification(
ArrayList newList, ArrayList oldList){
Expand Down Expand Up @@ -1513,8 +1557,8 @@ public void notifyGradebook(AssessmentGradingData data, PublishedAssessmentIfc p
}

// change the final score back to the original score since it may set to average score.
// data.getFinalScore() != originalFinalScore
if(!(MathUtils.equalsIncludingNaN(data.getFinalScore(), originalFinalScore, 0.0001))) {
// if we're deleting the last submission, the score might be null bugid 5440
if(originalFinalScore != null && data.getFinalScore() != null && !(MathUtils.equalsIncludingNaN(data.getFinalScore(), originalFinalScore, 0.0001))) {
data.setFinalScore(originalFinalScore);
}

Expand Down Expand Up @@ -2288,6 +2332,16 @@ public ArrayList getLastItemGradingDataPosition(Long assessmentGradingId, String
return results;
}

public List getItemGradingIds(Long assessmentGradingId) {
List results = null;
try {
results = PersistenceService.getInstance().getAssessmentGradingFacadeQueries().getItemGradingIds(assessmentGradingId);
} catch (Exception e) {
e.printStackTrace();
}
return results;
}

public List getPublishedItemIds(Long assessmentGradingId) {
List results = null;
try {
Expand Down

0 comments on commit b057d3d

Please sign in to comment.