Skip to content

Commit

Permalink
SAK-31948 Don't order anonymous assignments by sortname. (sakaiprojec…
Browse files Browse the repository at this point in the history
…t#3599)

* SAK-31948 Sort exported sheet by anonymous ID.

When exporting a spreadsheet of an assignment, sort by the anonymous ID rather then a user’s sort name.

* SAK-31948 Sort Anonymous Grade Report by Anon ID.

When showing the Grade report and it’s anonymous always sort based on the anonymous ID rather than the user’s surname.
  • Loading branch information
buckett authored Nov 28, 2016
1 parent e06c80b commit 46754fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.sakaiproject.assignment.impl.sort.AnonymousSubmissionComparator;
import org.sakaiproject.assignment.impl.sort.AssignmentSubmissionComparator;
import org.sakaiproject.assignment.impl.sort.UserComparator;
import org.slf4j.Logger;
Expand Down Expand Up @@ -4966,8 +4967,15 @@ else if (token.contains("searchFilterOnly"))
if (allowGradeSubmission(aRef))
{
AssignmentContent content = a.getContent();
zipSubmissions(aRef, a.getTitle(), content.getTypeOfGradeString(), content.getTypeOfSubmission(),
new SortedIterator(submissions.iterator(), new AssignmentSubmissionComparator()), out, exceptionMessage, withStudentSubmissionText, withStudentSubmissionAttachment, withGradeFile, withFeedbackText, withFeedbackComment, withFeedbackAttachment, withoutFolders,gradeFileFormat, includeNotSubmitted);
SortedIterator sortedIterator;
if (assignmentUsesAnonymousGrading(a))
{
sortedIterator = new SortedIterator(submissions.iterator(), new AnonymousSubmissionComparator());
} else {
sortedIterator = new SortedIterator(submissions.iterator(), new AssignmentSubmissionComparator());
}
zipSubmissions(aRef, a.getTitle(), content.getTypeOfGradeString(), content.getTypeOfSubmission(),
sortedIterator, out, exceptionMessage, withStudentSubmissionText, withStudentSubmissionAttachment, withGradeFile, withFeedbackText, withFeedbackComment, withFeedbackAttachment, withoutFolders,gradeFileFormat, includeNotSubmitted);

if (exceptionMessage.length() > 0)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.sakaiproject.assignment.impl.sort;

import org.sakaiproject.assignment.api.AssignmentSubmission;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.cover.SiteService;
import org.sakaiproject.user.api.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.Collator;
import java.text.ParseException;
import java.text.RuleBasedCollator;
import java.util.Comparator;

/**
* Sorts assignment submissions by the submission's anonymous ID.
*/
public class AnonymousSubmissionComparator implements Comparator<AssignmentSubmission> {

private static Logger M_log = LoggerFactory.getLogger(AnonymousSubmissionComparator.class);

private Collator collator;

public AnonymousSubmissionComparator() {
try {
collator = new RuleBasedCollator(((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
} catch (ParseException e) {
// error with init RuleBasedCollator with rules
// use the default Collator
collator = Collator.getInstance();
M_log.warn(this + " AssignmentComparator cannot init RuleBasedCollator. Will use the default Collator instead. " + e);
}
}

@Override
public int compare(AssignmentSubmission a1, AssignmentSubmission a2) {
int result;
String name1 = a1.getAnonymousSubmissionId();
String name2 = a2.getAnonymousSubmissionId();
result = collator.compare(name1, name2);
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11124,6 +11124,7 @@ public void doReport_submissions(RunData data)

state.setAttribute(STATE_MODE, MODE_INSTRUCTOR_REPORT_SUBMISSIONS);
state.setAttribute(SORTED_BY, SORTED_SUBMISSION_BY_LASTNAME);
state.setAttribute(SORTED_SUBMISSION_BY, SORTED_GRADE_SUBMISSION_BY_LASTNAME);
state.setAttribute(SORTED_ASC, Boolean.TRUE.toString());

} // doReport_submissions
Expand Down Expand Up @@ -14270,6 +14271,7 @@ protected int sizeResources(SessionState state)
String contextString = (String) state.getAttribute(STATE_CONTEXT_STRING);
// all the resources for paging
List returnResources = new ArrayList();
boolean hasOneAnon = false;

boolean allowAddAssignment = AssignmentService.allowAddAssignment(contextString);
if (MODE_LIST_ASSIGNMENTS.equals(mode))
Expand Down Expand Up @@ -14369,6 +14371,8 @@ else if (MODE_INSTRUCTOR_REPORT_SUBMISSIONS.equals(mode))
_dupUsers = usersInMultipleGroups(a, true);
}
}
// Have we found an anonymous assignment in the list.
hasOneAnon = hasOneAnon || AssignmentService.getInstance().assignmentUsesAnonymousGrading(a);
//get the list of users which are allowed to grade this assignment
List allowGradeAssignmentUsers = AssignmentService.allowGradeAssignmentUsers(a.getReference());
String deleted = a.getProperties().getProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);
Expand Down Expand Up @@ -14589,6 +14593,10 @@ else if (MODE_INSTRUCTOR_REPORT_SUBMISSIONS.equals(mode) && (sort == null || sor
// ignore, continue with default sort
}
}
else if (hasOneAnon)
{
ac.setAnon(true);
}

try
{
Expand Down

0 comments on commit 46754fe

Please sign in to comment.